delete whole classification with children
authorKatja Luther <k.luther@bgbm.org>
Mon, 2 Dec 2013 11:55:22 +0000 (11:55 +0000)
committerKatja Luther <k.luther@bgbm.org>
Mon, 2 Dec 2013 11:55:22 +0000 (11:55 +0000)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java

index d632a6bcbcbfa7b764a39958b26b5329dad74575..2df882e501934e06fa775e58f4ebfbb5a3b4e432 100644 (file)
@@ -62,9 +62,8 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
 
                String plural = selection.size() > 1 ? "s" : "";
                // Prompt user for confirmation
 
                String plural = selection.size() > 1 ? "s" : "";
                // Prompt user for confirmation
-               if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Are you sure you want to delete the selected node" + plural +"?")){
-                       return null;
-               }
+               
+               
 
                Iterator selectionIterator = selection.iterator();
                Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
 
                Iterator selectionIterator = selection.iterator();
                Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
@@ -85,17 +84,27 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                if (treeNodes.size() == 1 ){
                        try {
                                
                if (treeNodes.size() == 1 ){
                        try {
                                
+                               ITaxonTreeNode treeNode = treeNodes.iterator().next();
+                               ITaxonTreeNode taxonNode =treeNode;
+                               
+                               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")){
+                                               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?")){
+                                               return null;
+                                       }
+                               } else {
+                                       if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you really want to delete the selected node?")){
+                                               return null;
+                                       }
+                               }
        
                                if (allEditorsClosed){
        
                                if (allEditorsClosed){
-                                       ITaxonTreeNode treeNode = treeNodes.iterator().next();
-                                       /*if (treeNode instanceof Classification){
-                                               operation = new DeleteOperation(
-                                                               event.getCommand().getName(), NavigationUtil.getUndoContext(),
-                                                               treeNodes, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
-                       
-                                               NavigationUtil.executeOperation(operation);
-                                       }else {*/
-                                               ITaxonTreeNode taxonNode =treeNode;
+                                       /*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, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
                                                operation = new DeleteOperation(
                                                                event.getCommand().getName(), NavigationUtil.getUndoContext(),
                                                                taxonNode, new TaxonDeletionConfigurator(), taxonNavigator, taxonNavigator);
@@ -111,6 +120,9 @@ public class DeleteHandler extends AbstractHandler implements IHandler{
                        }
                } else{
                        try{
                        }
                } else{
                        try{
+                               if(! MessageDialog.openConfirm(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(),
                                if (allEditorsClosed){
                                        operation = new DeleteOperation(
                                                        event.getCommand().getName(), NavigationUtil.getUndoContext(),
index 49c6f77961672d07d05f151e50074920e8933c19..9cd017a222c44819d6cbb38fbc6bc7dcd39ec05a 100644 (file)
@@ -17,6 +17,8 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
@@ -113,16 +115,25 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
                                
                        }else if(taxonNode != null && taxonNode instanceof Classification){
                                Classification taxonomicTree = (Classification) taxonNode;
                                
                        }else if(taxonNode != null && taxonNode instanceof Classification){
                                Classification taxonomicTree = (Classification) taxonNode;
-                               if(taxonomicTree.hasChildNodes()){
-                                       StoreUtil.warningDialog("Tree is not empty", this, "It is not possible to delete a Taxonomic Tree that " +
-                                                       "is not empty. Please delete included taxa first");
-                               }else{
+                               /*if(taxonomicTree.hasChildNodes()){
+                                       if(! MessageDialog.openConfirm(null, "Confirm Deletion", "The selected tree has children, do yu realy want to delete the whole tree with its children?")){
+                                               return null;
+                                       }
+                               }*/
+                               try{
+                                       CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
+                               }catch(ReferencedObjectUndeletableException e){
+                                       throw new ExecutionException(e.getMessage());
+                               }
+                                       
+                                       
+                               /*}else{
                                        try{
                                        CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
                                        }catch(ReferencedObjectUndeletableException e){
                                                throw new ExecutionException(e.getMessage());
                                        }
                                        try{
                                        CdmStore.getService(IClassificationService.class).delete(taxonomicTree);
                                        }catch(ReferencedObjectUndeletableException e){
                                                throw new ExecutionException(e.getMessage());
                                        }
-                               }
+                               }*/
                        } else {
                                try {
                                        service.deleteTaxonNodes(treeNodes, config);
                        } else {
                                try {
                                        service.deleteTaxonNodes(treeNodes, config);