]>
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 public class Error
extends TitleAreaDialog
{
21 private final static Log log
= LogFactory
.getLog(Error
.class);
23 private final String message
;
24 private final Throwable exception
;
26 public static void show(String message
, Throwable e
) {
27 new Error(Display
.getDefault().getActiveShell(), message
, e
).open();
30 public static void show(String message
) {
31 new Error(Display
.getDefault().getActiveShell(), message
, null).open();
34 public Error(Shell parentShell
, String message
, Throwable e
) {
36 this.message
= message
;
38 log
.error(message
, e
);
41 protected Point
getInitialSize() {
42 if (exception
!= null)
43 return new Point(800, 600);
45 return new Point(400, 300);
49 protected Control
createDialogArea(Composite parent
) {
50 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
51 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
52 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
53 composite
.setLayout(new GridLayout(2, false));
54 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
56 setMessage(message
!= null ? message
57 + (exception
!= null ?
": " + exception
.getMessage() : "")
58 : exception
!= null ? exception
.getMessage() : "Unkown Error",
59 IMessageProvider
.ERROR
);
61 if (exception
!= null) {
62 Text stack
= new Text(composite
, SWT
.MULTI
| SWT
.LEAD
63 | SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
64 stack
.setEditable(false);
65 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
66 StringWriter sw
= new StringWriter();
67 exception
.printStackTrace(new PrintWriter(sw
));
68 stack
.setText(sw
.toString());
75 protected void configureShell(Shell shell
) {
76 super.configureShell(shell
);
77 shell
.setText("Error");