]>
git.argeo.org Git - gpl/argeo-jcr.git/blob - swt/org.argeo.cms.jcr.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
.argeo
.api
.cms
.CmsLog
;
7 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
8 import org
.eclipse
.swt
.SWT
;
9 import org
.eclipse
.swt
.events
.ShellAdapter
;
10 import org
.eclipse
.swt
.events
.ShellEvent
;
11 import org
.eclipse
.swt
.graphics
.Point
;
12 import org
.eclipse
.swt
.graphics
.Rectangle
;
13 import org
.eclipse
.swt
.layout
.GridData
;
14 import org
.eclipse
.swt
.layout
.GridLayout
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.swt
.widgets
.Display
;
18 import org
.eclipse
.swt
.widgets
.Label
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
20 import org
.eclipse
.swt
.widgets
.Text
;
23 * Generic lightweight dialog, not based on JFace.
25 * @deprecated Use CMS dialogs instead.
28 public class FeedbackDialog
extends LightweightDialog
{
29 private final static CmsLog log
= CmsLog
.getLog(FeedbackDialog
.class);
31 private String message
;
32 private Throwable exception
;
34 // private Shell parentShell;
37 public static void show(String message
, Throwable e
) {
38 // rethrow ThreaDeath in order to make sure that RAP will properly clean
40 if (e
instanceof ThreadDeath
)
41 throw (ThreadDeath
) e
;
43 new FeedbackDialog(getDisplay().getActiveShell(), message
, e
).open();
46 public static void show(String message
) {
47 new FeedbackDialog(getDisplay().getActiveShell(), message
, null).open();
50 /** Tries to find a display */
51 private static Display
getDisplay() {
53 Display display
= Display
.getCurrent();
57 return Display
.getDefault();
58 } catch (Exception e
) {
59 return Display
.getCurrent();
63 public FeedbackDialog(Shell parentShell
, String message
, Throwable e
) {
65 this.message
= message
;
67 log
.error(message
, e
);
72 throw new EclipseUiException("There is already a shell");
73 shell
= new Shell(getDisplay(), SWT
.NO_TRIM
| SWT
.BORDER
| SWT
.ON_TOP
);
74 shell
.setLayout(new GridLayout());
75 // shell.setText("Error");
76 shell
.setSize(getInitialSize());
77 createDialogArea(shell
);
81 Rectangle shellBounds
= Display
.getCurrent().getBounds();// RAP
82 Point dialogSize
= shell
.getSize();
83 int x
= shellBounds
.x
+ (shellBounds
.width
- dialogSize
.x
) / 2;
84 int y
= shellBounds
.y
+ (shellBounds
.height
- dialogSize
.y
) / 2;
85 shell
.setLocation(x
, y
);
87 shell
.addShellListener(new ShellAdapter() {
88 private static final long serialVersionUID
= -2701270481953688763L;
91 public void shellDeactivated(ShellEvent e
) {
100 protected void closeShell() {
106 protected Point
getInitialSize() {
107 // if (exception != null)
108 // return new Point(800, 600);
110 return new Point(400, 300);
113 protected Control
createDialogArea(Composite parent
) {
114 Composite dialogarea
= new Composite(parent
, SWT
.NONE
);
115 dialogarea
.setLayout(new GridLayout());
116 // Composite dialogarea = (Composite) super.createDialogArea(parent);
117 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
119 Label messageLbl
= new Label(dialogarea
, SWT
.NONE
);
121 messageLbl
.setText(message
);
122 else if (exception
!= null)
123 messageLbl
.setText(exception
.getLocalizedMessage());
125 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
126 composite
.setLayout(new GridLayout(2, false));
127 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
129 if (exception
!= null) {
130 Text stack
= new Text(composite
, SWT
.MULTI
| SWT
.LEAD
| SWT
.BORDER
| SWT
.V_SCROLL
| SWT
.H_SCROLL
);
131 stack
.setEditable(false);
132 stack
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
133 StringWriter sw
= new StringWriter();
134 exception
.printStackTrace(new PrintWriter(sw
));
135 stack
.setText(sw
.toString());