How to programmatically change the selection within package explorer

前端 未结 2 1154
说谎
说谎 2020-12-18 07:17

I am currently developing a plugin for eclipse that analyzes dependencies and references between projects within the Eclipse Workspace and displays them in its own View in a

2条回答
  •  感动是毒
    2020-12-18 07:42

    I have found the solution. Eclipse does offer direct access to the package explorer in org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart , but it is discouraged.

    import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
    
    ...
    
    PackageExplorerPart part= PackageExplorerPart.getFromActivePerspective();
    IResource resource =  /*any IResource to be selected in the explorer*/;
    
    part.selectAndReveal(resource);
    

    This will highlight whatever IResource resource is and expand the tree as necessary.

提交回复
热议问题