Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Menu Contributions/Dropdown Command

< Menu Contributions
Revision as of 11:02, 1 October 2007 by Unnamed Poltroon (Talk) (Handler)

You can create dropdown commands using menu contributions, and then use multiple menu contributions to create the dropdown menu.

Command Definition

Any command can be used as a toolbar dropdown ... the command itself is not aware of its dropdown rendering. If it were to need that information, 2 common ways of sharing it are:

  1. Create a parameterized command. The commands inserted in the dropdown menu would specify the parameter, and the dropdown tool item command would not.
  2. Back your handler with a model and rely on that information

This command declaration defines a parameter:

  <extension point="org.eclipse.ui.commands">
     <category id="z.ex.dropdown.category1" name="DropDown Examples">
     </category>
     <command categoryId="z.ex.dropdown.category1" defaultHandler="z.ex.dropdown.internal.DropDownHandler" id="z.ex.dropdown.command1" name="Drop">
        <commandParameter id="z.ex.dropdown.msg" name="Message" optional="true">
        </commandParameter>
     </command>
  </extension>
  <extension point="org.eclipse.ui.commandImages">
     <image commandId="z.ex.dropdown.command1" icon="icons/change_obj.gif">
     </image>
  </extension>

I've thrown in a default image for fun.

Handler

The command example includes a default handler, which is common for simple global commands. The handler needs to check for the parameter and then do its stuff.

public class DropDownHandler extends AbstractHandler {
  private static final String PARM_MSG = "z.ex.dropdown.msg";
  public Object execute(ExecutionEvent event) throws ExecutionException {
    String msg = event.getParameter(PARM_MSG);
    if (msg == null) {
      System.out.println("No message");
    } else {
      System.out.println("msg: " + msg);
    }
    return null;
  }
}

Menu Contribution

You need the menu contribution

Back to the top