切换菜单项的状态 [英] Toggling the state of a menu item
问题描述
我的问题是这样:如何设置切换这些菜单项的状态?当我选择菜单项时,我有一个IHandler处理事件,但我不确定如何更新GUI元素本身。
StackOverflow社区是否有任何想法关于我如何解决这个问题?
解决方案是让命令处理程序实现IElementUpdater界面。 UI元素可以这样更新:
public void updateElement(UIElement element,Map parameters)
{
element.setChecked(isSelected);
}
updateElement被调用为UI刷新的一部分,可以从处理程序的执行命令如下:
ICommandService service =(ICommandService)HandlerUtil
.getActiveWorkbenchWindowChecked(event).getService(
ICommandService.class);
service.refreshElements(event.getCommand()。getId(),null);
更多信息这里(参见单选按钮命令和更新检查状态条目)
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?
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)
这篇关于切换菜单项的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!