Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to add and remove resource listeners in an editor?
How to add and remove resource listeners in an editor? [message #194670] Sat, 14 February 2004 11:27 Go to next message
Eclipse UserFriend
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
Re: How to add and remove resource listeners in an editor? [message #195165 is a reply to message #194670] Mon, 16 February 2004 04:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: daniel.megert.gmx.net

Channing Walton wrote:

> 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

see AbstractTextEditor.dispose()

Dani

>
> Thanks,
>
> Channing
Re: How to add and remove resource listeners in an editor? [message #195916 is a reply to message #195165] Tue, 17 February 2004 01:59 Go to previous message
Eclipse UserFriend
Daniel Megert wrote:

>
> see AbstractTextEditor.dispose()

Of course! Thanks Daniel.

Chang
Previous Topic:How to expand property sheet b default
Next Topic:TrueType fonts in Eclipse (On Linux/GTK)
Goto Forum:
  


Current Time: Sat Jul 19 15:27:17 EDT 2025

Powered by FUDForum. Page generated in 0.24770 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top