Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Menu Contributions/Toggle Button Command"

(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...)
 
(No difference)

Latest revision as of 06:11, 4 August 2009

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