Skip to content

Commit

Permalink
Make sure to check for disposal in asyncExec (#276)
Browse files Browse the repository at this point in the history
* Check for disposal

* Bump patch version

* Code cleanup

---------

Co-authored-by: azoitl <[email protected]>
  • Loading branch information
kysmith-csg and azoitl authored Dec 8, 2023
1 parent 275e99c commit e049527
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
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

0 comments on commit e049527

Please sign in to comment.