KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > ui > MethodExceptionDialog


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.ui;
21
22 import org.openide.DialogDescriptor;
23 import org.openide.DialogDisplayer;
24 import org.openide.ErrorManager;
25 import org.openide.NotifyDescriptor;
26 import org.openide.util.NbBundle;
27 import org.openide.util.HelpCtx;
28 import javax.swing.text.html.HTMLEditorKit JavaDoc;
29
30 import java.io.StringWriter JavaDoc;
31
32 import javax.swing.JButton JavaDoc;
33
34 import java.awt.Dialog JavaDoc;
35
36 /**
37  * This Dialog will show exceptions encountered while a user is testing a web service client method.
38  * @author David Botterill
39  */

40 public class MethodExceptionDialog extends javax.swing.JPanel JavaDoc {
41     
42     private String JavaDoc currentMessage = "";
43     private JButton JavaDoc okButton = new JButton JavaDoc(NbBundle.getMessage(this.getClass(), "OPTION_OK"));
44     private DialogDescriptor dlg;
45     private Dialog JavaDoc dialog;
46     
47     /** Creates new form MethodExceptionDialog */
48     public MethodExceptionDialog(Exception JavaDoc inException) {
49         initComponents();
50         setMessage(inException,false);
51         
52     }
53     public void show(){
54         
55         dlg = new DialogDescriptor(this, NbBundle.getMessage(this.getClass(), "CLIENT_EXCEPTION"),
56         false, NotifyDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
57         DialogDescriptor.DEFAULT_ALIGN, this.getHelpCtx(), null);
58         dlg.setOptions(new Object JavaDoc[] { okButton });
59         dialog = DialogDisplayer.getDefault().createDialog(dlg);
60         dialog.setSize(500,300);
61         dialog.show();
62     }
63     public HelpCtx getHelpCtx() {
64         return new HelpCtx(TestWebServiceMethodDlg.class);
65     }
66     
67     /** This method is called from within the constructor to
68      * initialize the form.
69      * WARNING: Do NOT modify this code. The content of this method is
70      * always regenerated by the Form Editor.
71      */

72     private void initComponents() {//GEN-BEGIN:initComponents
73
scrollPane = new javax.swing.JScrollPane JavaDoc();
74         messagePane = new javax.swing.JEditorPane JavaDoc();
75
76         setLayout(new java.awt.BorderLayout JavaDoc());
77
78         messagePane.setEditorKit(new HTMLEditorKit JavaDoc()
79         );
80         scrollPane.setViewportView(messagePane);
81
82         add(scrollPane, java.awt.BorderLayout.CENTER);
83
84     }//GEN-END:initComponents
85

86     public void setMessage(Exception JavaDoc inException,boolean keepOld){
87         
88         
89         String JavaDoc htmlStart = "<HTML><HEAD>" +
90         "<style type=\"text/css\">" +
91         "body { font-family: Verdana, sans-serif; font-size: 12; }" +
92         "</style>" +
93         "</HEAD>" +
94         "<BODY>";
95         String JavaDoc htmlEnd = "</BODY></HTML>";
96         String JavaDoc exceptionString = "";
97         /**
98          * unwrap the exceptions.
99          */

100         Throwable JavaDoc cause = inException;
101         while(null != cause) {
102             exceptionString += "<BR><FONT COLOR=\"RED\">" + cause.getLocalizedMessage() + "</FONT>";
103             StackTraceElement JavaDoc [] traceElements = cause.getStackTrace();
104             String JavaDoc stackTrace = "<BR>Stack Trace<BR><BR>";
105             for(int ii=0;ii < traceElements.length;ii++) {
106                 exceptionString += "<BR>" + traceElements[ii].toString();
107             }
108             cause = cause.getCause();
109             if(null != cause) {
110                 exceptionString += "<BR>Next Exception Layer";
111             }
112         }
113         
114         
115         if(keepOld) {
116             currentMessage += exceptionString;
117         } else {
118             currentMessage = exceptionString;
119         }
120         
121         
122         
123         
124         messagePane.setText(htmlStart + currentMessage + htmlEnd);
125     }
126     
127     
128     // Variables declaration - do not modify//GEN-BEGIN:variables
129
private javax.swing.JEditorPane JavaDoc messagePane;
130     private javax.swing.JScrollPane JavaDoc scrollPane;
131     // End of variables declaration//GEN-END:variables
132

133 }
134
Popular Tags