]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsFeedback.java
3ee083394aa7f85c10d6c57e38c7a2288f737bdd
1 package org
.argeo
.cms
.ui
.dialogs
;
3 import java
.io
.PrintWriter
;
4 import java
.io
.StringWriter
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.cms
.CmsMsg
;
9 import org
.argeo
.eclipse
.ui
.Selected
;
10 import org
.argeo
.eclipse
.ui
.dialogs
.LightweightDialog
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.layout
.GridData
;
13 import org
.eclipse
.swt
.layout
.GridLayout
;
14 import org
.eclipse
.swt
.widgets
.Button
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.swt
.widgets
.Label
;
18 import org
.eclipse
.swt
.widgets
.Shell
;
19 import org
.eclipse
.swt
.widgets
.Text
;
21 public class CmsFeedback
extends LightweightDialog
{
22 private final static Log log
= LogFactory
.getLog(CmsFeedback
.class);
24 private String message
;
25 private Throwable exception
;
27 public CmsFeedback(Shell parentShell
, String message
, Throwable e
) {
29 this.message
= message
;
31 log
.error(message
, e
);
34 public static void show(String message
, Throwable e
) {
35 // rethrow ThreaDeath in order to make sure that RAP will properly clean
37 if (e
instanceof ThreadDeath
)
38 throw (ThreadDeath
) e
;
41 CmsFeedback cmsFeedback
= new CmsFeedback(null, message
, e
);
42 cmsFeedback
.setBlockOnOpen(false);
44 } catch (Throwable e1
) {
45 log
.error("Cannot open error feedback (" + e
.getMessage() + "), original error below", e
);
49 public static void show(String message
) {
50 new CmsFeedback(null, message
, null).open();
53 /** Tries to find a display */
54 // private static Display getDisplay() {
56 // Display display = Display.getCurrent();
57 // if (display != null)
60 // return Display.getDefault();
61 // } catch (Exception e) {
62 // return Display.getCurrent();
66 protected Control
createDialogArea(Composite parent
) {
67 parent
.setLayout(new GridLayout(2, false));
69 Label messageLbl
= new Label(parent
, SWT
.WRAP
);
71 messageLbl
.setText(message
);
72 else if (exception
!= null)
73 messageLbl
.setText(exception
.getLocalizedMessage());
75 Button close
= new Button(parent
, SWT
.FLAT
);
76 close
.setText(CmsMsg
.close
.lead());
77 close
.setLayoutData(new GridData(SWT
.END
, SWT
.TOP
, false, false));
78 close
.addSelectionListener((Selected
) (e
) -> closeShell(OK
));
80 // Composite composite = new Composite(dialogarea, SWT.NONE);
81 // composite.setLayout(new GridLayout(2, false));
82 // composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
84 if (exception
!= null) {
85 Text stack
= new Text(parent
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
86 stack
.setEditable(false);
87 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
88 StringWriter sw
= new StringWriter();
89 exception
.printStackTrace(new PrintWriter(sw
));
90 stack
.setText(sw
.toString());