KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > ErrorDialog


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc;
5
6 import org.apache.commons.io.IOUtils;
7
8 import org.dijon.Dialog;
9 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 JavaDoc;
16 import java.awt.event.ActionListener JavaDoc;
17 import java.io.PrintWriter JavaDoc;
18 import java.io.StringWriter JavaDoc;
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.findDialog("ErrorDialog");
29   }
30   
31   public ErrorDialog() {
32     super(m_dialogRes);
33     
34     m_errorText = (XTextArea)findComponent("ErrorText");
35     m_messageText = (XTextField)findComponent("MessageText");
36     m_closeButton = (XButton)findComponent("CloseButton");
37     
38     m_closeButton.addActionListener(new ActionListener JavaDoc() {
39       public void actionPerformed(ActionEvent JavaDoc ae) {
40         setVisible(false);
41       }
42     });
43   }
44   
45   public ErrorDialog(String JavaDoc message, Throwable JavaDoc t) {
46     this();
47
48     if(t != null) {
49       setError(t);
50     }
51     setMessage(message);
52   }
53
54   public void setError(Throwable JavaDoc t) {
55     StringWriter JavaDoc sw = new StringWriter JavaDoc();
56     PrintWriter JavaDoc pw = new PrintWriter JavaDoc(sw);
57     
58     t.printStackTrace(pw);
59     setErrorText(sw.toString());
60     IOUtils.closeQuietly(pw);
61   }
62   
63   public void setErrorText(String JavaDoc errorText) {
64     m_errorText.setText(errorText);
65   }
66   
67   public void setMessage(String JavaDoc message) {
68     m_messageText.setText(message);
69   }
70 }
71
Popular Tags