KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > struts > ui > StrutsConfigurationPanelVisual


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.struts.ui;
21
22 import javax.swing.event.DocumentListener JavaDoc;
23 import javax.swing.text.JTextComponent JavaDoc;
24
25 import org.openide.WizardDescriptor;
26 import org.openide.WizardValidationException;
27 import org.openide.util.HelpCtx;
28 import org.openide.util.NbBundle;
29
30 public class StrutsConfigurationPanelVisual extends javax.swing.JPanel JavaDoc implements HelpCtx.Provider, DocumentListener JavaDoc {
31
32     private StrutsConfigurationPanel panel;
33
34     /** Creates new form StrutsConfigurationPanelVisual */
35     public StrutsConfigurationPanelVisual(StrutsConfigurationPanel panel, boolean customizer) {
36         this.panel = panel;
37         initComponents();
38         
39         jTextFieldAppResource.getDocument().addDocumentListener(this);
40         jCheckBoxWAR.setVisible(false);
41         if (customizer) {
42             jCheckBoxTLD.setVisible(false);
43             //jCheckBoxWAR.setVisible(false);
44
enableComponents(false);
45         }
46         else {
47             jCheckBoxTLD.setVisible(true);
48             //jCheckBoxWAR.setVisible(true);
49
enableComponents(true);
50         }
51         
52         ((JTextComponent JavaDoc)jComboBoxURLPattern.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
53     }
54     
55     /** This method is called from within the constructor to
56      * initialize the form.
57      * WARNING: Do NOT modify this code. The content of this method is
58      * always regenerated by the Form Editor.
59      */

60     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
61
private void initComponents() {
62         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
63
64         jLabelServletName = new javax.swing.JLabel JavaDoc();
65         jTextFieldServletName = new javax.swing.JTextField JavaDoc();
66         jLabelURLPattern = new javax.swing.JLabel JavaDoc();
67         jComboBoxURLPattern = new javax.swing.JComboBox JavaDoc();
68         jLabelAppResource = new javax.swing.JLabel JavaDoc();
69         jTextFieldAppResource = new javax.swing.JTextField JavaDoc();
70         jCheckBoxTLD = new javax.swing.JCheckBox JavaDoc();
71         jCheckBoxWAR = new javax.swing.JCheckBox JavaDoc();
72
73         setLayout(new java.awt.GridBagLayout JavaDoc());
74
75         jLabelServletName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_ActionServletName_Mnemonic").charAt(0));
76         jLabelServletName.setLabelFor(jTextFieldServletName);
77         jLabelServletName.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_ActionServletName"));
78         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
79         gridBagConstraints.gridx = 0;
80         gridBagConstraints.gridy = 0;
81         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
82         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 12);
83         add(jLabelServletName, gridBagConstraints);
84
85         jTextFieldServletName.setEditable(false);
86         jTextFieldServletName.setText("action");
87         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
88         gridBagConstraints.gridx = 1;
89         gridBagConstraints.gridy = 0;
90         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
91         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
92         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
93         add(jTextFieldServletName, gridBagConstraints);
94         jTextFieldServletName.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jTextFieldServletName"));
95
96         jLabelURLPattern.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_URLPattern_Mnemonic").charAt(0));
97         jLabelURLPattern.setLabelFor(jComboBoxURLPattern);
98         jLabelURLPattern.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_URLPattern"));
99         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
100         gridBagConstraints.gridx = 0;
101         gridBagConstraints.gridy = 1;
102         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
103         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 12);
104         add(jLabelURLPattern, gridBagConstraints);
105
106         jComboBoxURLPattern.setEditable(true);
107         jComboBoxURLPattern.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "*.do", "/do/*" }));
108         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
109         gridBagConstraints.gridx = 1;
110         gridBagConstraints.gridy = 1;
111         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
112         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
113         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
114         add(jComboBoxURLPattern, gridBagConstraints);
115         jComboBoxURLPattern.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jComboBoxURLPattern"));
116
117         jLabelAppResource.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_ApplicationResource_Mnemonic").charAt(0));
118         jLabelAppResource.setLabelFor(jTextFieldAppResource);
119         jLabelAppResource.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_ApplicationResource"));
120         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
121         gridBagConstraints.gridx = 0;
122         gridBagConstraints.gridy = 2;
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 12);
125         add(jLabelAppResource, gridBagConstraints);
126
127         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
128         gridBagConstraints.gridx = 1;
129         gridBagConstraints.gridy = 2;
130         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
131         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
132         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
133         gridBagConstraints.weightx = 1.0;
134         gridBagConstraints.weighty = 0.01;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
136         add(jTextFieldAppResource, gridBagConstraints);
137         jTextFieldAppResource.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jTextFieldAppResource"));
138
139         jCheckBoxTLD.setMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_InstallStrutsTLDs_Mnemonic").charAt(0));
140         jCheckBoxTLD.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_InstallStrutsTLDs"));
141         jCheckBoxTLD.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
142         jCheckBoxTLD.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridx = 0;
145         gridBagConstraints.gridy = 3;
146         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
148         gridBagConstraints.weighty = 1.0;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
150         add(jCheckBoxTLD, gridBagConstraints);
151         jCheckBoxTLD.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/ui/Bundle").getString("ACSD_jCheckBoxTLD"));
152
153         jCheckBoxWAR.setMnemonic(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MNE_ConfigPanel_PackageStrutsJars_Mnemonic").charAt(0));
154         jCheckBoxWAR.setSelected(true);
155         jCheckBoxWAR.setText(org.openide.util.NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "LBL_ConfigPanel_PackageStrutsJars"));
156         jCheckBoxWAR.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
157         jCheckBoxWAR.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
159         gridBagConstraints.gridx = 0;
160         gridBagConstraints.gridy = 4;
161         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
162         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
163         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
164         gridBagConstraints.weighty = 1.0;
165         add(jCheckBoxWAR, gridBagConstraints);
166
167     }// </editor-fold>//GEN-END:initComponents
168

169     
170     // Variables declaration - do not modify//GEN-BEGIN:variables
171
private javax.swing.JCheckBox JavaDoc jCheckBoxTLD;
172     private javax.swing.JCheckBox JavaDoc jCheckBoxWAR;
173     private javax.swing.JComboBox JavaDoc jComboBoxURLPattern;
174     private javax.swing.JLabel JavaDoc jLabelAppResource;
175     private javax.swing.JLabel JavaDoc jLabelServletName;
176     private javax.swing.JLabel JavaDoc jLabelURLPattern;
177     private javax.swing.JTextField JavaDoc jTextFieldAppResource;
178     private javax.swing.JTextField JavaDoc jTextFieldServletName;
179     // End of variables declaration//GEN-END:variables
180

181     boolean valid(WizardDescriptor wizardDescriptor) {
182         String JavaDoc urlPattern = (String JavaDoc)jComboBoxURLPattern.getEditor().getItem();
183         if (urlPattern == null || urlPattern.trim().equals("")){
184           wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
185
NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MSG_URLPatternIsEmpty"));
186           return false;
187         }
188         if (!isPatternValid(urlPattern)){
189           wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
190
NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MSG_URLPatternIsNotValid"));
191           return false;
192         }
193         if (getAppResource() == null || getAppResource().trim().length() == 0) {
194             wizardDescriptor.putProperty("WizardPanel_errorMessage", // NOI18N
195
NbBundle.getMessage(StrutsConfigurationPanelVisual.class, "MSG_ApplicationResourceNotValid"));
196             return false;
197         }
198         if (wizardDescriptor != null)
199             wizardDescriptor.putProperty("WizardPanel_errorMessage", null); // NOI18N
200
return true;
201     }
202
203     private boolean isPatternValid(String JavaDoc pattern){
204         if (pattern.startsWith("*.")){
205             String JavaDoc p = pattern.substring(2);
206             if (p.indexOf('.') == -1 && p.indexOf('*') == -1
207                     && p.indexOf('/') == -1 && !p.trim().equals(""))
208                 return true;
209         }
210         if (pattern.endsWith("/*") && pattern.startsWith("/"))
211             return true;
212         return false;
213     }
214     
215     void validate (WizardDescriptor d) throws WizardValidationException {
216 // projectLocationPanel.validate (d);
217
}
218     
219     void read (WizardDescriptor d) {
220 // projectLocationPanel.read(d);
221
// optionsPanel.read(d);
222
}
223
224     void store(WizardDescriptor d) {
225 // projectLocationPanel.store(d);
226
// optionsPanel.store(d);
227
}
228     
229     void enableComponents(boolean enable) {
230         jComboBoxURLPattern.setEnabled(enable);
231         jTextFieldAppResource.setEnabled(enable);
232         jTextFieldServletName.setEnabled(enable);
233         jCheckBoxTLD.setEnabled(enable);
234         jCheckBoxWAR.setEnabled(enable);
235         jLabelAppResource.setEnabled(enable);
236         jLabelServletName.setEnabled(enable);
237         jLabelURLPattern.setEnabled(enable);
238                 
239     }
240
241     public String JavaDoc getURLPattern(){
242         return (String JavaDoc)jComboBoxURLPattern.getSelectedItem();
243     }
244     
245     public void setURLPattern(String JavaDoc pattern){
246         jComboBoxURLPattern.setSelectedItem(pattern);
247     }
248     
249     public String JavaDoc getServletName(){
250         return jTextFieldServletName.getText();
251     }
252     
253     public void setServletName(String JavaDoc name){
254         jTextFieldServletName.setText(name);
255     }
256     
257     public String JavaDoc getAppResource(){
258         return jTextFieldAppResource.getText();
259     }
260     
261     public void setAppResource(String JavaDoc resource){
262         jTextFieldAppResource.setText(resource);
263     }
264     
265     public boolean addTLDs(){
266         return jCheckBoxTLD.isSelected();
267     }
268     
269     public boolean packageWars(){
270         return jCheckBoxWAR.isSelected();
271     }
272     /** Help context where to find more about the paste type action.
273      * @return the help context for this action
274      */

275     public HelpCtx getHelpCtx() {
276         return new HelpCtx(StrutsConfigurationPanelVisual.class);
277     }
278
279     public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
280         panel.fireChangeEvent();
281     }
282
283     public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
284         panel.fireChangeEvent();
285     }
286
287     public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
288         panel.fireChangeEvent();
289     }
290
291 }
292
Popular Tags