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