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 viaplugin.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 evenorg.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
Perspective
s, each will come with its own contribution on the main toolbar. Does that mean I'm obliged to useplugin.xml
extensions everywhere?
TL;DR: Workbench coolbar actions including Save and actions from other
Perspective
s. How? (actionSets
extensions == deprecated).
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 theplugin.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 withcommands
and multiplehandlers
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 usecommands
andhandlers
.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.