Eclipse E4 - 菜单贡献和PersistedState [英] Eclipse E4 - Menu contribution and PersistedState

查看:342
本文介绍了Eclipse E4 - 菜单贡献和PersistedState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在菜单贡献和PersistedState中出现了一个问题。从VM参数中删除-clearPersistedState标志之前,我没有问题。

I have got ditched in a problem with Menu Contribution and PersistedState. I had no problem before removing the -clearPersistedState flag from the VM args.

现在,应用程序有一个奇怪的行为,菜单的贡献开始每个执行代码的时间。

Now, the app has a weird behaviour, the menu contribution starts to pile up a menu entry every time the code is executed.

这是处理器中包含的有罪的代码片段:

Here it's the guilty snippet enclosed in a Processor:

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);


推荐答案

添加到应用程序模型的菜单项将是坚持,所以你需要检查它们是否已经存在于菜单中。 包含检查您当前没有这样做。

The menu items you add to the application model will be persisted, so you need to check if they already exist in the menu. The contains check you currently have does not do this.

您需要检查标签的匹配(或贡献URI或ID),如下所示:

You need to check for a match of the label (or the contribution URI, or the id), something like:

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
 }

这篇关于Eclipse E4 - 菜单贡献和PersistedState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆