had to rename the packages to make them compliant with buckminster
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / handler / DeleteTaxonBaseHandler.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.editor.name.handler;
11 import org.eclipse.core.commands.AbstractHandler;
12 import org.eclipse.core.commands.ExecutionEvent;
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.IHandler;
15 import org.eclipse.core.commands.common.NotDefinedException;
16
17 import eu.etaxonomy.cdm.model.taxon.Synonym;
18 import eu.etaxonomy.cdm.model.taxon.Taxon;
19 import eu.etaxonomy.taxeditor.editor.EditorUtil;
20 import eu.etaxonomy.taxeditor.editor.Page;
21 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
22 import eu.etaxonomy.taxeditor.editor.name.operation.DeleteMisapplicationOperation;
23 import eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation;
24 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
25
26 /**
27 * <p>DeleteTaxonBaseHandler class.</p>
28 *
29 * @author n.hoffmann
30 * @created 21.04.2009
31 * @version 1.0
32 */
33 public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler {
34
35 /* (non-Javadoc)
36 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
37 */
38 /** {@inheritDoc} */
39 public Object execute(ExecutionEvent event) throws ExecutionException {
40 TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
41
42 Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
43
44 doExecute(event, editor, selectedElement);
45
46 return null;
47 }
48
49 /**
50 * @param editor
51 * @param selectedElement
52 * @param operation
53 * @param commandName
54 */
55 protected void doExecute(ExecutionEvent event, TaxonNameEditor editor, Object selectedElement) {
56 AbstractPostOperation operation = null;
57 String commandName = null;
58
59 try {
60 commandName = event.getCommand().getName();
61 } catch (NotDefinedException e) {
62 EditorUtil.error(getClass(), e);
63 }
64
65 // synonym
66 if(selectedElement instanceof Synonym){
67 operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
68 }
69 // misapplication
70 else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
71 operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor
72 .getTaxon(), (Taxon) selectedElement, editor);
73 }
74 else {
75 throw new IllegalArgumentException("Element has to be Synonym, Misapplication or Concept");
76 }
77
78 EditorUtil.executeOperation(operation);
79 }
80
81 }