Show in...

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.

  1. Add  a new menu contribution on your view.
  2. Add a menu under it, with label to “Show In” and command to org.eclipse.ui.navigate.showInQuickMenu
  3. Add a command under this menu. The commandId is org.eclipse.ui.navigate.showIn
  4. Add a parameter under this command. Name = org.eclipse.ui.navigate.showIn.targetId and 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.

The plugin.xml content

And the result…

Show in...

One thought on “Common Navigator and “Show In” menus

  1. Great! Your tip just saved me hours and works like a charm. I would *never* have come to this simple and declarative solution. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s