X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/2d9a13f7429fcccfc5c35dd176320a240c19ad76..9be11919897c3d782025cf1d443ec53b2d79b9e8:/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java index c33afd20d..adf079813 100644 --- a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java +++ b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java @@ -1,80 +1,77 @@ -/** -* 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 org.eclipse.core.commands.operations.IUndoableOperation; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; - -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.operations.DeleteMisapplicationOperation; -import eu.etaxonomy.taxeditor.operations.DeleteSynonymOperation; - -/** - * - * @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) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME); - - Object selectedElement = EditorUtil.getSelection(event).getFirstElement(); - - IUndoableOperation 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 - if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisappliedName()){ - operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor - .getTaxon(), (Taxon) selectedElement, editor); - } - - // concept relation - // TODO -// if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){ -// operation = new DeleteConceptRelationOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, editor); -// } - - EditorUtil.executeOperation(operation); - - return null; - } - -} +/** +* 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; + +/** + *

DeleteTaxonBaseHandler class.

+ * + * @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; + } + +}