Revision 95ee1b51
Added by U-BGBM\k.luther over 8 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java | ||
---|---|---|
14 | 14 |
import java.util.HashSet; |
15 | 15 |
import java.util.Iterator; |
16 | 16 |
import java.util.Set; |
17 |
import java.util.UUID; |
|
17 | 18 |
|
18 | 19 |
import org.apache.log4j.Logger; |
19 | 20 |
import org.eclipse.core.commands.operations.IUndoContext; |
20 | 21 |
import org.eclipse.core.runtime.IStatus; |
21 | 22 |
import org.eclipse.core.runtime.Status; |
22 |
import org.eclipse.jface.dialogs.IconAndMessageDialog; |
|
23 | 23 |
import org.eclipse.jface.dialogs.MessageDialog; |
24 | 24 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
25 | 25 |
import org.eclipse.jface.viewers.ISelection; |
26 | 26 |
import org.eclipse.jface.viewers.TreeSelection; |
27 | 27 |
import org.eclipse.swt.dnd.DropTargetEvent; |
28 | 28 |
import org.eclipse.swt.dnd.TransferData; |
29 |
import org.eclipse.swt.graphics.Image; |
|
30 |
import org.eclipse.swt.widgets.Shell; |
|
31 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
32 | 29 |
import org.eclipse.ui.navigator.CommonDropAdapter; |
33 | 30 |
import org.eclipse.ui.navigator.CommonDropAdapterAssistant; |
34 | 31 |
|
... | ... | |
69 | 66 |
public IStatus handleDrop(CommonDropAdapter dropAdapter, |
70 | 67 |
DropTargetEvent dropTargetEvent, Object target) { |
71 | 68 |
|
72 |
|
|
69 |
|
|
73 | 70 |
if (target instanceof ITaxonTreeNode) { |
74 | 71 |
Set<TaxonNode> taxonNodes = getSelectedTaxa(); |
75 | 72 |
ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target; |
... | ... | |
77 | 74 |
targetTreeNode = ((Classification)targetTreeNode).getRootNode(); |
78 | 75 |
targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class); |
79 | 76 |
} |
80 |
if(taxonNodes != null) { |
|
81 |
if (taxonNodes.size() == 1){
|
|
82 |
return moveTaxon(taxonNodes.iterator().next(), targetTreeNode);
|
|
83 |
} else{ |
|
77 |
//if(taxonNodes != null) {
|
|
78 |
if (taxonNodes.size() >= 1){
|
|
79 |
return moveTaxon(taxonNodes, targetTreeNode); |
|
80 |
/*} else{
|
|
84 | 81 |
if( MessageDialog.openConfirm(null, "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ |
85 | 82 |
return null; |
86 | 83 |
} |
87 |
} |
|
84 |
}*/
|
|
88 | 85 |
} |
89 | 86 |
} |
90 |
|
|
87 |
|
|
91 | 88 |
return Status.CANCEL_STATUS; |
92 | 89 |
} |
93 | 90 |
|
... | ... | |
168 | 165 |
* @param parentTaxon |
169 | 166 |
* @return |
170 | 167 |
*/ |
171 |
private IStatus moveTaxon(TaxonNode taxonNode, ITaxonTreeNode targetITaxonTreeNode) {
|
|
168 |
private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
|
|
172 | 169 |
|
173 | 170 |
TaxonNavigator taxonNavigator; |
174 | 171 |
taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); |
... | ... | |
184 | 181 |
} |
185 | 182 |
|
186 | 183 |
} |
184 |
Iterator<TaxonNode> taxIterator = taxonNodes.iterator(); |
|
185 |
Set<UUID> uuids = new HashSet<UUID>(); |
|
186 |
TaxonNode node = null; |
|
187 |
while(taxIterator.hasNext()){ |
|
188 |
node = taxIterator.next(); |
|
189 |
uuids.add(node.getUuid()); |
|
190 |
} |
|
187 | 191 |
if (!PreferencesUtil.getSortNodesNaturally()){ |
188 | 192 |
IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); |
189 | 193 |
if (workspaceUndoContext == null) { |
190 | 194 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
191 | 195 |
return Status.CANCEL_STATUS; |
192 | 196 |
} |
193 |
|
|
197 |
|
|
194 | 198 |
AbstractPostOperation operation = new MoveTaxonOperation |
195 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
199 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
196 | 200 |
NavigationUtil.executeOperation(operation); |
197 |
|
|
201 |
|
|
198 | 202 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
199 | 203 |
return Status.OK_STATUS; |
200 | 204 |
}else{ |
... | ... | |
208 | 212 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
209 | 213 |
return Status.CANCEL_STATUS; |
210 | 214 |
} |
211 |
|
|
215 |
|
|
212 | 216 |
AbstractPostOperation operation = new MoveTaxonOperation |
213 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
217 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
|
|
214 | 218 |
NavigationUtil.executeOperation(operation); |
215 |
|
|
219 |
|
|
216 | 220 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
217 | 221 |
return Status.OK_STATUS; |
218 | 222 |
}else if (returnCode == 1){ |
... | ... | |
221 | 225 |
logger.error("Workspace undo context is null. DND operation cancelled"); |
222 | 226 |
return Status.CANCEL_STATUS; |
223 | 227 |
} |
224 |
|
|
228 |
|
|
225 | 229 |
AbstractPostOperation operation = new MoveTaxonOperation |
226 |
("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false);
|
|
230 |
("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, false);
|
|
227 | 231 |
NavigationUtil.executeOperation(operation); |
228 |
|
|
232 |
|
|
229 | 233 |
logger.info("Moved taxa to new parent " + targetITaxonTreeNode); |
230 | 234 |
return Status.OK_STATUS; |
231 | 235 |
} else{ |
232 | 236 |
return Status.CANCEL_STATUS; |
233 | 237 |
} |
234 |
|
|
235 |
|
|
238 |
|
|
239 |
|
|
236 | 240 |
} |
237 | 241 |
} |
238 | 242 |
|
Also available in: Unified diff
moving more than one taxon node, merge of team and person, reusing name for new taxon