-
Notifications
You must be signed in to change notification settings - Fork 184
Description
Describe the bug
We got a Bug report in NatTable that when opening an editor on double click, where the editor opens a Browser of type SWT.EDGE, the editor gets opened again after the first one is closed.
The reason is that the second click on double click seems not to be cleared from the "deferredEvents". Edge.callAndWait() calls Display.readAndDispatch() which in turn calls Display.runDeferredEvents(). This actually means we get an additional mouseUp event after handling the mouseDoubleClick event.
To Reproduce
- Start the following snippet
- Double click on the first button, which opens a Browser in a dialog. In the console you see that you get a mouseUp event and a mouseDoubleClick event
- Double click on the second button "Open Edge Browser in Dialog". In the console you now see that after the mouseDoubleClick event, there is an additional mouseUp event.
public class SnippetEdgeEventIssue {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Snippet Edge Event Issue");
shell.setLayout(new RowLayout());
Button browserButton = new Button(shell, SWT.PUSH);
browserButton.setText("Open Browser in Dialog");
browserButton.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
System.out.println("mouse up");
}
@Override
public void mouseDown(MouseEvent e) {
}
@Override
public void mouseDoubleClick(MouseEvent e) {
System.out.println("mouse double click");
Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
dialog.setLayout(new FillLayout());
try {
Browser browser = new Browser(dialog, SWT.NONE);
} catch (SWTError err) {
System.out.println("Could not instantiate Browser: " + err.getMessage());
display.dispose();
return;
}
dialog.open();
}
});
Button browserEdgeButton = new Button(shell, SWT.PUSH);
browserEdgeButton.setText("Open Edge Browser in Dialog");
browserEdgeButton.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent e) {
System.out.println("mouse up");
}
@Override
public void mouseDown(MouseEvent e) {
}
@Override
public void mouseDoubleClick(MouseEvent e) {
System.out.println("mouse double click");
Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
dialog.setLayout(new FillLayout());
try {
Browser browser = new Browser(dialog, SWT.EDGE);
} catch (SWTError err) {
System.out.println("Could not instantiate Browser: " + err.getMessage());
display.dispose();
return;
}
dialog.open();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Expected behavior
There should be only a mouseUp event followed by a mouseDoubleClick event. The additional mouseUp event should not be fired.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
- Additional OS info (e.g. OS version, Linux Desktop, etc)
Windows 11
- JRE/JDK version
Java 11
Version since
Eclipse or SWT version since when the behavior is seen: 4.24, haven't tested older versions. But it is reported for the current Eclipse version 2024-06.