[英]How to get projects (IProject) from Working Sets?
In the next code, I am getting the information I need from projects by default Workspace, but I need to change it for Working Sets' projects. 在下一个代码中,默认情况下,我将从项目Workspace中获得项目所需的信息,但是我需要针对工作集的项目进行更改。
IWorkspace workspace = ResourcesPlugin.getWorkspace();
// Get the root of the workspace
IWorkspaceRoot root = workspace.getRoot();
// Get all projects in the workspace
IProject[] projects = root.getProjects();
// Loop over all projects
for (IProject project : projects) {
try {
if (project.getName().equals("RemoteSystemsTempFiles"))
{
System.out.println("Ignored project");
//setSystemName(project.getName());
}
else
{
// Load the data model by extracting APIs declaration (Imports)
printProjectInfo(project);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
So, I found an answer but as return after loop the I receive many information like: 因此,我找到了答案,但在循环后返回时,我收到许多信息,例如:
- ProjectName (not open)
or 要么
- ProjectName
src
<default> (...)
src (...)
src.tryone (...)
C:\Program Files\Java\jre1.8.0_31\lib\resources.jar (not open)
The code that is returning that information is: 返回该信息的代码是:
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
IWorkingSet [] allWorkingSets = manager.getAllWorkingSets();
for (IWorkingSet aWorkingset : allWorkingSets) {
IAdaptable[] elems = aWorkingset.getElements();
System.out.println("Working set " + aWorkingset.getName() + " has "+ elems.length + " projects.");
for (IAdaptable elem : elems) {
System.out.println("Working set " + aWorkingset.getName()+ " contains " + elem.toString());
}
}
So, briefly, I would like to know how can I get the IProjects from Working sets, in the same way or similar way I did with the workspace projects? 因此,简要地说,我想知道如何以与工作区项目相同或相似的方式从工作集中获取IProject?
On each IAdaptable
element call 在每个
IAdaptable
元素调用上
IResource resource = (IResource)elem.getAdapter(IResource.class);
which will return any resource that the element represents (some working sets contain other things so the result might be null). 它将返回元素表示的任何资源(某些工作集包含其他内容,因此结果可能为null)。
You can then call 然后你可以打电话
IProject project = resource.getProject();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.