import org.eclipse.core.commands.operations.IUndoContext;\r
import org.eclipse.core.commands.operations.UndoContext;\r
import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
import org.eclipse.ui.IEditorInput;\r
import org.eclipse.ui.IEditorPart;\r
import org.eclipse.ui.IEditorSite;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;\r
import eu.etaxonomy.taxeditor.editor.descriptiontree.TaxonDescriptionTreeEditor;\r
+import eu.etaxonomy.taxeditor.editor.name.NameComposite;\r
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;\r
import eu.etaxonomy.taxeditor.model.DataChangeBridge;\r
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;\r
conversation.bind();\r
}\r
\r
+ // do\r
handleDuplicates();\r
\r
+ // check for empty names\r
+ TaxonNameEditor nameEditor = (TaxonNameEditor) getPage(Page.NAME);\r
+ for(NameComposite nameComposite : nameEditor.getNameComposites()){\r
+ if(nameComposite.getName() == null || nameComposite.getName().getTitleCache().equals("")){\r
+ MessageDialog.openWarning(EditorUtil.getShell(), "No Name Specified", "An attempt was made to save a taxon or synonym with " +\r
+ "an empty name. Operation was cancelled.");\r
+ return;\r
+ }\r
+ }\r
+ \r
// commit the conversation and start a new transaction immediately\r
conversation.commit(true);\r
\r
package eu.etaxonomy.taxeditor.editor.handler;
-import java.util.Set;
-
import org.apache.log4j.Logger;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.ui.handlers.HandlerUtil;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.GroupedComposite;
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
-import eu.etaxonomy.taxeditor.editor.Page;
-import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList;
-import eu.etaxonomy.taxeditor.editor.name.NameComposite;
-import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
/**
* @author n.hoffmann
public Object execute(ExecutionEvent event) throws ExecutionException {
MultiPageTaxonEditor editor = EditorUtil.getActiveEditor();
- // check for non zero length of taxon name
-// if(isNameZeroLength(editor.getTaxon().getName())){
-
- // if taxon name has zero length it could mean that we parsed the name but did not save it already.
- // Verify that and show warning otherwise.
- // TODO maybe we want to instantiate a new editor with a TaxonNameBase of null so that we are clear, that it is a new
- // name, because this here feels a little bit kludgy
- for(GroupedComposite composite : ((TaxonNameEditor)editor.getPage(Page.NAME)).getNameComposites()){
- NameComposite nameComposite = (NameComposite) composite;
- if( nameComposite.getParsedName() == null && nameComposite.getName() == null){
- MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "No Name Specified", "An attempt was made to save a taxon with " +
- "an empty name. Operation was cancelled.");
- return null;
- }
-
- }
-
-
-// }
-
-// if (!areRelatedNamesNonZeroLength(editor.getTaxon())) {
-// MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Zero-Length Name", "One of this taxon's relationships " +
-// "has a zero-length name. Operation was cancelled.");
-// logger.trace("Tero length name detected.");
-// return null;
-// }
return EditorUtil.getActivePage().saveEditor(editor, false);
}
-
- /**
- * @param name
- * @return
- */
- private boolean isNameZeroLength(TaxonNameBase<?, ?> name) {
- if (name == null) {
- return true;
- }
- return (name.getFullTitleCache().length() == 0);
- }
-
- /**
- * @param taxon
- * @return
- */
- private boolean areRelatedNamesNonZeroLength(Taxon taxon) {
- for (TaxonBase<?> taxonBase : new IterableSynonymyList(taxon)) {
- if (isNameZeroLength(taxonBase.getName()) ) {
- return false;
- }
- }
- Set<TaxonRelationship> taxonRelations = taxon.getTaxonRelations();
- for (TaxonRelationship relationship : taxonRelations) {
- if (isNameZeroLength(relationship.getToTaxon().getName()) ||
- isNameZeroLength(relationship.getFromTaxon().getName())) {
-
- return false;
- }
- }
- return true;
- }
}