-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-\r
-package eu.etaxonomy.taxeditor.editor.name.handler;\r
-import org.apache.log4j.Logger;\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.commands.IHandler;\r
-import org.eclipse.core.commands.common.NotDefinedException;\r
-import org.eclipse.core.commands.operations.IUndoableOperation;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.StructuredSelection;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-\r
-import eu.etaxonomy.cdm.model.taxon.Synonym;\r
-import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.taxeditor.editor.EditorUtil;\r
-import eu.etaxonomy.taxeditor.editor.Page;\r
-import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;\r
-import eu.etaxonomy.taxeditor.operations.DeleteConceptRelationOperation;\r
-import eu.etaxonomy.taxeditor.operations.DeleteMisapplicationOperation;\r
-import eu.etaxonomy.taxeditor.operations.DeleteSynonymOperation;\r
-import eu.etaxonomy.taxeditor.propertysheet.name.ConceptPropertySource;\r
-import eu.etaxonomy.taxeditor.propertysheet.name.MisapplicationPropertySource;\r
-import eu.etaxonomy.taxeditor.propertysheet.name.SynonymPropertySource;\r
-import eu.etaxonomy.taxeditor.propertysheet.name.TaxonBasePropertySource;\r
-\r
-/**\r
- * \r
- * @author n.hoffmann\r
- * @created 21.04.2009\r
- * @version 1.0\r
- */\r
-public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler {\r
- private static final Logger logger = Logger\r
- .getLogger(DeleteTaxonBaseHandler.class);\r
- /* (non-Javadoc)\r
- * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)\r
- */\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);\r
- ISelection menuSelection = EditorUtil.getCurrentSelection();\r
- \r
- TaxonBasePropertySource taxonBasePropertySource = (TaxonBasePropertySource) ((StructuredSelection) menuSelection).getFirstElement();\r
- \r
- IUndoableOperation operation = null;\r
- String commandName = null;\r
- \r
- \r
- try {\r
- commandName = event.getCommand().getName();\r
- } catch (NotDefinedException e) {\r
- logger.error(e);\r
- throw new RuntimeException(e);\r
- }\r
- \r
- \r
- // synonym\r
- if(taxonBasePropertySource instanceof SynonymPropertySource){\r
- Synonym synonym = (Synonym) taxonBasePropertySource.getTaxonBase();\r
- operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), synonym, editor);\r
- }\r
- \r
- // misapplication\r
- if(taxonBasePropertySource instanceof MisapplicationPropertySource){\r
- Taxon misapplication = (Taxon) taxonBasePropertySource.getTaxonBase();\r
- operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor\r
- .getTaxon(), misapplication, editor);\r
- }\r
- \r
- // concept relation\r
- if(taxonBasePropertySource instanceof ConceptPropertySource){\r
- Taxon concept = (Taxon) taxonBasePropertySource.getTaxonBase();\r
- operation = new DeleteConceptRelationOperation(commandName, editor.getUndoContext(), editor.getTaxon(), concept, editor);\r
- }\r
- \r
- EditorUtil.executeOperation(operation);\r
- \r
- return null;\r
- }\r
-\r
-}\r
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.editor.name.handler;
+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.core.commands.IHandler;
+import org.eclipse.core.commands.common.NotDefinedException;
+
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.Page;
+import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
+import eu.etaxonomy.taxeditor.editor.name.operation.DeleteMisapplicationOperation;
+import eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation;
+import eu.etaxonomy.taxeditor.editor.view.concept.operation.DeleteConceptRelationOperation;
+import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+
+/**
+ * <p>DeleteTaxonBaseHandler class.</p>
+ *
+ * @author n.hoffmann
+ * @created 21.04.2009
+ * @version 1.0
+ */
+public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler {
+ private static final Logger logger = Logger
+ .getLogger(DeleteTaxonBaseHandler.class);
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ /** {@inheritDoc} */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
+
+ Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
+
+ AbstractPostOperation operation = null;
+ String commandName = null;
+
+
+ try {
+ commandName = event.getCommand().getName();
+ } catch (NotDefinedException e) {
+ logger.error(e);
+ throw new RuntimeException(e);
+ }
+
+
+ // synonym
+ if(selectedElement instanceof Synonym){
+ operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
+ }
+ // misapplication
+ else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
+ operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor
+ .getTaxon(), (Taxon) selectedElement, editor);
+ }
+ else {
+ throw new IllegalArgumentException("Element has to be Synonym, Misapplication or Concept");
+ }
+
+ EditorUtil.executeOperation(operation);
+
+ return null;
+ }
+
+}