KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > wizards > JSFConfigurationPanelVisual


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.web.jsf.wizards;
21
22 import javax.swing.event.DocumentListener JavaDoc;
23 import org.openide.WizardDescriptor;
24 import org.openide.WizardValidationException;
25 import org.openide.util.HelpCtx;
26 import org.openide.util.NbBundle;
27
28 /**
29  *
30  * @author petr
31  */

32 public class JSFConfigurationPanelVisual extends javax.swing.JPanel JavaDoc implements HelpCtx.Provider, DocumentListener JavaDoc {
33
34     private JSFConfigurationPanel panel;
35     /** Creates new form JSFConfigurationPanelVisual */
36     public JSFConfigurationPanelVisual(JSFConfigurationPanel panel, boolean customizer) {
37         initComponents();
38         this.panel = panel;
39         tURLPattern.getDocument().addDocumentListener(this);
40         cbPackageJars.setVisible(false);
41         if (customizer){
42             enableComponents(false);
43         }
44     }
45     
46     /** This method is called from within the constructor to
47      * initialize the form.
48      * WARNING: Do NOT modify this code. The content of this method is
49      * always regenerated by the Form Editor.
50      */

51     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
52
private void initComponents() {
53         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
54
55         lServletName = new javax.swing.JLabel JavaDoc();
56         tServletName = new javax.swing.JTextField JavaDoc();
57         lURLPattern = new javax.swing.JLabel JavaDoc();
58         tURLPattern = new javax.swing.JTextField JavaDoc();
59         cbValidate = new javax.swing.JCheckBox JavaDoc();
60         cbVerify = new javax.swing.JCheckBox JavaDoc();
61         cbPackageJars = new javax.swing.JCheckBox JavaDoc();
62         jPanel1 = new javax.swing.JPanel JavaDoc();
63
64         setLayout(new java.awt.GridBagLayout JavaDoc());
65
66         lServletName.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_lServletName").charAt(0));
67         lServletName.setLabelFor(tServletName);
68         lServletName.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_Servlet_Name"));
69         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
70         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
71         add(lServletName, gridBagConstraints);
72
73         tServletName.setEditable(false);
74         tServletName.setText("Faces Servlet");
75         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
76         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
77         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
78         gridBagConstraints.weightx = 1.0;
79         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 0);
80         add(tServletName, gridBagConstraints);
81         tServletName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "ACSD_ServletName"));
82
83         lURLPattern.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_lURLPattern").charAt(0));
84         lURLPattern.setLabelFor(tURLPattern);
85         lURLPattern.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "LBL_URL_Pattern"));
86         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
87         gridBagConstraints.gridx = 0;
88         gridBagConstraints.gridy = 1;
89         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
90         add(lURLPattern, gridBagConstraints);
91
92         tURLPattern.setText("/faces/*");
93         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
94         gridBagConstraints.gridx = 1;
95         gridBagConstraints.gridy = 1;
96         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
97         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
98         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 0);
99         add(tURLPattern, gridBagConstraints);
100         tURLPattern.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "ACSD_Mapping"));
101
102         cbValidate.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_cbValidate").charAt(0));
103         cbValidate.setSelected(true);
104         cbValidate.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "CB_Validate_XML"));
105         cbValidate.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
106         cbValidate.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
107         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
108         gridBagConstraints.gridx = 0;
109         gridBagConstraints.gridy = 2;
110         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 5, 0);
112         add(cbValidate, gridBagConstraints);
113         cbValidate.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "ACSD_ValidateXML"));
114
115         cbVerify.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/wizards/Bundle").getString("MNE_cbVerify").charAt(0));
116         cbVerify.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "CB_Verify_Objects"));
117         cbVerify.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
118         cbVerify.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridx = 1;
121         gridBagConstraints.gridy = 2;
122         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
123         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 5, 5, 0);
124         add(cbVerify, gridBagConstraints);
125         cbVerify.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "ACSD_VerifyObjects"));
126
127         cbPackageJars.setSelected(true);
128         cbPackageJars.setText(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "CB_Package_JARs"));
129         cbPackageJars.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
130         cbPackageJars.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
131         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
132         gridBagConstraints.gridx = 0;
133         gridBagConstraints.gridy = 3;
134         gridBagConstraints.gridwidth = 2;
135         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
136         add(cbPackageJars, gridBagConstraints);
137         cbPackageJars.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JSFConfigurationPanelVisual.class, "ACSD_PackageJarToWar"));
138
139         jPanel1.setEnabled(false);
140         jPanel1.setFocusable(false);
141         jPanel1.setRequestFocusEnabled(false);
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 0;
144         gridBagConstraints.gridy = 4;
145         gridBagConstraints.gridwidth = 2;
146         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147         gridBagConstraints.weighty = 1.0;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
149         add(jPanel1, gridBagConstraints);
150
151     }// </editor-fold>//GEN-END:initComponents
152

153     
154     // Variables declaration - do not modify//GEN-BEGIN:variables
155
private javax.swing.JCheckBox JavaDoc cbPackageJars;
156     private javax.swing.JCheckBox JavaDoc cbValidate;
157     private javax.swing.JCheckBox JavaDoc cbVerify;
158     private javax.swing.JPanel JavaDoc jPanel1;
159     private javax.swing.JLabel JavaDoc lServletName;
160     private javax.swing.JLabel JavaDoc lURLPattern;
161     private javax.swing.JTextField JavaDoc tServletName;
162     private javax.swing.JTextField JavaDoc tURLPattern;
163     // End of variables declaration//GEN-END:variables
164

165     boolean valid(WizardDescriptor wizardDescriptor) {
166         String JavaDoc urlPattern = tURLPattern.getText();
167         if (urlPattern == null || urlPattern.trim().equals("")){
168           wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
169
NbBundle.getMessage(JSFConfigurationPanelVisual.class, "MSG_URLPatternIsEmpty"));
170           return false;
171         }
172         if (!isPatternValid(urlPattern)){
173           wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
174
NbBundle.getMessage(JSFConfigurationPanelVisual.class, "MSG_URLPatternIsNotValid"));
175           return false;
176         }
177         if(wizardDescriptor!=null)
178             wizardDescriptor.putProperty("WizardPanel_errorMessage", null); // NOI18N
179
return true;
180     }
181     
182     private boolean isPatternValid(String JavaDoc pattern){
183         if (pattern.startsWith("*.")){
184             String JavaDoc p = pattern.substring(2);
185             if (p.indexOf('.') == -1 && p.indexOf('*') == -1
186                     && p.indexOf('/') == -1 && !p.trim().equals(""))
187                 return true;
188         }
189         if (pattern.endsWith("/*") && pattern.startsWith("/"))
190             return true;
191         return false;
192     }
193     
194     void validate (WizardDescriptor d) throws WizardValidationException {
195 // projectLocationPanel.validate (d);
196
}
197     
198     void read (WizardDescriptor d) {
199 // projectLocationPanel.read(d);
200
// optionsPanel.read(d);
201
}
202
203     void store(WizardDescriptor d) {
204 // projectLocationPanel.store(d);
205
// optionsPanel.store(d);
206
}
207     
208     /** Help context where to find more about the paste type action.
209      * @return the help context for this action
210      */

211     public HelpCtx getHelpCtx() {
212         return new HelpCtx(JSFConfigurationPanelVisual.class);
213     }
214     
215     public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
216         panel.fireChangeEvent();
217     }
218
219     public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
220         panel.fireChangeEvent();
221     }
222
223     public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
224         panel.fireChangeEvent();
225     }
226
227     public String JavaDoc getServletName(){
228         return tServletName.getText();
229     }
230     
231     public void setServletName(String JavaDoc name){
232         tServletName.setText(name);
233     }
234     
235     public String JavaDoc getURLPattern(){
236         return tURLPattern.getText();
237     }
238     
239     public void setURLPattern(String JavaDoc pattern){
240         tURLPattern.setText(pattern);
241     }
242     
243     public boolean validateXML(){
244         return cbValidate.isSelected();
245     }
246     
247     public void setValidateXML(boolean ver){
248         cbValidate.setSelected(ver);
249     }
250     
251     public boolean verifyObjects(){
252         return cbVerify.isSelected();
253     }
254     
255     public void setVerifyObjects(boolean val){
256         cbVerify.setSelected(val);
257     }
258     
259     public boolean packageJars(){
260         return cbPackageJars.isSelected();
261     }
262     
263     public void enableComponents(boolean enable){
264         cbPackageJars.setEnabled(enable);
265         cbValidate.setEnabled(enable);
266         cbVerify.setEnabled(enable);
267         lServletName.setEnabled(enable);
268         lURLPattern.setEnabled(enable);
269         tServletName.setEnabled(enable);
270         tURLPattern.setEnabled(enable);
271     }
272 }
273
Popular Tags