]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/FeedbackDialog.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
.argeo
.eclipse
.ui
.EclipseUiException
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.events
.ShellAdapter
;
11 import org
.eclipse
.swt
.events
.ShellEvent
;
12 import org
.eclipse
.swt
.graphics
.Point
;
13 import org
.eclipse
.swt
.graphics
.Rectangle
;
14 import org
.eclipse
.swt
.layout
.GridData
;
15 import org
.eclipse
.swt
.layout
.GridLayout
;
16 import org
.eclipse
.swt
.widgets
.Composite
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.swt
.widgets
.Display
;
19 import org
.eclipse
.swt
.widgets
.Label
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
21 import org
.eclipse
.swt
.widgets
.Text
;
24 * Generic lightweight dialog, not based on JFace.
26 * @deprecated Use CMS dialogs instead.
29 public class FeedbackDialog
extends LightweightDialog
{
30 private final static Log log
= LogFactory
.getLog(FeedbackDialog
.class);
32 private String message
;
33 private Throwable exception
;
35 // private Shell parentShell;
38 public static void show(String message
, Throwable e
) {
39 // rethrow ThreaDeath in order to make sure that RAP will properly clean
41 if (e
instanceof ThreadDeath
)
42 throw (ThreadDeath
) e
;
44 new FeedbackDialog(getDisplay().getActiveShell(), message
, e
).open();
47 public static void show(String message
) {
48 new FeedbackDialog(getDisplay().getActiveShell(), message
, null).open();
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 FeedbackDialog(Shell parentShell
, String message
, Throwable e
) {
66 this.message
= message
;
68 log
.error(message
, e
);
73 throw new EclipseUiException("There is already a shell");
74 shell
= new Shell(getDisplay(), SWT
.NO_TRIM
| SWT
.BORDER
| SWT
.ON_TOP
);
75 shell
.setLayout(new GridLayout());
76 // shell.setText("Error");
77 shell
.setSize(getInitialSize());
78 createDialogArea(shell
);
82 Rectangle shellBounds
= Display
.getCurrent().getBounds();// RAP
83 Point dialogSize
= shell
.getSize();
84 int x
= shellBounds
.x
+ (shellBounds
.width
- dialogSize
.x
) / 2;
85 int y
= shellBounds
.y
+ (shellBounds
.height
- dialogSize
.y
) / 2;
86 shell
.setLocation(x
, y
);
88 shell
.addShellListener(new ShellAdapter() {
89 private static final long serialVersionUID
= -2701270481953688763L;
92 public void shellDeactivated(ShellEvent e
) {
101 protected void closeShell() {
107 protected Point
getInitialSize() {
108 // if (exception != null)
109 // return new Point(800, 600);
111 return new Point(400, 300);
114 protected Control
createDialogArea(Composite parent
) {
115 Composite dialogarea
= new Composite(parent
, SWT
.NONE
);
116 dialogarea
.setLayout(new GridLayout());
117 // Composite dialogarea = (Composite) super.createDialogArea(parent);
118 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
120 Label messageLbl
= new Label(dialogarea
, SWT
.NONE
);
122 messageLbl
.setText(message
);
123 else if (exception
!= null)
124 messageLbl
.setText(exception
.getLocalizedMessage());
126 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
127 composite
.setLayout(new GridLayout(2, false));
128 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
130 if (exception
!= null) {
131 Text stack
= new Text(composite
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
132 stack
.setEditable(false);
133 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
134 StringWriter sw
= new StringWriter();
135 exception
.printStackTrace(new PrintWriter(sw
));
136 stack
.setText(sw
.toString());