Showing both images and text for certain toolbar items is a common requirement. The text is generally placed either to the right or below the image for the action, as shown in Figure 17-3. This improves usability for new users who do not know the meanings of the images. The Workbench supports mixing images and text, but only with programmatic actions.
Let's walk through how this is done. When an application contributes actions to the top-level toolbar, it adds them to an ICoolBarManager. The ICoolBarManager interface extends IContributionManager and can manage both IActions and IContributionItems. Contributed items wrap the SWT controls that are shown in the contribution manager and are ultimately responsible for rendering the items in a menu, a composite, or a coolbar.
JFace provides a helper class called ActionContributionItem for directly adding actions to a contribution manager. Contributed action items effectively transfer the properties of an action down to an SWT control. As such, they can be used to configure whether or not text is shown on the toolbar.
To control the ActionContributionItem for an action, first create the toolbar with a style flag that includes SWT.BOTTOM or SWT.RIGHT to indicate where to show the text. Then, for each action, create an ActionConfigurationItem and set its mode to ActionContributionItem.MODE_FORCE_TEXT. Next, call ToolBarManager.add(IContributionItem) to add the contribution item to the toolbar. The following code shows how to do this in Hyperbola's ActionBarAdvisor:
org.eclipsercp.hyperbola/ApplicationActionBarAdvisor