2 * Copyright (C) 2016 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
.InsertPolytomousKeyNodeOperation
;
32 public class InsertNewNodeHandler
extends AbstractPolytomousKeyNodeHandler
{
34 private PolytomousKeyNode parentNode
;
37 public InsertNewNodeHandler() {
38 super(PolytomousKeyEditorLabels
.INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL
);
46 public IStatus
allowOperations(ExecutionEvent event
) {
47 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
49 if (editor
instanceof KeyEditor
) {
50 editorPage
= (IPolytomousKeyEditorPage
) ((KeyEditor
) editor
)
53 if (editorPage
instanceof PolytomousKeyListEditor
) {
54 PolytomousKeyListEditor klEditor
= (PolytomousKeyListEditor
) editorPage
;
55 if(klEditor
.getTableItemCount() == 0) {
56 PolytomousKey pk
= klEditor
.getViewerInputKey();
57 parentNode
= pk
.getRoot();
60 IStructuredSelection selection
= (IStructuredSelection
) HandlerUtil
.getCurrentSelection(event
);
61 if (selection
.getFirstElement() instanceof PolytomousKeyNode
) {
62 parentNode
= ((PolytomousKeyNode
) selection
.getFirstElement()).getParent();
64 return new Status(IStatus
.ERROR
,
65 "unknown", //$NON-NLS-1$
66 PolytomousKeyEditorLabels
.NO_KEY_NODE_FOR_INSERT_NODE_SELECTED_MESSAGE
);
71 return Status
.OK_STATUS
;
78 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
79 return new InsertPolytomousKeyNodeOperation(event
.getTrigger(), false, parentNode
, editorPage
);
86 public void onComplete() {
87 // TODO Auto-generated method stub