KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.j2ee.dd.api.web.FilterMapping;
23 import org.openide.util.NbBundle;
24
25 /**
26  * FilterMappingPanel.java
27  * Panel for adding/editing filter mapping data
28  *
29  * Created on January 24, 2005, 4:22 PM
30  * @author mkuchtiak
31  */

32 public class FilterMappingPanel extends javax.swing.JPanel JavaDoc {
33     private FilterMapping fm;
34     private boolean hasFilterNames=true;
35     private boolean hasServletNames=true;
36     private static final String JavaDoc[] dispatcherTypes = {
37         "REQUEST","FORWARD", "INCLUDE", "ERROR" //NOI18N
38
};
39     
40     /** Creates new form FilterMappingPanel */
41     public FilterMappingPanel(FilterMapping fm, String JavaDoc[] filterNames, String JavaDoc[] servletNames) {
42         this.fm=fm;
43         initComponents();
44         jCheckBox1.setText(dispatcherTypes[0]);
45         jCheckBox2.setText(dispatcherTypes[1]);
46         jCheckBox3.setText(dispatcherTypes[2]);
47         jCheckBox4.setText(dispatcherTypes[3]);
48         jCheckBox1.setMnemonic(dispatcherTypes[0].charAt(0));
49         jCheckBox2.setMnemonic(dispatcherTypes[1].charAt(0));
50         jCheckBox3.setMnemonic(dispatcherTypes[2].charAt(0));
51         jCheckBox4.setMnemonic(dispatcherTypes[3].charAt(0));
52         
53         // fill CB1 with filter names
54
if(filterNames == null || filterNames.length == 0) {
55         filterNames = new String JavaDoc[1];
56         filterNames[0] = NbBundle.getMessage(FilterMappingPanel.class,"LBL_no_filters");
57         hasFilterNames = false;
58     }
59         for (int i=0;i<filterNames.length;i++) filterNameCB.addItem(filterNames[i]);
60         
61         // fill CB1 with servlet names
62
if(servletNames == null || servletNames.length == 0) {
63         servletNames = new String JavaDoc[1];
64         servletNames[0] = NbBundle.getMessage(FilterMappingPanel.class,"LBL_no_servlets");
65         hasServletNames = false;
66     }
67         for (int i=0;i<servletNames.length;i++) servletNameCB.addItem(servletNames[i]);
68         if (!hasServletNames) {
69             jRadioButton2.setEnabled(false);
70         }
71         
72         String JavaDoc servletName = fm.getServletName();
73         if (servletName != null) {
74             jRadioButton2.setSelected(true);
75             urlTF.setEnabled(false);
76             servletNameCB.setSelectedItem(servletName);
77         } else {
78         jRadioButton1.setSelected(true);
79         urlTF.setText(fm.getUrlPattern());
80             servletNameCB.setEnabled(false);
81         }
82         try {
83             String JavaDoc[] dispTypes = fm.getDispatcher();
84             for (int i=0;i<dispTypes.length;i++) {
85                 if (dispatcherTypes[0].equals(dispTypes[i])) jCheckBox1.setSelected(true);
86                 else if (dispatcherTypes[1].equals(dispTypes[i])) jCheckBox2.setSelected(true);
87                 else if (dispatcherTypes[2].equals(dispTypes[i])) jCheckBox3.setSelected(true);
88                 else if (dispatcherTypes[3].equals(dispTypes[i])) jCheckBox4.setSelected(true);
89             }
90         } catch (org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException ex) {}
91     }
92     
93     javax.swing.JTextField JavaDoc getUrlTF() {
94         return urlTF;
95     }
96     javax.swing.JRadioButton JavaDoc getUrlRB() {
97         return jRadioButton1;
98     }
99     javax.swing.JRadioButton JavaDoc getServletNameRB() {
100         return jRadioButton2;
101     }
102     String JavaDoc getUrlPattern() {
103         return (jRadioButton1.isSelected()?urlTF.getText().trim():null);
104     }
105     String JavaDoc getServletName() {
106         return (jRadioButton2.isSelected()?(String JavaDoc)servletNameCB.getSelectedItem():null);
107     }
108     String JavaDoc getFilterName() {
109         return (hasFilterNames?(String JavaDoc)filterNameCB.getSelectedItem():null);
110     }
111     String JavaDoc[] getDispatcherTypes() {
112         java.util.List JavaDoc list = new java.util.ArrayList JavaDoc();
113         if (jCheckBox1.isSelected()) list.add(dispatcherTypes[0]);
114         if (jCheckBox2.isSelected()) list.add(dispatcherTypes[1]);
115         if (jCheckBox3.isSelected()) list.add(dispatcherTypes[2]);
116         if (jCheckBox4.isSelected()) list.add(dispatcherTypes[3]);
117         String JavaDoc[] ret = new String JavaDoc[list.size()];
118         list.toArray(ret);
119         return ret;
120     }
121     
122     boolean hasFilterNames() {
123         return hasFilterNames;
124     }
125     boolean hasServletNames() {
126         return hasServletNames;
127     }
128     
129     /** This method is called from within the constructor to
130      * initialize the form.
131      * WARNING: Do NOT modify this code. The content of this method is
132      * always regenerated by the Form Editor.
133      */

134     private void initComponents() {//GEN-BEGIN:initComponents
135
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
136
137         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
138         jLabel1 = new javax.swing.JLabel JavaDoc();
139         filterNameCB = new javax.swing.JComboBox JavaDoc();
140         jLabel4 = new javax.swing.JLabel JavaDoc();
141         jPanel1 = new javax.swing.JPanel JavaDoc();
142         jCheckBox1 = new javax.swing.JCheckBox JavaDoc();
143         jCheckBox2 = new javax.swing.JCheckBox JavaDoc();
144         jCheckBox3 = new javax.swing.JCheckBox JavaDoc();
145         jCheckBox4 = new javax.swing.JCheckBox JavaDoc();
146         jPanel2 = new javax.swing.JPanel JavaDoc();
147         servletNameCB = new javax.swing.JComboBox JavaDoc();
148         urlTF = new javax.swing.JTextField JavaDoc();
149         jRadioButton1 = new javax.swing.JRadioButton JavaDoc();
150         jRadioButton2 = new javax.swing.JRadioButton JavaDoc();
151         jLabel2 = new javax.swing.JLabel JavaDoc();
152
153         setLayout(new java.awt.GridBagLayout JavaDoc());
154
155         jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_filterName_mnem").charAt(0));
156         jLabel1.setLabelFor(filterNameCB);
157         jLabel1.setText(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_filterName"));
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridx = 0;
160         gridBagConstraints.gridy = 0;
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
163         add(jLabel1, gridBagConstraints);
164
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridx = 1;
167         gridBagConstraints.gridy = 0;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
171         add(filterNameCB, gridBagConstraints);
172
173         jLabel4.setText(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_dispatcherTypes"));
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 0;
176         gridBagConstraints.gridy = 3;
177         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
178         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
179         add(jLabel4, gridBagConstraints);
180
181         jPanel1.setBorder(new javax.swing.border.LineBorder JavaDoc(new java.awt.Color JavaDoc(0, 0, 0)));
182         jPanel1.add(jCheckBox1);
183
184         jPanel1.add(jCheckBox2);
185
186         jPanel1.add(jCheckBox3);
187
188         jPanel1.add(jCheckBox4);
189
190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
191         gridBagConstraints.gridx = 0;
192         gridBagConstraints.gridy = 4;
193         gridBagConstraints.gridwidth = 2;
194         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
195         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
196         add(jPanel1, gridBagConstraints);
197
198         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
199
200         jPanel2.setBorder(new javax.swing.border.LineBorder JavaDoc(new java.awt.Color JavaDoc(0, 0, 0)));
201         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
202         gridBagConstraints.gridx = 1;
203         gridBagConstraints.gridy = 1;
204         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
206         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 5, 5);
207         jPanel2.add(servletNameCB, gridBagConstraints);
208
209         urlTF.setColumns(20);
210         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
211         gridBagConstraints.gridx = 1;
212         gridBagConstraints.gridy = 0;
213         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
214         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 5);
215         jPanel2.add(urlTF, gridBagConstraints);
216
217         buttonGroup1.add(jRadioButton1);
218         jRadioButton1.setMnemonic(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_urlPattern_mnem").charAt(0));
219         jRadioButton1.setSelected(true);
220         jRadioButton1.setText(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_urlPattern"));
221         jRadioButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
222             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
223                 jRadioButton1ActionPerformed(evt);
224             }
225         });
226
227         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
228         gridBagConstraints.gridx = 0;
229         gridBagConstraints.gridy = 0;
230         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
231         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 7, 0, 0);
232         jPanel2.add(jRadioButton1, gridBagConstraints);
233
234         buttonGroup1.add(jRadioButton2);
235         jRadioButton2.setMnemonic(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_servletName_mnem1").charAt(0));
236         jRadioButton2.setText(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_servletName"));
237         jRadioButton2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
238             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
239                 jRadioButton2ActionPerformed(evt);
240             }
241         });
242
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 0;
245         gridBagConstraints.gridy = 1;
246         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
247         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 7, 5, 0);
248         jPanel2.add(jRadioButton2, gridBagConstraints);
249
250         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
251         gridBagConstraints.gridx = 0;
252         gridBagConstraints.gridy = 2;
253         gridBagConstraints.gridwidth = 2;
254         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
255         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
256         add(jPanel2, gridBagConstraints);
257
258         jLabel2.setText(org.openide.util.NbBundle.getMessage(FilterMappingPanel.class, "LBL_applyTo"));
259         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
260         gridBagConstraints.gridx = 0;
261         gridBagConstraints.gridy = 1;
262         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
263         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
264         add(jLabel2, gridBagConstraints);
265
266     }//GEN-END:initComponents
267

268     private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
269
// TODO add your handling code here:
270
urlTF.setEnabled(false);
271             servletNameCB.setEnabled(true);
272             jRadioButton2.requestFocus();
273     }//GEN-LAST:event_jRadioButton2ActionPerformed
274

275     private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
276
// TODO add your handling code here:
277
urlTF.setEnabled(true);
278             servletNameCB.setEnabled(false);
279             urlTF.requestFocus();
280     }//GEN-LAST:event_jRadioButton1ActionPerformed
281

282     
283     // Variables declaration - do not modify//GEN-BEGIN:variables
284
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
285     private javax.swing.JComboBox JavaDoc filterNameCB;
286     private javax.swing.JCheckBox JavaDoc jCheckBox1;
287     private javax.swing.JCheckBox JavaDoc jCheckBox2;
288     private javax.swing.JCheckBox JavaDoc jCheckBox3;
289     private javax.swing.JCheckBox JavaDoc jCheckBox4;
290     private javax.swing.JLabel JavaDoc jLabel1;
291     private javax.swing.JLabel JavaDoc jLabel2;
292     private javax.swing.JLabel JavaDoc jLabel4;
293     private javax.swing.JPanel JavaDoc jPanel1;
294     private javax.swing.JPanel JavaDoc jPanel2;
295     private javax.swing.JRadioButton JavaDoc jRadioButton1;
296     private javax.swing.JRadioButton JavaDoc jRadioButton2;
297     private javax.swing.JComboBox JavaDoc servletNameCB;
298     private javax.swing.JTextField JavaDoc urlTF;
299     // End of variables declaration//GEN-END:variables
300

301 }
302
Popular Tags