这GMF类有一个直截了当的回答,如果你有机会到ResourcesPlugin名称:
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(myBundleName);
通用答案(来自可能过时的代码)可能类似于(如果您打开了编辑器):
IEditorPart editorPart =getSite().getWorkbenchWindow().getActivePage().getActiveEditor();if(editorPart != null){ IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ; IFile file = input.getFile(); IProject activeProject = file.getProject(); String activeProjectName = activeProject.getName(); //... use activeProjectName }
如果没有打开编辑器:
IViewPart [] parts = MyPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getViews(); IProject activeProject = null; for(int i=0;i<parts.length;i++) { if(parts[i] instanceof ResourceNavigator) { ResourceNavigator navigator = (ResourceNavigator)parts[i]; StructuredSelection sel = (StructuredSelection)navigator.getTreeViewer().getSelection(); IResource resource = (IResource)sel.getFirstElement(); activeProject = resource.getProject(); break; } } String activeProjectName = activeProject .getName();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)