#4574
authorKatja Luther <k.luther@bgbm.org>
Tue, 6 Jan 2015 12:37:58 +0000 (12:37 +0000)
committerKatja Luther <k.luther@bgbm.org>
Tue, 6 Jan 2015 12:37:58 +0000 (12:37 +0000)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java

index 09c3f22daecbca943431234d7f3589eeca165cd8..cf7ae81e43ed3c6cb6cc7142e22445a6a697f0d5 100644 (file)
@@ -28,10 +28,13 @@ import org.eclipse.ui.PartInitException;
 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.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.cdm.persistence.dao.hibernate.taxon.TaxonNodeDaoHibernateImpl;
 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
@@ -87,9 +90,10 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                                
                                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(! MessageDialog.openConfirm(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()){
@@ -97,8 +101,29 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                                                return null;
                                        }
                                } else {
-                                       if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
-                                               return null;
+                                       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);
+                                               int result = dialog.open();
+                                               
+                                               if (result == 0){
+                                                       //delete all children
+                                                       configNodes.setChildHandling(ChildHandling.DELETE);
+                                                       config.setTaxonNodeConfig(configNodes);
+                                               } else if (result == 1){
+                                                       //move children
+                                                       configNodes.setChildHandling(ChildHandling.MOVE_TO_PARENT);
+                                                       config.setTaxonNodeConfig(configNodes);
+                                               } else if (result == 2){
+                                                       //skip
+                                                       return null;
+                                                       
+                                               }
+                                       }else{
+                                               if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
+                                                       return null;
+                                               }
                                        }
                                }
        
@@ -108,7 +133,7 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                                        }*/
                                                operation = new DeleteOperation(
                                                                event.getCommand().getName(), NavigationUtil.getUndoContext(),
-                                                               taxonNode, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
+                                                               taxonNode, config, taxonNavigator, taxonNavigator);
                        
                                                NavigationUtil.executeOperation(operation);
                                                //}