繁体   English   中英

如何在 Eclipse e4 应用程序的菜单/工具栏中创建切换/收音机项目?

[英]How to create a toggle/radio item in the menu/toolbar of an Eclipse e4 application?

在 eclipse e4 rcp 应用程序中创建实现切换或无线电 state 的菜单项的规范方法是什么?

这似乎是一个基本的东西,但我发现的所有文档都依赖于 e3 API 并创建对 org.eclipse.ui 的依赖关系,这在 e4 中是不允许的。

我用于单选按钮菜单的一种可能方式,它将单选按钮 state 保存在 class 部分中。

我使用类型设置为Radio的多个Direct Menu Item条目。

我将标签值(在菜单项的补充页面上)设置为我想与菜单项关联的值。

我对所有菜单项使用相同的处理程序。

在处理程序中,我注入MPartMItem

@Execute
public void execute(final MPart part, final MItem mitem)
{
  // Only take action on the selected radio item

  if (!mitem.isSelected())
    return;

  // The tag value specifying the radio state

  String tag = mitem.getTags().get(0);

  // Get the part class

  MyPart myPart = (MyPart)part.getObject();

  // tell the part about the state change

  myPart.setState(tag);
}

除了MPart ,您还可以使用 Eclipse 上下文中的任何 class - 例如声明为@Creatable和 @Singleton 的任何@Singleton

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM