How to catch a moment when Eclipse is creating a new project?

与世无争的帅哥 提交于 2020-01-05 04:01:09

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/39515732/how-to-catch-a-moment-when-eclipse-is-creating-a-new-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!