import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IconAndMessageDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.navigator.CommonDropAdapter;
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
public IStatus handleDrop(CommonDropAdapter dropAdapter,
DropTargetEvent dropTargetEvent, Object target) {
+
if (target instanceof ITaxonTreeNode) {
Set<TaxonNode> taxonNodes = getSelectedTaxa();
ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target;
}
}
}
-
+
return Status.CANCEL_STATUS;
}
if(targetITaxonTreeNode instanceof TaxonNode){
TaxonNode targetTaxonNode = (TaxonNode) targetITaxonTreeNode;
-
-// for(TaxonNode taxonNode : taxonNodes){
-// if (taxonNode.equals(targetTaxonNode)) {
-// return Status.CANCEL_STATUS;
-// }
-// }
-
- // Make sure parent taxon does not have unsaved changes
+ // Make sure parent taxon does not have unsaved changes
if (NavigationUtil.isDirty(targetTaxonNode)){
MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " +
"changes in the parent taxon. Pleas save first.");
return Status.CANCEL_STATUS;
}
-
- /*if (((TaxonNode) targetITaxonTreeNode).isTopmostNode()) {
- MessageDialog.openConfirm(null, "Taxonnode can not be moved", "A taxonnode can not be moved to the classification");
- }*/
-
- // Make sure parentTaxon is not the drop target
-// if (!childTaxonNode.isTopmostNode() && childTaxonNode.getParent().equals(targetTaxonNode)){
-// return Status.CANCEL_STATUS;
-// }
-
- // Make sure taxon is not being dropped onto itself
-// if (childTaxonNode.equals(targetTaxonNode)) {
-// return Status.CANCEL_STATUS;
-// }
-
-
-
}
-
- IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
- if (workspaceUndoContext == null) {
- logger.error("Workspace undo context is null. DND operation cancelled");
- return Status.CANCEL_STATUS;
- }
-
- AbstractPostOperation operation = new MoveTaxonOperation
- ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator);
- NavigationUtil.executeOperation(operation);
+ if (!PreferencesUtil.getSortNodesNaturally()){
+ IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+ if (workspaceUndoContext == null) {
+ logger.error("Workspace undo context is null. DND operation cancelled");
+ return Status.CANCEL_STATUS;
+ }
+
+ AbstractPostOperation operation = new MoveTaxonOperation
+ ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
+ NavigationUtil.executeOperation(operation);
+
+ logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+ return Status.OK_STATUS;
+ }else{
+ String[] buttonLables = {"Parent", "Predecessor", "Cancel"};
+ MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to use the target node as parent or do you want to move the taxon below the target.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
+ dialog.open();
+ int returnCode = dialog.getReturnCode();
+ if (returnCode == 0){
+ IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+ if (workspaceUndoContext == null) {
+ logger.error("Workspace undo context is null. DND operation cancelled");
+ return Status.CANCEL_STATUS;
+ }
+
+ AbstractPostOperation operation = new MoveTaxonOperation
+ ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
+ NavigationUtil.executeOperation(operation);
+
+ logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+ return Status.OK_STATUS;
+ }else if (returnCode == 1){
+ IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
+ if (workspaceUndoContext == null) {
+ logger.error("Workspace undo context is null. DND operation cancelled");
+ return Status.CANCEL_STATUS;
+ }
- logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
- return Status.OK_STATUS;
+ AbstractPostOperation operation = new MoveTaxonOperation
+ ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false);
+ NavigationUtil.executeOperation(operation);
+
+ logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+ return Status.OK_STATUS;
+ } else{
+ return Status.CANCEL_STATUS;
+ }
+
+
+ }
}
/* (non-Javadoc)