KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > multiview > WebResourceCollectionPanel


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.j2ee.ddloaders.web.multiview;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.StringTokenizer JavaDoc;
24 import javax.swing.JTextField JavaDoc;
25
26 /**
27  * WebResourceCollectionPanel.java
28  *
29  * Panel for adding and editing the web-resource-collection element of the web
30  * deployment descriptor.
31  *
32  * @author ptliu
33  */

34 public class WebResourceCollectionPanel extends javax.swing.JPanel JavaDoc {
35     private static String JavaDoc GET = "GET"; //NOI18N
36
private static String JavaDoc POST = "POST"; //NOI18N
37
private static String JavaDoc HEAD = "HEAD"; //NOI18N
38
private static String JavaDoc PUT = "PUT"; //NOI18N
39
private static String JavaDoc OPTIONS = "OPTIONS"; //NOI18N
40
private static String JavaDoc TRACE = "TRACE"; //NOI18N
41
private static String JavaDoc DELETE = "DELETE"; //NOI18N
42
private static String JavaDoc[] allMethods = {GET, POST, HEAD, PUT, OPTIONS, TRACE,
43                                             DELETE};
44
45     /** Creates new form WebResourceCollectionPanel */
46     public WebResourceCollectionPanel() {
47         initComponents();
48     }
49     
50     public String JavaDoc getResourceName() {
51         return resourceNameTF.getText();
52     }
53     
54     public void setResourceName(String JavaDoc name) {
55         resourceNameTF.setText(name);
56     }
57     
58     public String JavaDoc[] getUrlPatterns() {
59         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(urlPatternsTF.getText(),
60                 ","); //NOI18N
61

62         ArrayList JavaDoc list = new ArrayList JavaDoc();
63         while (tokenizer.hasMoreTokens()) {
64             String JavaDoc pattern = tokenizer.nextToken().trim();
65             if (pattern.length() > 0)
66                 list.add(pattern);
67         }
68         
69         String JavaDoc[] result = new String JavaDoc[list.size()];
70         
71         return (String JavaDoc[]) list.toArray(result);
72     }
73     
74     public void setUrlPatterns(String JavaDoc[] patterns) {
75         urlPatternsTF.setText(WebResourceCollectionTableModel.getCommaSeparatedString(patterns));
76     }
77     
78     public String JavaDoc getDescription() {
79         return descriptionTF.getText();
80     }
81     
82     public void setDescription(String JavaDoc description) {
83         descriptionTF.setText(description);
84     }
85     
86     public void setHttpMethods(String JavaDoc[] methods) {
87         boolean allSelected = true;
88         
89         for (int i = 0; i < allMethods.length; i++) {
90             boolean found = false;
91             String JavaDoc method = allMethods[i];
92             
93             for (int j = 0; j < methods.length; j++) {
94                 if (method.equals(methods[j])) {
95                     found = true;
96                     break;
97                 }
98             }
99             
100             if (!found) {
101                 allSelected = false;
102                 break;
103             }
104         }
105         
106         if (allSelected) {
107             allHttpMethodsRB.setSelected(true);
108         } else {
109             subsetHttpMethodsRB.setSelected(true);
110             for (int i =0; i < methods.length; i++) {
111                 String JavaDoc method = methods[i];
112                 
113                 if (method.equals(GET)) {
114                     getCB.setSelected(true);
115                 } else if (method.equals(PUT)) {
116                     putCB.setSelected(true);
117                 } else if (method.equals(HEAD)) {
118                     headCB.setSelected(true);
119                 } else if (method.equals(POST)) {
120                     postCB.setSelected(true);
121                 } else if (method.equals(TRACE)) {
122                     traceCB.setSelected(true);
123                 } else if (method.equals(DELETE)) {
124                     deleteCB.setSelected(true);
125                 } else if (method.equals(OPTIONS)) {
126                     optionsCB.setSelected(true);
127                 }
128             }
129         }
130         
131         updateVisualState();
132     }
133                   
134     public String JavaDoc[] getSelectedHttpMethods() {
135         if (allHttpMethodsRB.isSelected()) {
136             return allMethods;
137         } else if (subsetHttpMethodsRB.isSelected()) {
138             ArrayList JavaDoc list = new ArrayList JavaDoc();
139             
140             if (getCB.isSelected()) {
141                 list.add(GET);
142             }
143             
144             if (putCB.isSelected()) {
145                 list.add(PUT);
146             }
147             
148             if (headCB.isSelected()) {
149                 list.add(HEAD);
150             }
151             
152             if (postCB.isSelected()) {
153                 list.add(POST);
154             }
155             
156             if (optionsCB.isSelected()) {
157                 list.add(OPTIONS);
158             }
159             
160             if (traceCB.isSelected()) {
161                 list.add(TRACE);
162             }
163             
164             if (deleteCB.isSelected()) {
165                 list.add(DELETE);
166             }
167             
168             String JavaDoc[] results = new String JavaDoc[list.size()];
169             return (String JavaDoc[]) list.toArray(results);
170         }
171         
172         return new String JavaDoc[] {};
173     }
174     
175     private void updateVisualState() {
176         if (subsetHttpMethodsRB.isSelected()) {
177             getCB.setEnabled(true);
178             putCB.setEnabled(true);
179             headCB.setEnabled(true);
180             postCB.setEnabled(true);
181             optionsCB.setEnabled(true);
182             traceCB.setEnabled(true);
183             deleteCB.setEnabled(true);
184         } else {
185             getCB.setEnabled(false);
186             putCB.setEnabled(false);
187             headCB.setEnabled(false);
188             postCB.setEnabled(false);
189             optionsCB.setEnabled(false);
190             traceCB.setEnabled(false);
191             deleteCB.setEnabled(false);
192         }
193     }
194     
195     public JTextField JavaDoc getResourceNameTF() {
196         return resourceNameTF;
197     }
198     
199     public JTextField JavaDoc getDescriptionTF() {
200         return descriptionTF;
201     }
202     
203     public JTextField JavaDoc getUrlPatternsTF() {
204         return urlPatternsTF;
205     }
206     
207     /** This method is called from within the constructor to
208      * initialize the form.
209      * WARNING: Do NOT modify this code. The content of this method is
210      * always regenerated by the Form Editor.
211      */

212     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
213
private void initComponents() {
214         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
215         resourceNameLabel = new javax.swing.JLabel JavaDoc();
216         resourceNameTF = new javax.swing.JTextField JavaDoc();
217         descriptionLabel = new javax.swing.JLabel JavaDoc();
218         descriptionTF = new javax.swing.JTextField JavaDoc();
219         urlPatternsLabel = new javax.swing.JLabel JavaDoc();
220         urlPatternsTF = new javax.swing.JTextField JavaDoc();
221         httpMethodLabel = new javax.swing.JLabel JavaDoc();
222         getCB = new javax.swing.JCheckBox JavaDoc();
223         postCB = new javax.swing.JCheckBox JavaDoc();
224         headCB = new javax.swing.JCheckBox JavaDoc();
225         putCB = new javax.swing.JCheckBox JavaDoc();
226         optionsCB = new javax.swing.JCheckBox JavaDoc();
227         traceCB = new javax.swing.JCheckBox JavaDoc();
228         deleteCB = new javax.swing.JCheckBox JavaDoc();
229         jLabel5 = new javax.swing.JLabel JavaDoc();
230         allHttpMethodsRB = new javax.swing.JRadioButton JavaDoc();
231         subsetHttpMethodsRB = new javax.swing.JRadioButton JavaDoc();
232
233         resourceNameLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_resourceName_mnem").charAt(0));
234         resourceNameLabel.setLabelFor(resourceNameTF);
235         resourceNameLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionName"));
236
237         descriptionLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_description_mnem").charAt(0));
238         descriptionLabel.setLabelFor(descriptionTF);
239         descriptionLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionDescription"));
240
241         urlPatternsLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_urlPatterns_mnem2").charAt(0));
242         urlPatternsLabel.setLabelFor(urlPatternsTF);
243         urlPatternsLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionUrlPatterns"));
244
245         httpMethodLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionHttpMethods"));
246
247         getCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_get_mnem").charAt(0));
248         getCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_GET"));
249         getCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
250         getCB.setEnabled(false);
251         getCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
252
253         postCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_post_mnem").charAt(0));
254         postCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_POST"));
255         postCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
256         postCB.setEnabled(false);
257         postCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
258
259         headCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_head_mnem").charAt(0));
260         headCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_HEAD"));
261         headCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
262         headCB.setEnabled(false);
263         headCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
264
265         putCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_put_mnem").charAt(0));
266         putCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_PUT"));
267         putCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
268         putCB.setEnabled(false);
269         putCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
270
271         optionsCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_options_mnem").charAt(0));
272         optionsCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_OPTIONS"));
273         optionsCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
274         optionsCB.setEnabled(false);
275         optionsCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
276
277         traceCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_trace_mnem").charAt(0));
278         traceCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_TRACE"));
279         traceCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
280         traceCB.setEnabled(false);
281         traceCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
282
283         deleteCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_delete_mnem").charAt(0));
284         deleteCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_DELETE"));
285         deleteCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
286         deleteCB.setEnabled(false);
287         deleteCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
288
289         jLabel5.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("HINT_urlPatterns"));
290
291         buttonGroup1.add(allHttpMethodsRB);
292         allHttpMethodsRB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_allHttpMethods_mnem").charAt(0));
293         allHttpMethodsRB.setSelected(true);
294         allHttpMethodsRB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_AllHttpMethods"));
295         allHttpMethodsRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
296         allHttpMethodsRB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
297         allHttpMethodsRB.addActionListener(new java.awt.event.ActionListener JavaDoc() {
298             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
299                 allHttpMethodsRBActionPerformed(evt);
300             }
301         });
302
303         buttonGroup1.add(subsetHttpMethodsRB);
304         subsetHttpMethodsRB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_subsetHttpMethods_mnem").charAt(0));
305         subsetHttpMethodsRB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_SubsetOfHttpMethods"));
306         subsetHttpMethodsRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
307         subsetHttpMethodsRB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
308         subsetHttpMethodsRB.addActionListener(new java.awt.event.ActionListener JavaDoc() {
309             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
310                 subsetHttpMethodsRBActionPerformed(evt);
311             }
312         });
313
314         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
315         this.setLayout(layout);
316         layout.setHorizontalGroup(
317             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
318             .add(layout.createSequentialGroup()
319                 .addContainerGap()
320                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
321                     .add(resourceNameLabel)
322                     .add(descriptionLabel)
323                     .add(urlPatternsLabel)
324                     .add(httpMethodLabel))
325                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
326                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
327                     .add(urlPatternsTF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
328                     .add(descriptionTF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
329                     .add(resourceNameTF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
330                     .add(layout.createSequentialGroup()
331                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
332                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
333                             .add(jLabel5)
334                             .add(allHttpMethodsRB)
335                             .add(subsetHttpMethodsRB)))
336                     .add(layout.createSequentialGroup()
337                         .add(25, 25, 25)
338                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
339                             .add(optionsCB)
340                             .add(getCB)
341                             .add(headCB)
342                             .add(deleteCB))
343                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
344                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
345                             .add(postCB)
346                             .add(traceCB)
347                             .add(putCB))
348                         .add(163, 163, 163)))
349                 .addContainerGap())
350         );
351         layout.setVerticalGroup(
352             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
353             .add(layout.createSequentialGroup()
354                 .addContainerGap()
355                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
356                     .add(resourceNameLabel)
357                     .add(resourceNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
358                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
359                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
360                     .add(descriptionLabel)
361                     .add(descriptionTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
362                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
363                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
364                     .add(urlPatternsLabel)
365                     .add(urlPatternsTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
366                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
367                 .add(jLabel5)
368                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
369                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
370                     .add(httpMethodLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
371                     .add(allHttpMethodsRB))
372                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
373                 .add(subsetHttpMethodsRB)
374                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
375                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
376                     .add(getCB)
377                     .add(postCB))
378                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
379                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
380                     .add(headCB)
381                     .add(putCB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
382                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
383                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
384                     .add(optionsCB)
385                     .add(traceCB))
386                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
387                 .add(deleteCB)
388                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
389         );
390     }// </editor-fold>//GEN-END:initComponents
391

392     private void subsetHttpMethodsRBActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_subsetHttpMethodsRBActionPerformed
393
// TODO add your handling code here:
394
updateVisualState();
395     }//GEN-LAST:event_subsetHttpMethodsRBActionPerformed
396

397     private void allHttpMethodsRBActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_allHttpMethodsRBActionPerformed
398
// TODO add your handling code here:
399
updateVisualState();
400     }//GEN-LAST:event_allHttpMethodsRBActionPerformed
401

402     
403     // Variables declaration - do not modify//GEN-BEGIN:variables
404
private javax.swing.JRadioButton JavaDoc allHttpMethodsRB;
405     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
406     private javax.swing.JCheckBox JavaDoc deleteCB;
407     private javax.swing.JLabel JavaDoc descriptionLabel;
408     private javax.swing.JTextField JavaDoc descriptionTF;
409     private javax.swing.JCheckBox JavaDoc getCB;
410     private javax.swing.JCheckBox JavaDoc headCB;
411     private javax.swing.JLabel JavaDoc httpMethodLabel;
412     private javax.swing.JLabel JavaDoc jLabel5;
413     private javax.swing.JCheckBox JavaDoc optionsCB;
414     private javax.swing.JCheckBox JavaDoc postCB;
415     private javax.swing.JCheckBox JavaDoc putCB;
416     private javax.swing.JLabel JavaDoc resourceNameLabel;
417     private javax.swing.JTextField JavaDoc resourceNameTF;
418     private javax.swing.JRadioButton JavaDoc subsetHttpMethodsRB;
419     private javax.swing.JCheckBox JavaDoc traceCB;
420     private javax.swing.JLabel JavaDoc urlPatternsLabel;
421     private javax.swing.JTextField JavaDoc urlPatternsTF;
422     // End of variables declaration//GEN-END:variables
423

424 }
425
Popular Tags