Properly cancel dialog by thread death
authormbaudier <mbaudier@europe>
Tue, 3 Jul 2018 09:21:06 +0000 (11:21 +0200)
committermbaudier <mbaudier@europe>
Tue, 3 Jul 2018 09:21:06 +0000 (11:21 +0200)
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java

index a923b0134c6c0173eef2eb0dd5bb7ea4555a915f..cc8a830bf07e77fd1a4db207b5989bbeb512f2d5 100644 (file)
@@ -95,6 +95,8 @@ public class LightweightDialog {
 
                        @Override
                        public void shellDeactivated(ShellEvent e) {
+                               if (hasChildShells())
+                                       return;
                                if (returnCode == null)// not yet closed
                                        closeShell(CANCEL);
                        }
@@ -118,6 +120,8 @@ public class LightweightDialog {
 
                        @Override
                        public void focusGained(FocusEvent event) {
+                               if (hasChildShells())
+                                       return;
                                if (returnCode == null)// not yet closed
                                        closeShell(CANCEL);
                        }
@@ -126,7 +130,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 +144,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 +255,8 @@ public class LightweightDialog {
                        getForegoundShell().setText(title);
        }
 
+       public Integer getReturnCode() {
+               return returnCode;
+       }
+
 }
\ No newline at end of file