1 11 12 package org.eclipse.ui.internal; 13 14 import org.eclipse.ui.PartInitException; 15 import org.eclipse.ui.WorkbenchException; 16 import org.eclipse.ui.internal.misc.StatusUtil; 17 18 22 public final class StartupThreading { 23 24 static Workbench workbench; 25 26 public static abstract class StartupRunnable implements Runnable { 27 private Throwable throwable; 28 29 public final void run() { 30 try { 31 runWithException(); 32 } catch (Throwable t) { 33 this.throwable = t; 34 } 35 } 36 37 public abstract void runWithException() throws Throwable ; 38 39 public Throwable getThrowable() { 40 return throwable; 41 } 42 } 43 44 static void setWorkbench(Workbench wb) { 45 workbench = wb; 46 } 47 48 public static void runWithWorkbenchExceptions(StartupRunnable r) 49 throws WorkbenchException { 50 workbench.getDisplay().syncExec(r); 51 Throwable throwable = r.getThrowable(); 52 if (throwable != null) { 53 if (throwable instanceof Error ) { 54 throw (Error ) throwable; 55 } else if (throwable instanceof RuntimeException ) { 56 throw (RuntimeException ) throwable; 57 } else if (throwable instanceof WorkbenchException) { 58 throw (WorkbenchException) throwable; 59 } else { 60 throw new WorkbenchException(StatusUtil.newStatus( 61 WorkbenchPlugin.PI_WORKBENCH, throwable)); 62 } 63 } 64 } 65 66 public static void runWithPartInitExceptions(StartupRunnable r) 67 throws PartInitException { 68 workbench.getDisplay().syncExec(r); 69 Throwable throwable = r.getThrowable(); 70 if (throwable != null) { 71 if (throwable instanceof Error ) { 72 throw (Error ) throwable; 73 } else if (throwable instanceof RuntimeException ) { 74 throw (RuntimeException ) throwable; 75 } else if (throwable instanceof WorkbenchException) { 76 throw (PartInitException) throwable; 77 } else { 78 throw new PartInitException(StatusUtil.newStatus( 79 WorkbenchPlugin.PI_WORKBENCH, throwable)); 80 } 81 } 82 } 83 84 public static void runWithThrowable(StartupRunnable r) throws Throwable { 85 workbench.getDisplay().syncExec(r); 86 Throwable throwable = r.getThrowable(); 87 if (throwable != null) { 88 throw throwable; 89 } 90 } 91 92 public static void runWithoutExceptions(StartupRunnable r) 93 throws RuntimeException { 94 workbench.getDisplay().syncExec(r); 95 Throwable throwable = r.getThrowable(); 96 if (throwable != null) { 97 if (throwable instanceof Error ) { 98 throw (Error ) throwable; 99 } else if (throwable instanceof RuntimeException ) { 100 throw (RuntimeException ) throwable; 101 } else { 102 throw new RuntimeException (throwable); 103 } 104 } 105 } 106 107 } 108 | Popular Tags |