X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.eclipse.ui%2Fsrc%2Forg%2Fargeo%2Feclipse%2Fui%2Fdialogs%2FLightweightDialog.java;h=33a0d2781d7f968943bd9542e87ab25bc0020f16;hb=62d5fd1e1caad85423e45cc878b93c4be2f09713;hp=3174c4e0f01e9a14b96d59bfd974fd823ef11660;hpb=4976a9f749b4a37e980830c2d4a8d79815cc28c3;p=lgpl%2Fargeo-commons.git 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() {