Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365214

Summary: no event on menu item selection
Product: [Eclipse Project] Platform Reporter: Andrei Diaconu <andi_dm1>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: remy.suen
Version: 3.7.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Andrei Diaconu CLA 2011-11-30 10:53:17 EST
To reproduce the bug, do the following using the snippet given below:

* click anywhere on the shell without trim (a popup menu appears)
* click on the menu item

You will notice that no selection event has been generated.


import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

public class NoSelectionEvent {

	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display);
		shell.open();

		final Shell secondShell = new Shell(shell, SWT.NO_TRIM);
		final Listener listener = new Listener() {
			@Override
			public void handleEvent(Event event) {
				switch (event.type) {
					case SWT.MouseUp:
						final Menu menu = new Menu(secondShell, SWT.POP_UP);
						final MenuItem menuItem = new MenuItem(menu, SWT.NONE);
						menuItem.addListener(SWT.Selection, new Listener() {
							@Override
							public void handleEvent(Event event) {
								System.out.println("menu item selected");
							}
						});
						menu.setVisible(true);
						break;
					case SWT.MouseExit:
						secondShell.dispose();
						break;
				}
			}
		};
		secondShell.addListener(SWT.MouseUp, listener);
		secondShell.addListener(SWT.MouseExit, listener);
		secondShell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}



I need this dispose-on-exit behavior for tools that appear on hover, sort of rich tooltips.
Comment 1 Andrei Diaconu CLA 2011-12-01 03:05:13 EST
The workaround is to setVisible(false) instead of disposing the shell, and schedule the disposing for later with asyncExec.
Comment 2 Lars Vogel CLA 2019-11-14 03:14:24 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.
Comment 3 Andrei Diaconu CLA 2019-11-14 03:26:20 EST
The problem still occurs, but as mentioned before, I have a workaround.

Maybe it is OK to close the ticket, because it is a strange timing situation: 
* the shell is being disposed because the exit event
* the menu belonging to the shell being disposed wants to fire the event