Does anybody know or have an example on how to select node(s) programmatically in the Package Explorer view in Eclipse plugin? I see some help on how to get current selection but not on how to set them.
Thanks.
Although a commenter has already pointed to a solution, it uses internal API. If you wanted a a portable API implementation try this. It will select all "open" projects in your workspace.
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 ) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With