From: Mathieu Baudier Date: Wed, 7 Feb 2018 11:16:18 +0000 (+0100) Subject: Make lightweight dialog more robust X-Git-Tag: argeo-commons-2.1.71~8 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=0553f7fa3e80d37b5a0c17945a0816dff4a47e8e;p=lgpl%2Fargeo-commons.git Make lightweight dialog more robust --- diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java index 3174c4e0f..33a0d2781 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java @@ -15,13 +15,10 @@ */ package org.argeo.eclipse.ui.dialogs; -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ShellAdapter; import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.graphics.Point; @@ -31,13 +28,11 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; /** Generic lightweight dialog, not based on JFace. */ public class LightweightDialog { - private final static Log log = LogFactory.getLog(LightweightDialog.class); + // private final static Log log = LogFactory.getLog(LightweightDialog.class); private Shell parentShell; private Shell backgroundShell; @@ -63,7 +58,7 @@ public class LightweightDialog { public void open() { if (shell != null) throw new EclipseUiException("There is already a shell"); - backgroundShell = new Shell(parentShell,SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); + backgroundShell = new Shell(parentShell, SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); backgroundShell.setMaximized(true); backgroundShell.setAlpha(128); backgroundShell.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); @@ -92,15 +87,32 @@ public class LightweightDialog { }); shell.open(); + // after the foreground shell has been opened + backgroundShell.addFocusListener(new FocusListener() { + private static final long serialVersionUID = 3137408447474661070L; + + @Override + public void focusLost(FocusEvent event) { + } + + @Override + public void focusGained(FocusEvent event) { + closeShell(); + } + }); } protected void closeShell() { - shell.close(); - shell.dispose(); - shell = null; - - backgroundShell.close(); - backgroundShell.dispose(); + if (shell != null) { + shell.close(); + shell.dispose(); + shell = null; + } + + if (backgroundShell != null) { + backgroundShell.close(); + backgroundShell.dispose(); + } } protected Point getInitialSize() {