Start single sourcing lightweight dialog
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui / src / org / argeo / eclipse / ui / dialogs / LightweightDialog.java
index a923b0134c6c0173eef2eb0dd5bb7ea4555a915f..5649a1571cdefa0fa3f62f88f8abdcb356f47080 100644 (file)
@@ -70,8 +70,11 @@ public class LightweightDialog {
        public int open() {
                if (foregoundShell != null)
                        throw new EclipseUiException("There is already a shell");
-               backgroundShell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.ON_TOP);
+               backgroundShell = new Shell(parentShell, SWT.ON_TOP);
                backgroundShell.setFullScreen(true);
+               // if (parentShell != null) {
+               // backgroundShell.setBounds(parentShell.getBounds());
+               // } else
                // backgroundShell.setMaximized(true);
                backgroundShell.setAlpha(128);
                backgroundShell.setBackground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
@@ -84,7 +87,7 @@ public class LightweightDialog {
                // shell.pack();
                // shell.layout();
 
-               Rectangle shellBounds = Display.getCurrent().getBounds();// RAP
+               Rectangle shellBounds = parentShell != null ? parentShell.getBounds() : Display.getCurrent().getBounds();// RAP
                Point dialogSize = foregoundShell.getSize();
                int x = shellBounds.x + (shellBounds.width - dialogSize.x) / 2;
                int y = shellBounds.y + (shellBounds.height - dialogSize.y) / 2;
@@ -95,6 +98,8 @@ public class LightweightDialog {
 
                        @Override
                        public void shellDeactivated(ShellEvent e) {
+                               if (hasChildShells())
+                                       return;
                                if (returnCode == null)// not yet closed
                                        closeShell(CANCEL);
                        }
@@ -118,6 +123,8 @@ public class LightweightDialog {
 
                        @Override
                        public void focusGained(FocusEvent event) {
+                               if (hasChildShells())
+                                       return;
                                if (returnCode == null)// not yet closed
                                        closeShell(CANCEL);
                        }
@@ -126,7 +133,12 @@ public class LightweightDialog {
                if (block) {
                        try {
                                runEventLoop(foregoundShell);
+                       } catch (ThreadDeath t) {
+                               returnCode = CANCEL;
+                               if (log.isTraceEnabled())
+                                       log.error("Thread death, canceling dialog", t);
                        } catch (Throwable t) {
+                               returnCode = CANCEL;
                                log.error("Cannot open blocking lightweight dialog", t);
                        }
                }
@@ -135,6 +147,12 @@ public class LightweightDialog {
                return returnCode;
        }
 
+       private boolean hasChildShells() {
+               if (foregoundShell == null)
+                       return false;
+               return foregoundShell.getShells().length != 0;
+       }
+
        // public synchronized int openAndWait() {
        // open();
        // while (returnCode == null)
@@ -240,4 +258,8 @@ public class LightweightDialog {
                        getForegoundShell().setText(title);
        }
 
+       public Integer getReturnCode() {
+               return returnCode;
+       }
+
 }
\ No newline at end of file