在Jface MenuManager和TreViewer中隐藏菜单项 [英] Hiding menu items in Jface MenuManager and TreViewer

查看:400
本文介绍了在Jface MenuManager和TreViewer中隐藏菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要隐藏所有的弹出菜单项,当我点击不是Item1的任何节点,但项目没有被隐藏,为什么?

管理器.getItems()[i] .setVisible(false)内部循环被触发)

I want to hide all popup menu items when I click on any node that is not "Item1", but the items are not being hidden, why?
(The manager.getItems()[i].setVisible(false) inside loop is triggered)

Action a1 = new Action("XXX") {};
Action a2 = new Action("YYY") {};
Action a3 = new Action("ZZZ") {};

final MenuManager mgr = new MenuManager();


mgr.add(a1);
mgr.add(a2);
mgr.add(a3);

mgr.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) tree
                    .getSelection();
            if (!selection.isEmpty()) {
                String str = ((MyModel) selection.getFirstElement())
                        .toString();
                if (str.equals("Item1")) {
                    for (int i = 0; i < 3; i++) {
                        manager.getItems()[i].setVisible(true);
                    }
                } else {
                    for (int i = 0; i < 3; i++) {
                        manager.getItems()[i].setVisible(false);
                    }
                }
            }
        }
    });

当我第一次点击Item( str.equals(Item1) ),点击其他项目不要隐藏菜单项。

When first I click on Item (str.equals("Item1")), clicking on other items don't hide the menu items.

推荐答案

你必须打电话 manager.update(true); 在设置菜单项的可见性后,使 MenuManager 更新底层的菜单小部件。

You have to call manager.update(true); after setting the visibility of your menu items to make the MenuManager update the underlying Menu widget.

这篇关于在Jface MenuManager和TreViewer中隐藏菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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