4 package eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.handler
;
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
;
15 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
16 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
17 import eu
.etaxonomy
.taxeditor
.editor
.key
.KeyEditor
;
18 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.IPolytomousKeyEditorPage
;
19 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.operation
.CreateNodeOperation
;
20 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
26 public class CreateNodeHandler
extends AbstractHandler
{
32 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.
36 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
38 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
40 if (editor
instanceof KeyEditor
) {
41 IPolytomousKeyEditorPage editorPage
= (IPolytomousKeyEditorPage
) ((KeyEditor
) editor
)
44 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
45 .getActiveMenuSelection(event
);
47 if (selection
.getFirstElement() instanceof PolytomousKeyNode
) {
49 String label
= event
.getCommand().getName();
50 IUndoContext undoContext
= EditorUtil
.getUndoContext();
52 PolytomousKeyNode keyNode
= (PolytomousKeyNode
) selection
55 AbstractPostOperation operation
= new CreateNodeOperation(
56 label
, undoContext
, keyNode
, editorPage
);
57 EditorUtil
.executeOperation(operation
);
58 } catch (NotDefinedException e
) {
59 EditorUtil
.warn(getClass(), "Command name not set.");