2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
11 import org
.apache
.log4j
.Logger
;
12 import org
.eclipse
.core
.commands
.AbstractHandler
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.IHandler
;
16 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
21 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
22 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
23 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteConceptRelationOperation
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteMisapplicationOperation
;
25 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.DeleteSynonymOperation
;
26 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
29 * <p>DeleteTaxonBaseHandler class.</p>
35 public class DeleteTaxonBaseHandler
extends AbstractHandler
implements IHandler
{
36 private static final Logger logger
= Logger
37 .getLogger(DeleteTaxonBaseHandler
.class);
39 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
42 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
43 TaxonNameEditor editor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
45 Object selectedElement
= EditorUtil
.getSelection(event
).getFirstElement();
47 AbstractPostOperation operation
= null;
48 String commandName
= null;
52 commandName
= event
.getCommand().getName();
53 } catch (NotDefinedException e
) {
55 throw new RuntimeException(e
);
60 if(selectedElement
instanceof Synonym
){
61 operation
= new DeleteSynonymOperation(commandName
, editor
.getUndoContext(), editor
.getTaxon(), (Synonym
) selectedElement
, editor
);
64 else if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isMisapplication()){
65 operation
= new DeleteMisapplicationOperation(commandName
, editor
.getUndoContext(), editor
66 .getTaxon(), (Taxon
) selectedElement
, editor
);
69 else if(selectedElement
instanceof Taxon
&& ((Taxon
) selectedElement
).isRelatedConcept()){
70 operation
= new DeleteConceptRelationOperation(commandName
, editor
.getUndoContext(), editor
.getTaxon(), (Taxon
) selectedElement
, editor
);
73 throw new IllegalArgumentException("Element has to be Synonym, Misapplication or Concept");
76 EditorUtil
.executeOperation(operation
);