[英]How to create a toggle/radio item in the menu/toolbar of an Eclipse e4 application?
What is the canonical way of creating a menu item that implements a toggle or radio state in an eclipse e4 rcp application?在 eclipse e4 rcp 应用程序中创建实现切换或无线电 state 的菜单项的规范方法是什么?
It seems such a basic thing, but all the documentation I found relies on e3 API and creates dependencies to org.eclipse.ui, which is not allowed in e4.这似乎是一个基本的东西,但我发现的所有文档都依赖于 e3 API 并创建对 org.eclipse.ui 的依赖关系,这在 e4 中是不允许的。
One possible way that I use for a radio button menu which saves the radio button state in the part class.我用于单选按钮菜单的一种可能方式,它将单选按钮 state 保存在 class 部分中。
I use multiple Direct Menu Item
entries with the type set to Radio
.我使用类型设置为
Radio
的多个Direct Menu Item
条目。
I set a Tag value (on the supplementary page of the menu item) to the value I want to associate with the menu item.我将标签值(在菜单项的补充页面上)设置为我想与菜单项关联的值。
I use the same handler for all of the menu items.我对所有菜单项使用相同的处理程序。
In the handler I inject the MPart
and the MItem
:在处理程序中,我注入
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);
}
Instead of the MPart
you could also use any class that is in the Eclipse Context - such as one declared as @Creatable
and @Singleton
.除了
MPart
,您还可以使用 Eclipse 上下文中的任何 class - 例如声明为@Creatable
和 @Singleton 的任何@Singleton
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.