1 |
83a1a479
|
Cherian Mathew
|
/**
|
2 |
|
|
* Copyright (C) 2015 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 |
95ccdfd3
|
Patrick Plitzner
|
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
|
10 |
83a1a479
|
Cherian Mathew
|
|
11 |
0fde7fba
|
Katja Luther
|
import java.util.HashSet;
|
12 |
|
|
import java.util.Iterator;
|
13 |
|
|
import java.util.Set;
|
14 |
83a1a479
|
Cherian Mathew
|
import java.util.UUID;
|
15 |
|
|
|
16 |
369d3230
|
Patrick Plitzner
|
import javax.inject.Named;
|
17 |
|
|
|
18 |
83a1a479
|
Cherian Mathew
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
19 |
|
|
import org.eclipse.core.runtime.IStatus;
|
20 |
|
|
import org.eclipse.core.runtime.Status;
|
21 |
369d3230
|
Patrick Plitzner
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
22 |
95ccdfd3
|
Patrick Plitzner
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
23 |
|
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
24 |
369d3230
|
Patrick Plitzner
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
25 |
83a1a479
|
Cherian Mathew
|
import org.eclipse.jface.dialogs.MessageDialog;
|
26 |
b30d0fe8
|
Patrick Plitzner
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
27 |
83a1a479
|
Cherian Mathew
|
import org.eclipse.jface.viewers.TreeSelection;
|
28 |
8c8ead8a
|
Cherian Mathew
|
import org.eclipse.swt.widgets.Shell;
|
29 |
83a1a479
|
Cherian Mathew
|
|
30 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
31 |
cedc4ff1
|
Katja Luther
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
32 |
83a1a479
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
33 |
939829bc
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
34 |
83a1a479
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
|
35 |
ebfb13c6
|
Katja Luther
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
|
36 |
85f62f44
|
Katja Luther
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
|
37 |
d991bdfe
|
Katja Luther
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
|
38 |
|
|
import eu.etaxonomy.taxeditor.operation.e4.CdmHandlerE4;
|
39 |
83a1a479
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
40 |
|
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
|
|
* @author cmathew
|
44 |
|
|
* @date 19 Jun 2015
|
45 |
|
|
*
|
46 |
|
|
*/
|
47 |
d991bdfe
|
Katja Luther
|
public class MoveTaxonNodeHandlerE4 extends CdmHandlerE4 {
|
48 |
83a1a479
|
Cherian Mathew
|
|
49 |
0fde7fba
|
Katja Luther
|
private Set<UUID> oldTaxonNodeUUIDs = new HashSet<>();
|
50 |
ebfb13c6
|
Katja Luther
|
private TaxonNavigatorE4 navigator;
|
51 |
0ac7eec9
|
Katja Luther
|
private UUID classificationUuid = null;
|
52 |
61e77456
|
Katja Luther
|
boolean isPublish = true;
|
53 |
83a1a479
|
Cherian Mathew
|
|
54 |
d991bdfe
|
Katja Luther
|
public MoveTaxonNodeHandlerE4() {
|
55 |
83a1a479
|
Cherian Mathew
|
super(TaxonNavigatorLabels.MOVE_TAXON_LABEL);
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
@Override
|
59 |
b30d0fe8
|
Patrick Plitzner
|
public IStatus allowOperations(IStructuredSelection selection,
|
60 |
95ccdfd3
|
Patrick Plitzner
|
Shell shell,
|
61 |
|
|
MPart activePart,
|
62 |
|
|
MHandledMenuItem menuItem) {
|
63 |
83a1a479
|
Cherian Mathew
|
// check for no taxon tree node selected
|
64 |
|
|
if(selection.size() == 0) {
|
65 |
|
|
return new Status(IStatus.ERROR,
|
66 |
939829bc
|
Patrick Plitzner
|
"unknown", //$NON-NLS-1$
|
67 |
83a1a479
|
Cherian Mathew
|
TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
|
68 |
|
|
}
|
69 |
|
|
// check that selected object is a taxon node
|
70 |
03c03694
|
Katja Luther
|
|
71 |
0fde7fba
|
Katja Luther
|
Object obj ;
|
72 |
|
|
Iterator iter = selection.iterator();
|
73 |
ebfb13c6
|
Katja Luther
|
oldTaxonNodeUUIDs = new HashSet<>();
|
74 |
7ff96e13
|
Katja Luther
|
isPublish = true;
|
75 |
0fde7fba
|
Katja Luther
|
while (iter.hasNext()){
|
76 |
|
|
obj = iter.next();
|
77 |
|
|
if(obj instanceof TaxonNodeDto) {
|
78 |
|
|
oldTaxonNodeUUIDs.add(((TaxonNodeDto)obj).getUuid());
|
79 |
61e77456
|
Katja Luther
|
isPublish &= ((TaxonNodeDto)obj).isPublish();
|
80 |
0ac7eec9
|
Katja Luther
|
if (classificationUuid == null){
|
81 |
|
|
classificationUuid = ((TaxonNodeDto)obj).getClassificationUUID();
|
82 |
|
|
}
|
83 |
0fde7fba
|
Katja Luther
|
} else {
|
84 |
|
|
return new Status(IStatus.ERROR,
|
85 |
|
|
"unknown", //$NON-NLS-1$
|
86 |
|
|
TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
|
87 |
|
|
}
|
88 |
83a1a479
|
Cherian Mathew
|
}
|
89 |
|
|
return Status.OK_STATUS;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
@Override
|
93 |
b30d0fe8
|
Patrick Plitzner
|
public AbstractOperation prepareOperation(IStructuredSelection selection,
|
94 |
95ccdfd3
|
Patrick Plitzner
|
Shell shell,
|
95 |
|
|
MPart activePart,
|
96 |
|
|
MHandledMenuItem menuItem) {
|
97 |
83a1a479
|
Cherian Mathew
|
TaxonNode parentTaxonNode;
|
98 |
e77e7f40
|
Katja Luther
|
MovingType moveToNewParent = MovingType.CHILD;
|
99 |
83a1a479
|
Cherian Mathew
|
|
100 |
432276e4
|
Katja Luther
|
if (PreferencesUtil.isNodesSortedNaturally()){
|
101 |
95ccdfd3
|
Patrick Plitzner
|
parentTaxonNode = TaxonNodeSelectionDialog.select(shell,
|
102 |
939829bc
|
Patrick Plitzner
|
Messages.RemotingMoveTaxonNodeHandler_CHOOSE_TAXON,
|
103 |
0fde7fba
|
Katja Luther
|
oldTaxonNodeUUIDs,
|
104 |
83a1a479
|
Cherian Mathew
|
null,
|
105 |
0ac7eec9
|
Katja Luther
|
classificationUuid, true);
|
106 |
939829bc
|
Patrick Plitzner
|
String[] buttonLables = {Messages.RemotingMoveTaxonNodeHandler_CHILD, Messages.RemotingMoveTaxonNodeHandler_BEHIND,Messages.RemotingMoveTaxonNodeHandler_CANCEL};
|
107 |
|
|
MessageDialog dialog = new MessageDialog(null, Messages.RemotingMoveTaxonNodeHandler_TARGET_NODE, null, Messages.RemotingMoveTaxonNodeHandler_TARGET_NODE_MESSAGE, MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
|
108 |
e77e7f40
|
Katja Luther
|
dialog.open();
|
109 |
|
|
int returnCode = dialog.getReturnCode();
|
110 |
|
|
if (returnCode == 0){
|
111 |
|
|
moveToNewParent = MovingType.CHILD;
|
112 |
|
|
} else if (returnCode == 1){
|
113 |
|
|
moveToNewParent = MovingType.BEHIND;
|
114 |
|
|
}
|
115 |
83a1a479
|
Cherian Mathew
|
} else {
|
116 |
95ccdfd3
|
Patrick Plitzner
|
parentTaxonNode = TaxonNodeSelectionDialog.select(shell,
|
117 |
939829bc
|
Patrick Plitzner
|
Messages.RemotingMoveTaxonNodeHandler_CHOOSE_PARENT,
|
118 |
0fde7fba
|
Katja Luther
|
oldTaxonNodeUUIDs,
|
119 |
|
|
null,
|
120 |
0ac7eec9
|
Katja Luther
|
classificationUuid, true);
|
121 |
83a1a479
|
Cherian Mathew
|
}
|
122 |
8c8ead8a
|
Cherian Mathew
|
|
123 |
61e77456
|
Katja Luther
|
if (parentTaxonNode.getTaxon().isPublish() != isPublish){
|
124 |
|
|
MessageDialog.openWarning(shell,
|
125 |
|
|
Messages.RemotingMoveTaxonNodeHandler_DIFFERENT_PUBLISH_TITLE,
|
126 |
|
|
Messages.RemotingMoveTaxonNodeHandler_DIFFERENT_PUBLISH_MESSAGE);
|
127 |
|
|
}
|
128 |
8c8ead8a
|
Cherian Mathew
|
|
129 |
83a1a479
|
Cherian Mathew
|
if(parentTaxonNode != null){
|
130 |
bc330e88
|
Patrick Plitzner
|
if(NavigationUtil.isDirty(parentTaxonNode, partService)){
|
131 |
95ccdfd3
|
Patrick Plitzner
|
MessageDialog.openWarning(shell,
|
132 |
939829bc
|
Patrick Plitzner
|
Messages.RemotingMoveTaxonNodeHandler_UNSAVED_PARENT,
|
133 |
|
|
Messages.RemotingMoveTaxonNodeHandler_UNSAVED_PARENT_MESSAGE);
|
134 |
83a1a479
|
Cherian Mathew
|
return null;
|
135 |
|
|
}
|
136 |
|
|
|
137 |
d991bdfe
|
Katja Luther
|
return new MoveTaxonOperation(getTrigger(),
|
138 |
83a1a479
|
Cherian Mathew
|
false,
|
139 |
0fde7fba
|
Katja Luther
|
oldTaxonNodeUUIDs,
|
140 |
83a1a479
|
Cherian Mathew
|
parentTaxonNode.getUuid(),
|
141 |
|
|
moveToNewParent);
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
return null;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
369d3230
|
Patrick Plitzner
|
@CanExecute
|
148 |
|
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
149 |
|
|
boolean canExecute = false;
|
150 |
8880b9b3
|
Katja Luther
|
canExecute = selection.getFirstElement() instanceof TaxonNodeDto
|
151 |
f853dd5b
|
Patrick Plitzner
|
&& ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null;
|
152 |
97de9a5d
|
Katja Luther
|
menuItem.setVisible(canExecute);
|
153 |
369d3230
|
Patrick Plitzner
|
return canExecute;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
83a1a479
|
Cherian Mathew
|
@Override
|
157 |
|
|
public void onComplete() {
|
158 |
|
|
}
|
159 |
|
|
|
160 |
95ccdfd3
|
Patrick Plitzner
|
/**
|
161 |
|
|
* {@inheritDoc}
|
162 |
|
|
*/
|
163 |
|
|
@Override
|
164 |
|
|
protected Object getTrigger() {
|
165 |
|
|
return this;
|
166 |
|
|
}
|
167 |
83a1a479
|
Cherian Mathew
|
}
|