我正在使用从Project Explorer获取所选项目的一个ISelection,它集中了Project Explorer窗口:
IProject project = null;
ISelectionService selectionService=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ISelection selection = selectionService.getSelection("org.eclipse.jdt.ui.ProjectExplorer");
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof IResource) {
project= ((IResource)element).getProject();
}
else if (element instanceof IPackageFragmentRoot) {
IJavaProject jProject = ((IPackageFragmentRoot)element).getJavaProject();
project = jProject.getProject();
}
else if (element instanceof IJavaElement) {
IJavaProject jProject= ((IJavaElement)element).getJavaProject();
project = jProject.getProject();
}
我需要将选择重点放在Navigator上,我在getSelection方法中尝试了org.eclipse.jdt.internal.ui.Navigator,但它没有用....
如何从导航器视图中获取所选项目?
答案 0 :(得分:2)
导航器视图的ID为:
org.eclipse.ui.views.ResourceNavigator
对于Project Explorer视图,它是
org.eclipse.ui.navigator.ProjectExplorer