[英]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.