]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/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
.eclipse
.ui
.Selected
;
9 import org
.argeo
.eclipse
.ui
.dialogs
.LightweightDialog
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.layout
.GridData
;
12 import org
.eclipse
.swt
.layout
.GridLayout
;
13 import org
.eclipse
.swt
.widgets
.Button
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Control
;
16 import org
.eclipse
.swt
.widgets
.Display
;
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
;
40 new CmsFeedback(getDisplay().getActiveShell(), message
, e
).open();
43 public static void show(String message
) {
44 new CmsFeedback(getDisplay().getActiveShell(), message
, null).open();
47 /** Tries to find a display */
48 private static Display
getDisplay() {
50 Display display
= Display
.getCurrent();
54 return Display
.getDefault();
55 } catch (Exception e
) {
56 return Display
.getCurrent();
60 protected Control
createDialogArea(Composite parent
) {
61 parent
.setLayout(new GridLayout(2, false));
63 Label messageLbl
= new Label(parent
, SWT
.WRAP
);
65 messageLbl
.setText(message
);
66 else if (exception
!= null)
67 messageLbl
.setText(exception
.getLocalizedMessage());
69 Button close
= new Button(parent
, SWT
.FLAT
);
70 close
.setText("Close");
71 close
.setLayoutData(new GridData(SWT
.END
, SWT
.TOP
, false, false));
72 close
.addSelectionListener((Selected
) (e
) -> closeShell(OK
));
74 // Composite composite = new Composite(dialogarea, SWT.NONE);
75 // composite.setLayout(new GridLayout(2, false));
76 // composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
78 if (exception
!= null) {
79 Text stack
= new Text(parent
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
80 stack
.setEditable(false);
81 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
82 StringWriter sw
= new StringWriter();
83 exception
.printStackTrace(new PrintWriter(sw
));
84 stack
.setText(sw
.toString());