如何解决如何在 Eclipse e4 应用程序的菜单/工具栏中创建切换/单选项?
在 eclipse e4 rcp 应用程序中创建实现切换或单选状态的菜单项的规范方法是什么?
这似乎是一件很基本的事情,但我找到的所有文档都依赖于 e3 API,并创建了对 org.eclipse.ui 的依赖,这在 e4 中是不允许的。
解决方法
我用于单选按钮菜单的一种可能方式,它将单选按钮状态保存在部件类中。
我使用多个 Direct Menu Item
条目并将类型设置为 Radio
。
我将 Tag 值(在菜单项的补充页面上)设置为要与菜单项关联的值。
我对所有菜单项使用相同的处理程序。
在处理程序中,我注入了 MPart
和 MItem
:
@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);
}
您还可以使用 Eclipse 上下文中的任何类来代替 MPart
- 例如声明为 @Creatable
和 @Singleton
的类。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。