X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/13c5d3f034d13a7ffa2d9e7a8e3d7bb0d2f0cc2a..e519dde1a4a6ef952db45d98086d259a39d3294d:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java index e44ad8f82..563b8a8a9 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java @@ -5,6 +5,7 @@ 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; @@ -13,7 +14,7 @@ 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.test.integration.SecurityExceptionUtils; import eu.etaxonomy.taxeditor.store.CdmStore; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; @@ -30,6 +31,9 @@ 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)."; 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 = "Problem accessing remote server"; + public static final String WIDGET_IS_DISPOSED_MESSAGE = "A widget was called, which was already disposed"; /** * Gets the Log4J logger for a given class @@ -192,6 +196,8 @@ public class MessagingUtils { contextInfo.add("editor version : " + version); contextInfo.add("server : " + server + " / " + name); 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; } @@ -216,6 +222,19 @@ public class MessagingUtils { return stackTraceAndContextInfo.toString(); } + public static String getContextInfo(List 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"); } @@ -237,14 +256,15 @@ public class MessagingUtils { final Throwable t, final List contextInfo, final String message, - final MultiStatus status) { + 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); + CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status, stackTraceWithContext, showReason); ced.open(); Class clazz = source != null ? source.getClass() : this.getClass(); @@ -259,6 +279,15 @@ public class MessagingUtils { }); } + 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}. * @@ -273,7 +302,8 @@ public class MessagingUtils { final String message, final String pluginId, final Throwable t, - boolean addContactMesg) { + boolean addContactMesg, + boolean showReason) { Throwable throwable = t; StringBuffer sbStackTrace = new StringBuffer(); @@ -293,21 +323,36 @@ public class MessagingUtils { throwable = getDefaultThrowable(); } - // add main execption - for (StackTraceElement ste : throwable.getStackTrace()) { - childStatuses.add(new Status(IStatus.ERROR, pluginId, "at " + ste.toString())); - } + int thCount = 0; + int maxTraces = 4; - // add cause - if(throwable.getCause() != null) { - childStatuses.add(new Status(IStatus.ERROR, pluginId, "")); - childStatuses.add(new Status(IStatus.ERROR, pluginId, "Caused by : " + throwable.getCause().toString())); - for (StackTraceElement ste : throwable.getCause().getStackTrace()) { - // build & add status - childStatuses.add(new Status(IStatus.ERROR, pluginId, "at " + ste.toString())); + 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()) { @@ -325,7 +370,7 @@ public class MessagingUtils { throwable.toString(), throwable); - errorDialog(title, source, throwable, contextInfo, finalMessage, ms); + errorDialog(title, source, throwable, contextInfo, finalMessage, ms, showReason); } /**