Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to check for disposal in asyncExec #276

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ protected Shell createShell() {
* @since 2.0
*/
public void dispose() {
if (isShowing())
if (isShowing()) {
hide();
if (shell != null && !shell.isDisposed())
}
if (shell != null && !shell.isDisposed()) {
shell.dispose();
}
}

/**
Expand Down Expand Up @@ -147,8 +149,9 @@ protected LightweightSystem getLightweightSystem() {
* @since 2.0
*/
protected void hide() {
if (shell != null && !shell.isDisposed())
if (shell != null && !shell.isDisposed()) {
shell.setVisible(false);
}
tipShowing = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
Expand All @@ -35,8 +32,9 @@ class EditPartTipHelper extends org.eclipse.draw2d.PopUpHelper {
private ShellListener shellListener;

private static void setHelper(EditPartTipHelper helper) {
if (currentHelper != null && currentHelper != helper && currentHelper.isShowing())
if (currentHelper != null && currentHelper != helper && currentHelper.isShowing()) {
currentHelper.hide();
}
currentHelper = helper;
}

Expand Down Expand Up @@ -121,15 +119,13 @@ public void mouseExit(MouseEvent e) {
* cursor is no longer in the tooltip. This occurs in the rare case that a
* mouseEnter is not received on the tooltip when it appears.
*/
getShell().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
if (!getShell().getBounds().contains(eventPoint)) {
if (isShowing())
getShell().setCapture(false);
dispose();
getShell().addMouseMoveListener(e -> {
Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
if (!getShell().getBounds().contains(eventPoint)) {
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
}
});

Expand All @@ -139,16 +135,16 @@ public void mouseMove(MouseEvent e) {
shellListener = new ShellAdapter() {
@Override
public void shellDeactivated(ShellEvent event) {
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
Shell active = Display.getCurrent().getActiveShell();
if (getShell() == active || control.getShell() == active || getShell().isDisposed())
return;
if (isShowing())
getShell().setCapture(false);
dispose();
Display.getCurrent().asyncExec(() -> {
Shell active = Display.getCurrent().getActiveShell();
if (getShell() == active || control.isDisposed() || control.getShell() == active
|| getShell().isDisposed()) {
return;
}
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
});
}
};
Expand All @@ -162,22 +158,17 @@ public void run() {
* dispose of the shell.
*/
if (SWT.getPlatform().equals("gtk")) { //$NON-NLS-1$
getShell().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
Point cursorLoc = Display.getCurrent().getCursorLocation();
if (!getShell().getBounds().contains(cursorLoc)) {
// This must be run asynchronously. If not, other paint
// listeners may attempt to paint on a disposed control.
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
if (isShowing())
getShell().setCapture(false);
dispose();
}
});
}
getShell().addPaintListener(event -> {
Point cursorLoc = Display.getCurrent().getCursorLocation();
if (!getShell().getBounds().contains(cursorLoc)) {
// This must be run asynchronously. If not, other paint
// listeners may attempt to paint on a disposed control.
Display.getCurrent().asyncExec(() -> {
if (isShowing()) {
getShell().setCapture(false);
}
dispose();
});
}
});
}
Expand Down
Loading