tags:

views:

575

answers:

1

Hi there,

I have an Eclipse RCP app I'm working on. It has some view-specific menus and one of the menu items is an item which I would like to display a tick next to when the corresponding functionality is enabled. Similarly, the next time the item is selected, the item should become unticked to reflect that the corresponding functionality is disabled.

My question is this: how do I set the toggle state of these menu items? I have an IHandler to deal with the event when the menu item is selected but I'm unsure how to update the GUI element itself.

Does the StackOverflow community have any thoughts on how I might solve this?

+1  A: 

The solution involves having the command handler implement the IElementUpdater interface. The UI element can then be updated as so:

public void updateElement(UIElement element, Map parameters) 
{
 element.setChecked(isSelected);  
}

updateElement is called as part of a UI refresh which can be invoked from the handler's execute command as so:

  ICommandService service = (ICommandService) HandlerUtil
       .getActiveWorkbenchWindowChecked(event).getService(
           ICommandService.class);
   service.refreshElements(event.getCommand().getId(), null);

Lots more info here (see Radio Button Command and Update checked state entries)

Daniel