01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.dso.dialogs;
06:
07: import org.eclipse.jface.dialogs.IDialogConstants;
08: import org.eclipse.jface.dialogs.MessageDialog;
09: import org.eclipse.swt.SWT;
10: import org.eclipse.swt.layout.GridData;
11: import org.eclipse.swt.layout.GridLayout;
12: import org.eclipse.swt.widgets.Composite;
13: import org.eclipse.swt.widgets.Control;
14: import org.eclipse.swt.widgets.Shell;
15: import org.eclipse.swt.widgets.Text;
16: import org.terracotta.ui.util.SWTUtil;
17:
18: public class ExceptionDialog extends MessageDialog {
19:
20: private final Shell m_parentShell;
21: private final String m_stackTrace;
22:
23: public ExceptionDialog(Shell shell, String title, String message,
24: String stackTrace) {
25: super (shell, title, null, " " + message, MessageDialog.ERROR,
26: new String[] { IDialogConstants.OK_LABEL }, 0);
27: setShellStyle(getShellStyle() | SWT.RESIZE);
28: this .m_parentShell = shell;
29: this .m_stackTrace = stackTrace;
30: }
31:
32: protected void configureShell(Shell shell) {
33: super .configureShell(shell);
34: if (m_parentShell != null) {
35: SWTUtil.placeDialogInCenter(m_parentShell, shell);
36: }
37: }
38:
39: protected Control createDialogArea(Composite parent) {
40: GridLayout gridLayout = new GridLayout();
41: gridLayout.marginWidth = gridLayout.marginHeight = 0;
42: parent.setLayout(gridLayout);
43: return super .createDialogArea(parent);
44: }
45:
46: protected Control createCustomArea(Composite parent) {
47: new Layout(parent, m_stackTrace);
48: return parent;
49: }
50:
51: // --------------------------------------------------------------------------------
52:
53: private static class Layout {
54: final Text m_area;
55:
56: private Layout(Composite parent, String stackTrace) {
57: Composite comp = new Composite(parent, SWT.NONE);
58: GridLayout gridLayout = new GridLayout();
59: gridLayout.marginHeight = gridLayout.marginWidth = 0;
60: comp.setLayout(gridLayout);
61: comp.setLayoutData(new GridData(GridData.FILL_BOTH));
62:
63: this .m_area = new Text(comp, SWT.BORDER | SWT.MULTI
64: | SWT.V_SCROLL | SWT.WRAP | SWT.READ_ONLY);
65: m_area.setText(stackTrace);
66: GridData gridData = new GridData(GridData.FILL_BOTH);
67: gridData.widthHint = SWTUtil.textColumnsToPixels(m_area,
68: 120);
69: gridData.heightHint = SWTUtil.textRowsToPixels(m_area, 24);
70: m_area.setLayoutData(gridData);
71: }
72: }
73: }
|