Currently Being Moderated

       

When you want a perspective to include a snazzy new button that launches an editor or opens a dialog, you most likely want to add that action into the toolbar section along the top, as well as in the top drop down menu. All of the needed configuration to do this can be done in the plug-in's own plugin.xml by adding a few extensions. We'll use the Create Order action in the Fulfillment perspective as an example. The end result will have a Create Order item in both the toolbar and the top menu, along with the keyboard binding for power users.

 

First, you'd want to create an ActionSet in the perspective to help group your new items together:

  <extension

        point="org.eclipse.ui.perspectiveExtensions">

      <perspectiveExtension

          targetID="com.elasticpath.cmclient.fulfillment.perspective">

        <actionSet

              id="com.elasticpath.cmclient.fulfillment.workbenchActionSet">

        </actionSet>

      </perspectiveExtension>

  </extension>

  <extension

        point="org.eclipse.ui.actionSets">

      <actionSet

          id="com.elasticpath.cmclient.fulfillment.workbenchActionSet"

          label="Create Order ActionSet">

      </actionSet>

  </extension>

 

We then define the commands that will be actually performed when the items are selected. This requires your own handler java class (in this case CreateOrderHandler) which extend org.eclipse.core.commands.AbstractHandler and has its own execute() method to perform your intended action.

  <extension

        point="org.eclipse.ui.commands">

      <category

          description="Create Order Command"

          id="com.elasticpath.cmclient.fulfillment.commands"

          name="Create Order">

      </category>

      <command

          categoryId="com.elasticpath.cmclient.fulfillment.commands"

          defaultHandler="com.elasticpath.cmclient.fulfillment.editors.actions.handler.CreateOrderHandler"

          description="Create Order"

          id="com.elasticpath.cmclient.fulfillment.command.create.order"

            name="Create Order">

      </command>

  </extension>

 

Add the key bindings for the commands for quick keyboard access:

  <extension

        point="org.eclipse.ui.bindings">

      <key

          commandId="com.elasticpath.cmclient.fulfillment.command.create.order"

          contextId="com.elasticpath.cmclient.fulfillment.workbenchActionSet"

          schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"

          sequence="M1+M2+O">

      </key>

  </extension>

Now we can add the menu item and toolbar item by extending the org.eclipse.ui.menus extension point. The visibleWhen attribute ensures that the items only show up when the ActionSet we defined earlier is activated.

  <menuContribution

            locationURI="menu:org.eclipse.ui.main.menu">

          <menu

              id="com.elasticpath.cmclient.fulfillment.workbenchMenu"

              label="%fulfillmentMenu.name"

              mnemonic="C">

          </menu>

      </menuContribution>

      <!-- toolbar -->

      <menuContribution

            locationURI="toolbar:org.eclipse.ui.main.toolbar">

          <toolbar

              id="com.elasticpath.cmclient.fulfillment.toolbar.createOrder">

            <command

                  commandId="com.elasticpath.cmclient.fulfillment.command.create.order"

                  icon="icons/order_create.png"

                  id="com.elasticpath.cmclient.fulfillment.toolbarMenus.createOrder"

                  label="%createOrder.label"

                  tooltip="%createOrder.toolTip">

              <visibleWhen>

                  <with

                        variable="activeContexts">

                      <iterate

                            operator="or">

                        <equals

                              value="com.elasticpath.cmclient.fulfillment.workbenchActionSet">

                        </equals>

                      </iterate>

                  </with>

              </visibleWhen>

            </command>

          </toolbar>

      </menuContribution>

      <!-- menu item -->

      <menuContribution

            locationURI="menu:com.elasticpath.cmclient.fulfillment.workbenchMenu">

          <menu

              id="com.elasticpath.cmclient.fulfillment.workbenchMenu"

              label="Create Order"

              mnemonic="O">

            <command

                  commandId="com.elasticpath.cmclient.fulfillment.command.create.order"

                  icon="icons/order_create.png"

                  id="com.elasticpath.cmclient.fulfillment.toolbarMenus.createOrderMenu"

                  label="%createOrder.label"

                  mnemonic="O"

                  tooltip="%createOrder.toolTip">

              <visibleWhen>

                  <with

                        variable="activeContexts">

                      <iterate

                            operator="or">

                        <equals

                              value="com.elasticpath.cmclient.fulfillment.workbenchActionSet">

                        </equals>

                    </iterate>

                  </with>

              </visibleWhen>

            </command>

          </menu>

      </menuContribution>

    </extension>

   

   

And the result:

danw-add-menu-01.jpg