Improved error reporting
authorn.hoffmann <n.hoffmann@localhost>
Wed, 25 May 2011 14:28:17 +0000 (14:28 +0000)
committern.hoffmann <n.hoffmann@localhost>
Wed, 25 May 2011 14:28:17 +0000 (14:28 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java

index 99ea66efd06745e00588070de05bb7c50c291c4a..f57000631b4527cdb3bc8a23ee512d3d5e08b019 100644 (file)
@@ -51,6 +51,7 @@ import org.eclipse.ui.themes.IThemeManager;
 
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
 import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
@@ -162,8 +163,8 @@ public abstract class AbstractUtility {
                                        .getActivePage()
                                        .showView(id, null, IWorkbenchPage.VIEW_VISIBLE);
                } catch (PartInitException e) {
-                       error(AbstractUtility.class, "Could not open view: " + id, e);
-                       throw new RuntimeException(e);
+                       errorDialog("Error opening view", AbstractUtility.class, "Could not open view: " + id, e);
+                       return null;
                }
        }
 
@@ -354,11 +355,24 @@ public abstract class AbstractUtility {
                Display.getDefault().asyncExec(new Runnable() {
 
                        public void run() {
-                               MessageDialog.openError(getShell(), title, message);
+                               MessageDialog.openError(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 null;
+                               }
+                               
+                               if(t.getCause() != null){
+                                       return getCauseRecursively(t.getCause());
+                               }else{
+                                       return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
+                               }
+
+                       }
                });
        }
 
@@ -427,15 +441,17 @@ public abstract class AbstractUtility {
                        public void run(IProgressMonitor monitor)
                                        throws InvocationTargetException, InterruptedException {
                                monitor.beginTask(operation.getLabel(), 100);
-                               IStatus status;
+                               IStatus status = Status.CANCEL_STATUS;
                                try {
                                        operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
                                        status = getOperationHistory().execute(operation, monitor,
                                                        uiInfoAdapter);
                                } catch (ExecutionException e) {
-                                       throw new RuntimeException(e);
+                                       errorDialog("Error executing operation", getClass(), String.format("An error occured while executing %s.", operation.getLabel()), e);
+                               } finally {
+                                       monitor.done();
                                }
-                               monitor.done();
+                               
                                String statusString = status.equals(Status.OK_STATUS) ? "completed"
                                                : "cancelled";
                                setStatusLine(operation.getLabel() + " " + statusString + ".");
@@ -445,10 +461,8 @@ public abstract class AbstractUtility {
 
                try {
                        runInUI(runnable, null);
-               } catch (InvocationTargetException e) {
-                       throw new RuntimeException(e);
-               } catch (InterruptedException e) {
-                       throw new RuntimeException(e);
+               } catch (Exception e) {
+                       errorDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
                }
 
                // // Start the main progress monitor.