The Platform Command Framework is one of the most powerful features of RCP. It’s also one of the most confusing. In truth, the command framework is a kind of mini-language that’s embedded inside RCP. Unfortunately it’s syntax consists of XML extension points and it’s semantics aren’t formally specified anywhere. This can make it difficult to get started with the command framework and even the simplest tasks can be somewhat daunting. Fortunately, once you begin to grok the necessary concepts and learn the language behind the language you’ll reach a point where every little task doesn’t require oodles of googling.
But until then here’s another HOWTO that addresses a common object: defining a top-level menu that only shows up when a specific type of editor is active.
Define your own top-level menu. This is done by making a
locationURI is something like
menu:org.eclipse.ui.main.menu?after=additions. In this
menuContribution you’ll define your own top-level menu like:
Contribute a command to your menu. You’ll need to define your own command and then add another menuContribution and this time the
locationURI will be your menu-id. The content of this contribution will be a
command element whose
commandId references your new command.
Use visibleWhen to restrict when the command is active. At this point you’ve simply created a new top-level menu that has your command in it. If you only want the command to be available when a certain editor-type is active you’ll need to use a Command Expression. (This is another mini-language!). To achieve the required effect you want something like (note that
<equals value="com.example.editor.myEditor" />
And that’s pretty much all there is to it. This general three step approach works for most command stuff. First, just get the command item to show up in the appropriate menu and the like. Then try to figure out how to further restrict its visibility using a core expression.