]> 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
Remove reference to TreeObject
[lgpl/argeo-commons.git] / eclipse / runtime / org.argeo.eclipse.ui / src / main / java / org / argeo / eclipse / ui / dialogs / Error.java
1 package org.argeo.eclipse.ui.dialogs;
2
3 import java.io.PrintWriter;
4 import java.io.StringWriter;
5
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
20 public class Error extends TitleAreaDialog {
21 private final static Log log = LogFactory.getLog(Error.class);
22
23 private final String message;
24 private final Throwable exception;
25
26 public static void show(String message, Throwable e) {
27 new Error(Display.getDefault().getActiveShell(), message, e).open();
28 }
29
30 public static void show(String message) {
31 new Error(Display.getDefault().getActiveShell(), message, null).open();
32 }
33
34 public Error(Shell parentShell, String message, Throwable e) {
35 super(parentShell);
36 this.message = message;
37 this.exception = e;
38 log.error(message, e);
39 }
40
41 protected Point getInitialSize() {
42 if (exception != null)
43 return new Point(800, 600);
44 else
45 return new Point(400, 300);
46 }
47
48 @Override
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));
55
56 setMessage(message != null ? message
57 + (exception != null ? ": " + exception.getMessage() : "")
58 : exception != null ? exception.getMessage() : "Unkown Error",
59 IMessageProvider.ERROR);
60
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());
69 }
70
71 parent.pack();
72 return composite;
73 }
74
75 protected void configureShell(Shell shell) {
76 super.configureShell(shell);
77 shell.setText("Error");
78 }
79
80 }