Home » Eclipse Projects » Eclipse Platform » How to add DirectoryDialog to InstallHandler Classpath?
How to add DirectoryDialog to InstallHandler Classpath? [message #222049] |
Mon, 05 April 2004 12:03  |
Eclipse User |
|
|
|
Originally posted by: cjammer.earthlink.net
If I write a custom install handler and I wish to use a class such as
DirectoryDialog, how would I get eclipse to load the org.eclipse.swt
plugin?
Adding this to the requires tag in feature.xml doesn't seem to do the
trick.
|
|
| |
Re: How to add DirectoryDialog to InstallHandler Classpath? [message #223264 is a reply to message #222062] |
Tue, 06 April 2004 19:22   |
Eclipse User |
|
|
|
Originally posted by: cjammer.earthlink.net
dorian birsan wrote:
> "Clinton Jammer" <cjammer@earthlink.net> wrote in message
> news:c4s01c$28t$1@eclipse.org...
> > If I write a custom install handler and I wish to use a class such as
> > DirectoryDialog, how would I get eclipse to load the org.eclipse.swt
> > plugin?
> Do you have a plugin already running?
> If yes, then use the handler extension point and make the feature.xml use
> the handler that's already in your plugin. Also, have your plugin <require>
> swt, so the handler has access to it.
> If not, use the plugin registry to get to the swt plugin class loader, and
> use java reflection api's to do what you need.
> -Dorian
> >
> > Adding this to the requires tag in feature.xml doesn't seem to do the
> > trick.
> >
Dorian,
Thanks for responding. I'm installing my plugin as part of a feature
using the Eclipse Update / Install Manager. The end user defines a site
bookmark, which points to my feature. My custom install handler loads,
but it appears to be running in a limited environment without most Eclipse
classes available to it. At this point, I'm at the mercy of the Eclipse
classloader, it seems.
I was a bit confused by your question. How can I be running my plugin if
I am trying to install it?
I did attempt your suggestion of using PluginRegistry to get a
classloader. Unfortuantely, I still get the ClassNotFoundException.
Perhaps you could post a code example? My code and exception follows:
try {
// Prompt the user
IPluginDescriptor pluginDescriptor =
Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.swt ");
if (pluginDescriptor != null) {
ClassLoader classLoader = pluginDescriptor.getPluginClassLoader();
Shell shell = (Shell) classLoader.loadClass("Shell").newInstance();
classLoader.loadClass("DirectoryDialog");
DirectoryDialog directoryDialog = new DirectoryDialog(shell);
directoryDialog.setFilterPath(flexDirectory);
directoryDialog.setMessage("Select the MacroMedia Flex
directory.");
flexDirectory = directoryDialog.open();
}
} catch (Exception e) {
e.printStackTrace();
}
java.lang.NoClassDefFoundError: org.eclipse.swt.widgets.Shell
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.NoClassDefFoundError.<init>(NoClassDefFoundError.java:57)
at java.lang.Class.verifyImpl(Native Method)
at java.lang.Class.verify(Class.java)
at java.lang.Class.initialize(Class.java)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java)
at
org.eclipse.update.internal.core.InstallHandlerProxy.getLoca lHandler(InstallHandlerProxy.java:501)
at
org.eclipse.update.internal.core.InstallHandlerProxy.initial ize(InstallHandlerProxy.java:101)
at
org.eclipse.update.internal.core.InstallHandlerProxy.<init>(InstallHandlerProxy.java:57)
at org.eclipse.update.core.Feature.install(Feature.java:255)
at org.eclipse.update.internal.core.SiteFile.install(SiteFile.j ava:74)
at
org.eclipse.update.internal.core.ConfiguredSite.install(Conf iguredSite.java:194)
at
org.eclipse.update.internal.core.ConfiguredSite.install(Conf iguredSite.java:159)
at
org.eclipse.update.internal.ui.wizards.InstallWizard.execute (InstallWizard.java:211)
at
org.eclipse.update.internal.ui.wizards.InstallWizard.access$ 3(InstallWizard.java:193)
at
org.eclipse.update.internal.ui.wizards.InstallWizard$1.run(I nstallWizard.java:93)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:101)
|
|
|
Re: How to add DirectoryDialog to InstallHandler Classpath? [message #223341 is a reply to message #223264] |
Tue, 06 April 2004 21:43   |
Eclipse User |
|
|
|
Originally posted by: dorian.birsan.net
First, don't use Shell as a class, because it won't be resolved. Use java
reflection classes.
The code should be more like:
try {
// Prompt the user
IPluginDescriptor pluginDescriptor =
Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.swt ");
if (pluginDescriptor != null) {
ClassLoader classLoader = pluginDescriptor.getPluginClassLoader();
Class ShellClass = classLoader.loadClass("Shell");
Object shell = ShellClass.newInstance();
Class DirectoryDialogClass =
classLoader.loadClass("DirectoryDialog");
Method m = DirectoryDialogClass.getDeclaredConstructor(new
Class[ShellClass]);
m.invoke(......)
etc.
I think I also mislead you a bit: as of a few builds ago, the update plugin
has removed its dependency on runtime.compatibility, so the plugin registry
does not work correctly. This is a murky area right now, but you could use
the osgi related API's:
Replace the
getPluginRegistry().getPluginDescriptor().getClassLoader().l oadClass()
by Platfrom.getBundle("org.eclipse.swt").loadClass(...)
"Clinton Jammer" <cjammer@earthlink.net> wrote in message
news:c4ve3h$7tl$1@eclipse.org...
> dorian birsan wrote:
>
> > "Clinton Jammer" <cjammer@earthlink.net> wrote in message
> > news:c4s01c$28t$1@eclipse.org...
> > > If I write a custom install handler and I wish to use a class such as
> > > DirectoryDialog, how would I get eclipse to load the org.eclipse.swt
> > > plugin?
>
> > Do you have a plugin already running?
> > If yes, then use the handler extension point and make the feature.xml
use
> > the handler that's already in your plugin. Also, have your plugin
<require>
> > swt, so the handler has access to it.
>
> > If not, use the plugin registry to get to the swt plugin class loader,
and
> > use java reflection api's to do what you need.
>
> > -Dorian
>
> > >
> > > Adding this to the requires tag in feature.xml doesn't seem to do the
> > > trick.
> > >
>
> Dorian,
>
> Thanks for responding. I'm installing my plugin as part of a feature
> using the Eclipse Update / Install Manager. The end user defines a site
> bookmark, which points to my feature. My custom install handler loads,
> but it appears to be running in a limited environment without most Eclipse
> classes available to it. At this point, I'm at the mercy of the Eclipse
> classloader, it seems.
>
> I was a bit confused by your question. How can I be running my plugin if
> I am trying to install it?
>
> I did attempt your suggestion of using PluginRegistry to get a
> classloader. Unfortuantely, I still get the ClassNotFoundException.
> Perhaps you could post a code example? My code and exception follows:
>
>
> try {
> // Prompt the user
> IPluginDescriptor pluginDescriptor =
> Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.swt ");
> if (pluginDescriptor != null) {
> ClassLoader classLoader = pluginDescriptor.getPluginClassLoader();
> Shell shell = (Shell)
classLoader.loadClass("Shell").newInstance();
> classLoader.loadClass("DirectoryDialog");
> DirectoryDialog directoryDialog = new DirectoryDialog(shell);
> directoryDialog.setFilterPath(flexDirectory);
> directoryDialog.setMessage("Select the MacroMedia Flex
> directory.");
> flexDirectory = directoryDialog.open();
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
>
>
> java.lang.NoClassDefFoundError: org.eclipse.swt.widgets.Shell
> at java.lang.Throwable.<init>(Throwable.java)
> at java.lang.Throwable.<init>(Throwable.java)
> at java.lang.NoClassDefFoundError.<init>(NoClassDefFoundError.java:57)
> at java.lang.Class.verifyImpl(Native Method)
> at java.lang.Class.verify(Class.java)
> at java.lang.Class.initialize(Class.java)
> at java.lang.Class.newInstanceImpl(Native Method)
> at java.lang.Class.newInstance(Class.java)
> at
>
org.eclipse.update.internal.core.InstallHandlerProxy.getLoca lHandler(Install
HandlerProxy.java:501)
> at
>
org.eclipse.update.internal.core.InstallHandlerProxy.initial ize(InstallHandl
erProxy.java:101)
> at
>
org.eclipse.update.internal.core.InstallHandlerProxy.<init>(InstallHandlerPr
oxy.java:57)
> at org.eclipse.update.core.Feature.install(Feature.java:255)
> at org.eclipse.update.internal.core.SiteFile.install(SiteFile.j ava:74)
> at
>
org.eclipse.update.internal.core.ConfiguredSite.install(Conf iguredSite.java:
194)
> at
>
org.eclipse.update.internal.core.ConfiguredSite.install(Conf iguredSite.java:
159)
> at
>
org.eclipse.update.internal.ui.wizards.InstallWizard.execute (InstallWizard.j
ava:211)
> at
>
org.eclipse.update.internal.ui.wizards.InstallWizard.access$ 3(InstallWizard.
java:193)
> at
>
org.eclipse.update.internal.ui.wizards.InstallWizard$1.run(I nstallWizard.jav
a:93)
> at
>
org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext
..java:101)
>
|
|
|
Re: How to add DirectoryDialog to InstallHandler Classpath? [message #225573 is a reply to message #223341] |
Fri, 09 April 2004 16:47   |
Eclipse User |
|
|
|
Originally posted by: cjammer.earthlink.net
Dorian,
Thanks for trying to help, but I could not get this working. Running the
following line will basically quit my thread without printing any
exception traces:
> Object shell = ShellClass.newInstance();
Furthermore, if I try to use reflection to get the shell from the active
workbench window, it fails to get a window.
A call like
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l() fails
because the getActiveWorkbenchWindow() call returns null.
I wasn't able to get your getBundle suggestion to work... it wasn't a
method on Platform or any other Eclipse 2 class that I found.
I think the Eclipse 2 install handler environment is too limited to allow
me to popup a DirectoryDialog window.
[here is my code if you were curious...]
IPluginDescriptor workbenchPluginDescriptor =
Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.ui.workbench ");
ClassLoader workbenchClassLoader =
workbenchPluginDescriptor.getPluginClassLoader();
IPluginDescriptor swtPluginDescriptor =
Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.swt ");
ClassLoader swtClassLoader = swtPluginDescriptor.getPluginClassLoader();
Class[] emptyParms = {};
output += " emptyParms = " + emptyParms;
Class shellClass =
swtClassLoader.loadClass("org.eclipse.swt.widgets.Shell");
output += " shellClass = " + shellClass;
Class[] shellClassParms = new Class[] {shellClass};
output += " shellClassParms = " + shellClassParms;
Class stringClass = (new String("")).getClass();
output += " stringClass = " + stringClass;
Class[] stringClassParms = new Class[] {stringClass};
output += " stringClassParms = " + stringClassParms;
Class platformUIClass =
workbenchClassLoader.loadClass("org.eclipse.ui.PlatformUI");
output += "\r\n platformUIClass = " + platformUIClass;
Method method = platformUIClass.getDeclaredMethod("getWorkbench",
emptyParms);
output += "\r\n method = " + method;
Object workbench = method.invoke(null, emptyParms);
method =
workbenchClassLoader.loadClass("org.eclipse.ui.IWorkbench").getDeclaredMethod( "getActiveWorkbenchWindow",
emptyParms);
output += "\r\n workbench = " + workbench;
Object workbenchWindow = method.invoke(workbench, emptyParms);
method =
workbenchClassLoader.loadClass("org.eclipse.ui.IWorkbenchWindow ").getDeclaredMethod("getShell",
emptyParms);
output += "\r\n workbenchWindow = " + workbenchWindow;
Object shell = method.invoke(workbenchWindow, emptyParms);
dorian birsan wrote:
> First, don't use Shell as a class, because it won't be resolved. Use java
> reflection classes.
> The code should be more like:
> try {
> // Prompt the user
> IPluginDescriptor pluginDescriptor =
> Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.swt ");
> if (pluginDescriptor != null) {
> ClassLoader classLoader = pluginDescriptor.getPluginClassLoader();
> Class ShellClass = classLoader.loadClass("Shell");
> Object shell = ShellClass.newInstance();
> Class DirectoryDialogClass =
> classLoader.loadClass("DirectoryDialog");
> Method m = DirectoryDialogClass.getDeclaredConstructor(new
> Class[ShellClass]);
> m.invoke(......)
> etc.
> I think I also mislead you a bit: as of a few builds ago, the update plugin
> has removed its dependency on runtime.compatibility, so the plugin registry
> does not work correctly. This is a murky area right now, but you could use
> the osgi related API's:
> Replace the
> getPluginRegistry().getPluginDescriptor().getClassLoader().l oadClass()
> by Platfrom.getBundle("org.eclipse.swt").loadClass(...)
[rest deleted]
|
|
|
Re: How to add DirectoryDialog to InstallHandler Classpath? [message #225699 is a reply to message #225573] |
Sat, 10 April 2004 00:36  |
Eclipse User |
|
|
|
Originally posted by: dorian.birsan.net
So, you're using eclipse 2.x, not 3.0? The Bundle api's are 3.0 level
(especially post M8).
You're code looks fine and my only guess is that there may be some threading
problem. The UI code is usually caled form the UI thread, but the handler
may not run in that thread. Usually a Display.asynchExec() or synchExec() is
employed when calling from another (non-UI) thread.
This may not be the problem, but that's all I can think of now.
One thing is for sure: it is a pain to call the UI from the the handler.
A dirty workaround is to first install a feature with a UI plugin (I think
you can mark a feature as exclusive, so it must be installed by itself) that
defines the handler, and then, after that install the second feature using
the buit-in hander, which access to the UI environment.
-Dorian
----- Original Message -----
From: "Clinton Jammer" <cjammer@earthlink.net>
To: "dorian birsan" <dorian@birsan.net>
Sent: Friday, April 09, 2004 4:55 PM
Subject: Re: Regarding the advice you gave in the Eclipse forum...
> Dorian,
>
> I've been replying to the newsgroup, but older messages scroll off the
main web page, so I figure it would be a good idea to copy you via email.
>
> Thanks for trying to help, but I could not get this working. Running the
following line will basically quit my thread without printing any exception
traces:
>
> > Object shell = ShellClass.newInstance();
>
> Furthermore, if I try to use reflection to get the shell from the active
workbench window, it fails to get a window.
>
> A call like
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l() fails
because the getActiveWorkbenchWindow() call returns null.
>
> I wasn't able to get your getBundle suggestion to work... it wasn't a
method on Platform or any other Eclipse 2 class that I found.
>
> I think the Eclipse 2 install handler environment is too limited to allow
me to popup a DirectoryDialog window.
>
> [here is my code if you were curious...]
> IPluginDescriptor workbenchPluginDescriptor =
Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.ui.workbench ")
;
> ClassLoader workbenchClassLoader =
workbenchPluginDescriptor.getPluginClassLoader();
> IPluginDescriptor swtPluginDescriptor =
Platform.getPluginRegistry().getPluginDescriptor("org.eclipse.swt ");
> ClassLoader swtClassLoader = swtPluginDescriptor.getPluginClassLoader();
>
> Class[] emptyParms = {};
> output += " emptyParms = " + emptyParms;
> Class shellClass =
swtClassLoader.loadClass("org.eclipse.swt.widgets.Shell");
> output += " shellClass = " + shellClass;
> Class[] shellClassParms = new Class[] {shellClass};
> output += " shellClassParms = " + shellClassParms;
> Class stringClass = (new String("")).getClass();
> output += " stringClass = " + stringClass;
> Class[] stringClassParms = new Class[] {stringClass};
> output += " stringClassParms = " + stringClassParms;
>
> Class platformUIClass =
workbenchClassLoader.loadClass("org.eclipse.ui.PlatformUI");
> output += "\r\n platformUIClass = " + platformUIClass;
> Method method = platformUIClass.getDeclaredMethod("getWorkbench",
emptyParms);
> output += "\r\n method = " + method;
> Object workbench = method.invoke(null, emptyParms);
> method =
workbenchClassLoader.loadClass("org.eclipse.ui.IWorkbench").getDeclaredMetho
d("getActiveWorkbenchWindow", emptyParms);
> output += "\r\n workbench = " + workbench;
> Object workbenchWindow = method.invoke(workbench, emptyParms);
> method =
workbenchClassLoader.loadClass("org.eclipse.ui.IWorkbenchWindow ").getDeclare
dMethod("getShell", emptyParms);
> output += "\r\n workbenchWindow = " + workbenchWindow;
|
|
|
Goto Forum:
Current Time: Fri May 30 02:16:58 EDT 2025
Powered by FUDForum. Page generated in 0.03021 seconds
|