How to programmatically change choices in explorer package

I am currently developing an eclipse plugin that analyzes dependencies and links between projects in the Eclipse workspace and displays them in a native view in a diagram similar to UML.

To increase the usefulness of my plugin, I want to add interactivity to the diagram, allowing users to open the project in the package explorer, and, if applicable, open it in the editor by clicking on the displayed graph.

However, my problem is that although I know how to get the given selection from the package explorer, I could not find a way to change the selection or simply open the project in the software package programmatically.

Does anyone have a solution to this problem?

+3
source share
2 answers

I have found a solution. Eclipse offers 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 allocate any IResource resource and expand the tree as needed.

+1
source

This answer extends what the accepted answer says, but takes it further for people who mean the β€œDenied Access” warning when using PackageExplorerPart . The exact warning (more for a more convenient Google search) that you see is

Failsafe access: PackageExplorerPart type PackageExplorerPart not available due to restrict the required library /eclipse_install_path/eclipse/plugins/org.eclipse.jdt.ui_3.9.1.v20130820-1427.jar

Code example:

 final IWorkbenchPart activePart = getActivePart(); if (activePart != null && activePart instanceof IPackagesViewPart) { ((IPackagesViewPart) activePart).selectAndReveal(newElement); } 

Helper Code:

 private IWorkbenchPart getActivePart() { final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow(); if (activeWindow != null) { final IWorkbenchPage activePage = activeWindow.getActivePage(); if (activePage != null) { return activePage.getActivePart(); } } return null; } 
+2
source

All Articles