1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
|
5
|
|
6
|
import org.eclipse.core.commands.AbstractHandler;
|
7
|
import org.eclipse.core.commands.ExecutionEvent;
|
8
|
import org.eclipse.core.commands.ExecutionException;
|
9
|
import org.eclipse.core.commands.common.NotDefinedException;
|
10
|
import org.eclipse.core.commands.operations.IUndoContext;
|
11
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
12
|
import org.eclipse.ui.IEditorPart;
|
13
|
import org.eclipse.ui.handlers.HandlerUtil;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
16
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
17
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditor;
|
18
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.CreateNodeOperation;
|
19
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
20
|
|
21
|
/**
|
22
|
* @author n.hoffmann
|
23
|
*
|
24
|
*/
|
25
|
public class CreateNodeHandler extends AbstractHandler {
|
26
|
|
27
|
/* (non-Javadoc)
|
28
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
29
|
*/
|
30
|
@Override
|
31
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
32
|
|
33
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
34
|
|
35
|
if(editor instanceof PolytomousKeyEditor){
|
36
|
PolytomousKeyEditor keyEditor = (PolytomousKeyEditor) editor;
|
37
|
|
38
|
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
|
39
|
|
40
|
if(selection.getFirstElement() instanceof PolytomousKeyNode){
|
41
|
try {
|
42
|
String label = event.getCommand().getName();
|
43
|
IUndoContext undoContext = EditorUtil.getUndoContext();
|
44
|
|
45
|
PolytomousKeyNode keyNode = (PolytomousKeyNode) selection.getFirstElement();
|
46
|
|
47
|
AbstractPostOperation operation = new CreateNodeOperation(label, undoContext, keyNode, keyEditor);
|
48
|
EditorUtil.executeOperation(operation);
|
49
|
} catch (NotDefinedException e) {
|
50
|
EditorUtil.warn(getClass(), "Command name not set.");
|
51
|
}
|
52
|
|
53
|
}
|
54
|
}
|
55
|
|
56
|
return null;
|
57
|
}
|
58
|
|
59
|
}
|