[英]Eclipse E4 - Menu contribution and PersistedState
我陷入了菜单贡献和PersistedState的问题。 从VM args删除-clearPersistedState标志之前,我没有任何问题。
现在,该应用程序具有怪异的行为,每次执行代码时,菜单项就会开始堆积菜单项。
这是包含在处理器中的内代码段:
MDirectMenuItem menuItem = MMenuFactory.INSTANCE.createDirectMenuItem();
menuItem.setLabel("Another Exit");
menuItem.setContributionURI("bundleclass://"
+ "com.telespazio.optsat.wizard/"
+ ExitHandlerWithCheck.class.getName());
if (!menu.getChildren().contains(menuItem))
menu.getChildren().add(menuItem);
您添加到应用程序模型中的菜单项将保留下来,因此您需要检查菜单中是否已经存在。 您当前拥有的contains
支票不执行此操作。
您需要检查标签(或贡献URI或ID)是否匹配,例如:
List<MMenuElement> children = menu.getChildren();
boolean gotExisting = false;
for (MMenuElement child : children)
{
if ("Another Exit".equals(child.getLabel())
{
gotExisting = true;
break;
}
}
if (!gotExisting)
{
... add to menu
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.