]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - swt/org.argeo.cms.swt/src/org/argeo/cms/swt/dialogs/CmsFeedback.java
1 package org
.argeo
.cms
.swt
.dialogs
;
3 import java
.io
.PrintWriter
;
4 import java
.io
.StringWriter
;
6 import org
.argeo
.api
.cms
.CmsLog
;
7 import org
.argeo
.cms
.CmsMsg
;
8 import org
.argeo
.cms
.swt
.Selected
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.layout
.GridData
;
11 import org
.eclipse
.swt
.layout
.GridLayout
;
12 import org
.eclipse
.swt
.widgets
.Button
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.swt
.widgets
.Control
;
15 import org
.eclipse
.swt
.widgets
.Label
;
16 import org
.eclipse
.swt
.widgets
.Shell
;
17 import org
.eclipse
.swt
.widgets
.Text
;
19 /** A dialog feedback based on a {@link LightweightDialog}. */
20 public class CmsFeedback
extends LightweightDialog
{
21 private final static CmsLog log
= CmsLog
.getLog(CmsFeedback
.class);
23 private String message
;
24 private Throwable exception
;
26 public CmsFeedback(Shell parentShell
, String message
, Throwable e
) {
28 this.message
= message
;
30 log
.error(message
, e
);
33 public static CmsFeedback
show(String message
, Throwable e
) {
34 // rethrow ThreaDeath in order to make sure that RAP will properly clean
36 if (e
instanceof ThreadDeath
)
37 throw (ThreadDeath
) e
;
40 CmsFeedback cmsFeedback
= new CmsFeedback(null, message
, e
);
41 cmsFeedback
.setBlockOnOpen(false);
44 } catch (Throwable e1
) {
45 log
.error("Cannot open error feedback (" + e
.getMessage() + "), original error below", e
);
50 public static CmsFeedback
show(String message
) {
51 CmsFeedback cmsFeedback
= new CmsFeedback(null, message
, null);
56 /** Tries to find a display */
57 // private static Display getDisplay() {
59 // Display display = Display.getCurrent();
60 // if (display != null)
63 // return Display.getDefault();
64 // } catch (Exception e) {
65 // return Display.getCurrent();
69 protected Control
createDialogArea(Composite parent
) {
70 parent
.setLayout(new GridLayout(2, false));
72 Label messageLbl
= new Label(parent
, SWT
.WRAP
);
74 messageLbl
.setText(message
);
75 else if (exception
!= null)
76 messageLbl
.setText(exception
.getLocalizedMessage());
78 Button close
= new Button(parent
, SWT
.FLAT
);
79 close
.setText(CmsMsg
.close
.lead());
80 close
.setLayoutData(new GridData(SWT
.END
, SWT
.TOP
, false, false));
81 close
.addSelectionListener((Selected
) (e
) -> closeShell(OK
));
83 // Composite composite = new Composite(dialogarea, SWT.NONE);
84 // composite.setLayout(new GridLayout(2, false));
85 // composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
87 if (exception
!= null) {
88 Text stack
= new Text(parent
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
89 stack
.setEditable(false);
90 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
91 StringWriter sw
= new StringWriter();
92 exception
.printStackTrace(new PrintWriter(sw
));
93 stack
.setText(sw
.toString());