Why is a windowOpened event not fired/captured when my Eclipse plug-in starts?
I am writing an Eclipse plug-in and one of the classes implements IWindowListener. As a result, I have a few methods that must be in my class including windowOpened(IWorkbenchWindow window). My understanding of the windowOpened me开发者_JAVA技巧thod is that it should be called when the Eclipse Application is launched and the plug-in starts, however I have included some log statements in this method and it never gets called.
Does anyone know why this is happening? Has anyone experienced a similar issue?
It should be noted that the other IWindowListener methods seem to work fine. For instance, the windowClosed method is properly called when I exit the Eclipse Application that the plug-in is running in.
Probably because by the time your IWindowListener is registered, the window is already open. Remember that Eclipse plug-ins are started lazily; unless you've taken steps to have your plug-in start up early, it won't get started until the first time one of its classes gets loaded.
You can access eclipse startup by using extension point called "org.eclipse.ui.startup"
, with this you need to implement interface IStartup
and you can do any startup processes there. This is really done before the actually UI is even loaded.
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
will return null! You can get pass that by doing Display.asyncExec(Runnable)
what will wait until the things are started
Please notice that this will not load your eclipse plug-in, that IStartup class is just executed at the startup. Your own plugin should really be loaded when it is needed first time, not before that. Because there is no need for it to be started until it is really required.
Also a proper place to do some plugins startup stuff is at Activator's start() function. This is called when your plugin is really loaded first time.
精彩评论