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.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;
|
17
|
|
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.operations.AbstractPostOperation;
|
24
|
import eu.etaxonomy.taxeditor.operations.DeleteConceptRelationOperation;
|
25
|
import eu.etaxonomy.taxeditor.operations.DeleteMisapplicationOperation;
|
26
|
import eu.etaxonomy.taxeditor.operations.DeleteSynonymOperation;
|
27
|
|
28
|
/**
|
29
|
* <p>DeleteTaxonBaseHandler class.</p>
|
30
|
*
|
31
|
* @author n.hoffmann
|
32
|
* @created 21.04.2009
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler {
|
36
|
private static final Logger logger = Logger
|
37
|
.getLogger(DeleteTaxonBaseHandler.class);
|
38
|
/* (non-Javadoc)
|
39
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
40
|
*/
|
41
|
/** {@inheritDoc} */
|
42
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
43
|
TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
|
44
|
|
45
|
Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
|
46
|
|
47
|
AbstractPostOperation operation = null;
|
48
|
String commandName = null;
|
49
|
|
50
|
|
51
|
try {
|
52
|
commandName = event.getCommand().getName();
|
53
|
} catch (NotDefinedException e) {
|
54
|
logger.error(e);
|
55
|
throw new RuntimeException(e);
|
56
|
}
|
57
|
|
58
|
|
59
|
// synonym
|
60
|
if(selectedElement instanceof Synonym){
|
61
|
operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Synonym) selectedElement, editor);
|
62
|
}
|
63
|
// misapplication
|
64
|
else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisappliedName()){
|
65
|
operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(), editor
|
66
|
.getTaxon(), (Taxon) selectedElement, editor);
|
67
|
}
|
68
|
// concept relation
|
69
|
else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isRelatedConcept()){
|
70
|
operation = new DeleteConceptRelationOperation(commandName, editor.getUndoContext(), editor.getTaxon(), (Taxon) selectedElement, editor);
|
71
|
}
|
72
|
else {
|
73
|
throw new IllegalArgumentException("Element has to be Synonym, Misapplication or Concept");
|
74
|
}
|
75
|
|
76
|
EditorUtil.executeOperation(operation);
|
77
|
|
78
|
return null;
|
79
|
}
|
80
|
|
81
|
}
|