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/Toggle Button Command

< Menu Contributions
Revision as of 06:11, 4 August 2009 by Unnamed Poltroon (Talk) (New page: You can create a command with a required parameter. The parameter will be passed during every execution. == Command Definition == Define a command with a state. The state id should be o...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

You can create a command with a required parameter. The parameter will be passed during every execution.

Command Definition

Define a command with a state. The state id should be org.eclipse.ui.commands.toggleState.

<command
      defaultHandler="org.eclipse.examples.BoldHandler"
      id="org.eclipse.examples.boldCommand"
      name="Bold">
   <state
         class="org.eclipse.ui.handlers.RegistryToggleState:true"
         id="org.eclipse.ui.commands.toggleState">
   </state>
</command>

The state can be initialized with a default value, which reflects in the Menu

Handler

The handler will receive the state. Its the responsibility of the handler to update the state of the command.

public class CheckHandler extends AbstractHandler{
 
 public Object execute(ExecutionEvent event) throws ExecutionException {
 
     Command command = event.getCommand();
     boolean oldValue = HandlerUtil.toggleCommandState(command);
     // use the old value and perform the operation
 
    return null; 
  }
 
}

Menu Contribution

Then you add menu contributions as you would do with any command, except you need to set the style to toggle:

<menuContribution
        locationURI="menu:help?after=additions">
    <command
            commandId="org.eclipse.examples.boldCommand"
            label="Bold"
            style="toggle">
    </command>

Back to the top