How does my plugin know if it's running headless? [message #318205] |
Mon, 23 July 2007 12:36  |
Eclipse User |
|
|
|
Hello,
I'm writing a plugin that can be used in both headless applications as
well as Eclipse with full UI; at some places (e.g. user interaction) it
should behave differently when running headless or running with UI.
Is there a commonly accepted technique for knowing whether the current
application is headless or not?
What I'm currently trying is this:
Bundle swtBundle = null;
BundleContext ctx =
Activator.getDefault().getBundle().getBundleContext();
Bundle[] bundles = ctx.getBundles();
for (int i=0; i<bundles.length; i++) {
if ("org.eclipse.swt".equals(bundles[i].getSymbolicName())) {
if (swtBundle==null || bundles[i].getState()==Bundle.ACTIVE) {
swtBundle = bundles[i];
}
}
}
if (swtBundle==null) {
System.out.println("HEADLESS detected!");
}
Does that make sense?
Thanks,
--
Martin Oberhuber
Target Management Project Lead, DSDP PMC Member
http://www.eclipse.org/dsdp/tm
|
|
|
|
|
|
|
|
Re: How does my plugin know if it's running headless? [message #318321 is a reply to message #318309] |
Wed, 25 July 2007 14:17  |
Eclipse User |
|
|
|
Martin Oberhuber wrote:
> FYI,
>
> zx cross-posted this question on his blog at
> http://mea-bloga.blogspot.com/2007/07/am-i-headless.html
> and some commenters said that the check were not appropriate
> in some cases.
>
> I guess that in fact a really correct check depends on what you want to
> accomplish in your headless application. Some headless apps like a
> graphics converter may want SWT for some tasks even if there is no
> display and no window. Others might use a different UI toolkit than SWT.
Like you mentioned, you could "move up" the hierarchy, then.
org.eclipse.ui.workbench is where most of the PlatformUI code resides.
If that's not active, you are definitely not running a workbench :-) If
it is active, you could query your isWorkbenchRunning().
Later,
PW
|
|
|
Powered by
FUDForum. Page generated in 0.03504 seconds