From 0312bc5985da332ebbf702435f2e176da4febc25 Mon Sep 17 00:00:00 2001 From: mbaudier Date: Tue, 3 Jul 2018 11:21:06 +0200 Subject: [PATCH] Properly cancel dialog by thread death --- .../eclipse/ui/dialogs/LightweightDialog.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 -- 2.30.2