corrected usage of service calls returning update/delete result objects
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / DeleteHandler.java
index 117250e04c79a406a0deefe9d7e2dc9cc801dabb..14fea3aa97a7fe6be693dcf766f2981e27223711 100644 (file)
@@ -17,7 +17,6 @@ import java.util.Set;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
 import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.TreeSelection;
@@ -40,6 +39,8 @@ import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.DeleteOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.ui.dialog.DeleteConfiguratorDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.DeleteTaxonConfiguratorDialog;
 
 /**
  * <p>DeleteTreeNodeHandler class.</p>
@@ -48,7 +49,7 @@ import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
  * @created 06.04.2009
  * @version 1.0
  */
-public class DeleteHandler extends AbstractHandler implements IHandler{
+public class DeleteHandler extends AbstractHandler{
 
        protected IWorkbenchPage activePage;
        protected TaxonNavigator taxonNavigator;
@@ -63,6 +64,7 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
 
+
                String plural = selection.size() > 1 ? "s" : "";
                // Prompt user for confirmation
 
@@ -84,26 +86,32 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                        }
                }
                AbstractPostOperation operation = null;
+               TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
                if (treeNodes.size() == 1 ){
                        try {
 
                                ITaxonTreeNode treeNode = treeNodes.iterator().next();
                                ITaxonTreeNode taxonNode =treeNode;
                                TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
-                               TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
                                if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){
-                                       if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){
+                                       if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){
                                                return null;
                                        }
                                } else if (taxonNode instanceof Classification && !taxonNode.hasChildNodes()){
-                                       if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){
+                                       if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){
                                                return null;
                                        }
                                } else {
+
                                        if (taxonNode.hasChildNodes()){
-                                               MessageDialog dialog = new MessageDialog(HandlerUtil.getActiveShell(event), "Confirm Deletion", null,
-                                                           "Do you really want to delete the selected node? It has childnodes, they will be deleted, too.", MessageDialog.WARNING, new String[] { "Delete all children",
-                                                         "Move children to parent node", "Skip" }, 0);
+                        DeleteConfiguratorDialog dialog = new DeleteTaxonConfiguratorDialog(
+                                config,
+                                HandlerUtil.getActiveShell(event),
+                                "Confirm Deletion",
+                                null,
+                                "Do you really want to delete the selected node? It has childnodes, they will be deleted, too.",
+                                MessageDialog.WARNING, new String[] { "Delete all children",
+                                        "Move children to parent node", "Skip" }, 0);
                                                int result = dialog.open();
 
                                                if (result == 0){
@@ -120,7 +128,7 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 
                                                }
                                        }else{
-                                               if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
+                                               if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
                                                        return null;
                                                }
                                        }
@@ -130,6 +138,7 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                                        /*if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected nodes?")){
                                                return null;
                                        }*/
+
                                                operation = new DeleteOperation(event.getCommand().getName(),
                                                        NavigationUtil.getUndoContext(),
                                                                taxonNode,
@@ -139,6 +148,7 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                                                                taxonNavigator);
 
                                                NavigationUtil.executeOperation(operation);
+
                                                //}
                                }
 
@@ -149,10 +159,11 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                        }
                } else{
                        try{
-                               if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected nodes?")){
+                               if(!DeleteTaxonConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected nodes?")){
                                        return null;
                                }
                                if (allEditorsClosed){
+
                                        operation = new DeleteOperation(event.getCommand().getName(),
                                                NavigationUtil.getUndoContext(),
                                                        treeNodes,
@@ -162,6 +173,7 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                                                        taxonNavigator);
 
                                        NavigationUtil.executeOperation(operation);
+
                                }
                        }catch (NotDefinedException e) {
                                MessagingUtils.warn(getClass(), "Command name not set");