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
.polytomous
.PolytomousKeyEditor
;
18 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.operation
.CreateNodeOperation
;
19 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
25 public class CreateNodeHandler
extends AbstractHandler
{
28 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
31 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
33 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
35 if(editor
instanceof PolytomousKeyEditor
){
36 PolytomousKeyEditor keyEditor
= (PolytomousKeyEditor
) editor
;
38 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getActiveMenuSelection(event
);
40 if(selection
.getFirstElement() instanceof PolytomousKeyNode
){
42 String label
= event
.getCommand().getName();
43 IUndoContext undoContext
= EditorUtil
.getUndoContext();
45 PolytomousKeyNode keyNode
= (PolytomousKeyNode
) selection
.getFirstElement();
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.");