Elastic Path Commerce Development

Adding Menu Items To Commerce Manager's Main Toolbar

Adding Menu Items To Commerce Manager's Main Toolbar

Commerce Manager implements all its toolbars as ToolBar objects, with the exception of the main (top) toolbar, which is implemented as a CoolBar. Items, such as icons or buttons, are added to the menu as ContributionItems.

To add a new menu item to an existing Commerce Manager toolbar, you must extend the existing toolbar using an Eclipse Extension Point and add a new toolbar and add your ContributionItems to that toolbar. Like all extensions, Toolbar extensions are created in commerce-extensions/cm/ext-cm-modules/ext-cm-plugins.

First, define your new toolbar as a menuContribution child element of the org.eclipse.ui.menus extension point in plugin.xml.

Note: Separators

Adding Seperators has no effect. In order to achive separation of UI elements, consider grouping items within separate toolbars.

Extending Eclipse Extension Points

For more information on extending Eclipse Toolbars, see the Eclipse Workbench Extension documentation.

To add a contribution item to the main Commerce Manager toolbar, you must do the following in your extension project:
  • Provide an extension point for org.eclipse.ui.menus in your extended plugin's plugin.xml file.
  • Populate the extension point with <menuContribution> and its child elements, <toolbar> and <command>.
    • <menuContribution> has one attribute, locationURI. When adding to the main commerce manager toolbar, locationURI should be toolbar:org.eclipse.ui.main.toolbarFor more information on locationURI syntax, see Eclipse's Menu Contributions documentation.
    • <toolbar> has one attribute, id, which defines the name of the new toolbar you wish to contribute to the main menu bar.
    • <command>, which represents the behaviour of a menu item in the abstract. <command> is a very flexible element, and is best understood by reading Eclipse Workbench's <command> documentation.

The following example adds a contribution item added to the Entitlements perspective.

<extension
			point="org.eclipse.ui.menus">

		<menuContribution
				locationURI="toolbar:org.eclipse.ui.main.toolbar">
			<toolbar
					id="com.elasticpath.cmclient.core.toolbars.preferences">
				<command
						commandId="com.elasticpath.extensions.entitlements.handlers.EntitlementCommand"
						id="com.elasticpath.extensions.entitlements.handlers.EntitlementCommand"
						label="Entitlement Contribution Item"
						tooltip="Entitlement Contribution Item">
				</command>

			</toolbar>
		</menuContribution>
</extension>
            

In order to provide actual implementation of the command, you must also extend the org.eclipse.ui.commands extension point, where defaultHandler is a path to the class where your menu item is implemented. The extension point for the commands is needed in order to provide implementation. The id in this case matches the command id.

<extension point="org.eclipse.ui.commands">
    <command
        id="com.elasticpath.extensions.entitlements.handlers.EntitlementCommand"
        defaultHandler="com.elasticpath.extensions.entitlements.handlers.EntitlementCommand"
        name="Open Entitlement Stuff">
    </command>
</extension>

Exceptions

When adding contribution items to menus, there are two exceptions to the rules presented above.

toolbar:org.eclipse.ui.trim.command2

RAP does not render toolbar:org.eclipse.ui.trim.command2 – the right trim area – of the toolbar correctly. If attempting to contribute UI elements to toolbar:org.eclipse.ui.trim.command2, use Elastic Path's alternative, toolbar:com.elasticpath.cmclient.core.toolbars.right instead. This uses Elastic Path's ContributionLoader class to extract all the items contributed to a specific toolbar URI and load them into ToolBarManager correctly.

Perspective Toolbar

In order to add a new item to the Perspective toolbar the following id must be used as the locationURI: com.elasticpath.cmclient.core.toolbars.activities.