]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.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
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
9 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.graphics
.Point
;
12 import org
.eclipse
.swt
.layout
.GridData
;
13 import org
.eclipse
.swt
.layout
.GridLayout
;
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
.Shell
;
18 import org
.eclipse
.swt
.widgets
.Text
;
20 /** Generic error dialog to be used in try/catch blocks */
21 public class ErrorFeedback
extends TitleAreaDialog
{
22 private static final long serialVersionUID
= -8918084784628179044L;
24 private final static Log log
= LogFactory
.getLog(ErrorFeedback
.class);
26 private final String message
;
27 private final Throwable exception
;
29 public static void show(String message
, Throwable e
) {
30 // rethrow ThreaDeath in order to make sure that RAP will properly clean
32 if (e
instanceof ThreadDeath
)
33 throw (ThreadDeath
) e
;
35 new ErrorFeedback(newShell(), message
, e
).open();
38 public static void show(String message
) {
39 new ErrorFeedback(newShell(), message
, null).open();
42 private static Shell
newShell() {
43 return new Shell(getDisplay(), SWT
.NO_TRIM
);
46 /** Tries to find a display */
47 private static Display
getDisplay() {
49 Display display
= Display
.getCurrent();
53 return Display
.getDefault();
54 } catch (Exception e
) {
55 return Display
.getCurrent();
59 public ErrorFeedback(Shell parentShell
, String message
, Throwable e
) {
61 setShellStyle(SWT
.NO_TRIM
);
62 this.message
= message
;
64 log
.error(message
, e
);
67 protected Point
getInitialSize() {
68 if (exception
!= null)
69 return new Point(800, 600);
71 return new Point(400, 300);
75 protected Control
createDialogArea(Composite parent
) {
76 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
77 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
78 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
79 composite
.setLayout(new GridLayout(2, false));
80 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
82 setMessage(message
!= null ? message
+ (exception
!= null ?
": " + exception
.getMessage() : "")
83 : exception
!= null ? exception
.getMessage() : "Unkown Error", IMessageProvider
.ERROR
);
85 if (exception
!= null) {
86 Text stack
= new Text(composite
, 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));
89 StringWriter sw
= new StringWriter();
90 exception
.printStackTrace(new PrintWriter(sw
));
91 stack
.setText(sw
.toString());
98 protected void configureShell(Shell shell
) {
99 super.configureShell(shell
);
100 shell
.setText("Error");