1
|
/**
|
2
|
* Copyright (C) 2016 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.key.polytomous.e4.handler;
|
10
|
|
11
|
import javax.inject.Named;
|
12
|
|
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.e4.core.di.annotations.CanExecute;
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
18
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
import org.eclipse.swt.widgets.Shell;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
24
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
25
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
|
26
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4;
|
27
|
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.InsertPolytomousKeyNodeOperation;
|
28
|
|
29
|
/**
|
30
|
* @author k.luther
|
31
|
* @date 17.11.2016
|
32
|
*
|
33
|
*/
|
34
|
public class InsertNewNodeHandlerE4 extends AbstractPolytomousKeyNodeHandlerE4{
|
35
|
|
36
|
private PolytomousKeyNode parentNode ;
|
37
|
|
38
|
|
39
|
public InsertNewNodeHandlerE4() {
|
40
|
super(PolytomousKeyEditorLabels.INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL);
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
public IStatus allowOperations(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
45
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
46
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
47
|
MHandledMenuItem menuItem) {
|
48
|
|
49
|
PolytomousKeyListEditorE4 editor = (PolytomousKeyListEditorE4) activePart.getObject();
|
50
|
|
51
|
if(editor.getTableItemCount() == 0) {
|
52
|
PolytomousKey pk = editor.getViewerInputKey();
|
53
|
parentNode = pk.getRoot();
|
54
|
|
55
|
} else {
|
56
|
if (selection.getFirstElement() instanceof PolytomousKeyNode) {
|
57
|
parentNode = ((PolytomousKeyNode) selection.getFirstElement()).getParent();
|
58
|
} else {
|
59
|
return new Status(IStatus.ERROR,
|
60
|
"unknown", //$NON-NLS-1$
|
61
|
PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_INSERT_NODE_SELECTED_MESSAGE);
|
62
|
}
|
63
|
}
|
64
|
return Status.OK_STATUS;
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public AbstractOperation prepareOperation(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
69
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
70
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
71
|
MHandledMenuItem menuItem) {
|
72
|
return new InsertPolytomousKeyNodeOperation(getTrigger(), false, parentNode, editorPage);
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void onComplete() {
|
77
|
}
|
78
|
|
79
|
@CanExecute
|
80
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
|
81
|
MHandledMenuItem menuItem){
|
82
|
boolean canExecute = false;
|
83
|
canExecute = selection instanceof PolytomousKeyNode;
|
84
|
menuItem.setVisible(canExecute);
|
85
|
return canExecute;
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* {@inheritDoc}
|
90
|
*/
|
91
|
@Override
|
92
|
protected Object getTrigger() {
|
93
|
return this;
|
94
|
}
|
95
|
|
96
|
}
|