fixing #5341 and colouring for cache relevant fields #4915 and #4944
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / DeleteHandler.java
index 5a8650098b30cf91fe380d90fb7f994e7be7fc87..ea3fb60d95574044088195bfcc1cd162e470636c 100644 (file)
@@ -28,13 +28,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
-import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator.ChildHandling;
+import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
 import eu.etaxonomy.cdm.model.common.ITreeNode;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
@@ -64,6 +63,12 @@ public class DeleteHandler extends AbstractHandler{
 
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
 
+
+               String plural = selection.size() > 1 ? "s" : "";
+               // Prompt user for confirmation
+
+
+
                Iterator selectionIterator = selection.iterator();
                Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
 
@@ -81,12 +86,15 @@ public class DeleteHandler extends AbstractHandler{
                }
                AbstractPostOperation operation = null;
                TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
+               config.setDeleteInAllClassifications(false);
+
                if (treeNodes.size() == 1 ){
                        try {
 
                                ITaxonTreeNode treeNode = treeNodes.iterator().next();
                                ITaxonTreeNode taxonNode =treeNode;
                                TaxonNodeDeletionConfigurator configNodes = new TaxonNodeDeletionConfigurator();
+
                                //configNodes.setDeleteTaxon(false);
                                if (taxonNode instanceof Classification && taxonNode.hasChildNodes()){
                                        if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){
@@ -107,17 +115,17 @@ public class DeleteHandler extends AbstractHandler{
                                 "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();
+                                               int dialog_result = dialog.open();
 
-                                               if (result == 0){
+                                               if (dialog_result == 0){
                                                        //delete all children
                                                        configNodes.setChildHandling(ChildHandling.DELETE);
                                                        config.setTaxonNodeConfig(configNodes);
-                                               } else if (result == 1){
+                                               } else if (dialog_result == 1){
                                                        //move children
                                                        configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT);
                                                        config.setTaxonNodeConfig(configNodes);
-                                               } else if (result == 2){
+                                               } else if (dialog_result == 2){
                                                        //skip
                                                        return null;
 
@@ -125,7 +133,7 @@ public class DeleteHandler extends AbstractHandler{
                                        }else{
                                                if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
                                                        return null;
-                                               } 
+                                               }
                                                config.setTaxonNodeConfig(configNodes);
                                        }
                                }
@@ -134,11 +142,17 @@ public class DeleteHandler extends AbstractHandler{
                                        /*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, config, taxonNavigator, taxonNavigator);
 
-                                               AbstractUtility.executeOperation(operation);
+                                               operation = new DeleteOperation(event.getCommand().getName(),
+                                                       NavigationUtil.getUndoContext(),
+                                                               taxonNode,
+                                                               config,
+                                                               taxonNavigator,
+                                                               taxonNavigator,
+                                                               taxonNavigator);
+
+                                               NavigationUtil.executeOperation(operation);
+
                                                //}
                                }
 
@@ -146,6 +160,8 @@ public class DeleteHandler extends AbstractHandler{
 
                        } catch (NotDefinedException e) {
                                MessagingUtils.warn(getClass(), "Command name not set");
+                       } catch (Exception e){
+                           MessagingUtils.error(getClass(), e);
                        }
                } else{
                        try{
@@ -153,15 +169,23 @@ public class DeleteHandler extends AbstractHandler{
                                        return null;
                                }
                                if (allEditorsClosed){
-                                       operation = new DeleteOperation(
-                                                       event.getCommand().getName(), NavigationUtil.getUndoContext(),
-                                                       treeNodes, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
 
-                                       AbstractUtility.executeOperation(operation);
+                                       operation = new DeleteOperation(event.getCommand().getName(),
+                                               NavigationUtil.getUndoContext(),
+                                                       treeNodes,
+                                                       new TaxonDeletionConfigurator(),
+                                                       taxonNavigator,
+                                                       taxonNavigator,
+                                                       taxonNavigator);
+
+                                       NavigationUtil.executeOperation(operation);
+
                                }
                        }catch (NotDefinedException e) {
                                MessagingUtils.warn(getClass(), "Command name not set");
-                       }
+                       } catch (Exception e){
+                MessagingUtils.error(getClass(), e);
+            }
                }
                return null;
        }