]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/ErrorFeedback.java
bdbf64234632ad69cb9af72fadae4b1f8c225069
1 package org
.argeo
.eclipse
.ui
;
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
;
19 import org
.eclipse
.ui
.PlatformUI
;
21 /** Generic error dialog to be used in try/catch blocks */
22 public class ErrorFeedback
extends TitleAreaDialog
{
23 private final static Log log
= LogFactory
.getLog(ErrorFeedback
.class);
25 private final String message
;
26 private final Throwable exception
;
28 public static void show(String message
, Throwable e
) {
29 // rethrow ThreaDeath in order to make sure that RAP will properly clean
31 if (e
instanceof ThreadDeath
)
32 throw (ThreadDeath
) e
;
34 new ErrorFeedback(getDisplay().getActiveShell(), message
, e
).open();
37 public static void show(String message
) {
38 new ErrorFeedback(getDisplay().getActiveShell(), message
, null).open();
41 /** Tries to find a display */
42 private static Display
getDisplay() {
44 Display display
= PlatformUI
.getWorkbench().getDisplay();
48 return Display
.getDefault();
49 } catch (Exception e
) {
50 return Display
.getCurrent();
54 public ErrorFeedback(Shell parentShell
, String message
, Throwable e
) {
56 this.message
= message
;
58 log
.error(message
, e
);
61 protected Point
getInitialSize() {
62 if (exception
!= null)
63 return new Point(800, 600);
65 return new Point(400, 300);
69 protected Control
createDialogArea(Composite parent
) {
70 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
71 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
72 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
73 composite
.setLayout(new GridLayout(2, false));
74 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
76 setMessage(message
!= null ? message
77 + (exception
!= null ?
": " + exception
.getMessage() : "")
78 : exception
!= null ? exception
.getMessage() : "Unkown Error",
79 IMessageProvider
.ERROR
);
81 if (exception
!= null) {
82 Text stack
= new Text(composite
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
83 | SWT
.V_SCROLL
| SWT
.H_SCROLL
);
84 stack
.setEditable(false);
85 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
86 StringWriter sw
= new StringWriter();
87 exception
.printStackTrace(new PrintWriter(sw
));
88 stack
.setText(sw
.toString());
95 protected void configureShell(Shell shell
) {
96 super.configureShell(shell
);
97 shell
.setText("Error");