Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Identify create or delete file, using IResourceDelta object
Identify create or delete file, using IResourceDelta object [message #1069604] Tue, 16 July 2013 08:21
Krishnaveni S is currently offline Krishnaveni SFriend
Messages: 2
Registered: April 2012
Junior Member
Hi,

I am using Resource Change Listener to track the changes done to my
project. This listener is invoked if I delete, or create or save any
changes to a file, in the project. I have the ResourceDelta object. With
this, how can I find if the file is being created or is going to be deleted.
Below is my code:

In the activator class of my plugin I have:

IResourceChangeListener listener = new MyResourceChangeListener();
this.workspace.addResourceChangeListener(this.listener);

In the MyResourceChangeListener class I have:

System.out.println(event.getBuildKind());
System.out.println(event.getSource());
System.out.println(event.getType());
if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
System.out.println("this is post change event");
final IResourceDelta delta = event.getDelta();

System.out.println(delta.getFlags());
System.out.println(delta.getKind());
System.out.println(delta.getFlags());

if (delta.getKind() == IResourceDelta.ADDED) {
System.out.println("this is ADD event");
}

if (delta.getKind() == IResourceDelta.CHANGED) {
System.out.println("this is CHANGED event");
}

if ((delta.getFlags() & IResourceDelta.CONTENT) == 0) {
System.out.println("this is CONTENT event");
}
}
Output is always as below, either i create a class, delete a class, or
make changes and save a class :

0
org.eclipse.core.internal.resources.Workspace@5f9f1f42
1
this is post change event
0
4
0
this is CHANGED event
this is CONTENT event

How can I differentiate between save, delete or create events.

PS: I deleted a project in the workspace, this time i got a pre_delete
event. How can i git this triggered for files/classes in a projec as well.
Previous Topic:Eclipse, Annotation "@Asynchronous"
Next Topic:A few newcomer questions
Goto Forum:
  


Current Time: Fri Dec 19 16:37:40 GMT 2014

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

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