added new error dialog for operations
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Sep 2014 12:27:38 +0000 (12:27 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Sep 2014 12:27:38 +0000 (12:27 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java

index a55a03de33824865111ca34a73e4c317c899628a..189827643df3b9ad7a77092bfb540e75e2e8fe80 100644 (file)
@@ -30,6 +30,7 @@ import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
@@ -146,7 +147,7 @@ public class MultiPageTaxonEditor extends FormEditor implements
             monitor.worked(1);            
         } catch (Exception e) {
             setFocus();
             monitor.worked(1);            
         } catch (Exception e) {
             setFocus();
-            MessagingUtils.operationDialog(this, e, "saving a taxon", " Please close and reopen the taxon again.");
+            MessagingUtils.operationDialog(this, e, TaxeditorEditorPlugin.PLUGIN_ID,"saving a taxon", " Please close and reopen the taxon again.");
             disableEditor(true);
         } finally {
             monitor.done();
             disableEditor(true);
         } finally {
             monitor.done();
index 2b8c4bbe8a527a62679f7837609eeab4f2479c07..2d21f05c071faad720ffdee9321fe36bda723f15 100644 (file)
@@ -10,9 +10,6 @@
 
 package eu.etaxonomy.taxeditor.model;
 
 
 package eu.etaxonomy.taxeditor.model;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -25,7 +22,6 @@ import org.eclipse.core.commands.operations.IOperationHistory;
 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.core.runtime.MultiStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Status;
@@ -56,7 +52,6 @@ import org.eclipse.ui.themes.ITheme;
 import org.eclipse.ui.themes.IThemeManager;
 
 import eu.etaxonomy.cdm.model.common.IEnumTerm;
 import org.eclipse.ui.themes.IThemeManager;
 
 import eu.etaxonomy.cdm.model.common.IEnumTerm;
-import eu.etaxonomy.cdm.persistence.hibernate.permission.SecurityExceptionUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
@@ -75,8 +70,9 @@ import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
  */
 public abstract class AbstractUtility {
 
  */
 public abstract class AbstractUtility {
 
-       /** Constant <code>statusLineManager</code> */
-       protected static IStatusLineManager statusLineManager;
+    /** Constant <code>statusLineManager</code> */
+    protected static IStatusLineManager statusLineManager;
+
 
        /**
         * <p>
 
        /**
         * <p>
@@ -318,7 +314,7 @@ public abstract class AbstractUtility {
                                                        uiInfoAdapter);
                                } catch (ExecutionException e) {
 
                                                        uiInfoAdapter);
                                } catch (ExecutionException e) {
 
-                                       MessagingUtils.operationDialog(this, e, operationlabel, null);
+                                       MessagingUtils.operationDialog(this, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
 
                                } finally {
                                        monitor.done();
 
                                } finally {
                                        monitor.done();
index 0e8e2c456115beb5d056246130d5ae3d4717d0d3..566fab4e923b1d36b6febebae75d4ca43d59c99e 100644 (file)
@@ -16,9 +16,9 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 /**
  * Utility class which handles all the messaging information generated by the
  * Editor.
 /**
  * Utility class which handles all the messaging information generated by the
  * Editor.
- * 
+ *
  * This includes logging as well as dialogs.
  * This includes logging as well as dialogs.
- * 
+ *
  * @author cmathew
  *
  */
  * @author cmathew
  *
  */
@@ -36,7 +36,7 @@ public class MessagingUtils {
        public static Logger getLog4JLogger(Class clazz) {
                return Logger.getLogger(clazz);
        }
        public static Logger getLog4JLogger(Class clazz) {
                return Logger.getLogger(clazz);
        }
-       
+
        /**
         * Logs details from a given Status object
         *
        /**
         * Logs details from a given Status object
         *
@@ -48,7 +48,7 @@ public class MessagingUtils {
        }
 
        /**
        }
 
        /**
-        * Logs a status object as information.  
+        * Logs a status object as information.
         *
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         *
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
@@ -58,7 +58,7 @@ public class MessagingUtils {
        }
 
        /**
        }
 
        /**
-        * Logs a string as information.         
+        * Logs a string as information.
         *
         * @param message
         *            a {@link java.lang.String} object.
         *
         * @param message
         *            a {@link java.lang.String} object.
@@ -69,8 +69,8 @@ public class MessagingUtils {
        }
 
        /**
        }
 
        /**
-        * Logs an exception from a given source as a warning.   
-        * 
+        * Logs an exception from a given source as a warning.
+        *
         * @param source
         * @param t
         */
         * @param source
         * @param t
         */
@@ -81,8 +81,8 @@ public class MessagingUtils {
        }
 
        /**
        }
 
        /**
-        * Logs a status object from a given source as a warning.        
-        * 
+        * Logs a status object from a given source as a warning.
+        *
         * @param source
         * @param status
         */
         * @param source
         * @param status
         */
@@ -92,8 +92,8 @@ public class MessagingUtils {
        }
 
        /**
        }
 
        /**
-        * Logs a string from a given source as a warning.       
-        * 
+        * Logs a string from a given source as a warning.
+        *
         *
         * @param source
         *            a {@link java.lang.Class} object.
         *
         * @param source
         *            a {@link java.lang.Class} object.
@@ -107,8 +107,8 @@ public class MessagingUtils {
        }
 
        /**
        }
 
        /**
-        * Logs a status object from a given source as an error.         
-        * 
+        * Logs a status object from a given source as an error.
+        *
         *
         * @param source
         *            a {@link java.lang.Class} object.
         *
         * @param source
         *            a {@link java.lang.Class} object.
@@ -122,8 +122,8 @@ public class MessagingUtils {
        }
 
        /**
        }
 
        /**
-        * Logs a string and exception from a given source as an error.  
-        * 
+        * Logs a string and exception from a given source as an error.
+        *
         *
         * @param source
         *            a {@link java.lang.Class} object.
         *
         * @param source
         *            a {@link java.lang.Class} object.
@@ -140,8 +140,8 @@ public class MessagingUtils {
 
 
        /**
 
 
        /**
-        * Logs an exception from a given source as an error.    
-        * 
+        * Logs an exception from a given source as an error.
+        *
         *
         * @param source
         *            a {@link java.lang.Class} object.
         *
         * @param source
         *            a {@link java.lang.Class} object.
@@ -162,15 +162,15 @@ public class MessagingUtils {
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         */
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         */
-       public static void errorDialog(final String title, 
-                       final Object source, 
-                       final String message, 
+       public static void errorDialog(final String title,
+                       final Object source,
+                       final String message,
                        final IStatus status) {
 
                Display.getDefault().asyncExec(new Runnable() {
 
                        @Override
                        final IStatus status) {
 
                Display.getDefault().asyncExec(new Runnable() {
 
                        @Override
-                       public void run() {             
+                       public void run() {
                                CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status);
                                ced.open();
                                Class<? extends Object> clazz = source != null ? source
                                CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status);
                                ced.open();
                                Class<? extends Object> clazz = source != null ? source
@@ -179,40 +179,40 @@ public class MessagingUtils {
                        }
                });
        }
                        }
                });
        }
-       
+
        /**
         * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
        /**
         * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
-        * 
+        *
         * @param title
         * @param source
         * @param message
         * @param pluginId
         * @param t
         */
         * @param title
         * @param source
         * @param message
         * @param pluginId
         * @param t
         */
-       public static void errorDialog(final String title, 
+       public static void errorDialog(final String title,
                        final Object source,
                        final String message,
                        final Object source,
                        final String message,
-                       final String pluginId,                  
+                       final String pluginId,
                        final Throwable t,
                        boolean addContactMesg) {
                // Usually the status contains only the first line of the stack trace.
                        final Throwable t,
                        boolean addContactMesg) {
                // Usually the status contains only the first line of the stack trace.
-               // For the unexpected messages we need the entire stack trace so we 
-               // create a new status with the entire stacktrace       
+               // For the unexpected messages we need the entire stack trace so we
+               // create a new status with the entire stacktrace
                StringWriter sw = new StringWriter();
                t.printStackTrace(new PrintWriter(sw));
                String finalMessage = t.getMessage();
                if(addContactMesg) {
                        finalMessage += MessagingUtils.CONTACT_MESSAGE;
                }
                StringWriter sw = new StringWriter();
                t.printStackTrace(new PrintWriter(sw));
                String finalMessage = t.getMessage();
                if(addContactMesg) {
                        finalMessage += MessagingUtils.CONTACT_MESSAGE;
                }
-               IStatus status = new Status(IStatus.ERROR, 
-                               pluginId, 
-                               finalMessage, 
-                               new Exception(sw.toString()));   
+               IStatus status = new Status(IStatus.ERROR,
+                               pluginId,
+                               finalMessage,
+                               new Exception(sw.toString()));
                errorDialog(title, source, message, status);
        }
                errorDialog(title, source, message, status);
        }
-       
 
 
-       
+
+
        /**
         * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
         *
        /**
         * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
         *
@@ -223,18 +223,18 @@ public class MessagingUtils {
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         */
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         */
-       public static void errorDialog(final String title, 
-                       final Object source, 
-                       final String message, 
+       public static void errorDialog(final String title,
+                       final Object source,
+                       final String message,
                        final IStatus status,
                        final IStatus status,
-                       final boolean showStackTrace) {             
-               if(showStackTrace && status.getException() != null) {                                           
+                       final boolean showStackTrace) {
+               if(showStackTrace && status.getException() != null) {
                        errorDialog(title, source,  status.getPlugin(), message, status.getException(),true);
                } else {
                        errorDialog(title, source, message, status);
                        errorDialog(title, source,  status.getPlugin(), message, status.getException(),true);
                } else {
                        errorDialog(title, source, message, status);
-               }                       
+               }
        }
        }
-       
+
 
        /**
         * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
 
        /**
         * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
@@ -250,11 +250,11 @@ public class MessagingUtils {
                        final IStatus status) {
                errorDialog(title, source, null, status);
        }
                        final IStatus status) {
                errorDialog(title, source, null, status);
        }
-       
+
        /**
         * Displays a dialog for an exception occurring in an operation.
        /**
         * Displays a dialog for an exception occurring in an operation.
-        * 
-        * This will be either a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog} in case of a 
+        *
+        * This will be either a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog} in case of a
         * security runtime exception or a warning {@link org.eclipse.jface.dialogs.MessageDialog} in
         * case of any other exception.
         *
         * security runtime exception or a warning {@link org.eclipse.jface.dialogs.MessageDialog} in
         * case of any other exception.
         *
@@ -265,18 +265,19 @@ public class MessagingUtils {
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         */
         * @param status
         *            a {@link org.eclipse.core.runtime.IStatus} object.
         */
-       public static void operationDialog(final Object source,                         
+       public static void operationDialog(final Object source,
                        final Exception ex,
                        final Exception ex,
-                       final String operationlabel, 
+                       final String pluginId,
+                       final String operationlabel,
                        final String hint) {
 
                Display.getDefault().asyncExec(new Runnable() {
 
                        @Override
                        final String hint) {
 
                Display.getDefault().asyncExec(new Runnable() {
 
                        @Override
-                       public void run() {             
+                       public void run() {
                                MultiStatus info = null;
                        String title = null;
                                MultiStatus info = null;
                        String title = null;
-                       
+
                        // FIXME cannot access TaxonomicEditorPlugin.PLUGIN_ID from here
                        // String PID = TaxonomicEditorPlugin.PLUGIN_ID;
                        String PID = "eu.etaxonomy.taxeditor.application";
                        // FIXME cannot access TaxonomicEditorPlugin.PLUGIN_ID from here
                        // String PID = TaxonomicEditorPlugin.PLUGIN_ID;
                        String PID = "eu.etaxonomy.taxeditor.application";
@@ -289,17 +290,17 @@ public class MessagingUtils {
                                title = "Your changes could not be saved!";
                                warningDialog(title, source, String.format("You are missing sufficient permissions for the operation \"%s\". %s", operationlabel, hint));
                        } else {
                                title = "Your changes could not be saved!";
                                warningDialog(title, source, String.format("You are missing sufficient permissions for the operation \"%s\". %s", operationlabel, hint));
                        } else {
-                               title = "Error executing operation";                            
-                               errorDialog(title, source, String.format("An error occured while executing %s. %s", operationlabel, hint), PID, ex, true);
-                               
+                               title = "Error executing operation";
+                               errorDialog(title, source, String.format("An error occured while executing %s. %s", operationlabel, hint), pluginId, ex, true);
+
                        }
                        }
-                       
-                       
+
+
                        }
                });
        }
                        }
                });
        }
-       
-       
+
+
 
 
        /**
 
 
        /**
@@ -317,15 +318,17 @@ public class MessagingUtils {
 
        /**
         * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
 
        /**
         * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
-        * 
+        *
         * @param title
         * @param source
         * @param message
         */
        public static void messageDialog(final String title, final Object source, final String message) {
         * @param title
         * @param source
         * @param message
         */
        public static void messageDialog(final String title, final Object source, final String message) {
-               MessagingUtils.messageDialog(title, source, message, null);
+               MessagingUtils.messageDialog(title, source, message, null, true);
        }
 
        }
 
+
+
        /**
         * Displays an error {@link org.eclipse.jface.dialogs.MessageDialog}.
         *
        /**
         * Displays an error {@link org.eclipse.jface.dialogs.MessageDialog}.
         *
@@ -340,36 +343,67 @@ public class MessagingUtils {
         * @param t
         *            a Throwable if one exists or null
         */
         * @param t
         *            a Throwable if one exists or null
         */
-       public static void messageDialog(final String title, final Object source,
-                       final String message, final Throwable t) {
-               Display.getDefault().asyncExec(new Runnable() {
-       
-                       @Override
-               public void run() {
-                               MessageDialog.openError(AbstractUtility.getShell(), title, message + getCauseRecursively(t));
-                               Class<? extends Object> clazz = source != null ? source
-                                               .getClass() : this.getClass();
-                               error(clazz, message, t);
-                       }
-       
-                       private String getCauseRecursively(Throwable t) {
-                               if(t == null){
-                                       return "";
-                               }
-       
-                               if(t.getCause() != null){
-                                       return getCauseRecursively(t.getCause());
-                               }else{
-                                       return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
-                               }
-       
-                       }
-               });
+       public static void messageDialog(final String title,
+               final Object source,
+                       final String message,
+                       final Throwable t) {
+           MessagingUtils.messageDialog(title, source, message, t, true);
        }
 
        }
 
+          /**
+     * Displays an error {@link org.eclipse.jface.dialogs.MessageDialog}.
+     *
+     * @param title
+     *            The dialogs title
+     * @param source
+     *            The object where the warning was generated (used by log4j)
+     * @param message
+     *            An informative String to be presented to the user
+     * @param title
+     *            The dialogs title
+     * @param t
+     *            a Throwable if one exists or null
+     */
+       public static void messageDialog(final String title,
+               final Object source,
+               final String message,
+               final Throwable t,
+               boolean async) {
+           if(async) {
+               Display.getDefault().asyncExec(new Runnable() {
+
+                   @Override
+                   public void run() {
+                       MessageDialog.openError(AbstractUtility.getShell(), title, message + getCauseRecursively(t));
+                       Class<? extends Object> clazz = source != null ? source
+                               .getClass() : this.getClass();
+                               error(clazz, message, t);
+                   }
+
+
+               });
+           } else {
+               MessageDialog.openError(AbstractUtility.getShell(), title, message + getCauseRecursively(t));
+               Class<? extends Object> clazz = source != null ? source.getClass() : TaxeditorStorePlugin.class;
+               error(clazz, message, t);
+           }
+       }
+
+    public static String getCauseRecursively(Throwable t) {
+        if(t == null){
+            return "";
+        }
+
+        if(t.getCause() != null){
+            return getCauseRecursively(t.getCause());
+        }else{
+            return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
+        }
+
+    }
        /**
         * Displays a warning {@link org.eclipse.jface.dialogs.MessageDialog}.
        /**
         * Displays a warning {@link org.eclipse.jface.dialogs.MessageDialog}.
-        * 
+        *
         * @param title
         * @param termBase
         * @param status
         * @param title
         * @param termBase
         * @param status
@@ -391,7 +425,7 @@ public class MessagingUtils {
         */
        public static void warningDialog(final String title, final Object source, final String message) {
                Display.getDefault().asyncExec(new Runnable() {
         */
        public static void warningDialog(final String title, final Object source, final String message) {
                Display.getDefault().asyncExec(new Runnable() {
-       
+
                        @Override
                public void run() {
                                MessageDialog.openWarning(AbstractUtility.getShell(), title, message);
                        @Override
                public void run() {
                                MessageDialog.openWarning(AbstractUtility.getShell(), title, message);
@@ -404,7 +438,7 @@ public class MessagingUtils {
 
        /**
         * Displays an information {@link org.eclipse.jface.dialogs.MessageDialog}.
 
        /**
         * Displays an information {@link org.eclipse.jface.dialogs.MessageDialog}.
-        * 
+        *
         * @param title
         * @param status
         */
         * @param title
         * @param status
         */
@@ -423,7 +457,7 @@ public class MessagingUtils {
        public static void informationDialog(final String title,
                        final String message) {
                Display.getDefault().asyncExec(new Runnable() {
        public static void informationDialog(final String title,
                        final String message) {
                Display.getDefault().asyncExec(new Runnable() {
-       
+
                        @Override
                public void run() {
                                MessageDialog.openInformation(AbstractUtility.getShell(), title, message);
                        @Override
                public void run() {
                                MessageDialog.openInformation(AbstractUtility.getShell(), title, message);