I'm developing an eclipse plugin , and at some point in my plugin , a jframe is opened , and inside the jframe, there is a button . I have added a mouselistener to the button , and when pressed , I want some code to be added to the editor at caret point . but, I get null pointer exception here:
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage();
-
1Which of those three calls is returning null? getWorkbench()? getActiveWorkbenchWindow()? getActivePage()?greg-449– greg-4492014-08-08 15:04:23 +00:00Commented Aug 8, 2014 at 15:04
-
getActivePage() is returning nullrazieh babaee– razieh babaee2014-08-08 16:32:52 +00:00Commented Aug 8, 2014 at 16:32
Add a comment
|
1 Answer
It appears you don't have an active page. Maybe your Swing based code is displaying a separate window?
Use IWorkbenchWindow.getPages() to get an array of IWorkbenchPage containing all the pages and look through the pages for the one containing the editor you want.
5 Comments
razieh babaee
thanks! that was the problem! sorry , I am still learning eclipse plugin development !
razieh babaee
what is an acivePage exactly? I tried to change the focused window using a robot , but it didn't work.
greg-449
It is all the things you can see on an Eclipse window, there are multiple pages if you have used several perspectives. Normally you use SWT controls in the page and there will be an active page. Or if a dialog is displayed you schedule work to run after the dialog closes and the page is active again.
razieh babaee
I first ran dispose() on the jframe, and then tried to get the active window, and got null pointer. Apparently the page is considered active only after I click on the window...
greg-449
Sorry, using Swing windows is very unusual with Eclipse plugins, I don't know exactly how this would behave.