I am developing a CDT plug-in for Eclipse IDE. I want to write to a project-scoped preference file when creating a project or just store an info to identify this project later and write to a file. How can I seize a moment when Eclipse is creating a new project and store some info about it?
You can use an IResourceChangeListener
listener to listen for all resource changes:
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
The listener implements the single method:
public void resourceChanged(IResourceChangeEvent event)
From the event you get the resource delta:
IResourceDelta delta = event.getDelta();
The delta getKind()
method will be IResourceData.ADDED
for a new resource.
The delta has a getResource
method which will get you the resource - you are interested in an IProject
.
Note: Deltas can contain nested entries. You may have to use the getAffectedChildren()
method of the delta to find the project, or use the accept
method to visit all the nodes in the delta.