001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.saas.ui.wizards;
043:
044: import org.openide.DialogDescriptor;
045: import org.openide.DialogDisplayer;
046: import org.openide.NotifyDescriptor;
047: import org.openide.util.NbBundle;
048: import org.openide.util.HelpCtx;
049: import javax.swing.text.html.HTMLEditorKit;
050:
051: import javax.swing.JButton;
052:
053: import java.awt.Dialog;
054: import java.lang.reflect.InvocationTargetException;
055:
056: /**
057: * This Dialog will show exceptions encountered while a user is testing a web service client method.
058: * @author David Botterill
059: */
060: public class MethodExceptionDialog extends javax.swing.JPanel {
061:
062: private String currentMessage = "";
063: private JButton okButton = new JButton(NbBundle.getMessage(this
064: .getClass(), "OPTION_OK"));
065: private DialogDescriptor dlg;
066: private Dialog dialog;
067:
068: /** Creates new form MethodExceptionDialog */
069: public MethodExceptionDialog(Throwable inException) {
070: initComponents();
071: messagePane.getAccessibleContext().setAccessibleName(
072: NbBundle.getMessage(this .getClass(),
073: "MethodExceptionDialog.messagePane.ACC_name"));
074: messagePane.getAccessibleContext().setAccessibleDescription(
075: NbBundle.getMessage(this .getClass(),
076: "MethodExceptionDialog.messagePane.ACC_desc"));
077:
078: // Only show the root cause of the exception if there was an exception during the method call
079: if (inException instanceof InvocationTargetException) {
080: inException = ((InvocationTargetException) inException)
081: .getTargetException();
082: }
083:
084: setMessage(inException, false);
085:
086: }
087:
088: public void show() {
089:
090: dlg = new DialogDescriptor(this , NbBundle.getMessage(this
091: .getClass(), "CLIENT_EXCEPTION"), false,
092: NotifyDescriptor.OK_CANCEL_OPTION,
093: DialogDescriptor.OK_OPTION,
094: DialogDescriptor.DEFAULT_ALIGN, this .getHelpCtx(), null);
095: dlg.setOptions(new Object[] { okButton });
096: dialog = DialogDisplayer.getDefault().createDialog(dlg);
097: dialog.setPreferredSize(new java.awt.Dimension(500, 300));
098: dialog.show();
099: }
100:
101: public HelpCtx getHelpCtx() {
102: return new HelpCtx(
103: "projrave_ui_elements_server_nav_test_websvcdb");
104: }
105:
106: /** This method is called from within the constructor to
107: * initialize the form.
108: * WARNING: Do NOT modify this code. The content of this method is
109: * always regenerated by the Form Editor.
110: */
111: private void initComponents() {//GEN-BEGIN:initComponents
112: scrollPane = new javax.swing.JScrollPane();
113: messagePane = new javax.swing.JEditorPane();
114:
115: setLayout(new java.awt.BorderLayout());
116:
117: messagePane.setEditorKit(new HTMLEditorKit());
118: scrollPane.setViewportView(messagePane);
119:
120: add(scrollPane, java.awt.BorderLayout.CENTER);
121:
122: }//GEN-END:initComponents
123:
124: public void setMessage(Throwable inException, boolean keepOld) {
125:
126: String htmlStart = "<HTML><HEAD>"
127: + "<style type=\"text/css\">"
128: + "body { font-family: Verdana, sans-serif; font-size: 12; }"
129: + "</style>" + "</HEAD>" + "<BODY>";
130: String htmlEnd = "</BODY></HTML>";
131: String exceptionString = "";
132: /**
133: * unwrap the exceptions.
134: */
135: Throwable cause = inException;
136: while (null != cause) {
137: exceptionString += "<BR><FONT COLOR=\"RED\">"
138: + cause.getLocalizedMessage() + "</FONT>";
139: StackTraceElement[] traceElements = cause.getStackTrace();
140: String stackTrace = "<BR>Stack Trace<BR><BR>";
141: for (int ii = 0; ii < traceElements.length; ii++) {
142: exceptionString += "<BR>"
143: + traceElements[ii].toString();
144: }
145: cause = cause.getCause();
146: }
147:
148: if (keepOld) {
149: currentMessage += exceptionString;
150: } else {
151: currentMessage = exceptionString;
152: }
153:
154: messagePane.setText(htmlStart + currentMessage + htmlEnd);
155: }
156:
157: // Variables declaration - do not modify//GEN-BEGIN:variables
158: private javax.swing.JEditorPane messagePane;
159: private javax.swing.JScrollPane scrollPane;
160: // End of variables declaration//GEN-END:variables
161:
162: }
|