You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/07/20 10:05:29 UTC

svn commit: r557917 - /incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/RunnableAction.java

Author: twgoetz
Date: Fri Jul 20 01:05:27 2007
New Revision: 557917

URL: http://svn.apache.org/viewvc?view=rev&rev=557917
Log:
Jira UIMA-481: apply UIMA-481.patch.

https://issues.apache.org/jira/browse/UIMA-481

Modified:
    incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/RunnableAction.java

Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/RunnableAction.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/RunnableAction.java?view=diff&rev=557917&r1=557916&r2=557917
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/RunnableAction.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/RunnableAction.java Fri Jul 20 01:05:27 2007
@@ -19,88 +19,88 @@
 
 package org.apache.uima.caseditor.ui.action;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
 import java.lang.reflect.InvocationTargetException;
 
-import org.apache.uima.UIMAException;
 import org.apache.uima.caseditor.CasEditorPlugin;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.util.Assert;
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.progress.IProgressService;
 
 /**
- * TODO: add javadoc here
+ * This class executes a {@link IRunnableWithProgress} runnable.
  */
-public class RunnableAction extends Action
-{
-    private Shell mShell;
-    private IRunnableWithProgress mRunnable;
-    private String mName;
-    
-    /**
-     * Initializes a new instance.
-     * 
-     * @param shell
-     * @param name
-     * @param runnable
-     */
-    public RunnableAction(Shell shell, String name, IRunnableWithProgress runnable)
-    {
-        Assert.isNotNull(shell);
-        mShell = shell;
-        
-        Assert.isNotNull(name);
-        mName = name;
-        setText(name);
-        
-        Assert.isNotNull(runnable);
-        mRunnable = runnable;
+public class RunnableAction extends Action {
+  
+  private Shell mShell;
+
+  private IRunnableWithProgress mRunnable;
+
+  private String mName;
+
+  /**
+   * Initializes a new instance.
+   * 
+   * @param shell
+   * @param name
+   * @param runnable
+   */
+  public RunnableAction(Shell shell, String name, IRunnableWithProgress runnable) {
+    Assert.isNotNull(shell);
+    mShell = shell;
+
+    Assert.isNotNull(name);
+    mName = name;
+    setText(name);
+
+    Assert.isNotNull(runnable);
+    mRunnable = runnable;
+  }
+
+  @Override
+  public void run() {
+    IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
+
+    try {
+      progressService.run(true, false, mRunnable);
+    } catch (InvocationTargetException e) {
+
+      Status status = new Status(IStatus.ERROR, CasEditorPlugin.ID, 0, getRootCauseStackTrace(e), 
+              null);
+
+      ErrorDialog.openError(mShell, "Unexpected exception in " + mName,
+              "Unexpected exception!", status);
+      
+    } catch (InterruptedException e) {
+      // task terminated ... just ignore
     }
-    
-    @Override
-    public void run()
-    {
-        IProgressService progressService = PlatformUI.getWorkbench()
-                .getProgressService();
-
-        try
-        {
-            progressService.run(true, false, mRunnable);
-        }
-        catch (InvocationTargetException e)
-        {
-            Throwable cause = e.getCause();
-            
-            Status status;
-            // TODO: Workarround for UIMAException problems ...
-            if (cause instanceof UIMAException)
-            {
-                UIMAException uimaException = (UIMAException) cause;
-                
-                Object[] argument = uimaException.getArguments();
-                
-                    status = new Status(IStatus.ERROR, CasEditorPlugin.ID, 0,
-                            argument.length > 0 ? argument[0].toString() : 
-                            "Unkown error, see log.", cause);
-            }
-            else
-            {
-                status = new Status(IStatus.ERROR, CasEditorPlugin.ID, 0,
-                        cause.getMessage() != null ? cause.getMessage() : 
-                            "Unkown error, see log.", cause);
-            }
-            
-            ErrorDialog.openError(mShell, "Unexpected exception in " + 
-                    mName, null, status);            
-        }
-        catch (InterruptedException e)
-        {
-            // task terminated ... just ignore
-        }
+  }
+
+  public String getRootCauseStackTrace(Throwable e) {
+
+    StringBuffer b = new StringBuffer(200);
+
+    Throwable cur = e;
+    Throwable next;
+
+    while (null != (next = cur.getCause())) {
+      cur = next;
     }
+
+    ByteArrayOutputStream ba = new ByteArrayOutputStream();
+    PrintStream ps = new PrintStream(ba);
+    cur.printStackTrace(ps);
+    ps.flush();
+    b.append(ba.toString());
+    ps.close();
+
+    return b.toString();
+  }
 }