ref #6595 Use only e4 handler for opening name editor
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / DeleteHandler.java
index 5a8650098b30cf91fe380d90fb7f994e7be7fc87..bafa4430c5b5ce39fd0e4e38ba4bcee950a9dfeb 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
 * European Distributed Institute of Taxonomy
@@ -26,21 +25,21 @@ import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.api.service.config.NodeDeletionConfigurator.ChildHandling;
 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.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.l10n.Messages;
 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.deleteConfigurator.DeleteConfiguratorDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog;
 
 /**
  * <p>DeleteTreeNodeHandler class.</p>
@@ -51,7 +50,16 @@ import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDia
  */
 public class DeleteHandler extends AbstractHandler{
 
-       protected IWorkbenchPage activePage;
+    protected static final String SKIP = Messages.DeleteHandler_SKIP;
+    protected static final String MOVE_CHILDREN_TO_PARENT_NODE = Messages.DeleteHandler_MOVE_TO_PARENT;
+    protected static final String DELETE_ALL_CHILDREN = Messages.DeleteHandler_DELETE_ALL;
+    protected static final String THERE_ARE_CHILDNODES_WHICH_WILL_BE_DELETED_TOO = Messages.DeleteHandler_THERE_ARE_CHILDNODES;
+    protected static final String THE_TREE_HAS_CHILDREN_THEY_WILL_BE_DELETED_TOO = Messages.DeleteHandler_THERE_ARE_CHILDREN;
+    protected static final String DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S = Messages.DeleteHandler_DELETE_NODE;
+    protected static final String DO_YOU_REALLY_WANT_TO_DELETE_THE_CLASSIFICATION = Messages.DeleteHandler_DELETE_CLASSIFICATION;
+    protected static final String CONFIRM_DELETION = Messages.DeleteHandler_CONFIRM_DELETE;
+
+    protected IWorkbenchPage activePage;
        protected TaxonNavigator taxonNavigator;
 
        /** {@inheritDoc} */
@@ -64,6 +72,11 @@ public class DeleteHandler extends AbstractHandler{
 
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
 
+
+               // Prompt user for confirmation
+
+
+
                Iterator selectionIterator = selection.iterator();
                Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
 
@@ -81,19 +94,22 @@ 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.")){
+                                       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)){
                                                return null;
                                        }
                                } else if (taxonNode instanceof Classification && !taxonNode.hasChildNodes()){
-                                       if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the classification?")){
+                                       if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION, DO_YOU_REALLY_WANT_TO_DELETE_THE_CLASSIFICATION)){
                                                return null;
                                        }
                                } else {
@@ -102,30 +118,30 @@ public class DeleteHandler extends AbstractHandler{
                         DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(
                                 config,
                                 HandlerUtil.getActiveShell(event),
-                                "Confirm Deletion",
+                                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();
+                                DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S+THERE_ARE_CHILDNODES_WHICH_WILL_BE_DELETED_TOO,
+                                MessageDialog.WARNING, new String[] { DELETE_ALL_CHILDREN,
+                                        MOVE_CHILDREN_TO_PARENT_NODE, SKIP }, 0);
+                                               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;
 
                                                }
                                        }else{
-                                               if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
+                                               if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(configNodes, HandlerUtil.getActiveShell(event), CONFIRM_DELETION, DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S)){
                                                        return null;
-                                               } 
+                                               }
                                                config.setTaxonNodeConfig(configNodes);
                                        }
                                }
@@ -134,34 +150,50 @@ 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);
+
                                                //}
                                }
 
 
 
                        } catch (NotDefinedException e) {
-                               MessagingUtils.warn(getClass(), "Command name not set");
+                               MessagingUtils.warn(getClass(), "Command name not set"); //$NON-NLS-1$
+                       } catch (Exception e){
+                           MessagingUtils.error(getClass(), e);
                        }
                } else{
                        try{
-                               if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected nodes?")){
+                               if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), CONFIRM_DELETION, DO_YOU_REALLY_WANT_TO_DELETE_THE_SELECTED_NODE_S)){
                                        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");
-                       }
+                               MessagingUtils.warn(getClass(), Messages.DeleteHandler_9);
+                       } catch (Exception e){
+                MessagingUtils.error(getClass(), e);
+            }
                }
                return null;
        }