]>
git.argeo.org Git - gpl/argeo-jcr.git/blob - swt/org.argeo.cms.jcr.ui/src/org/argeo/eclipse/ui/dialogs/ErrorFeedback.java
1 package org
.argeo
.eclipse
.ui
.dialogs
;
3 import java
.io
.PrintWriter
;
4 import java
.io
.StringWriter
;
6 import org
.argeo
.api
.cms
.CmsLog
;
7 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
8 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.graphics
.Point
;
11 import org
.eclipse
.swt
.layout
.GridData
;
12 import org
.eclipse
.swt
.layout
.GridLayout
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.swt
.widgets
.Control
;
15 import org
.eclipse
.swt
.widgets
.Display
;
16 import org
.eclipse
.swt
.widgets
.Shell
;
17 import org
.eclipse
.swt
.widgets
.Text
;
20 * Generic error dialog to be used in try/catch blocks.
22 * @deprecated Use CMS dialogs instead.
25 public class ErrorFeedback
extends TitleAreaDialog
{
26 private static final long serialVersionUID
= -8918084784628179044L;
28 private final static CmsLog log
= CmsLog
.getLog(ErrorFeedback
.class);
30 private final String message
;
31 private final Throwable exception
;
33 public static void 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
;
39 new ErrorFeedback(newShell(), message
, e
).open();
42 public static void show(String message
) {
43 new ErrorFeedback(newShell(), message
, null).open();
46 private static Shell
newShell() {
47 return new Shell(getDisplay(), SWT
.NO_TRIM
);
50 /** Tries to find a display */
51 private static Display
getDisplay() {
53 Display display
= Display
.getCurrent();
57 return Display
.getDefault();
58 } catch (Exception e
) {
59 return Display
.getCurrent();
63 public ErrorFeedback(Shell parentShell
, String message
, Throwable e
) {
65 setShellStyle(SWT
.NO_TRIM
);
66 this.message
= message
;
68 log
.error(message
, e
);
71 protected Point
getInitialSize() {
72 if (exception
!= null)
73 return new Point(800, 600);
75 return new Point(400, 300);
79 protected Control
createDialogArea(Composite parent
) {
80 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
81 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
82 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
83 composite
.setLayout(new GridLayout(2, false));
84 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
86 setMessage(message
!= null ? message
+ (exception
!= null ?
": " + exception
.getMessage() : "")
87 : exception
!= null ? exception
.getMessage() : "Unkown Error", IMessageProvider
.ERROR
);
89 if (exception
!= null) {
90 Text stack
= new Text(composite
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
91 stack
.setEditable(false);
92 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
93 StringWriter sw
= new StringWriter();
94 exception
.printStackTrace(new PrintWriter(sw
));
95 stack
.setText(sw
.toString());
102 protected void configureShell(Shell shell
) {
103 super.configureShell(shell
);
104 shell
.setText("Error");