Switching the status of a menu item

I have an Eclipse RCP application that I am working on. It has some menus for viewing, and one of the menu items is an item that I would like to display next to when the corresponding functionality is enabled. Likewise, the next time an item is selected, the item must be outdated to indicate that the corresponding functionality is disabled.

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

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

+3
source share
2 answers

The solution implies that the command handler implements the IElementUpdater interface. Then the user interface element can be updated as follows:

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

updateElement is called as part of the update UI, which can be called from the execution command of the handler like this:

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

A lot more information here (see Radio Button Command and Update Checked Records Status )

+1
source

Maybe something has changed, maybe there is a difference between RCP and the Eclipse plugin, but I just set my action style to toggleand it automatically switched. You can see the source code of github.com .

     <action
           class="live_py.EnableAction"
           id="live-py.enable.action"
           label="Li&amp;ve Coding"
           menubarPath="pyGeneralMenu/pyNavigateGroup"
           state="false"
           style="toggle">

, , , isChecked().

+1

Source: https://habr.com/ru/post/1697327/


All Articles