Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » IResourceListener only called at workspace level.
IResourceListener only called at workspace level. [message #336164] Wed, 27 May 2009 16:41 Go to next message
Ray Pendergraph is currently offline Ray PendergraphFriend
Messages: 6
Registered: July 2009
Junior Member
I am trying to listen to deletes (via the default eclipse package
explorer) within projects using IResourceListener via the
ResourcesPlugin.getWorkspace().addResourceChangeListener(... ) call as
stated in the documentation here:
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/resAdv_events.htm

I am able to see renames, deletes, etc. on workspace level artifacts
(projects) but not any of the project children. The event just never
occurs at all. The docs make it sound like any change in the workspace
will trigger an event call to your resource listener but that is not
working for me. Is there something else that needs to be done our plugin
code to make this work? Does the package explorer delegate that
responsibility to us somewhere and perhaps we are just not propagating the
event correctly?


Ray
Re: IResourceListener only called at workspace level. [message #336165 is a reply to message #336164] Wed, 27 May 2009 16:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Ray,

Are you using a ResourceDeltaVisitor? Are your changes happening as
part of a workspace modify operation?


Ray Pendergraph wrote:
> I am trying to listen to deletes (via the default eclipse package
> explorer) within projects using IResourceListener via the
> ResourcesPlugin.getWorkspace().addResourceChangeListener(... ) call as
> stated in the documentation here:
> http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/resAdv_events.htm
>
>
> I am able to see renames, deletes, etc. on workspace level artifacts
> (projects) but not any of the project children. The event just never
> occurs at all. The docs make it sound like any change in the workspace
> will trigger an event call to your resource listener but that is not
> working for me. Is there something else that needs to be done our
> plugin code to make this work? Does the package explorer delegate that
> responsibility to us somewhere and perhaps we are just not propagating
> the event correctly?
>
> Ray
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: IResourceListener only called at workspace level. [message #336167 is a reply to message #336165] Wed, 27 May 2009 17:49 Go to previous messageGo to next message
Ray Pendergraph is currently offline Ray PendergraphFriend
Messages: 6
Registered: July 2009
Junior Member
Yes the ResourceDeltaVisitor is accepted after some conditional code
within the resourceChanged(IResourceChangeEvent event) method like so...

event.getDelta().accept(new IResourceDeltaVisitor() {
...
}
The thing I did not expect is that resourceChanged(IResourceChangeEvent
event) is only called for resources directly under the workspace. An
example of what I am doing:

Create a new -> project "XYZ".
Create a new -> plugin artifacts for my plugin (make it load, etc) under
the project.
Create some other misc. subfolders, plain files, etc.
Deleting or renaming the sub artifacts or folders never results in an
event.
Rename project "XYZ" to "ABC" via refactor (or delete it) and I get the
expected events.

Am I making the wrong assumption about these events being propagated to
the root level? I don't think it ever actually says this is the case.
Re: IResourceListener only called at workspace level. [message #336168 is a reply to message #336167] Wed, 27 May 2009 18:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Ray,

Comments below.

Ray Pendergraph wrote:
> Yes the ResourceDeltaVisitor is accepted after some conditional code
> within the resourceChanged(IResourceChangeEvent event) method like so...
>
> event.getDelta().accept(new IResourceDeltaVisitor() {
> ..
> }
Does your visit method return true so that children are visited? I
suspect you're returning false because I'm not having any trouble
getting the deltas for changes at any level...
> The thing I did not expect is that
> resourceChanged(IResourceChangeEvent event) is only called for
> resources directly under the workspace. An example of what I am doing:
>
> Create a new -> project "XYZ".
> Create a new -> plugin artifacts for my plugin (make it load, etc)
> under the project.
> Create some other misc. subfolders, plain files, etc.
> Deleting or renaming the sub artifacts or folders never results in an
> event. Rename project "XYZ" to "ABC" via refactor (or delete it) and I
> get the expected events.
>
> Am I making the wrong assumption about these events being propagated
> to the root level? I don't think it ever actually says this is the case.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: IResourceListener only called at workspace level. [message #336169 is a reply to message #336168] Wed, 27 May 2009 18:23 Go to previous messageGo to next message
Ray Pendergraph is currently offline Ray PendergraphFriend
Messages: 6
Registered: July 2009
Junior Member
But I am not even getting any notification to say "go look at the deltas".
In other words, given:

IResourceChangeListener rcl = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
System.out.println("Got event "+event.getType()+"
"+event.getResource().getName());
...
}
};
ResourcesPlugin.getWorkspace().addResourceChangeListener(rcl );


The println is never seen except for workspace level artifacts ... I
should at least get that is what I am thinking. Even if there was a bug in
my code handling the deltas later. I can successfully get the
notification and deltas for a renamed project, but no notification
whatsoever for renamed artifacts within a project.
Re: IResourceListener only called at workspace level. [message #336175 is a reply to message #336169] Wed, 27 May 2009 20:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Ray,

If you aren't getting a delta, then it's likely the workspace doesn't
know that a change has happened. If you select all the projects and
invoke "Refresh" from the context menu, does that result in a delta? I
know this stuff works (in EMF's generated editors, which register a
resource change listener), so it's likely there's something you've not
told us that's the key to the problem...


Ray Pendergraph wrote:
> But I am not even getting any notification to say "go look at the
> deltas". In other words, given:
>
> IResourceChangeListener rcl = new IResourceChangeListener() {
> public void resourceChanged(IResourceChangeEvent event) {
> System.out.println("Got event "+event.getType()+"
> "+event.getResource().getName());
> .. }
> };
> ResourcesPlugin.getWorkspace().addResourceChangeListener(rcl );
>
>
> The println is never seen except for workspace level artifacts ... I
> should at least get that is what I am thinking. Even if there was a
> bug in my code handling the deltas later. I can successfully get the
> notification and deltas for a renamed project, but no notification
> whatsoever for renamed artifacts within a project.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: IResourceListener only called at workspace level. [message #336176 is a reply to message #336169] Wed, 27 May 2009 21:30 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Ray Pendergraph wrote:
> But I am not even getting any notification to say "go look at the
> deltas". In other words, given:
>
> IResourceChangeListener rcl = new IResourceChangeListener() {
> public void resourceChanged(IResourceChangeEvent event) {
> System.out.println("Got event "+event.getType()+"
> "+event.getResource().getName());
> .. }
> };
> ResourcesPlugin.getWorkspace().addResourceChangeListener(rcl );
>
>
> The println is never seen except for workspace level artifacts ... I
> should at least get that is what I am thinking. Even if there was a bug
> in my code handling the deltas later. I can successfully get the
> notification and deltas for a renamed project, but no notification
> whatsoever for renamed artifacts within a project.

The event holds a single delta, but that delta likely has child
deltas containing the information you seek. Use a
IResourceDeltaVisitor as indicated previously, and as Ed pointed
out, return *true* so that you also visit the child deltas as far
down as they go.

http://www.eclipse.org/articles/Article-Resource-deltas/reso urce-deltas.html
--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: IResourceListener only called at workspace level. [message #336187 is a reply to message #336164] Thu, 28 May 2009 12:45 Go to previous message
Ray Pendergraph is currently offline Ray PendergraphFriend
Messages: 6
Registered: July 2009
Junior Member
I loaded the code on a windows machine (brand new Eclipse install) to see
if it was an environment and/or OS issue. It worked! I got all the
workspace notifications I expected and then some. Then I went back to
linux and updated the platform via the eclipse update option to make see
if it was a platform version issue and all is well now ( like magic....
:-S ). Sorry to waste everyone's time on this but I was certainly not
getting the notifications before. Looks like an environment problem though.
Previous Topic:Common Navigator - Global menu contributions
Next Topic:Listener when unload/load resource
Goto Forum:
  


Current Time: Thu Apr 25 16:33:46 GMT 2024

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

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

Back to the top