Merge branch 'release/4.4.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / key / polytomous / handler / RemotingCreateChildPolytomousKeyNodeHandler.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.editor.key.polytomous.handler;
11
12 import org.eclipse.core.commands.ExecutionEvent;
13 import org.eclipse.core.commands.operations.AbstractOperation;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.handlers.HandlerUtil;
19
20 import eu.etaxonomy.cdm.model.description.PolytomousKey;
21 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
22 import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
23 import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
24 import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
25 import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
26 import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.RemotingCreatePolytomousKeyNodeOperation;
27
28 /**
29 * @author cmathew
30 * @date 21 Jul 2015
31 *
32 */
33 public class RemotingCreateChildPolytomousKeyNodeHandler extends AbstractPolytomousKeyNodeHandler {
34
35 private PolytomousKeyNode parentNode;
36 IPolytomousKeyEditorPage editorPage;
37
38
39 public RemotingCreateChildPolytomousKeyNodeHandler() {
40 super(PolytomousKeyEditorLabels.CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL);
41 }
42 /* (non-Javadoc)
43 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
44 */
45 @Override
46 public IStatus allowOperations(ExecutionEvent event) {
47 IEditorPart editor = HandlerUtil.getActiveEditor(event);
48
49 if (editor instanceof KeyEditor) {
50 editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
51 .getActiveEditor();
52
53 if (editorPage instanceof PolytomousKeyListEditor) {
54 PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
55 if(klEditor.getTableItemCount() == 0) {
56 PolytomousKey pk = klEditor.getViewerInputKey();
57 parentNode = pk.getRoot();
58
59 } else {
60 IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
61 if (selection.getFirstElement() instanceof PolytomousKeyNode) {
62 parentNode = (PolytomousKeyNode) selection.getFirstElement();
63 } else {
64 return new Status(IStatus.ERROR,
65 "unknown",
66 PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE);
67 }
68 }
69 }
70 }
71 return Status.OK_STATUS;
72 }
73
74 /* (non-Javadoc)
75 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
76 */
77 @Override
78 public AbstractOperation prepareOperation(ExecutionEvent event) {
79 return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
80 }
81
82 /* (non-Javadoc)
83 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
84 */
85 @Override
86 public void onComplete() {
87
88
89 }
90
91
92
93 }