01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc;
05:
06: import org.apache.commons.io.IOUtils;
07:
08: import org.dijon.Dialog;
09: import org.dijon.DialogResource;
10:
11: import com.tc.admin.common.XButton;
12: import com.tc.admin.common.XTextArea;
13: import com.tc.admin.common.XTextField;
14:
15: import java.awt.event.ActionEvent;
16: import java.awt.event.ActionListener;
17: import java.io.PrintWriter;
18: import java.io.StringWriter;
19:
20: public class ErrorDialog extends Dialog {
21: private static DialogResource m_dialogRes;
22:
23: private XTextArea m_errorText;
24: private XTextField m_messageText;
25: private XButton m_closeButton;
26:
27: static {
28: m_dialogRes = SessionIntegrator.getContext().topRes
29: .findDialog("ErrorDialog");
30: }
31:
32: public ErrorDialog() {
33: super (m_dialogRes);
34:
35: m_errorText = (XTextArea) findComponent("ErrorText");
36: m_messageText = (XTextField) findComponent("MessageText");
37: m_closeButton = (XButton) findComponent("CloseButton");
38:
39: m_closeButton.addActionListener(new ActionListener() {
40: public void actionPerformed(ActionEvent ae) {
41: setVisible(false);
42: }
43: });
44: }
45:
46: public ErrorDialog(String message, Throwable t) {
47: this ();
48:
49: if (t != null) {
50: setError(t);
51: }
52: setMessage(message);
53: }
54:
55: public void setError(Throwable t) {
56: StringWriter sw = new StringWriter();
57: PrintWriter pw = new PrintWriter(sw);
58:
59: t.printStackTrace(pw);
60: setErrorText(sw.toString());
61: IOUtils.closeQuietly(pw);
62: }
63:
64: public void setErrorText(String errorText) {
65: m_errorText.setText(errorText);
66: }
67:
68: public void setMessage(String message) {
69: m_messageText.setText(message);
70: }
71: }
|