]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/dialogs/Error.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 Error
extends TitleAreaDialog
{
22 private final static Log log
= LogFactory
.getLog(Error
.class);
24 private final String message
;
25 private final Throwable exception
;
27 public static void show(String message
, Throwable e
) {
28 new Error(Display
.getDefault().getActiveShell(), message
, e
).open();
31 public static void show(String message
) {
32 new Error(Display
.getDefault().getActiveShell(), message
, null).open();
35 public Error(Shell parentShell
, String message
, Throwable e
) {
37 this.message
= message
;
39 log
.error(message
, e
);
42 protected Point
getInitialSize() {
43 if (exception
!= null)
44 return new Point(800, 600);
46 return new Point(400, 300);
50 protected Control
createDialogArea(Composite parent
) {
51 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
52 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
53 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
54 composite
.setLayout(new GridLayout(2, false));
55 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
57 setMessage(message
!= null ? message
58 + (exception
!= null ?
": " + exception
.getMessage() : "")
59 : exception
!= null ? exception
.getMessage() : "Unkown Error",
60 IMessageProvider
.ERROR
);
62 if (exception
!= null) {
63 Text stack
= new Text(composite
, SWT
.MULTI
| SWT
.LEAD
64 | SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
65 stack
.setEditable(false);
66 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
67 StringWriter sw
= new StringWriter();
68 exception
.printStackTrace(new PrintWriter(sw
));
69 stack
.setText(sw
.toString());
76 protected void configureShell(Shell shell
) {
77 super.configureShell(shell
);
78 shell
.setText("Error");