1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler;
|
5
|
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.List;
|
8
|
import java.util.UUID;
|
9
|
|
10
|
import javax.inject.Named;
|
11
|
|
12
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
13
|
import org.eclipse.e4.core.di.annotations.Execute;
|
14
|
import org.eclipse.e4.core.di.annotations.Optional;
|
15
|
import org.eclipse.e4.ui.di.UISynchronize;
|
16
|
import org.eclipse.e4.ui.model.application.MApplication;
|
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.model.application.ui.menu.MMenuItem;
|
20
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
21
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
22
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
23
|
import org.eclipse.jface.dialogs.MessageDialog;
|
24
|
import org.eclipse.jface.viewers.ISelection;
|
25
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
26
|
import org.eclipse.swt.widgets.Display;
|
27
|
import org.eclipse.swt.widgets.Shell;
|
28
|
|
29
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
30
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
31
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
32
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
33
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
34
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
35
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
36
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
37
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
38
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
39
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionToOtherTaxonOperation;
|
40
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
41
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
42
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
43
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
44
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
45
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
46
|
|
47
|
/**
|
48
|
*
|
49
|
* @author pplitzner
|
50
|
* @date 15.08.2017
|
51
|
*
|
52
|
*/
|
53
|
public class MoveDescriptionToOtherTaxonHandlerE4 implements IPostOperationEnabled {
|
54
|
|
55
|
private MoveDescriptionToOtherTaxonOperation operation;
|
56
|
|
57
|
private UUID newAcceptedTaxonNodeUuid;
|
58
|
private TaxonNameEditorE4 editor;
|
59
|
private MApplication application;
|
60
|
private EModelService modelService;
|
61
|
private EPartService partService;
|
62
|
|
63
|
@Execute
|
64
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
65
|
@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object selection,
|
66
|
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, MMenuItem menuItem, EPartService partService,
|
67
|
EModelService modelService, MApplication application, UISynchronize sync) {
|
68
|
|
69
|
this.modelService = modelService;
|
70
|
this.application = application;
|
71
|
this.partService = partService;
|
72
|
|
73
|
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
|
74
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(factualDataPart.getSelectionProvidingPart());
|
75
|
if(e4WrappedPart instanceof TaxonNameEditorE4){
|
76
|
editor = (TaxonNameEditorE4) e4WrappedPart;
|
77
|
if (this.editor.isDirty()){
|
78
|
boolean proceed = MessageDialog.openQuestion(null,
|
79
|
Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES, Messages.MoveDescriptionToOtherTaxonHandler_SAVE_CHANGES_MESSAGE);
|
80
|
if (proceed) {
|
81
|
editor.save(AbstractUtility.getMonitor());
|
82
|
} else {
|
83
|
return;
|
84
|
}
|
85
|
|
86
|
}
|
87
|
}
|
88
|
|
89
|
List<TaxonDescription> descriptions = new ArrayList<TaxonDescription>();
|
90
|
TaxonDescription description = null;
|
91
|
if (selection instanceof FeatureNodeContainer){
|
92
|
FeatureNodeContainer container = (FeatureNodeContainer)selection;
|
93
|
description = (TaxonDescription) container.getDescription();
|
94
|
}else if (selection instanceof TaxonDescription){
|
95
|
description = (TaxonDescription)selection;
|
96
|
}
|
97
|
descriptions.add(description);
|
98
|
|
99
|
// Choose the target taxon
|
100
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
101
|
|
102
|
excludeTaxa.add(descriptions.get(0).getTaxon().getUuid());
|
103
|
|
104
|
//get current taxon node
|
105
|
TaxonNode node = null;
|
106
|
Classification classification = null;
|
107
|
if(editor!=null){
|
108
|
node = editor.getEditorInput().getTaxonNode();
|
109
|
classification = node.getClassification();
|
110
|
}
|
111
|
TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(shell,
|
112
|
editor.getConversationHolder(),
|
113
|
Messages.MoveDescriptionToOtherTaxonHandler_CHOOSE_ACC_TAXON,
|
114
|
excludeTaxa,
|
115
|
node,
|
116
|
classification);
|
117
|
|
118
|
if (newAcceptedTaxonNode == null) {
|
119
|
return ;
|
120
|
}
|
121
|
|
122
|
newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();
|
123
|
|
124
|
for(TaxonDescription taxonDescription : descriptions){
|
125
|
operation = new MoveDescriptionToOtherTaxonOperation(menuItem.getLocalizedLabel(),
|
126
|
editor.getUndoContext(),
|
127
|
taxonDescription,
|
128
|
newAcceptedTaxonNode,
|
129
|
this,
|
130
|
editor,
|
131
|
editor.getEditorInput());
|
132
|
AbstractUtility.executeOperation(operation, sync);
|
133
|
}
|
134
|
|
135
|
|
136
|
}
|
137
|
|
138
|
/** {@inheritDoc} */
|
139
|
@Override
|
140
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
141
|
Display.getDefault().asyncExec(new Runnable(){
|
142
|
|
143
|
@Override
|
144
|
public void run() {
|
145
|
//FIXME E4 migrate
|
146
|
// AbstractUtility.close(editor);
|
147
|
//
|
148
|
try {
|
149
|
// MultiPageTaxonEditor possibleOpenEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid);
|
150
|
// if(possibleOpenEditor != null){
|
151
|
// AbstractUtility.close(possibleOpenEditor);
|
152
|
// }
|
153
|
EditorUtil.openTaxonNodeE4(newAcceptedTaxonNodeUuid, modelService, partService, application);
|
154
|
// } catch (PartInitException e) {
|
155
|
// MessagingUtils.error(this.getClass(), e);
|
156
|
// throw new RuntimeException(e);
|
157
|
} catch (Exception e) {
|
158
|
MessagingUtils.warningDialog(Messages.MoveDescriptionToOtherTaxonHandler_CREATE_FAILED, this, e.getMessage());
|
159
|
}
|
160
|
}
|
161
|
|
162
|
});
|
163
|
|
164
|
|
165
|
return true;
|
166
|
}
|
167
|
|
168
|
@Override
|
169
|
public boolean onComplete() {
|
170
|
return false;
|
171
|
}
|
172
|
|
173
|
@CanExecute
|
174
|
public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
|
175
|
MHandledMenuItem menuItem){
|
176
|
boolean canExecute = false;
|
177
|
FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
|
178
|
|
179
|
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(factualDataPart.getSelectionProvidingPart());
|
180
|
if(e4WrappedPart instanceof TaxonNameEditorE4){
|
181
|
ISelection selection = factualDataPart.getViewer().getSelection();
|
182
|
if(selection instanceof IStructuredSelection){
|
183
|
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
|
184
|
canExecute = firstElement instanceof FeatureNodeContainer
|
185
|
|| firstElement instanceof DescriptionElementBase
|
186
|
|| firstElement instanceof DescriptionBase;
|
187
|
menuItem.setVisible(canExecute);
|
188
|
}
|
189
|
}
|
190
|
return canExecute;
|
191
|
}
|
192
|
}
|