1
|
/**
|
2
|
* Copyright (C) 2017 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.navigation.navigator.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.jface.viewers.TreeSelection;
|
22
|
import org.eclipse.jface.window.Window;
|
23
|
import org.eclipse.jface.wizard.WizardDialog;
|
24
|
import org.eclipse.swt.widgets.Shell;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
28
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
29
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
30
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
|
31
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
|
32
|
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
|
33
|
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationWizard;
|
34
|
|
35
|
/**
|
36
|
* @author k.luther
|
37
|
* @author pplitzner
|
38
|
* @date 10.02.2017
|
39
|
*
|
40
|
*/
|
41
|
public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
|
42
|
|
43
|
private ITaxonTreeNode taxonNode;
|
44
|
private SecundumForSubtreeConfigurator configurator;
|
45
|
|
46
|
public SetSecReferenceForSubtreeHandlerE4() {
|
47
|
super(TaxonNavigatorLabels.CHANGE_SECUNDUM_FOR_SUBTREE);
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public IStatus allowOperations(IStructuredSelection selection,
|
52
|
Shell shell,
|
53
|
MPart activePart,
|
54
|
MHandledMenuItem menuItem) {
|
55
|
// check that only a single taxon tree node has been selected
|
56
|
if(selection.size() > 1) { }
|
57
|
|
58
|
// check for no taxon tree node selected
|
59
|
if(selection.size() == 0) {
|
60
|
return new Status(IStatus.ERROR,
|
61
|
"unknown", //$NON-NLS-1$
|
62
|
TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
|
63
|
}
|
64
|
|
65
|
// check that selected object is a taxon node
|
66
|
Object obj = selection.iterator().next();
|
67
|
if(obj instanceof ITaxonTreeNode) {
|
68
|
if (obj instanceof Classification){
|
69
|
taxonNode = ((Classification)obj).getRootNode();
|
70
|
}else{
|
71
|
taxonNode = (ITaxonTreeNode)obj;
|
72
|
}
|
73
|
} else{
|
74
|
return new Status(IStatus.ERROR,
|
75
|
"unknown", //$NON-NLS-1$
|
76
|
TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
|
77
|
}
|
78
|
|
79
|
|
80
|
// check if corresponding name editor is closed
|
81
|
//FIXME E4 migrate
|
82
|
// boolean editorClosed = NavigatorHandlerUtils.closeObsoleteEditor(event, (TaxonNode) taxonNode);
|
83
|
// if(editorClosed != true) {
|
84
|
// return new Status(IStatus.ERROR,
|
85
|
// "unknown", //$NON-NLS-1$
|
86
|
// TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE);
|
87
|
// }
|
88
|
|
89
|
configurator = new SecundumForSubtreeConfigurator(taxonNode.getUuid());
|
90
|
SetSecundumForSubtreeConfigurationWizard wizard = new SetSecundumForSubtreeConfigurationWizard(configurator);
|
91
|
|
92
|
WizardDialog dialog = new WizardDialog(AbstractUtility.getShell(), wizard);
|
93
|
|
94
|
if (dialog.open() == Window.OK) {
|
95
|
return Status.OK_STATUS;
|
96
|
}else{
|
97
|
return Status.CANCEL_STATUS;
|
98
|
}
|
99
|
}
|
100
|
|
101
|
@CanExecute
|
102
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
103
|
boolean canExecute = false;
|
104
|
canExecute = selection.getFirstElement() instanceof ITaxonTreeNode;
|
105
|
menuItem.setVisible(canExecute);
|
106
|
return canExecute;
|
107
|
}
|
108
|
|
109
|
@Override
|
110
|
public AbstractOperation prepareOperation(IStructuredSelection selection,
|
111
|
Shell shell,
|
112
|
MPart activePart,
|
113
|
MHandledMenuItem menuItem) {
|
114
|
SetSecundumForSubtreeOperation operation =
|
115
|
new SetSecundumForSubtreeOperation(getTrigger(),
|
116
|
false,
|
117
|
taxonNode.getUuid(),
|
118
|
configurator);
|
119
|
|
120
|
return operation;
|
121
|
}
|
122
|
|
123
|
@Override
|
124
|
public void onComplete() {
|
125
|
}
|
126
|
|
127
|
/**
|
128
|
* {@inheritDoc}
|
129
|
*/
|
130
|
@Override
|
131
|
protected Object getTrigger() {
|
132
|
return this;
|
133
|
}
|
134
|
|
135
|
}
|