KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.JComboBox JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import org.netbeans.modules.j2ee.dd.api.web.FilterMapping;
25 import org.netbeans.modules.j2ee.dd.api.web.Servlet;
26 import org.netbeans.modules.j2ee.dd.api.web.ServletMapping;
27 import org.netbeans.modules.j2ee.ddloaders.web.*;
28 import org.netbeans.modules.xml.multiview.ui.*;
29 import org.netbeans.modules.xml.multiview.Utils;
30 import org.netbeans.modules.xml.multiview.Error;
31 import org.netbeans.api.project.SourceGroup;
32 import org.netbeans.modules.j2ee.dd.api.common.RunAs;
33 import org.openide.util.NbBundle;
34
35 /**
36  * @author mkuchtiak
37  */

38 public class ServletPanel extends SectionInnerPanel implements java.awt.event.ActionListener JavaDoc {
39     private DDDataObject dObj;
40     private Servlet servlet;
41     private javax.swing.JButton JavaDoc linkServletClass, linkJspFile;
42     private InitParamsPanel initParamsPanel;
43     private JComboBox JavaDoc runAsCB;
44     
45     /** Creates new form ServletPanel */
46     public ServletPanel(SectionView sectionView, DDDataObject dObj,Servlet servlet) {
47         super(sectionView);
48         this.dObj=dObj;
49         this.servlet=servlet;
50         initComponents();
51         // Servlet Name
52
servletNameTF.setText(servlet.getServletName());
53         addValidatee(servletNameTF);
54         
55         // description
56
Utils.makeTextAreaLikeTextField(descriptionTA,servletNameTF);
57         descriptionTA.setText(servlet.getDefaultDescription());
58         addModifier(descriptionTA);
59         
60         // Order
61
java.math.BigInteger JavaDoc los = servlet.getLoadOnStartup();
62         orderTF.setText(los==null?"":los.toString());
63         addValidatee(orderTF);
64         
65         // servlet-class/jsp-file
66
String JavaDoc jspFile = servlet.getJspFile();
67         if (jspFile!=null) {
68             jspFileRB.setSelected(true);
69             servletClassTF.setEnabled(false);
70             browseButton.setEnabled(false);
71             jspFileTF.setText(jspFile);
72         } else {
73             servletClassRB.setSelected(true);
74             jspFileTF.setEnabled(false);
75             browseButton1.setEnabled(false);
76             servletClassTF.setText(servlet.getServletClass());
77         }
78         servletClassRB.addActionListener(this);
79         jspFileRB.addActionListener(this);
80         addValidatee(servletClassTF);
81         addValidatee(jspFileTF);
82         
83         
84         // URL Patterns
85
String JavaDoc[] urlPatterns = DDUtils.getUrlPatterns(dObj.getWebApp(),servlet);
86         servletMappingsTF.setText(DDUtils.urlPatternList(urlPatterns));
87         addValidatee(servletMappingsTF);
88         
89         // Init Params
90
InitParamTableModel model = new InitParamTableModel();
91         initParamsPanel = new InitParamsPanel(dObj, model);
92         initParamsPanel.setModel(servlet,servlet.getInitParam());
93         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
94         gridBagConstraints.gridx = 0;
95         gridBagConstraints.gridy = 7;
96         gridBagConstraints.gridwidth = 5;
97         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
98         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
99         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 10, 0, 0);
100         //gridBagConstraints.weightx = 1.0;
101
//gridBagConstraints.weighty = 5.0;
102
add(initParamsPanel, gridBagConstraints);
103         
104         JLabel JavaDoc securityRoleRefsLabel = new JLabel JavaDoc();
105         securityRoleRefsLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_securityRoleRefs_mnem").charAt(0));
106         securityRoleRefsLabel.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_SecurityRoleRefs"));
107         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
108         gridBagConstraints.gridx = 0;
109         gridBagConstraints.gridy = 8;
110         gridBagConstraints.gridwidth = 5;
111         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
112         gridBagConstraints.insets = new java.awt.Insets JavaDoc(15, 10, 0, 0);
113         add(securityRoleRefsLabel, gridBagConstraints);
114         
115         // Security Role Refs
116
SecurityRoleRefTableModel roleRefModel = new SecurityRoleRefTableModel();
117         SecurityRoleRefTablePanel roleRefPanel = new SecurityRoleRefTablePanel(dObj, roleRefModel);
118         roleRefPanel.setModel(dObj.getWebApp(), servlet, servlet.getSecurityRoleRef());
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridx = 0;
121         gridBagConstraints.gridy = 9;
122         gridBagConstraints.gridwidth = 5;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
124         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 10, 0, 0);
126         add(roleRefPanel, gridBagConstraints);
127         
128         RunAsPanel runAsPanel = new RunAsPanel(dObj.getWebApp());
129         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 0;
131         gridBagConstraints.gridy = 10;
132         gridBagConstraints.gridwidth = 5;
133         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
134         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 10, 0, 0);
136         add(runAsPanel, gridBagConstraints);
137         runAsCB = runAsPanel.getRunAsCB();
138         
139         RunAs runAs = servlet.getRunAs();
140         if (runAs == null) {
141             runAsCB.setSelectedItem(""); //NOI18N
142
} else {
143             runAsCB.setSelectedItem(runAs.getRoleName());
144         }
145         addModifier(runAsCB);
146         
147         linkServletClass = new LinkButton(this, servlet, "ClassName"); //NOI18N
148
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.gridx = 3;
150         gridBagConstraints.gridy = 2;
151         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
152         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
153         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 0);
154         linkServletClass.setText(NbBundle.getMessage(ServletPanel.class, "LBL_goToSource"));
155         add(linkServletClass, gridBagConstraints);
156         
157         linkJspFile = new LinkButton(this, servlet, "JspFile"); //NOI18N
158
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridx = 3;
160         gridBagConstraints.gridy = 3;
161         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
162         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
163         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 0);
164         linkJspFile.setText(NbBundle.getMessage(ServletPanel.class, "LBL_goToSource"));
165         add(linkJspFile, gridBagConstraints);
166         
167         setAccessibility();
168     }
169     
170     private void setAccessibility() {
171         linkServletClass.setMnemonic(NbBundle.getMessage(ServletPanel.class, "LBL_goToSource_mnem").charAt(0));
172         linkJspFile.setMnemonic(NbBundle.getMessage(ServletPanel.class, "LBL_goToSource_mnem2").charAt(0));
173         initParamsLabel.setLabelFor(initParamsPanel.getTable());
174     }
175     
176     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc property) {
177         if ("ClassName".equals(property)) { //NOI18N
178
DDUtils.openEditorFor(dObj,((Servlet)ddBean).getServletClass());
179         } else if ("JspFile".equals(property)) { //NOI18N
180
DDUtils.openEditorForSingleFile(dObj,((Servlet)ddBean).getJspFile());
181         }
182     }
183     
184     /** This method is called from within the constructor to
185      * initialize the form.
186      * WARNING: Do NOT modify this code. The content of this method is
187      * always regenerated by the Form Editor.
188      */

189     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
190
private void initComponents() {
191         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
192
193         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
194         servletNameLabel = new javax.swing.JLabel JavaDoc();
195         servletNameTF = new javax.swing.JTextField JavaDoc();
196         orderLabel = new javax.swing.JLabel JavaDoc();
197         orderTF = new javax.swing.JTextField JavaDoc();
198         descriptionLabel = new javax.swing.JLabel JavaDoc();
199         descriptionTA = new javax.swing.JTextArea JavaDoc();
200         servletClassRB = new javax.swing.JRadioButton JavaDoc();
201         servletClassTF = new javax.swing.JTextField JavaDoc();
202         browseButton = new javax.swing.JButton JavaDoc();
203         jspFileRB = new javax.swing.JRadioButton JavaDoc();
204         jspFileTF = new javax.swing.JTextField JavaDoc();
205         browseButton1 = new javax.swing.JButton JavaDoc();
206         servletMappingLabel = new javax.swing.JLabel JavaDoc();
207         servletMappingsTF = new javax.swing.JTextField JavaDoc();
208         jLabel1 = new javax.swing.JLabel JavaDoc();
209         initParamsLabel = new javax.swing.JLabel JavaDoc();
210         filler = new javax.swing.JPanel JavaDoc();
211
212         setLayout(new java.awt.GridBagLayout JavaDoc());
213
214         servletNameLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_servletName_mnem").charAt(0));
215         servletNameLabel.setLabelFor(servletNameTF);
216         servletNameLabel.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_servletName"));
217         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
218         gridBagConstraints.gridx = 0;
219         gridBagConstraints.gridy = 0;
220         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
221         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 10);
222         add(servletNameLabel, gridBagConstraints);
223
224         servletNameTF.setColumns(20);
225         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
226         gridBagConstraints.gridx = 1;
227         gridBagConstraints.gridy = 0;
228         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
229         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
230         add(servletNameTF, gridBagConstraints);
231
232         orderLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_order_mnem").charAt(0));
233         orderLabel.setLabelFor(orderTF);
234         orderLabel.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_order"));
235         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
236         gridBagConstraints.gridx = 3;
237         gridBagConstraints.gridy = 0;
238         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
239         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 10);
240         add(orderLabel, gridBagConstraints);
241
242         orderTF.setColumns(2);
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 4;
245         gridBagConstraints.gridy = 0;
246         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
247         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
248         add(orderTF, gridBagConstraints);
249
250         descriptionLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_description_mnem").charAt(0));
251         descriptionLabel.setLabelFor(descriptionTA);
252         descriptionLabel.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_description"));
253         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.gridx = 0;
255         gridBagConstraints.gridy = 1;
256         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
257         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 10);
258         add(descriptionLabel, gridBagConstraints);
259
260         descriptionTA.setRows(3);
261         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
262         gridBagConstraints.gridx = 1;
263         gridBagConstraints.gridy = 1;
264         gridBagConstraints.gridwidth = 4;
265         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
266         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
267         add(descriptionTA, gridBagConstraints);
268
269         buttonGroup1.add(servletClassRB);
270         servletClassRB.setMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_servletClass_mnem").charAt(0));
271         servletClassRB.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_servletClass"));
272         servletClassRB.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
273         servletClassRB.setOpaque(false);
274         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
275         gridBagConstraints.gridx = 0;
276         gridBagConstraints.gridy = 2;
277         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
278         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 10);
279         add(servletClassRB, gridBagConstraints);
280
281         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
282         gridBagConstraints.gridx = 1;
283         gridBagConstraints.gridy = 2;
284         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
285         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
286         add(servletClassTF, gridBagConstraints);
287
288         browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_browse_mnem").charAt(0));
289         browseButton.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_browse"));
290         browseButton.setMargin(new java.awt.Insets JavaDoc(0, 14, 0, 14));
291         browseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
292             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
293                 browseButtonActionPerformed(evt);
294             }
295         });
296
297         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
298         gridBagConstraints.gridx = 2;
299         gridBagConstraints.gridy = 2;
300         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
301         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 10, 0, 0);
302         add(browseButton, gridBagConstraints);
303
304         buttonGroup1.add(jspFileRB);
305         jspFileRB.setMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_jspFile_mnem").charAt(0));
306         jspFileRB.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_jspFile"));
307         jspFileRB.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
308         jspFileRB.setOpaque(false);
309         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
310         gridBagConstraints.gridx = 0;
311         gridBagConstraints.gridy = 3;
312         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
313         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 10);
314         add(jspFileRB, gridBagConstraints);
315
316         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
317         gridBagConstraints.gridx = 1;
318         gridBagConstraints.gridy = 3;
319         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
320         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
321         add(jspFileTF, gridBagConstraints);
322
323         browseButton1.setMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_browse_mnem2").charAt(0));
324         browseButton1.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_browse"));
325         browseButton1.setMargin(new java.awt.Insets JavaDoc(0, 14, 0, 14));
326         browseButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
327             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
328                 browseButton1ActionPerformed(evt);
329             }
330         });
331
332         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
333         gridBagConstraints.gridx = 2;
334         gridBagConstraints.gridy = 3;
335         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
336         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 10, 0, 0);
337         add(browseButton1, gridBagConstraints);
338
339         servletMappingLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_urlPatterns_mnem").charAt(0));
340         servletMappingLabel.setLabelFor(servletMappingsTF);
341         servletMappingLabel.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_urlPatterns"));
342         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
343         gridBagConstraints.gridx = 0;
344         gridBagConstraints.gridy = 4;
345         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
346         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 10, 0, 10);
347         add(servletMappingLabel, gridBagConstraints);
348
349         servletMappingsTF.setColumns(30);
350         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
351         gridBagConstraints.gridx = 1;
352         gridBagConstraints.gridy = 4;
353         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
354         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
355         add(servletMappingsTF, gridBagConstraints);
356
357         jLabel1.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "HINT_urlPatterns"));
358         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
359         gridBagConstraints.gridx = 1;
360         gridBagConstraints.gridy = 5;
361         gridBagConstraints.gridwidth = 4;
362         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
363         add(jLabel1, gridBagConstraints);
364
365         initParamsLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_initParams_mnem").charAt(0));
366         initParamsLabel.setText(org.openide.util.NbBundle.getMessage(ServletPanel.class, "LBL_initParams"));
367         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
368         gridBagConstraints.gridx = 0;
369         gridBagConstraints.gridy = 6;
370         gridBagConstraints.gridwidth = 5;
371         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
372         gridBagConstraints.insets = new java.awt.Insets JavaDoc(15, 10, 0, 0);
373         add(initParamsLabel, gridBagConstraints);
374
375         filler.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
376         filler.setOpaque(false);
377         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
378         gridBagConstraints.gridx = 5;
379         gridBagConstraints.gridy = 0;
380         gridBagConstraints.gridheight = 6;
381         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
382         gridBagConstraints.weightx = 1.0;
383         add(filler, gridBagConstraints);
384
385     }
386     // </editor-fold>//GEN-END:initComponents
387

388     private void browseButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButton1ActionPerformed
389
// TODO add your handling code here:
390
try {
391             org.netbeans.api.project.SourceGroup[] groups = DDUtils.getDocBaseGroups(dObj);
392             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
393             if (fo!=null) {
394                 String JavaDoc res = "/"+DDUtils.getResourcePath(groups,fo,'/',true);
395                 if (!res.equals(jspFileTF.getText())) {
396                     dObj.modelUpdatedFromUI();
397                     jspFileTF.setText(res);
398                     dObj.setChangedFromUI(true);
399                     servlet.setJspFile(res);
400                     dObj.setChangedFromUI(false);
401                     getSectionView().checkValidity();
402                 }
403             }
404         } catch (java.io.IOException JavaDoc ex) {}
405     }//GEN-LAST:event_browseButton1ActionPerformed
406

407     private void browseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButtonActionPerformed
408
// TODO add your handling code here:
409
try {
410             SourceGroup[] groups = DDUtils.getJavaSourceGroups(dObj);
411             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
412             if (fo!=null) {
413                 String JavaDoc className = DDUtils.getResourcePath(groups,fo);
414                 if (className.length()>0 && !className.equals(servletClassTF.getText())) {
415                     dObj.modelUpdatedFromUI();
416                     servletClassTF.setText(className);
417                     dObj.setChangedFromUI(true);
418                     servlet.setServletClass(className);
419                     dObj.setChangedFromUI(false);
420                     getSectionView().checkValidity();
421                 }
422             }
423         } catch (java.io.IOException JavaDoc ex) {}
424     }//GEN-LAST:event_browseButtonActionPerformed
425

426     
427     // Variables declaration - do not modify//GEN-BEGIN:variables
428
private javax.swing.JButton JavaDoc browseButton;
429     private javax.swing.JButton JavaDoc browseButton1;
430     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
431     private javax.swing.JLabel JavaDoc descriptionLabel;
432     private javax.swing.JTextArea JavaDoc descriptionTA;
433     private javax.swing.JPanel JavaDoc filler;
434     private javax.swing.JLabel JavaDoc initParamsLabel;
435     private javax.swing.JLabel JavaDoc jLabel1;
436     private javax.swing.JRadioButton JavaDoc jspFileRB;
437     private javax.swing.JTextField JavaDoc jspFileTF;
438     private javax.swing.JLabel JavaDoc orderLabel;
439     private javax.swing.JTextField JavaDoc orderTF;
440     private javax.swing.JRadioButton JavaDoc servletClassRB;
441     private javax.swing.JTextField JavaDoc servletClassTF;
442     private javax.swing.JLabel JavaDoc servletMappingLabel;
443     private javax.swing.JTextField JavaDoc servletMappingsTF;
444     private javax.swing.JLabel JavaDoc servletNameLabel;
445     private javax.swing.JTextField JavaDoc servletNameTF;
446     // End of variables declaration//GEN-END:variables
447

448     public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
449         if (servletClassRB.isSelected()) {
450             servletClassTF.setEnabled(true);
451             jspFileTF.setEnabled(false);
452             browseButton.setEnabled(true);
453             browseButton1.setEnabled(false);
454             String JavaDoc servletClass = servletClassTF.getText().trim();
455             if (servletClass.length()>0 && !servletClass.equals(servlet.getServletClass())) {
456                 dObj.modelUpdatedFromUI();
457                 dObj.setChangedFromUI(true);
458                 servlet.setServletClass(servletClass);
459                 dObj.setChangedFromUI(false);
460                 getSectionView().checkValidity();
461             }
462         } else {
463             servletClassTF.setEnabled(false);
464             jspFileTF.setEnabled(true);
465             browseButton.setEnabled(false);
466             browseButton1.setEnabled(true);
467             String JavaDoc jspFile = jspFileTF.getText().trim();
468             if (jspFile.length()>0 && !jspFile.equals(servlet.getJspFile())) {
469                 dObj.modelUpdatedFromUI();
470                 dObj.setChangedFromUI(true);
471                 servlet.setJspFile(jspFile);
472                 dObj.setChangedFromUI(false);
473                 getSectionView().checkValidity();
474             }
475         }
476     }
477     public javax.swing.JComponent JavaDoc getErrorComponent(String JavaDoc name) {
478         if ("ServletName".equals(name)) return servletNameTF; //NOI18N
479
else if ("ServletClass".equals(name)) return servletClassTF; //NOI18N
480
else if ("JspFile".equals(name)) return jspFileTF; //NOI18N
481
else if ("ServletMapping".equals(name)) return servletMappingsTF; //NOI18N
482
return null;
483     }
484     
485     public void documentChanged(javax.swing.text.JTextComponent JavaDoc comp, String JavaDoc value) {
486         if (comp==servletNameTF) {
487             String JavaDoc val = (String JavaDoc)value;
488             if (val.length()==0) {
489                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Servlet Name",servletNameTF));
490                 return;
491             }
492             Servlet[] servlets = dObj.getWebApp().getServlet();
493             for (int i=0;i<servlets.length;i++) {
494                 if (servlet!=servlets[i] && val.equals(servlets[i].getServletName())) {
495                     getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.TYPE_FATAL, Error.DUPLICATE_VALUE_MESSAGE, val, servletNameTF));
496                     return;
497                 }
498             }
499             getSectionView().getErrorPanel().clearError();
500         } else if (comp==servletClassTF) {
501             String JavaDoc text = (String JavaDoc)value;
502             if (text.length()==0) {
503                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Servlet Class",servletClassTF));
504                 return;
505             }
506             getSectionView().getErrorPanel().clearError();
507         } else if (comp==jspFileTF) {
508             String JavaDoc text = (String JavaDoc)value;
509             if (text.length()==0) {
510                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.MISSING_VALUE_MESSAGE, "Jsp File",jspFileTF));
511                 return;
512             }
513             getSectionView().getErrorPanel().clearError();
514         } else if (comp==servletMappingsTF) {
515             String JavaDoc text = (String JavaDoc)value;
516             String JavaDoc[] patterns = DDUtils.getStringArray(text);
517             for (int i=0;i<patterns.length;i++) {
518                 String JavaDoc errorMessage = DDUtils.checkServletMappig(patterns[i]);
519                 if (errorMessage!=null) {
520                     getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.ERROR_MESSAGE, errorMessage, servletMappingsTF));
521                     return;
522                 }
523                 if (DDUtils.isServletMapping(dObj.getWebApp(),servlet,patterns[i])) {
524                     getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.DUPLICATE_VALUE_MESSAGE, patterns[i], servletMappingsTF));
525                     return;
526                 }
527             }
528             getSectionView().getErrorPanel().clearError();
529         } else if (comp==orderTF) {
530             String JavaDoc text = (String JavaDoc)value;
531             java.math.BigInteger JavaDoc los=null;
532             try {
533                 los = new java.math.BigInteger JavaDoc(text);
534             } catch (NumberFormatException JavaDoc ex) {}
535             if (los==null) {
536                 getSectionView().getErrorPanel().setError(new Error JavaDoc(Error.TYPE_FATAL, Error.ERROR_MESSAGE, "Invalid Value : "+text, orderTF));
537                 return;
538             }
539             getSectionView().getErrorPanel().clearError();
540         }
541     }
542     
543     public void setValue(javax.swing.JComponent JavaDoc source, Object JavaDoc value) {
544         if (source==servletNameTF) {
545             String JavaDoc text = (String JavaDoc)value;
546             // change servlet-mappings
547
ServletMapping[] maps = DDUtils.getServletMappings(dObj.getWebApp(), servlet);
548             for (int i=0;i<maps.length;i++) {
549                 maps[i].setServletName(text);
550             }
551             // change refering filter mappings
552
FilterMapping[] filterMappings = DDUtils.getFilterMappings(dObj.getWebApp(), servlet);
553             for (int i = 0; i < filterMappings.length; i++) {
554                 filterMappings[i].setServletName(text);
555             }
556             // change servlet-name
557
servlet.setServletName(text);
558             //change panel title, node name
559
SectionPanel enclosingPanel = getSectionView().findSectionPanel(servlet);
560             enclosingPanel.setTitle(((ServletsMultiViewElement.ServletsView)getSectionView()).getServletTitle(servlet));
561             enclosingPanel.getNode().setDisplayName(text);
562         } else if (source==servletClassTF) {
563             String JavaDoc text = (String JavaDoc)value;
564             servlet.setServletClass(text.length()==0?null:text);
565         } else if (source==jspFileTF) {
566             String JavaDoc text = (String JavaDoc)value;
567             servlet.setJspFile(text.length()==0?null:text);
568         } else if (source==descriptionTA) {
569             String JavaDoc text = (String JavaDoc)value;
570             servlet.setDescription(text.length()==0?null:text);
571         } else if (source==servletMappingsTF) {
572             DDUtils.setServletMappings(dObj.getWebApp(),servlet,DDUtils.getStringArray((String JavaDoc)value));
573             SectionPanel enclosingPanel = getSectionView().findSectionPanel(servlet);
574             enclosingPanel.setTitle(((ServletsMultiViewElement.ServletsView)getSectionView()).getServletTitle(servlet));
575         } else if (source==orderTF) {
576             String JavaDoc text = (String JavaDoc)value;
577             servlet.setLoadOnStartup(text.length()==0?null:new java.math.BigInteger JavaDoc(text));
578         } else if (source == runAsCB) {
579             String JavaDoc text = (String JavaDoc) runAsCB.getSelectedItem();
580             
581             if (text.length() == 0) {
582                 servlet.setRunAs(null);
583             } else {
584                 try {
585                     RunAs runAs = (RunAs) dObj.getWebApp().createBean("RunAs"); //NOI18N
586
runAs.setRoleName(text);
587                     servlet.setRunAs(runAs);
588                 } catch (ClassNotFoundException JavaDoc ex) {
589                     ex.printStackTrace();
590                 } //NOI18N
591

592             }
593         }
594     }
595     
596     public void rollbackValue(javax.swing.text.JTextComponent JavaDoc source) {
597         if (source==servletNameTF) {
598             servletNameTF.setText(servlet.getServletName());
599         } else if (source==servletClassTF) {
600             servletClassTF.setText(servlet.getServletClass());
601         } else if (source==jspFileTF) {
602             jspFileTF.setText(servlet.getJspFile());
603         } else if (source==servletMappingsTF) {
604             String JavaDoc[] urlPatterns = DDUtils.getUrlPatterns(dObj.getWebApp(),servlet);
605             servletMappingsTF.setText(DDUtils.urlPatternList(urlPatterns));
606         } else if (source==orderTF) {
607             java.math.BigInteger JavaDoc los = servlet.getLoadOnStartup();
608             orderTF.setText(los==null?"":los.toString());
609         }
610     }
611     
612     /** This will be called before model is changed from this panel
613      */

614     protected void startUIChange() {
615         dObj.setChangedFromUI(true);
616     }
617     
618     /** This will be called after model is changed from this panel
619      */

620     protected void endUIChange() {
621         dObj.modelUpdatedFromUI();
622         dObj.setChangedFromUI(false);
623     }
624     
625     
626 }
627
Popular Tags