Add remoting operation / handlers for key list editor
[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 import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
28
29 /**
30 * @author cmathew
31 * @date 21 Jul 2015
32 *
33 */
34 public class RemotingCreateChildPolytomousKeyNodeHandler extends RemotingCdmHandler {
35
36 private PolytomousKeyNode parentNode;
37
38 public RemotingCreateChildPolytomousKeyNodeHandler() {
39 super(PolytomousKeyEditorLabels.CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL);
40 }
41 /* (non-Javadoc)
42 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
43 */
44 @Override
45 public IStatus allowOperations(ExecutionEvent event) {
46 IEditorPart editor = HandlerUtil.getActiveEditor(event);
47
48 if (editor instanceof KeyEditor) {
49 IPolytomousKeyEditorPage editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
50 .getActiveEditor();
51
52 if (editorPage instanceof PolytomousKeyListEditor) {
53 PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
54 if(klEditor.getTableItemCount() == 0) {
55 PolytomousKey pk = klEditor.getViewerInputKey();
56 parentNode = pk.getRoot();
57
58 } else {
59 IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
60 if (selection.getFirstElement() instanceof PolytomousKeyNode) {
61 parentNode = (PolytomousKeyNode) selection.getFirstElement();
62 } else {
63 return new Status(IStatus.ERROR,
64 "unknown",
65 PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_CHILD_SELECTED_MESSAGE);
66 }
67 }
68 }
69 }
70 return Status.OK_STATUS;
71 }
72
73 /* (non-Javadoc)
74 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
75 */
76 @Override
77 public AbstractOperation prepareOperation(ExecutionEvent event) {
78 return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode);
79 }
80
81 /* (non-Javadoc)
82 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
83 */
84 @Override
85 public void onComplete() {
86 // TODO Auto-generated method stub
87
88 }
89
90 }