]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - dialogs/CmsFeedback.java
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 /** A dialog feedback based on a {@link LightweightDialog}. */
22 public class CmsFeedback
extends LightweightDialog
{
23 private final static Log log
= LogFactory
.getLog(CmsFeedback
.class);
25 private String message
;
26 private Throwable exception
;
28 public CmsFeedback(Shell parentShell
, String message
, Throwable e
) {
30 this.message
= message
;
32 log
.error(message
, e
);
35 public static void show(String message
, Throwable e
) {
36 // rethrow ThreaDeath in order to make sure that RAP will properly clean
38 if (e
instanceof ThreadDeath
)
39 throw (ThreadDeath
) e
;
42 CmsFeedback cmsFeedback
= new CmsFeedback(null, message
, e
);
43 cmsFeedback
.setBlockOnOpen(false);
45 } catch (Throwable e1
) {
46 log
.error("Cannot open error feedback (" + e
.getMessage() + "), original error below", e
);
50 public static void show(String message
) {
51 new CmsFeedback(null, message
, null).open();
54 /** Tries to find a display */
55 // private static Display getDisplay() {
57 // Display display = Display.getCurrent();
58 // if (display != null)
61 // return Display.getDefault();
62 // } catch (Exception e) {
63 // return Display.getCurrent();
67 protected Control
createDialogArea(Composite parent
) {
68 parent
.setLayout(new GridLayout(2, false));
70 Label messageLbl
= new Label(parent
, SWT
.WRAP
);
72 messageLbl
.setText(message
);
73 else if (exception
!= null)
74 messageLbl
.setText(exception
.getLocalizedMessage());
76 Button close
= new Button(parent
, SWT
.FLAT
);
77 close
.setText(CmsMsg
.close
.lead());
78 close
.setLayoutData(new GridData(SWT
.END
, SWT
.TOP
, false, false));
79 close
.addSelectionListener((Selected
) (e
) -> closeShell(OK
));
81 // Composite composite = new Composite(dialogarea, SWT.NONE);
82 // composite.setLayout(new GridLayout(2, false));
83 // composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
85 if (exception
!= null) {
86 Text stack
= new Text(parent
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
87 stack
.setEditable(false);
88 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
89 StringWriter sw
= new StringWriter();
90 exception
.printStackTrace(new PrintWriter(sw
));
91 stack
.setText(sw
.toString());