]>
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
;
21 * Generic error dialog to be used in try/catch blocks.
23 * @deprecated Use CMS dialogs instead.
26 public class ErrorFeedback
extends TitleAreaDialog
{
27 private static final long serialVersionUID
= -8918084784628179044L;
29 private final static Log log
= LogFactory
.getLog(ErrorFeedback
.class);
31 private final String message
;
32 private final Throwable exception
;
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 ErrorFeedback(newShell(), message
, e
).open();
43 public static void show(String message
) {
44 new ErrorFeedback(newShell(), message
, null).open();
47 private static Shell
newShell() {
48 return new Shell(getDisplay(), SWT
.NO_TRIM
);
51 /** Tries to find a display */
52 private static Display
getDisplay() {
54 Display display
= Display
.getCurrent();
58 return Display
.getDefault();
59 } catch (Exception e
) {
60 return Display
.getCurrent();
64 public ErrorFeedback(Shell parentShell
, String message
, Throwable e
) {
66 setShellStyle(SWT
.NO_TRIM
);
67 this.message
= message
;
69 log
.error(message
, e
);
72 protected Point
getInitialSize() {
73 if (exception
!= null)
74 return new Point(800, 600);
76 return new Point(400, 300);
80 protected Control
createDialogArea(Composite parent
) {
81 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
82 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
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 setMessage(message
!= null ? message
+ (exception
!= null ?
": " + exception
.getMessage() : "")
88 : exception
!= null ? exception
.getMessage() : "Unkown Error", IMessageProvider
.ERROR
);
90 if (exception
!= null) {
91 Text stack
= new Text(composite
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
92 stack
.setEditable(false);
93 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
94 StringWriter sw
= new StringWriter();
95 exception
.printStackTrace(new PrintWriter(sw
));
96 stack
.setText(sw
.toString());
103 protected void configureShell(Shell shell
) {
104 super.configureShell(shell
);
105 shell
.setText("Error");