Eclipse RCP
20.09.2010 - 24.09.2010, Hamburg
git
07.10.2010 - 08.10.2010, Essen
21.01.2009

Toggle Handler for Eclipse Commands

Based on Moritz Posts blog post Toggling a Command contribution I built a base class for a command handler which automatically handles the toggle state. To use it add the base class to your project:

ToggleHandler.java

Add a state element to your command contribution:

<command id="somecommand" name="SomeCommand">
    <state class="org.eclipse.jface.commands.ToggleState" id="STYLE"/>
</command>

Contribute your handler using the style="toggle" attribute:

<extension point="org.eclipse.ui.menus">
    <menuContribution
        locationURI="menu:de.ralfebert.somemenu">
            <command commandId="somecommand" style="toggle"/>
    </menuContribution>
</extension>

And use ToggleHandler to implement your Handler class:

public class SomeCommandHandler extends ToggleHandler {

      @Override
      protected void executeToggle(ExecutionEvent event, boolean newState) {
            System.out.println(newState);
      }

}

That’s everything required to get toggling commands:

Toggling commands

Philipp Kursawe, 16. Dezember, 18:54 Uhr

I think this functionality has been added to HandlerUtil recently. Please also see how the toggling handler can drive other contributions:
http://philondev.blogspot.com/2009/12/toggle-commands-toggle-other.html

I'm looking forward to your comments:

Schulungen

Eclipse RCP

Ralf Ebert | Blog | Eclipse RCP | Toggle Handler for Eclipse Commands