Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / operation / DeleteOperation.java
index 692c5ad87611391286c581a354f7d98137f8bdf8..a2fea97595d44cac993dbb5498591d26fc726f81 100644 (file)
@@ -90,42 +90,47 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
     }
 
 
-    /* (non-Javadoc)
-     * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
-     */
-    /** {@inheritDoc} */
-    @Override
-    public IStatus execute(IProgressMonitor monitor, IAdaptable info)
-            throws ExecutionException {
-
-        bind();
-        monitor.worked(20);
-        ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
-        ITaxonNodeService service = controller.getTaxonNodeService();
-        DeleteResult result;
-
-        if(taxonNode != null && taxonNode instanceof TaxonNode) {
 
-            element = ((TaxonNode)taxonNode).getTaxon();
-
-            result = service.deleteTaxonNode(taxonNode.getUuid(), config);
-            if (result.isError() || result.isAbort()){
-                MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
-            }
-
-        } else if(taxonNode != null && taxonNode instanceof Classification) {
-            Classification taxonomicTree = (Classification) taxonNode;
-            /*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;
-                                       }
-                               }*/
-
-            result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree.getUuid());
-            if (result.isError() || result.isAbort()){
-                MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
-            }
 
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+        */
+       /** {@inheritDoc} */
+       @Override
+       public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+                       throws ExecutionException {
+
+               bind();
+               monitor.worked(20);
+               ICdmApplicationConfiguration controller = CdmStore.getCurrentApplicationConfiguration();
+               ITaxonNodeService service = controller.getTaxonNodeService();
+                       if(taxonNode != null && taxonNode instanceof TaxonNode){
+                               //((TaxonNode) treeNode).delete();
+
+                               element = ((TaxonNode)taxonNode).getTaxon();
+
+                               DeleteResult result = service.deleteTaxonNode((TaxonNode)taxonNode, config);
+                               if (result.isError() && !result.getExceptions().isEmpty()){
+                                       //TODO:Error message!
+                                       MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
+                               } else if (!result.getExceptions().isEmpty()){
+                                       String separator = ", ";
+                                   String exceptionString = "";
+                                   for (Exception exception : result.getExceptions()) {
+                                   exceptionString += exception.getLocalizedMessage()+separator;
+                               }
+                                       MessageDialog.openInformation(null, "Delete of the node was successful but the taxon could not be deleted.", exceptionString);
+                               }
+
+
+                       }else if(taxonNode != null && taxonNode instanceof Classification){
+                               Classification taxonomicTree = (Classification) taxonNode;
+
+                               DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonomicTree.getUuid());
+                if (result.isError() && !result.getExceptions().isEmpty()){
+                    //TODO:Error message!
+                    MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
+                }
         } else {
             Set<UUID> treeNodeUuids = new HashSet<UUID>();
             ITaxonTreeNode entity = null;
@@ -136,10 +141,11 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
                 treeNodeUuids.add(treeNode.getUuid());
             }
 
-            result = service.deleteTaxonNodes(treeNodeUuids, config);
-            if (result.isError() || result.isAbort()){
-                MessageDialog.openError(null, "Delete failed", result.getExceptions().get(0).getMessage());
-            }
+            DeleteResult result = service.deleteTaxonNodes(treeNodeUuids, config);
+            if (result.isError() && !result.getExceptions().isEmpty()){
+                               //TODO:Error message!
+                               MessageDialog.openError(null, "Delete failed", result.getExceptions().iterator().next().getMessage());
+                       }
 
         }