切换菜单项的状态 [英] Toggling the state of a menu item

查看:177
本文介绍了切换菜单项的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我正在开发的Eclipse RCP应用程序。它有一些特定于视图的菜单,其中一个菜单项是一个项目,我想在启用相应的功能时显示一个勾号。类似地,下一次选择项目时,该项目应该被忽略,以反映相应的功能被禁用。



我的问题是这样:如何设置切换这些菜单项的状态?当我选择菜单项时,我有一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆