From: mbaudier Date: Tue, 3 Jul 2018 09:21:06 +0000 (+0200) Subject: Properly cancel dialog by thread death X-Git-Tag: argeo-commons-2.1.74~9 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=0312bc5985da332ebbf702435f2e176da4febc25;p=lgpl%2Fargeo-commons.git Properly cancel dialog by thread death --- 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 a923b0134..cc8a830bf 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 @@ -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