2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.handler
;
11 import org
.eclipse
.core
.commands
.ExecutionEvent
;
12 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
13 import org
.eclipse
.core
.runtime
.IStatus
;
14 import org
.eclipse
.core
.runtime
.Status
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.ui
.IEditorPart
;
17 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
19 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
20 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
21 import eu
.etaxonomy
.taxeditor
.editor
.key
.KeyEditor
;
22 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.IPolytomousKeyEditorPage
;
23 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyEditorLabels
;
24 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.PolytomousKeyListEditor
;
25 import eu
.etaxonomy
.taxeditor
.editor
.key
.polytomous
.operation
.RemotingCreatePolytomousKeyNodeOperation
;
32 public class RemotingCreateChildPolytomousKeyNodeHandler
extends AbstractPolytomousKeyNodeHandler
{
34 private PolytomousKeyNode parentNode
;
35 IPolytomousKeyEditorPage editorPage
;
38 public RemotingCreateChildPolytomousKeyNodeHandler() {
39 super(PolytomousKeyEditorLabels
.CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL
);
42 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
45 public IStatus
allowOperations(ExecutionEvent event
) {
46 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
48 if (editor
instanceof KeyEditor
) {
49 editorPage
= (IPolytomousKeyEditorPage
) ((KeyEditor
) editor
)
52 if (editorPage
instanceof PolytomousKeyListEditor
) {
53 PolytomousKeyListEditor klEditor
= (PolytomousKeyListEditor
) editorPage
;
54 if(klEditor
.getTableItemCount() == 0) {
55 PolytomousKey pk
= klEditor
.getViewerInputKey();
56 parentNode
= pk
.getRoot();
59 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getCurrentSelection(event
);
60 if (selection
.getFirstElement() instanceof PolytomousKeyNode
) {
61 parentNode
= (PolytomousKeyNode
) selection
.getFirstElement();
63 return new Status(IStatus
.ERROR
,
65 PolytomousKeyEditorLabels
.NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE
);
70 return Status
.OK_STATUS
;
74 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
77 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
78 return new RemotingCreatePolytomousKeyNodeOperation(event
.getTrigger(), false, parentNode
, editorPage
);
82 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
85 public void onComplete() {