Common Navigator and “Show In” menus
I recently had to work on the interactions between a custom view (based on the Eclipse Common Navigator) and the package explorer.
The first part consisted in adding my view in the Show In menu from the Package Explorer.
The Eclipse FAQ provided the required information, although I had to extend the CommonNavigator class.
I guess it must be feasible with adapters…
The second part consisted in adding the Show in menu on my view, and in adapting the selection to show it into the Package Explorer.
My first idea was to add an action by hand, that would show the Package Explorer and highlight my selection.
But it appeared to be really complicated. Eclipse had to provide something much more simple.
And it does!
In fact, the Eclipse Command Framework provides everything I needed.
The solution appeared when I noticed the Navigate menu already contained a Show In sub-menu with my view selections.
Here is the solution.
- Add a new menu contribution on your view.
- Add a menu under it, with label to “Show In” and command to
- Add a command under this menu. The commandId is
- Add a parameter under this command. Name =
org.eclipse.ui.navigate.showIn.targetIdand Value = the target view ID.
Applied for the Package Explorer ( org.eclipse.jdt.ui.PackageExplorer ) and the properties view ( org.eclipse.ui.views.PropertySheet ), I have the following structure.
And the result…