How to add and remove resource listeners in an editor? [message #194670] |
Sat, 14 February 2004 11:27  |
Eclipse User |
|
|
|
Hi,
I have an editor that needs to listen to resource changes in the
directory containing the file its an editor of.
So I added a IResourceChangeListener after the editor's input is set:
protected void doSetInput(IEditorInput input) throws CoreException {
super.doSetInput(input);
addResourceListener();
}
I do this because I need the input set so I can find resources in the
same directory as the file being edited.
To remove the listener I needed to add a PartListener to the active page
and when the part is closed, remove the ResourceListener:
getActivePage().addPartListener(new IPartListener() {
public void partClosed(IWorkbenchPart part) {
ResourcesPlugin.getWorkspace().removeResourceChangeListener( listener);
}
....
}
This all works nicely except when Eclipse is first launched and my
editor is opened as a result of it being there when Eclipse was last
closed. The call to getActivePage() returns null so I get a NPE.
So, what is the right way for me to achieve what I need which is:
1) when the editor is opened it needs to add a listener to resource changes
2) when the editor is closed it needs to remove itself as a listener
Thanks,
Channing
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.24770 seconds