Vlad Ilie
Vlad Ilie

Reputation: 1409

IResourceChangeEvent - how to identify a project delete/rename

How can I properly distinguish, inside an IResourceChangeListener that is added via ResourcePlugin.getWorkspace().addResourceChangeListener(...) that a Project was deleted / renamed?

Through trying things out, it would seem that the IResourceChangeEvent.getDelta() -> IResourceDelta would be the answer.

From Eclipse API:

After-the-fact batch reports of arbitrary creations, deletions and modifications to one or more resources expressed as a hierarchical resource delta. Event type is POST_CHANGE, and getDelta returns the hierarchical delta. The resource delta is rooted at the workspace root. These events are broadcast to interested parties after a set of resource changes and happen whether or not autobuilding is enabled. The workspace is closed for change during notification of these events. The delta reported in this event cycle is identical across all listeners registered for this type of event.

EDIT: adding my findings so far

So, the Event.getType() is POST_CHANGE and there needs to be either

Can someone confirm this supposition? Is if it really necessary to do a tree depth search for children to realize if the Event is of a project rename/delete or a file/folder?

Upvotes: 6

Views: 1241

Answers (1)

Prakash G. R.
Prakash G. R.

Reputation: 4892

  • You need to add a resource change listener via ResourcePlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE)

  • In your listener, use a IResourceDeltaVisitor to visit all the changes in the delta via event.getDelta().accept(...)

  • The visitor should look into the projects that are REMOVED

  • If you are expecting the project to be removed and created with the same name (as happens to files & folders during build events), then in addition to the REMOVED, also look for REPLACED in the delta

Upvotes: 1

Related Questions