From c0e5fd02ab6e485045dd6763fc4598f6b8f3dd4e Mon Sep 17 00:00:00 2001 From: Katja Luther Date: Mon, 2 Dec 2013 11:55:22 +0000 Subject: [PATCH] delete whole classification with children --- .../navigator/handler/DeleteHandler.java | 36 ++++++++++++------- .../navigator/operation/DeleteOperation.java | 21 ++++++++--- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java index d632a6bcb..2df882e50 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java @@ -62,9 +62,8 @@ public class DeleteHandler extends AbstractHandler implements IHandler{ 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 treeNodes = new HashSet(); @@ -85,17 +84,27 @@ public class DeleteHandler extends AbstractHandler implements IHandler{ 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){ - 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); @@ -111,6 +120,9 @@ 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?")){ + return null; + } if (allEditorsClosed){ operation = new DeleteOperation( event.getCommand().getName(), NavigationUtil.getUndoContext(), diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java index 49c6f7796..9cd017a22 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java @@ -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.jface.dialogs.MessageDialog; +import org.eclipse.ui.handlers.HandlerUtil; 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; - 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()); } - } + }*/ } else { try { service.deleteTaxonNodes(treeNodes, config); -- 2.34.1