我因菜单贡献和 PersistedState 的问题而被抛弃。在从虚拟机参数中删除 -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
}
关于java - Eclipse E4 - 菜单贡献和 PersistedState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27550002/