How can an Eclipse plugin access the project directory?

北战南征 提交于 2019-12-08 19:14:58

问题


Is there a way to get the directory of a project in Eclipse? We are writing a plugin that will allow the user to select files, and then run some processes on those files. I would ideally like to be able to get all the files with a certain extension, but that is not necessary.


回答1:


sure:

ResourcesPlugin.getWorkspace().getRoot().getProjects()

will get you a list of all the projects in the workspace. you can easily iterate to find the one you want. At that point, you can look for certain files by extensions, etc.




回答2:


If you want to enable your users to select files inside eclipse workspace with a certain extension, you can look at the class org.eclipse.ui.dialogs.ElementTreeSelectionDialog (org.eclipse.ui.dialogs plugin)as a start.

Then, to have an example on how to make it filter extensions, you can look at the class org.eclipse.jdt.internal.ui.viewsupport.FilteredElementTreeSelectionDialog (org.eclipse.jdt.ui plugin) to see how they do it and then reimplement the stuff.

This should give you a higher level of action than going threw files inside projects by hand and reimplement dialogs.



来源:https://stackoverflow.com/questions/242032/how-can-an-eclipse-plugin-access-the-project-directory

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