Merge branch 'develop' into taxonDescription
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / MessagingUtils.java
index 0e8e2c456115beb5d056246130d5ae3d4717d0d3..c8f1e26a37281f8c3c2262e62c95ff9d43b648d5 100644 (file)
@@ -2,445 +2,646 @@ package eu.etaxonomy.taxeditor.model;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
 
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.swt.widgets.Display;
 
-import eu.etaxonomy.cdm.persistence.hibernate.permission.SecurityExceptionUtils;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.config.ICdmSource;
+import eu.etaxonomy.cdm.test.integration.SecurityExceptionUtils;
+import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 
 /**
  * Utility class which handles all the messaging information generated by the
  * Editor.
- * 
+ *
  * This includes logging as well as dialogs.
- * 
+ *
  * @author cmathew
  *
  */
 public class MessagingUtils {
-       public final static String UNEXPECTED_ERROR_MESSAGE = "This is an unexpected error.";
-       public final static String CONTACT_MESSAGE = System.getProperty("line.separator") +  "Please contact EDIT Support (EditSupport@bgbm.org) with the error trace below (click on the 'Details' button).";
-
-       /**
-        * Gets the Log4J logger for a given class
-        *
-        * @param clazz
-        *            a {@link java.lang.Class} object.
-        * @return a {@link org.apache.log4j.Logger} object.
-        */
-       public static Logger getLog4JLogger(Class clazz) {
-               return Logger.getLogger(clazz);
-       }
-       
-       /**
-        * Logs details from a given Status object
-        *
-        * @param status
-        *                              a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       private static void log(IStatus status) {
-               TaxeditorStorePlugin.getDefault().getLog().log(status);
-       }
-
-       /**
-        * Logs a status object as information.  
-        *
-        * @param status
-        *            a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       public static void info(IStatus status) {
-               log(status);
-       }
-
-       /**
-        * Logs a string as information.         
-        *
-        * @param message
-        *            a {@link java.lang.String} object.
-        */
-       public static void info(String message) {
-               IStatus status = new Status(IStatus.INFO, AbstractUtility.getPluginId(), message);
-               info(status);
-       }
-
-       /**
-        * Logs an exception from a given source as a warning.   
-        * 
-        * @param source
-        * @param t
-        */
-       public static void warn(Class source, Throwable t) {
-               IStatus status = new Status(IStatus.WARNING, AbstractUtility.getPluginId(), t.getMessage(), t);
-               MessagingUtils.getLog4JLogger(source).warn(t);
-               log(status);
-       }
-
-       /**
-        * Logs a status object from a given source as a warning.        
-        * 
-        * @param source
-        * @param status
-        */
-       public static void warn(Class source, IStatus status) {
-               MessagingUtils.getLog4JLogger(source).warn(status.getMessage(), status.getException());
-               log(status);
-       }
-
-       /**
-        * Logs a string from a given source as a warning.       
-        * 
-        *
-        * @param source
-        *            a {@link java.lang.Class} object.
-        * @param message
-        *            a {@link java.lang.String} object.
-        */
-       public static void warn(Class source, String message) {
-               IStatus status = new Status(IStatus.WARNING, AbstractUtility.getPluginId(), message);
-               MessagingUtils.getLog4JLogger(source).warn(message);
-               log(status);
-       }
-
-       /**
-        * Logs a status object from a given source as an error.         
-        * 
-        *
-        * @param source
-        *            a {@link java.lang.Class} object.
-        * @param status
-        *            a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       public static void error(Class source, IStatus status) {
-               getLog4JLogger(source)
-                               .error(status.getMessage(), status.getException());
-               log(status);
-       }
-
-       /**
-        * Logs a string and exception from a given source as an error.  
-        * 
-        *
-        * @param source
-        *            a {@link java.lang.Class} object.
-        * @param message
-        *            a {@link java.lang.String} object.
-        * @param t
-        *            a {@link java.lang.Throwable} object.
-        */
-       public static void error(Class source, String message, Throwable t) {
-               IStatus status = new Status(IStatus.ERROR, AbstractUtility.getPluginId(), message, t);
-               error(source, status);
-       }
-
-
-
-       /**
-        * Logs an exception from a given source as an error.    
-        * 
-        *
-        * @param source
-        *            a {@link java.lang.Class} object.
-        * @param t
-        *            a {@link java.lang.Throwable} object.
-        */
-       public static void error(Class source, Throwable t) {
-               error(source.getClass(), t.getMessage(), t);
-       }
-
-       /**
-        * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
-        *
-        * @param title
-        *            a {@link java.lang.String} object.
-        * @param source
-        *            a {@link java.lang.Object} object.
-        * @param status
-        *            a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       public static void errorDialog(final String title, 
-                       final Object source, 
-                       final String message, 
-                       final IStatus status) {
-
-               Display.getDefault().asyncExec(new Runnable() {
-
-                       @Override
-                       public void run() {             
-                               CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status);
-                               ced.open();
-                               Class<? extends Object> clazz = source != null ? source
-                                               .getClass() : this.getClass();
-                                               error(clazz, status);
-                       }
-               });
-       }
-       
-       /**
-        * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
-        * 
-        * @param title
-        * @param source
-        * @param message
-        * @param pluginId
-        * @param t
-        */
-       public static void errorDialog(final String title, 
-                       final Object source,
-                       final String message,
-                       final String pluginId,                  
-                       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       
-               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()));   
-               errorDialog(title, source, message, status);
-       }
-       
-
-       
-       /**
-        * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
-        *
-        * @param title
-        *            a {@link java.lang.String} object.
-        * @param source
-        *            a {@link java.lang.Object} object.
-        * @param status
-        *            a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       public static void errorDialog(final String title, 
-                       final Object source, 
-                       final String message, 
-                       final IStatus status,
-                       final boolean showStackTrace) {             
-               if(showStackTrace && status.getException() != null) {                                           
-                       errorDialog(title, source,  status.getPlugin(), message, status.getException(),true);
-               } else {
-                       errorDialog(title, source, message, status);
-               }                       
-       }
-       
-
-       /**
-        * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
-        *
-        * @param title
-        *            a {@link java.lang.String} object.
-        * @param source
-        *            a {@link java.lang.Object} object.
-        * @param status
-        *            a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       public static void errorDialog(final String title, final Object source,
-                       final IStatus status) {
-               errorDialog(title, source, null, status);
-       }
-       
-       /**
-        * 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 
-        * security runtime exception or a warning {@link org.eclipse.jface.dialogs.MessageDialog} in
-        * case of any other exception.
-        *
-        * @param title
-        *            a {@link java.lang.String} object.
-        * @param source
-        *            a {@link java.lang.Object} object.
-        * @param status
-        *            a {@link org.eclipse.core.runtime.IStatus} object.
-        */
-       public static void operationDialog(final Object source,                         
-                       final Exception ex,
-                       final String operationlabel, 
-                       final String hint) {
-
-               Display.getDefault().asyncExec(new Runnable() {
-
-                       @Override
-                       public void run() {             
-                               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";
-
-                       // checking security exceptions for every operation
-                       RuntimeException securityRuntimeException = SecurityExceptionUtils.findSecurityRuntimeException(ex);
-
-                       // in case of a security exception it is a warning, else it is an error
-                       if(securityRuntimeException != null){
-                               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);
-                               
-                       }
-                       
-                       
-                       }
-               });
-       }
-       
-       
-
-
-       /**
-        * Displays a question {@link org.eclipse.jface.dialogs.MessageDialog}.
-        *
-        * @param title
-        *            a {@link java.lang.String} object.
-        * @param message
-        *            a {@link java.lang.String} object.
-        * @return a boolean.
-        */
-       public static boolean confirmDialog(String title, String message) {
-               return MessageDialog.openQuestion(AbstractUtility.getShell(), title, message);
-       }
-
-       /**
-        * 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) {
-               MessagingUtils.messageDialog(title, source, message, null);
-       }
-
-       /**
-        * 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) {
-               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());
-                               }
-       
-                       }
-               });
-       }
-
-       /**
-        * Displays a warning {@link org.eclipse.jface.dialogs.MessageDialog}.
-        * 
-        * @param title
-        * @param termBase
-        * @param status
-        */
-       public static void warningDialog(String title, Object source,
-                       IStatus status) {
-               MessagingUtils.warningDialog(title, source, status.getMessage());
-       }
-
-       /**
-        * Displays a warning {@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
-        */
-       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);
-                               Class<? extends Object> clazz = source != null ? source
-                                               .getClass() : AbstractUtility.class;
-                               warn(clazz, message);
-                       }
-               });
-       }
-
-       /**
-        * Displays an information {@link org.eclipse.jface.dialogs.MessageDialog}.
-        * 
-        * @param title
-        * @param status
-        */
-       public static void informationDialog(final String title, final IStatus status) {
-               MessagingUtils.informationDialog(title, status.getMessage());
-       }
-
-       /**
-        * Displays an information {@link org.eclipse.jface.dialogs.MessageDialog}.
-        *
-        * @param title
-        *            a {@link java.lang.String} object.
-        * @param message
-        *            a {@link java.lang.String} object.
-        */
-       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);
-                       }
-               });
-       }
-
-       /**
-        * Open a message box that informs the user about unimplemented
-        * functionality. This method is for developer convenience.
-        *
-        * @param source
-        *            a {@link java.lang.Object} object.
-        */
-       public static void notImplementedMessage(Object source) {
-               warningDialog("Not yet implemented", source,
-                               "This functionality is not yet implemented.");
-       }
+    public final static String UNEXPECTED_ERROR_MESSAGE = "This is an unexpected error.";
+    public final static String CONTACT_MESSAGE = System.getProperty("line.separator") +  "Please contact EDIT Support (EditSupport@bgbm.org) with the error trace below (click on the 'Details' button).";
+    public final static String DEFAULT_MESSAGE = "Error thrown but no associated message";
+    public final static String CONNECTION_FAILURE_MESSAGE = "The connection to the remote server has been broken";
+    public final static String REMOTE_ACCESS_FAILURE_MESSAGE = "Maybe the server is currently not available. If the problem persists please contact the server admin with the error trace below.";
+    public static final String WIDGET_IS_DISPOSED_MESSAGE = "A widget was called, which was already disposed";
+
+    /**
+     * Gets the Log4J logger for a given class
+     *
+     * @param clazz
+     *            a {@link java.lang.Class} object.
+     * @return a {@link org.apache.log4j.Logger} object.
+     */
+    public static Logger getLog4JLogger(Class clazz) {
+        return Logger.getLogger(clazz);
+    }
+
+    /**
+     * Logs details from a given Status object
+     *
+     * @param status
+     *                                 a {@link org.eclipse.core.runtime.IStatus} object.
+     */
+    private static void log(IStatus status) {
+        TaxeditorStorePlugin.getDefault().getLog().log(status);
+    }
+
+    /**
+     * Logs a status object as information.
+     *
+     * @param status
+     *            a {@link org.eclipse.core.runtime.IStatus} object.
+     */
+    public static void info(IStatus status) {
+        log(status);
+    }
+
+    /**
+     * Logs a string as information.
+     *
+     * @param message
+     *            a {@link java.lang.String} object.
+     */
+    public static void info(String message) {
+        IStatus status = new Status(IStatus.INFO, AbstractUtility.getPluginId(), message);
+        info(status);
+    }
+
+    /**
+     * Logs an exception from a given source as a warning.
+     *
+     * @param source
+     * @param t
+     */
+    public static void warn(Class source, Throwable t) {
+        IStatus status = new Status(IStatus.WARNING, AbstractUtility.getPluginId(), t.getMessage(), t);
+        MessagingUtils.getLog4JLogger(source).warn(t);
+        log(status);
+    }
+
+    /**
+     * Logs a status object from a given source as a warning.
+     *
+     * @param source
+     * @param status
+     */
+    public static void warn(Class source, IStatus status) {
+        MessagingUtils.getLog4JLogger(source).warn(status.getMessage(), status.getException());
+        log(status);
+    }
+
+    /**
+     * Logs a string from a given source as a warning.
+     *
+     *
+     * @param source
+     *            a {@link java.lang.Class} object.
+     * @param message
+     *            a {@link java.lang.String} object.
+     */
+    public static void warn(Class source, String message) {
+        IStatus status = new Status(IStatus.WARNING, AbstractUtility.getPluginId(), message);
+        MessagingUtils.getLog4JLogger(source).warn(message);
+        log(status);
+    }
+
+    /**
+     * Logs a status object from a given source as an error.
+     *
+     *
+     * @param source
+     *            a {@link java.lang.Class} object.
+     * @param status
+     *            a {@link org.eclipse.core.runtime.IStatus} object.
+     */
+    public static void error(Class source, IStatus status) {
+        getLog4JLogger(source)
+        .error(status.getMessage(), status.getException());
+        log(status);
+    }
+
+    /**
+     * Logs a string and exception from a given source as an error.
+     *
+     *
+     * @param source
+     *            a {@link java.lang.Class} object.
+     * @param message
+     *            a {@link java.lang.String} object.
+     * @param t
+     *            a {@link java.lang.Throwable} object.
+     */
+    public static void error(Class source, String message, Throwable t) {
+        IStatus status = new Status(IStatus.ERROR, AbstractUtility.getPluginId(), message, t);
+        error(source, status);
+    }
+
+
+
+    /**
+     * Logs an exception from a given source as an error.
+     *
+     *
+     * @param source
+     *            a {@link java.lang.Class} object.
+     * @param t
+     *            a {@link java.lang.Throwable} object.
+     */
+    public static void error(Class source, Throwable t) {
+        error(source.getClass(), t.getMessage(), t);
+    }
+
+
+
+    /**
+     * Returns a list of strings, providing info on,
+     *  - login
+     *  - editor version
+     *  - server (address + source name)
+     *  - db schema version
+     *
+     * @return
+     */
+    public static List<String> getContextInfo() {
+        List<String> contextInfo = new ArrayList<String>();
+        String name = "";
+        String contextPath = "";
+        String schemaVersion = "";
+        String server = "";
+        String version = "";
+        String login = "";
+        try {
+            version = Platform.getBundle("eu.etaxonomy.taxeditor.application").getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
+
+            ICdmSource activeCdmSource = CdmStore.getActiveCdmSource();
+            if(activeCdmSource != null ) {
+                login = CdmStore.getLoginManager().getAuthenticatedUser().getUsername();
+                name = activeCdmSource.getName();
+                schemaVersion = activeCdmSource.getDbSchemaVersion();
+                server = activeCdmSource.getServer();
+                if(activeCdmSource instanceof CdmRemoteSource){
+                    contextPath = ((CdmRemoteSource) activeCdmSource).getContextPath();
+                    if (contextPath != null && contextPath.startsWith("cdmserver/")){
+                       contextPath = contextPath.substring("cdmserver/".length());
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            // Nothing to do
+        }
+        contextInfo.add("login : " + login);
+        contextInfo.add("editor version : " + version);
+        contextInfo.add("server : " + server + " (" + name + ")" + (CdmUtils.isNotBlank(contextPath)?" / "+contextPath:""));
+        contextInfo.add("schema version : " + schemaVersion);
+        contextInfo.add("os : " + System.getProperty("os.name")+" "+System.getProperty("os.version")+" "+System.getProperty("os.arch"));
+        contextInfo.add("java : "+System.getProperty("java.version"));
+
+        return contextInfo;
+    }
+
+    public static String getStackTraceAndContextInfo(Throwable t, List<String> contextInfo)  {
+        StringBuffer stackTraceAndContextInfo = new StringBuffer();
+        Throwable throwable = t;
+
+        for(String infoItem : contextInfo) {
+            stackTraceAndContextInfo.append(infoItem + System.getProperty("line.separator"));
+        }
+
+        StringWriter sw = new StringWriter();
+
+        if(throwable == null) {
+            throwable = getDefaultThrowable();
+        }
+        throwable.printStackTrace(new PrintWriter(sw));
+
+        stackTraceAndContextInfo.append(sw.toString());
+
+        return stackTraceAndContextInfo.toString();
+    }
+
+    public static String getContextInfo(List<String> contextInfo)  {
+        StringBuffer scontextInfoStringBuffer = new StringBuffer();
+
+
+        for(String infoItem : contextInfo) {
+            scontextInfoStringBuffer.append(infoItem + System.getProperty("line.separator"));
+        }
+
+
+
+        return scontextInfoStringBuffer.toString();
+    }
+
+    private static Throwable getDefaultThrowable() {
+        return new Throwable("Error thrown but no associated exception");
+    }
+
+
+
+    /**
+     * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
+     *
+     * @param title
+     * @param source
+     * @param t
+     * @param contextInfo
+     * @param message
+     * @param status
+     */
+    private static void errorDialog(final String title,
+            final Object source,
+            final Throwable t,
+            final List<String> contextInfo,
+            final String message,
+            final MultiStatus status,
+            final boolean showReason) {
+
+        Display.getDefault().asyncExec(new Runnable() {
+
+            @Override
+            public void run() {
+                String stackTraceWithContext = getStackTraceAndContextInfo(t, contextInfo);
+                CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status, stackTraceWithContext, showReason);
+                ced.open();
+                Class<? extends Object> clazz = source != null ? source.getClass() : this.getClass();
+
+
+                IStatus singleStatus = new Status(IStatus.ERROR,
+                        status.getPlugin(),
+                        message,
+                        new Exception(stackTraceWithContext));
+
+                error(clazz, singleStatus);
+            }
+        });
+    }
+
+    public static void errorDialog(final String title,
+            final Object source,
+            final String message,
+            final String pluginId,
+            final Throwable t,
+            boolean addContactMesg) {
+        errorDialog(title, source, message, pluginId, t, addContactMesg, true);
+
+    }
+    /**
+     * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
+     *
+     * @param title
+     * @param source
+     * @param message
+     * @param pluginId
+     * @param t
+     */
+    public static void errorDialog(final String title,
+            final Object source,
+            final String message,
+            final String pluginId,
+            final Throwable t,
+            boolean addContactMesg,
+            boolean showReason) {
+
+        Throwable throwable = t;
+        StringBuffer sbStackTrace = new StringBuffer();
+
+        // We need to build a MultiStatus object since the simple
+        // idea of writing out the stack trace as a single string
+        // leads to a single line on windows
+        List<Status> childStatuses = new ArrayList<Status>();
+
+        // add context info
+        List<String> contextInfo = getContextInfo();
+        for(String infoItem : contextInfo) {
+            childStatuses.add(new Status(IStatus.ERROR, pluginId, infoItem));
+        }
+
+        if(throwable == null) {
+            throwable = getDefaultThrowable();
+        }
+
+        int thCount = 0;
+        int maxTraces = 4;
+
+        for(Throwable th : ExceptionUtils.getThrowables(throwable)) {
+            // add main exception
+            if(thCount == 0) {
+                for (StackTraceElement ste : th.getStackTrace()) {
+                    childStatuses.add(new Status(IStatus.ERROR, pluginId, "  at " + ste.toString()));
+                }
+            } else {
+                // add recursive causes
+                if(th != null) {
+                    childStatuses.add(new Status(IStatus.ERROR, pluginId, ""));
+                    String msg = th.toString();
+                    childStatuses.add(new Status(IStatus.ERROR, pluginId, "Caused by : " + msg));
+                    int traceCount = 0;
+                    for (StackTraceElement ste : th.getStackTrace()) {
+                        // add only pre-defined number of trace elements
+                        if(traceCount > maxTraces) {
+                            childStatuses.add(new Status(IStatus.ERROR, pluginId, "  ...."));
+                            break;
+                        }
+                        // build & add status
+                        childStatuses.add(new Status(IStatus.ERROR, pluginId, "  at " + ste.toString()));
+                        traceCount++;
+                    }
+                }
+            }
+            thCount++;
+        }
+        String finalMessage = message;
+
+        if(finalMessage == null || finalMessage.isEmpty()) {
+            finalMessage = DEFAULT_MESSAGE;
+        }
+
+        if(addContactMesg) {
+            // add edit support contact info to message
+            finalMessage += MessagingUtils.CONTACT_MESSAGE;
+        }
+
+        MultiStatus ms = new MultiStatus(pluginId,
+                IStatus.ERROR,
+                childStatuses.toArray(new Status[] {}),
+                throwable.toString(),
+                throwable);
+
+        errorDialog(title, source, throwable, contextInfo, finalMessage, ms, showReason);
+    }
+
+    /**
+     * 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
+     * security runtime exception or a warning {@link org.eclipse.jface.dialogs.MessageDialog} in
+     * case of any other exception.
+     *
+     * @param title
+     *            a {@link java.lang.String} object.
+     * @param source
+     *            a {@link java.lang.Object} object.
+     * @param status
+     *            a {@link org.eclipse.core.runtime.IStatus} object.
+     */
+    public static void operationDialog(final Object source,
+            final Exception ex,
+            final String pluginId,
+            final String operationlabel,
+            final String hint) {
+
+        Display.getDefault().asyncExec(new Runnable() {
+
+            @Override
+            public void run() {
+                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";
+
+                // checking security exceptions for every operation
+                RuntimeException securityRuntimeException = SecurityExceptionUtils.findSecurityRuntimeException(ex);
+
+                // in case of a security exception it is a warning, else it is an error
+                if(securityRuntimeException != null){
+                    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 occurred while executing %s. %s", operationlabel, hint), pluginId, ex, true);
+
+                }
+
+
+            }
+        });
+    }
+
+
+
+
+    /**
+     * Displays a question {@link org.eclipse.jface.dialogs.MessageDialog}.
+     *
+     * @param title
+     *            a {@link java.lang.String} object.
+     * @param message
+     *            a {@link java.lang.String} object.
+     * @return a boolean.
+     */
+    public static boolean confirmDialog(String title, String message) {
+        return MessageDialog.openQuestion(AbstractUtility.getShell(), title, message);
+    }
+
+    public static int confirmDialog(String title, String message, String...labels){
+        MessageDialog dialog =new MessageDialog(AbstractUtility.getShell(), title, null, message, MessageDialog.QUESTION,labels, 0);
+        int result = dialog.open();
+        return result;
+    }
+
+    /**
+     * 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) {
+        MessagingUtils.messageDialog(title, source, message, null, 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) {
+        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}.
+     *
+     * @param title
+     * @param termBase
+     * @param status
+     */
+    public static void warningDialog(String title, Object source,
+            IStatus status) {
+        MessagingUtils.warningDialog(title, source, status.getMessage());
+    }
+
+    /**
+     * Standard warning dialog for the case when the application is not yet connected to the datasource
+     *
+     * @param source
+     */
+    public static void noDataSourceWarningDialog(Object source) {
+        MessagingUtils
+        .warningDialog(
+                "Application is not connected to a datastore",
+                source,
+                "The requested operation is only available when "
+                + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
+    }
+
+    /**
+     * Standard warning dialog for the case when the datasource is not available
+     *
+     * @param source
+     */
+    public static void dataSourceNotAvailableWarningDialog(Object source) {
+        MessagingUtils
+        .warningDialog(
+                "The datasource is not available",
+                source,
+                "The editor is not connected to a datasource. Maybe the datasource is not available.");
+    }
+
+
+    /**
+     * Displays a warning {@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
+     */
+    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);
+                Class<? extends Object> clazz = source != null ? source
+                        .getClass() : AbstractUtility.class;
+                        warn(clazz, message);
+            }
+        });
+    }
+
+    /**
+     * Displays an information {@link org.eclipse.jface.dialogs.MessageDialog}.
+     *
+     * @param title
+     * @param status
+     */
+    public static void informationDialog(final String title, final IStatus status) {
+        MessagingUtils.informationDialog(title, status.getMessage());
+    }
+
+    /**
+     * Displays an information {@link org.eclipse.jface.dialogs.MessageDialog}.
+     *
+     * @param title
+     *            a {@link java.lang.String} object.
+     * @param message
+     *            a {@link java.lang.String} object.
+     */
+    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);
+            }
+        });
+    }
+
+    /**
+     * Open a message box that informs the user about unimplemented
+     * functionality. This method is for developer convenience.
+     *
+     * @param source
+     *            a {@link java.lang.Object} object.
+     */
+    public static void notImplementedMessage(Object source) {
+        warningDialog("Not yet implemented", source,
+                "This functionality is not yet implemented.");
+    }
 
 }