Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Menumanager setVisible doesn't work as expected
Menumanager setVisible doesn't work as expected [message #741662] Wed, 19 October 2011 15:22
davids  is currently offline davids
Messages: 2
Registered: October 2011
Junior Member
I want to show a popup menu on a tree, with following conditions:
When the node "Item1" is selected, show the menu items via setVisible(true), when any other node is selected hide items setVisible(false).

In my code there is a problem, if on application start, I right click on node "Item1" I see the menu items. Then if I try to click on any other nodes THE MENU ITEMS STILL VISIBLE.

Why??


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);
                    }
                }
            }
        }
    });
Previous Topic:TableViewer - DoubleClick events for column
Next Topic:Rebroadcast selection after TableViewer row changed
Goto Forum:
  


Current Time: Sat Aug 30 12:31:55 EDT 2014

Powered by FUDForum. Page generated in 0.02443 seconds