improve messaging for deleteresults
authorKatja Luther <k.luther@bgbm.org>
Wed, 7 Oct 2015 12:13:48 +0000 (14:13 +0200)
committerKatja Luther <k.luther@bgbm.org>
Wed, 7 Oct 2015 12:13:48 +0000 (14:13 +0200)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteSynonymOperation.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/DeleteTaxonOperation.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/CdmErrorDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DeleteResultMessagingUtils.java

index 49aaed0..3f15c4f 100644 (file)
@@ -154,7 +154,7 @@ public class DeleteHandler extends AbstractHandler {
                                                        messages.add(e.getMessage());
                                                }
                                                errorMessage += "could not be deleted.";
-
+                                               //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
                                                DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
                                        }else{
                                                MessagingUtils.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
@@ -168,7 +168,8 @@ public class DeleteHandler extends AbstractHandler {
                         for (Exception e:result.getExceptions()){
                             messages.add(e.getMessage());
                         }
-                                           errorMessage += "was deleted but there where updated objects";
+                                           errorMessage += "was deleted but related object(s) could not be deleted. ";
+                                           //MessagingUtils.errorDialog("test", getClass(), "message", TaxeditorBulkeditorPlugin.PLUGIN_ID, result.getExceptions().iterator().next(),true);
                                            DeleteResultMessagingUtils.messageDialogWithDetails(result, errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
                                        }
 
index b21efef..00d27bf 100644 (file)
@@ -16,7 +16,6 @@ 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 eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.service.DeleteResult;
@@ -24,6 +23,8 @@ import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
+import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -81,9 +82,9 @@ public class DeleteSynonymOperation extends AbstractPostTaxonOperation {
 
                                        DeleteResult result = service.deleteSynonym(synonym.getUuid(), element.getUuid(), null);
                                        if (result.isError()){
-                                               MessageDialog.openError(null, "Delete failed", result.toString());
+                                               DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID);
                                        } else if (!result.getUpdatedObjects().isEmpty()){
-                                               MessageDialog.openInformation(null, "Delete successfull", "The Synonym could be deleted, but there is an updated object: " + result.toString());
+                                           DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Synonym could be deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID);
                                        }
                                }
                        //      taxon.removeSynonym(synonym);
index b22c6b6..48632e4 100644 (file)
@@ -8,7 +8,6 @@ import org.eclipse.core.commands.operations.IUndoContext;
 import org.eclipse.core.runtime.IAdaptable;\r
 import org.eclipse.core.runtime.IProgressMonitor;\r
 import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
 import org.eclipse.ui.IWorkbenchPage;\r
 \r
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
@@ -19,7 +18,8 @@ import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 import eu.etaxonomy.cdm.model.taxon.Classification;\r
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
-import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
+import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;\r
+import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;\r
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;\r
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;\r
 import eu.etaxonomy.taxeditor.store.CdmStore;\r
@@ -75,9 +75,9 @@ public class DeleteTaxonOperation extends DeleteTaxonBaseOperation{
                                DeleteResult result =   service.deleteTaxon(element.getUuid(), configurator, classification.getUuid());\r
 
                                if (result.isError()){\r
-                                       MessageDialog.openError(null, "Delete failed", result.toString());\r
+                                   DeleteResultMessagingUtils.messageDialogWithDetails(result, "Delete failed", TaxeditorEditorPlugin.PLUGIN_ID);\r
                                } else if (!result.getUpdatedObjects().isEmpty()){\r
-                                       MessagingUtils.informationDialog("Delete successfull", result.toString());\r
+                    DeleteResultMessagingUtils.messageDialogWithDetails(result, "The Taxon was deleted, but related object(s) could not be deleted", TaxeditorEditorPlugin.PLUGIN_ID);\r
                                }\r
 \r
                                monitor.worked(40);\r
index a2fea97..cd0fbef 100644 (file)
@@ -19,7 +19,6 @@ 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 eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
@@ -31,6 +30,8 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 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.model.DeleteResultMessagingUtils;
+import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
 import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
@@ -111,15 +112,15 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
 
                                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());
+
+                                       DeleteResultMessagingUtils.messageDialogWithDetails(result, "TaxonNode could not be deleted.", TaxeditorNavigationPlugin.PLUGIN_ID);
                                } 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);
+                                   DeleteResultMessagingUtils.messageDialogWithDetails(result, "TaxonNode was successfully deleted, but related object(s) could not be deleted", TaxeditorNavigationPlugin.PLUGIN_ID);
                                }
 
 
@@ -129,7 +130,7 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
                                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());
+                    DeleteResultMessagingUtils.messageDialogWithDetails(result, "TaxonNode could not be deleted.", TaxeditorNavigationPlugin.PLUGIN_ID);
                 }
         } else {
             Set<UUID> treeNodeUuids = new HashSet<UUID>();
@@ -144,7 +145,7 @@ public class DeleteOperation extends AbstractPersistentPostOperation{
             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());
+                DeleteResultMessagingUtils.messageDialogWithDetails(result, "TaxonNode could not be deleted.", TaxeditorNavigationPlugin.PLUGIN_ID);
                        }
 
         }
index 9d33e2a..087fa83 100644 (file)
@@ -53,6 +53,26 @@ public       class CdmErrorDialog extends ErrorDialog {
                 message, status,
                 IStatus.OK| IStatus.INFO | IStatus.WARNING | IStatus.ERROR);
         this.stackTrace = stackTrace;
+
+
+    }
+
+    /**
+     * @param parentShell
+     * @param dialogTitle
+     * @param message
+     * @param status
+     * @param stackTrace
+     */
+    public CdmErrorDialog(Shell parentShell,
+            String dialogTitle,
+            String message,
+            IStatus status,
+            String stackTrace,
+            Object[] updatedObjects) {
+        this(parentShell, dialogTitle, message, status, stackTrace);
+        this.message = message == null ? status.getMessage()
+                : message + "\n " + status.getMessage(); //$NON-NLS-1$
     }
 
     /**
@@ -136,4 +156,6 @@ public      class CdmErrorDialog extends ErrorDialog {
                        new Transfer[] { TextTransfer.getInstance() });
            }
        }
+
+
 }
index ef473c3..8e46d48 100644 (file)
 package eu.etaxonomy.taxeditor.model;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 
 import eu.etaxonomy.cdm.api.service.DeleteResult;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
 
 /**
  * @author k.luther
@@ -37,14 +40,40 @@ public class DeleteResultMessagingUtils extends MessagingUtils {
         List<String> details = new ArrayList<String>();
         String title= "";
 
-        if (result.isOk() && result.getExceptions().size() > 0){
+        if (result.getExceptions().size() > 0){
             for (Exception e:result.getExceptions()){
                 details.add(e.getMessage());
             }
-            title = "The delete was successfull.";
+            if (result.isOk()){
+                title = "Delete was successfull.";
+            } else {
+                title = "Delete was aborted.";
+            }
+        }
+        StringBuffer relatedObjectsString = new StringBuffer();
+        List<String> relatedObjects = new ArrayList<String>();
+        if (result.getUpdatedObjects().size() > 0){
+            Iterator<CdmBase> objects = result.getRelatedObjects().iterator();
+            while (objects.hasNext()){
+                CdmBase object = objects.next();
+                if (object instanceof IdentifiableEntity){
+                    relatedObjects.add("[" + object.getClass().getSimpleName() + "] " +((IdentifiableEntity)object).getTitleCache() );
+                } else{
+                    relatedObjects.add(object.getUserFriendlyTypeName());
+                }
+
+            }
+
+            for (String relatedObject: relatedObjects){
+
+                relatedObjectsString.append(relatedObject);
+                relatedObjectsString.append("\n");
+            }
         }
+        message = message + "\n" ;
         String stackTraceWithContext = getContextInfo(details);
-        CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, new Status(IStatus.ERROR, pluginId, null), stackTraceWithContext);
+        CdmDeleteErrorDialog ced = new CdmDeleteErrorDialog(AbstractUtility.getShell(), title, message,new Status(IStatus.INFO, pluginId, relatedObjectsString.toString(), result.getExceptions().iterator().next()), stackTraceWithContext, result.getUpdatedObjects().toArray());
+
         ced.open();