Reputation: 3730
In an Eclipse RCP, I want to install certain listeners in IWorkbenchWindow and in IPartService. This is easy enough after Eclipse has started. But at startup, these objects are not available yet when my plugin Activator gets called; For example if I use:
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow wbw = wb.getActiveWorkbenchWindow();
IPartService ps = wbw.getPartService();
this just causes NullPointerExceptions.
One way around this is to schedule a job and see if I can get an IPartService. If I can't, I reschedule the job to run again in a second or so until it is successful. This is definitely a dirty hack, and I have the feeling that I'm missing something here.
What is the proper way to deal with this?
Upvotes: 0
Views: 81
Reputation: 111217
In an RCP your class derived from WorkbenchWindowAdvisor
can override the preWindowOpen
class to set up hooks just before the main window is opened.
As an example, the Eclipse RCP uses this to set up an IPageListener to watch for workbench page changes.
Upvotes: 1