+ /**
+ * 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());
+ }
+
+ }