Menumanager setVisible doesn't work as expected [message #741662] |
Wed, 19 October 2011 19:22 |
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);
}
}
}
}
});
|
|
|
Powered by
FUDForum. Page generated in 0.04203 seconds