KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > jaxrpc > client > ui > RefreshWsdlPanel


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.jaxrpc.client.ui;
21
22 import java.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.awt.Color JavaDoc;
26
27 import javax.swing.event.DocumentEvent JavaDoc;
28 import javax.swing.event.DocumentListener JavaDoc;
29
30 import org.openide.DialogDescriptor;
31 import org.openide.util.NbBundle;
32 import org.openide.filesystems.FileObject;
33
34 import org.netbeans.modules.websvc.api.webservices.WsCompileEditorSupport;
35
36 /**
37  *
38  * @author peterw99
39  */

40 public class RefreshWsdlPanel extends javax.swing.JPanel JavaDoc {
41
42     public static final Color JavaDoc ErrorTextForegroundColor = new Color JavaDoc(89, 79, 191);
43     
44     private DialogDescriptor descriptor;
45     private String JavaDoc wsdlSource;
46     private boolean hasMultipleServices;
47     private String JavaDoc [] serviceNames;
48     
49     
50     /** Creates new form RefreshWsdlPanel */
51     public RefreshWsdlPanel(String JavaDoc wsdlSource, String JavaDoc [] supportedServices) {
52         this.wsdlSource = wsdlSource;
53         this.hasMultipleServices = (supportedServices.length > 1);
54         this.serviceNames = supportedServices;
55         
56         initComponents();
57         initUserComponents();
58     }
59     
60     /** This method is called from within the constructor to
61      * initialize the form.
62      * WARNING: Do NOT modify this code. The content of this method is
63      * always regenerated by the Form Editor.
64      */

65     private void initComponents() {//GEN-BEGIN:initComponents
66
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
67
68         jLblDescription = new javax.swing.JLabel JavaDoc();
69         jLblWsdlSource = new javax.swing.JLabel JavaDoc();
70         jTxtWsdlSource = new javax.swing.JTextField JavaDoc();
71         jLblMultipleServices = new javax.swing.JLabel JavaDoc();
72         jLblError = new javax.swing.JLabel JavaDoc();
73
74         setLayout(new java.awt.GridBagLayout JavaDoc());
75
76         jLblDescription.setText(NbBundle.getMessage(RefreshWsdlPanel.class, "LBL_Description"));
77         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
78         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
79         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
80         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 11, 11, 11);
81         add(jLblDescription, gridBagConstraints);
82
83         jLblWsdlSource.setLabelFor(jTxtWsdlSource);
84         jLblWsdlSource.setText(NbBundle.getMessage(RefreshWsdlPanel.class, "LBL_WsdlSource"));
85         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
86         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 11, 11, 0);
87         add(jLblWsdlSource, gridBagConstraints);
88
89         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
90         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
91         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
92         gridBagConstraints.weightx = 1.0;
93         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 11, 11);
94         add(jTxtWsdlSource, gridBagConstraints);
95
96         jLblMultipleServices.setText(" ");
97         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
98         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
99         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
100         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 11, 0, 11);
101         add(jLblMultipleServices, gridBagConstraints);
102
103         jLblError.setText("xxx");
104         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
105         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
106         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
107         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
108         gridBagConstraints.weightx = 1.0;
109         gridBagConstraints.weighty = 1.0;
110         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 11, 11, 11);
111         add(jLblError, gridBagConstraints);
112
113     }//GEN-END:initComponents
114

115     
116     // Variables declaration - do not modify//GEN-BEGIN:variables
117
private javax.swing.JLabel JavaDoc jLblDescription;
118     private javax.swing.JLabel JavaDoc jLblError;
119     private javax.swing.JLabel JavaDoc jLblMultipleServices;
120     private javax.swing.JLabel JavaDoc jLblWsdlSource;
121     private javax.swing.JTextField JavaDoc jTxtWsdlSource;
122     // End of variables declaration//GEN-END:variables
123

124     private void initUserComponents() {
125         jLblError.setForeground(ErrorTextForegroundColor);
126         jTxtWsdlSource.setText(wsdlSource);
127         
128         jTxtWsdlSource.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
129             public void removeUpdate(DocumentEvent JavaDoc e) {
130                 updateWsdlSource();
131             }
132             public void insertUpdate(DocumentEvent JavaDoc e) {
133                 updateWsdlSource();
134             }
135             public void changedUpdate(DocumentEvent JavaDoc e) {
136                 updateWsdlSource();
137             }
138         });
139         
140         if(hasMultipleServices) {
141             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(16+16*serviceNames.length);
142             for(int i = 0; i < serviceNames.length; i++) {
143                 if(i > 0) {
144                     buf.append(", "); // NOI18N
145
}
146                 buf.append(serviceNames[i]);
147             }
148             jLblMultipleServices.setText(NbBundle.getMessage(RefreshWsdlPanel.class,
149                 "LBL_MultipleServiceWarning", buf.toString())); // NOI18N
150
} else {
151             jLblMultipleServices.setText(" "); // NOI18N
152
}
153     }
154     
155     public void addNotify() {
156         super.addNotify();
157         
158         checkSettings();
159     }
160     
161     private void updateWsdlSource() {
162         wsdlSource = jTxtWsdlSource.getText();
163         checkSettings();
164     }
165
166     public String JavaDoc getWsdlSource() {
167         return wsdlSource;
168     }
169     
170     public void setDescriptor(DialogDescriptor descriptor) {
171         this.descriptor = descriptor;
172     }
173     
174     private boolean checkSettings() {
175         String JavaDoc message = validateSettings();
176         if(message != null) {
177             jLblError.setText(message);
178         } else {
179             jLblError.setText(" ");
180         }
181         
182         boolean isValid = (message == null);
183         descriptor.setValid(isValid);
184         return isValid;
185     }
186     
187     private String JavaDoc validateSettings() {
188         String JavaDoc message = null;
189
190         if(wsdlSource == null || wsdlSource.length() == 0) {
191             message = NbBundle.getMessage(RefreshWsdlPanel.class, "ERR_EnterSourceWsdlPath"); // NOI18N
192
} else if(wsdlSource.indexOf("://") != -1) { // NOI18N
193
try {
194                 URL JavaDoc wsdlSourceUrl = new URL JavaDoc(wsdlSource);
195             } catch(MalformedURLException JavaDoc ex) {
196                 // not a URL
197
message = NbBundle.getMessage(RefreshWsdlPanel.class, "ERR_InvalidURL", ex.getLocalizedMessage()); // NOI18N
198
}
199         } else {
200             File JavaDoc wsdlSourceFile = new File JavaDoc(wsdlSource);
201             if(!wsdlSourceFile.exists()) {
202                 message = NbBundle.getMessage(RefreshWsdlPanel.class, "ERR_FileDoesNotExist"); // NOI18N
203
}
204         }
205         
206         return message;
207     }
208 }
209
Popular Tags