Context-sensitive popup menu on TreeItem - trying to avoid extra Dispatch loops [message #533570] |
Fri, 14 May 2010 15:09 |
Misha Koshelev Messages: 31 Registered: May 2010 |
Member |
|
|
Dear All:
I have followed instructions in a prior post to come up with something like:
tree.addListener(SWT.MouseDown,new Listener() {
public void handleEvent(Event event) {
Point point=new Point(event.x,event.y);
TreeItem item=tree.getItem(point);
if (item!=null&&event.button==3) {
Menu menu=new Menu(getShell(),SWT.POP_UP);
MenuItem menuItem=new MenuItem(menu,SWT.PUSH);
menuItem.setText("&Find on Page");
menuItem.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
// do something
}
});
Point shellLocation=shell.getLocation();
Point treeLocation=tree.getLocation();
menu.setLocation(shellLocation.x+treeLocation.x+event.x,shellLocation.y+treeLocation.y+event.y);
menu.setVisible(true);
/* I AM TRYING TO AVOID THIS LOOP IS THIS NECESSARY
while (!menu.isDisposed()&&menu.isVisible()) {
if (!Display.getDefault().readAndDispatch())
Display.getDefault().sleep();
}
menu.dispose(); */
}
}
}
});
Specifically, this is similar to:
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Showapopup menuwaitforittoclose.htm
Taking in or leaving out event loop above seems to have no effect. Is it necessary?
Also, if I don't have the event loop, when is the right time to dispose the menu?
Thank you
Misha
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02364 seconds