From: Mathieu Baudier Date: Mon, 21 May 2018 16:58:04 +0000 (+0200) Subject: Make lightweight dialog more robust X-Git-Tag: argeo-commons-2.1.74~25 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=b7606ca647d875808ee3fdd19240dc9d51f40ac6 Make lightweight dialog more robust --- diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsFeedback.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsFeedback.java index a4f3362da..3ee083394 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsFeedback.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsFeedback.java @@ -5,6 +5,7 @@ import java.io.StringWriter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.cms.CmsMsg; import org.argeo.eclipse.ui.Selected; import org.argeo.eclipse.ui.dialogs.LightweightDialog; import org.eclipse.swt.SWT; @@ -36,7 +37,13 @@ public class CmsFeedback extends LightweightDialog { if (e instanceof ThreadDeath) throw (ThreadDeath) e; - new CmsFeedback(null, message, e).open(); + try { + CmsFeedback cmsFeedback = new CmsFeedback(null, message, e); + cmsFeedback.setBlockOnOpen(false); + cmsFeedback.open(); + } catch (Throwable e1) { + log.error("Cannot open error feedback (" + e.getMessage() + "), original error below", e); + } } public static void show(String message) { @@ -44,17 +51,17 @@ public class CmsFeedback extends LightweightDialog { } /** Tries to find a display */ -// private static Display getDisplay() { -// try { -// Display display = Display.getCurrent(); -// if (display != null) -// return display; -// else -// return Display.getDefault(); -// } catch (Exception e) { -// return Display.getCurrent(); -// } -// } + // private static Display getDisplay() { + // try { + // Display display = Display.getCurrent(); + // if (display != null) + // return display; + // else + // return Display.getDefault(); + // } catch (Exception e) { + // return Display.getCurrent(); + // } + // } protected Control createDialogArea(Composite parent) { parent.setLayout(new GridLayout(2, false)); @@ -66,7 +73,7 @@ public class CmsFeedback extends LightweightDialog { messageLbl.setText(exception.getLocalizedMessage()); Button close = new Button(parent, SWT.FLAT); - close.setText("Close"); + close.setText(CmsMsg.close.lead()); close.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false)); close.addSelectionListener((Selected) (e) -> closeShell(OK)); 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 6e9b668bf..a923b0134 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,6 +15,8 @@ */ package org.argeo.eclipse.ui.dialogs; +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; @@ -32,6 +34,8 @@ import org.eclipse.swt.widgets.Shell; /** Generic lightweight dialog, not based on JFace. */ public class LightweightDialog { + private final static Log log = LogFactory.getLog(LightweightDialog.class); + // must be the same value as org.eclipse.jface.window.Window#OK public final static int OK = 0; // must be the same value as org.eclipse.jface.window.Window#CANCEL @@ -120,7 +124,11 @@ public class LightweightDialog { }); if (block) { - runEventLoop(foregoundShell); + try { + runEventLoop(foregoundShell); + } catch (Throwable t) { + log.error("Cannot open blocking lightweight dialog", t); + } } if (returnCode == null) returnCode = OK;