How to programmatically select nodes in package explorer in Eclipse plugin

Does anyone know or have an example on how to programmatically select node (s) in the Package Explorer view in the Eclipse plugin? I see some help on how to get the current selection, but not on how to install them.

Thanks.

+7
source share
1 answer

Although the commentator has already pointed out the solution, he uses the internal API. If you want to implement a portable API, try this. He will select all the β€œopen” projects in your work area.

List<Object> openProjects = new ArrayList<Object>(); for( IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects() ) { if( project.isOpen() ) { final IJavaProject javaProject = JavaCore.create( project ); if( javaProject != null ) { openProjects.add( javaProject ); } openProjects.add( project ); } } Object[] projectsToSelect = openProjects.toArray(); IViewPart view = window.getActivePage().showView( "org.eclipse.jdt.ui.PackageExplorer" ); view.getSite().getSelectionProvider().setSelection( new StructuredSelection( projectsToSelect ) ); 
+3
source

All Articles