summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-09-12 21:02:52 (EDT)
committer pelder2007-09-12 21:02:52 (EDT)
commit360d0381f74cd346df5f25de067d69f4543f8db9 (patch)
tree9ef3bd3ccd141340d5da237318f132780a73872a
parente317678035f7dc94801659da60ea29f504c08910 (diff)
downloadorg.eclipse.jet-360d0381f74cd346df5f25de067d69f4543f8db9.zip
org.eclipse.jet-360d0381f74cd346df5f25de067d69f4543f8db9.tar.gz
org.eclipse.jet-360d0381f74cd346df5f25de067d69f4543f8db9.tar.bz2
[203181] Improve robustness of getShellContext() when SWT fails to start on linux/gtk
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java50
1 files changed, 28 insertions, 22 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
index 588e401..8caacd7 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/JET2Platform.java
@@ -61,7 +61,6 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IRegion;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.BundleException;
@@ -91,41 +90,48 @@ public class JET2Platform
/**
* Return the value of the shell context, suitable for passing to
* {@link TransformContextExtender#setShellContext(Object)}.
- * This method will work, even in the abscences of a shell or even SWT.
+ * This method will work, even in the abscence of a shell or even SWT.
* @return the shell context or <code>null</code> if none is set
*/
public static final Object getShellContext()
{
+ final Object shell[] = { null };
try
{
- Display display = Display.getDefault();
- final Shell[] shell = new Shell []{ null };
- display.syncExec(new Runnable()
+ // use a runnable to defer class loading of PlatformUI and Display until the runnable is instantiated.
+ Runnable runnable = new Runnable()
+ {
+
+ public void run()
{
-
- public void run()
+ if (PlatformUI.isWorkbenchRunning())
{
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- shell[0] = activeWorkbenchWindow != null ? activeWorkbenchWindow.getShell() : null;
+ Display.getDefault().asyncExec(new Runnable()
+ {
+
+ public void run()
+ {
+ final IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (activeWorkbenchWindow != null)
+ {
+ shell[0] = activeWorkbenchWindow.getShell();
+ }
+ }
+ });
}
- });
- return shell[0];
+ }
+
+ };
+ runnable.run();
+
}
catch (NoClassDefFoundError e)
{
// happens if swt or platform core plug-ins are not present, and Display, Shell or PlatformUI cannot be loaded
- return null;
- }
- catch (IllegalStateException e)
- {
- // happens when PlatformUI.getWorkbench() is called in a headless launch
- return null;
- }
- catch (UnsatisfiedLinkError e)
- {
- // happens on linux/GTK during Display init when headless.
- return null;
+ // ignore
}
+
+ return shell[0];
}
/**