diff options
author | Uwe Stieber | 2014-05-27 12:50:02 +0000 |
---|---|---|
committer | Uwe Stieber | 2014-05-27 12:50:02 +0000 |
commit | 9383c7cd00e32c75e3b0154f74a32a6a9030cfb6 (patch) | |
tree | 659d34132a126875feb171b4415fcee261eea67f | |
parent | cec947cc44e78e5a433579df83c276cef1df1d4f (diff) | |
download | org.eclipse.tcf-9383c7cd00e32c75e3b0154f74a32a6a9030cfb6.tar.gz org.eclipse.tcf-9383c7cd00e32c75e3b0154f74a32a6a9030cfb6.tar.xz org.eclipse.tcf-9383c7cd00e32c75e3b0154f74a32a6a9030cfb6.zip |
Target Explorer: Fix popup notification leaks shells
3 files changed, 53 insertions, 41 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AbstractNotificationPopup.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AbstractNotificationPopup.java index 559c3d638..6e8743273 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AbstractNotificationPopup.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/AbstractNotificationPopup.java @@ -79,8 +79,6 @@ public abstract class AbstractNotificationPopup extends Window { /* default */ GradientColors color; - /* default */ final Display display; - private Shell shell; private Region lastUsedRegion; @@ -91,24 +89,27 @@ public abstract class AbstractNotificationPopup extends Window { @Override protected IStatus run(IProgressMonitor monitor) { - if (!display.isDisposed()) { - display.asyncExec(new Runnable() { - @Override - public void run() { - Shell shell = AbstractNotificationPopup.this.getShell(); - if (shell == null || shell.isDisposed()) { - return; - } + if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null && PlatformUI.getWorkbench().getDisplay() != null) { + final Display display = PlatformUI.getWorkbench().getDisplay(); + if (!display.isDisposed()) { + display.asyncExec(new Runnable() { + @Override + public void run() { + Shell shell = AbstractNotificationPopup.this.getShell(); + if (shell == null || shell.isDisposed()) { + return; + } - if (isMouseOver(shell)) { - scheduleAutoClose(); - return; - } + if (isMouseOver(shell)) { + scheduleAutoClose(); + return; + } - AbstractNotificationPopup.this.closeFade(); - } + AbstractNotificationPopup.this.closeFade(); + } - }); + }); + } } if (monitor.isCanceled()) { return Status.CANCEL_STATUS; @@ -126,17 +127,29 @@ public abstract class AbstractNotificationPopup extends Window { private final boolean fadingEnabled; - public AbstractNotificationPopup(Display display) { - this(display, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); + /** + * Constructor + * + * @param parent The parent shell or <code>null</code> to create a top level shell. + * @param style The shell style. + */ + public AbstractNotificationPopup(Shell parent) { + this(parent, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); } - public AbstractNotificationPopup(Display display, int style) { - super(new Shell(display)); + /** + * Constructor + * + * @param parent The parent shell or <code>null</code> to create a top level shell. + * @param style The shell style. + */ + public AbstractNotificationPopup(Shell parent, int style) { + super(parent); setShellStyle(style); - this.display = display; resources = new LocalResourceManager(JFaceResources.getResources()); - initResources(); + + color = new GradientColors(PlatformUI.getWorkbench().getDisplay(), resources); closeJob.setSystem(true); @@ -245,10 +258,6 @@ public abstract class AbstractNotificationPopup extends Window { return color.getTitleText(); } - private void initResources() { - color = new GradientColors(display, resources); - } - @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); @@ -311,10 +320,11 @@ public abstract class AbstractNotificationPopup extends Window { } /* default */ boolean isMouseOver(Shell shell) { - if (display.isDisposed()) { - return false; + if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null + && PlatformUI.getWorkbench().getDisplay() != null && !PlatformUI.getWorkbench().getDisplay().isDisposed()) { + return shell.getBounds().contains(PlatformUI.getWorkbench().getDisplay().getCursorLocation()); } - return shell.getBounds().contains(display.getCursorLocation()); + return false; } @Override @@ -522,6 +532,7 @@ public abstract class AbstractNotificationPopup extends Window { if (!shell.isDisposed()) { if (alpha == 0) { shell.close(); + shell.dispose(); } else if (isMouseOver(shell)) { if (fadeJob != null) { fadeJob.cancelAndWait(false); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/NotificationPopup.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/NotificationPopup.java index bc1d7320a..9a62b4621 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/NotificationPopup.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/NotificationPopup.java @@ -52,10 +52,10 @@ public class NotificationPopup extends AbstractNotificationPopup { /** * Constructor * - * @param parent The parent shell. Must not be <code>null</code>. + * @param parent The parent shell or <code>null</code> to create a top level shell. */ public NotificationPopup(Shell parent) { - super(parent.getDisplay()); + super(parent); } /* (non-Javadoc) diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/PopupNotificationSink.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/PopupNotificationSink.java index b83d49fbe..27d6f8b78 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/PopupNotificationSink.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.notifications/src/org/eclipse/tcf/te/ui/notifications/internal/popup/PopupNotificationSink.java @@ -27,7 +27,6 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; import org.eclipse.tcf.te.runtime.events.NotifyEvent; import org.eclipse.tcf.te.ui.notifications.nls.Messages; import org.eclipse.ui.PlatformUI; @@ -135,14 +134,16 @@ public class PopupNotificationSink { popup.close(); } - Shell shell = new Shell(PlatformUI.getWorkbench().getDisplay()); - popup = new NotificationPopup(shell); - List<NotifyEvent> toDisplay = new ArrayList<NotifyEvent>(currentlyNotifying); - Collections.sort(toDisplay); - popup.setContents(toDisplay); - cleanNotified(); - popup.setBlockOnOpen(false); - popup.open(); + if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench() != null + && PlatformUI.getWorkbench().getDisplay() != null && !PlatformUI.getWorkbench().getDisplay().isDisposed()) { + popup = new NotificationPopup(PlatformUI.getWorkbench().getDisplay().getActiveShell()); + List<NotifyEvent> toDisplay = new ArrayList<NotifyEvent>(currentlyNotifying); + Collections.sort(toDisplay); + popup.setContents(toDisplay); + cleanNotified(); + popup.setBlockOnOpen(false); + popup.open(); + } } } |