在eclipse e4 rcp应用程序中创建实现切换或无线电状态的菜单项的规范方法是什么?
这似乎是一件很基本的事情,但我找到的所有文档都依赖于e3 API,并创建了对org.eclipse.ui的依赖关系,这在e4中是不允许的。
我用于单选按钮菜单的一种可能方式,它将单选按钮状态保存在部件类中。
我使用多个类型设置为Radio
的Direct Menu Item
条目。
我将标记值(在菜单项的补充页上(设置为要与菜单项关联的值。
我对所有菜单项使用相同的处理程序。
在处理程序中,我注入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
的类。