Question

Google is my best friend, but the information I'm getting is too scattered and very unclear. There isn't a concise tutorial describing my needs.

I want to add actions to my RCP app's main toolbar, but I need every way of doing this explained thoroughly. But since this is StackOverflow, I will write down the questions off the top of my head, and hope the answers will do.

  • Which is the new and old way of adding actions? Via ActionBarAdvisor or via plugin.xml?

  • Can actions be added to the main toolbar ONLY using plugin.xml?

  • How many steps are there to add an action via extensions? (handlers, commands, menuContribution, etc.)

  • Which is the best parent for an action implementation? org.eclipse.jface.action.Action? org.eclipse.ui.menus.WorkbenchWindowControlContribution? Or even org.eclipse.ui.commands.AbstractHandler?

  • What about workbench-specific actions (Save, Undo, Redo etc.)? How are these added?

  • In Eclipse Kepler IDE, the coolbar looks beautiful. You can even move toolbars around. How's that implemented? Couldn't find out not even with Plug-in Spy.

  • Since I have several Perspectives, each will come with its own contribution on the main toolbar. Does that mean I'm obliged to use plugin.xml extensions everywhere?


TL;DR: Workbench coolbar actions including Save and actions from other Perspectives. How? (actionSets extensions == deprecated).

Was it helpful?

Solution

The really new way is to use a pure e4 RCP which uses the new application model with commands and handlers! (but e4 doesn't support a lot of existing code). In e4 menus and toolbars are defined in the application model. Commands and handlers are used in a similar way to traditional code (but handlers are implemented differently).

For Eclipse 3 style as you have found there is a jumble or ways of doing things. Eclipse 4.3 does deprecate some of the oldest (and this is now flagged in the plugin.xml).

If you are writing a RCP which uses its own ActionBarAdvisor then you can define your tool bar items there. Or you can define them in the plugin.xml for individual plugins. Both methods are fine. Eclipse itself defines core actions in the advisor with add on plugins defining more in their plugin.xmls.

Actions such as Save which need to be handled by multiple parts (such as editors) should be created in the advisor and use RetargetAction. This allows each individual part to hook up its own action with the globally defined action. This can also be done with commands and multiple handlers which are closer to the e4 style.

org.eclipse.ui.menus is now the main extension point for contributing to menus and toolbars (ignoring all the deprecated parts). This does pretty much force you to use commands and handlers.

The Eclipse action bar advisor is org.eclipse.ui.internal.ide.WorkbenchActionBuilder which may help although it is big.

I think the coolbar in Kepler is constructed using the new e4 application model with styling using some tricky CSS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top