From e6f46bd3c8c11c840160276bfa58ff3da93cefa4 Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Fri, 3 Nov 2023 10:16:50 -0400 Subject: [PATCH 1/3] Check for disposal --- .../gef/internal/ui/palette/editparts/EditPartTipHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java b/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java index 51ea73e9e..b9595563d 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java +++ b/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java @@ -143,7 +143,8 @@ public void shellDeactivated(ShellEvent event) { @Override public void run() { Shell active = Display.getCurrent().getActiveShell(); - if (getShell() == active || control.getShell() == active || getShell().isDisposed()) + if (getShell() == active || control.isDisposed() || control.getShell() == active + || getShell().isDisposed()) return; if (isShowing()) getShell().setCapture(false); From b5b1c40ac34be6d67fd5fb98e426ae50b1ce457a Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Fri, 3 Nov 2023 10:22:23 -0400 Subject: [PATCH 2/3] Bump patch version --- org.eclipse.gef/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.gef/META-INF/MANIFEST.MF b/org.eclipse.gef/META-INF/MANIFEST.MF index 37ce81a45..ffe6c6778 100644 --- a/org.eclipse.gef/META-INF/MANIFEST.MF +++ b/org.eclipse.gef/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Plugin.name Bundle-SymbolicName: org.eclipse.gef; singleton:=true -Bundle-Version: 3.15.100.qualifier +Bundle-Version: 3.15.200.qualifier Bundle-Activator: org.eclipse.gef.internal.InternalGEFPlugin Bundle-Vendor: %Plugin.providerName Bundle-Localization: plugin From 16d55ef09f94c22f00ccc70722bf43843643cbab Mon Sep 17 00:00:00 2001 From: Kyle Smith Date: Fri, 3 Nov 2023 10:22:54 -0400 Subject: [PATCH 3/3] Code cleanup --- .../src/org/eclipse/draw2d/PopUpHelper.java | 43 ++++++------ .../palette/editparts/EditPartTipHelper.java | 70 ++++++++----------- 2 files changed, 53 insertions(+), 60 deletions(-) diff --git a/org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java b/org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java index 201393572..ce7eef351 100644 --- a/org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java +++ b/org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java @@ -1,7 +1,7 @@ /******************************************************************************* * Copyright (c) 2000, 2010 IBM Corporation and others. * - * This program and the accompanying materials are made available under the + * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * @@ -38,14 +38,14 @@ public abstract class PopUpHelper { /** * These style bits should be used when creating the Shell. - * + * * @see #createShell() */ protected final int shellStyle; /** * Constructs a PopUpHelper to assist with popups on Control c. - * + * * @param c the Control * @since 2.0 */ @@ -55,7 +55,7 @@ protected PopUpHelper(Control c) { /** * Constructs a PopUpHelper to display the given shell style popup. - * + * * @param c the control on which the popup is active. * @param shellStyle the SWT style bits for the shell * @since 3.1 @@ -68,7 +68,7 @@ protected PopUpHelper(Control c, int shellStyle) { /** * Creates and returns the LightweightSystem object used by PopUpHelper to draw * upon. - * + * * @return the newly created LightweightSystem * @since 2.0 */ @@ -78,7 +78,7 @@ protected LightweightSystem createLightweightSystem() { /** * Creates a new Shell object with the style specified for this helper. - * + * * @return the newly created Shell * @since 2.0 */ @@ -88,20 +88,22 @@ protected Shell createShell() { /** * Dispose of this PopUpHelper object. - * + * * @since 2.0 */ public void dispose() { - if (isShowing()) + if (isShowing()) { hide(); - if (shell != null && !shell.isDisposed()) + } + if (shell != null && !shell.isDisposed()) { shell.dispose(); + } } /** * Returns this PopUpHelper's shell. If no shell exists for this PopUpHelper, a * new shell is created and hookShellListeners() is called. - * + * * @return the Shell * @since 2.0 */ @@ -116,7 +118,7 @@ protected Shell getShell() { /** * Returns the size needed to display the shell's trim. This method should not * be called until the shell has been created. - * + * * @return the size of the shells trim. * @since 3.1 */ @@ -129,7 +131,7 @@ protected Dimension getShellTrimSize() { * Returns this PopUpHelper's LightweightSystem. If no LightweightSystem exists * for this PopUpHelper, a new LightweightSystem is created with this * PopUpHelper's Shell as its Control. - * + * * @return the LightweightSystem * @since 2.0 */ @@ -143,12 +145,13 @@ protected LightweightSystem getLightweightSystem() { /** * Hides this PopUpHelper's Shell. - * + * * @since 2.0 */ protected void hide() { - if (shell != null && !shell.isDisposed()) + if (shell != null && !shell.isDisposed()) { shell.setVisible(false); + } tipShowing = false; } @@ -156,7 +159,7 @@ protected void hide() { * Desired popup helper behavior is achieved by writing listeners that * manipulate the behavior of the PopUpHelper's Shell. Override this method and * add these listeners here. - * + * * @since 2.0 */ protected abstract void hookShellListeners(); @@ -164,7 +167,7 @@ protected void hide() { /** * Returns true if this PopUpHelper's Shell is visible, * false otherwise. - * + * * @return true if this PopUpHelper's Shell is visible * @since 2.0 */ @@ -174,7 +177,7 @@ public boolean isShowing() { /** * Sets the background color of this PopUpHelper's Shell. - * + * * @param c the new background color * @since 2.0 */ @@ -184,7 +187,7 @@ public void setBackgroundColor(Color c) { /** * Sets the foreground color of this PopUpHelper's Shell. - * + * * @param c the new foreground color * @since 2.0 */ @@ -194,7 +197,7 @@ public void setForegroundColor(Color c) { /** * Sets the bounds on this PopUpHelper's Shell. - * + * * @param x the x coordinate * @param y the y coordinate * @param width the width @@ -207,7 +210,7 @@ protected void setShellBounds(int x, int y, int width, int height) { /** * Displays this PopUpHelper's Shell. - * + * * @since 2.0 */ protected void show() { diff --git a/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java b/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java index b9595563d..08ba2db99 100644 --- a/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java +++ b/org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java @@ -1,7 +1,7 @@ /******************************************************************************* * Copyright (c) 2000, 2010 IBM Corporation and others. * - * This program and the accompanying materials are made available under the + * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * @@ -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; @@ -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; } @@ -49,7 +47,7 @@ public EditPartTipHelper(Control c) { * displays the tip at the coordianates specified by tipPosX and tipPosY. The * given coordinates will be adjusted if the tip cannot be completely visible on * the screen. - * + * * @param tip The tool tip to be displayed. * @param tipPosX X coordiante of tooltip to be displayed * @param tipPosY Y coordinate of tooltip to be displayed @@ -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(); } }); @@ -139,17 +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.isDisposed() || 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(); }); } }; @@ -163,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(); + }); } }); }