문제

I'm writing an Eclipse command plugin and want to select the first project in the project explorer view.
note, that no editor is opened.
How do I do this?

도움이 되었습니까?

해결책

First get the active workbench page and find the view:

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

IViewPart viewPart = page.findView(id);

The id for the Projects View is org.eclipse.jdt.ui.ProjectsView

If the view is not open viewPart will be null.

Get the selection provider from the view site:

ISelectionProvider selProvider = viewPart.getSite().getSelectionProvider();

Set selection:

selProvider.setSelection(new StructuredSelection(project));

project is the IProject object for the project you want to select.

다른 팁

Accepted answer here is correct but the "Projects View" id worked for me is org.eclipse.ui.navigator.ProjectExplorer on Eclipse 4.6

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top