KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > struts > dialogs > AddFormPropertyPanel


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.dialogs;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.AbstractButton JavaDoc;
25 import javax.swing.DefaultComboBoxModel JavaDoc;
26 import javax.swing.SwingUtilities JavaDoc;
27 import javax.swing.text.JTextComponent JavaDoc;
28 //import org.netbeans.modules.j2ee.common.FQNSearch;
29
import org.netbeans.modules.web.struts.StrutsConfigDataObject;
30 import org.netbeans.modules.web.struts.StrutsConfigUtilities;
31 import org.netbeans.modules.web.struts.config.model.FormBean;
32 import org.openide.util.NbBundle;
33
34 /**
35  *
36  * @author mkuchtiak
37  */

38 public class AddFormPropertyPanel extends javax.swing.JPanel JavaDoc implements ValidatingPanel {
39     StrutsConfigDataObject config;
40     /** Creates new form AddForwardDialog */
41     public AddFormPropertyPanel(StrutsConfigDataObject config, String JavaDoc targetFormName) {
42         this.config=config;
43         initComponents();
44         List JavaDoc beans = StrutsConfigUtilities.getAllFormBeansInModule(config);
45         DefaultComboBoxModel JavaDoc model = (DefaultComboBoxModel JavaDoc)jComboBoxFormName.getModel();
46         Iterator JavaDoc iter = beans.iterator();
47         while (iter.hasNext()) {
48             String JavaDoc name=((FormBean)iter.next()).getAttributeValue("name"); //NOI18N
49
model.addElement(name);
50         }
51         if (targetFormName != null) {
52             jComboBoxFormName.setSelectedItem(targetFormName);
53         }
54     }
55     
56     public AddFormPropertyPanel(StrutsConfigDataObject config) {
57         this(config,null);
58     }
59
60     public String JavaDoc validatePanel() {
61         if (getPropertyName()==null)
62             return NbBundle.getMessage(AddFormPropertyPanel.class,"MSG_EmptyPropertyName");
63         if (getFormName()==null)
64             return NbBundle.getMessage(AddFormPropertyPanel.class,"MSG_EmptyFormName");
65         if (getPropertyType()==null)
66             return NbBundle.getMessage(AddFormPropertyPanel.class,"MSG_EmptyPropertyType");
67         if (jRadioButtonArray.isSelected() && getArraySize()==null) {
68                 return NbBundle.getMessage(AddFormPropertyPanel.class,"MSG_IncorrectSize");
69         }
70         return null;
71     }
72
73     public AbstractButton JavaDoc[] getStateChangeComponents() {
74         return new AbstractButton JavaDoc[] {jRadioButtonSingle};
75     }
76
77     public JTextComponent JavaDoc[] getDocumentChangeComponents() {
78         return new JTextComponent JavaDoc[]{jTextFieldPropertyName, jTextFieldSize, (JTextComponent JavaDoc)jComboBoxPropertyType.getEditor().getEditorComponent()};
79     }
80     
81     /** This method is called from within the constructor to
82      * initialize the form.
83      * WARNING: Do NOT modify this code. The content of this method is
84      * always regenerated by the Form Editor.
85      */

86     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
87
private void initComponents() {
88         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
89
90         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
91         jLabelPropertyName = new javax.swing.JLabel JavaDoc();
92         jTextFieldPropertyName = new javax.swing.JTextField JavaDoc();
93         jRadioButtonSingle = new javax.swing.JRadioButton JavaDoc();
94         jTextFieldSize = new javax.swing.JTextField JavaDoc();
95         jComboBoxFormName = new javax.swing.JComboBox JavaDoc();
96         jLabelFormName = new javax.swing.JLabel JavaDoc();
97         jLabel2 = new javax.swing.JLabel JavaDoc();
98         jComboBoxPropertyType = new javax.swing.JComboBox JavaDoc();
99         jLabelInitValue = new javax.swing.JLabel JavaDoc();
100         jLabelSize = new javax.swing.JLabel JavaDoc();
101         jRadioButtonArray = new javax.swing.JRadioButton JavaDoc();
102         jTextFieldInitValue = new javax.swing.JTextField JavaDoc();
103         jPanel1 = new javax.swing.JPanel JavaDoc();
104         jButton1 = new javax.swing.JButton JavaDoc();
105
106         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
107         setLayout(new java.awt.GridBagLayout JavaDoc());
108
109         jLabelPropertyName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_PropertyName_mnem").charAt(0));
110         jLabelPropertyName.setLabelFor(jTextFieldPropertyName);
111         jLabelPropertyName.setText(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_PropertyName")); // NOI18N
112
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
113         gridBagConstraints.gridx = 0;
114         gridBagConstraints.gridy = 1;
115         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
116         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
117         add(jLabelPropertyName, gridBagConstraints);
118
119         jTextFieldPropertyName.setColumns(30);
120         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
121         gridBagConstraints.gridx = 1;
122         gridBagConstraints.gridy = 1;
123         gridBagConstraints.gridwidth = 3;
124         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
125         gridBagConstraints.weightx = 1.0;
126         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
127         add(jTextFieldPropertyName, gridBagConstraints);
128         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle"); // NOI18N
129
jTextFieldPropertyName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jTextFieldPropertyName")); // NOI18N
130

131         buttonGroup1.add(jRadioButtonSingle);
132         jRadioButtonSingle.setMnemonic(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_SingleType_mnem").charAt(0));
133         jRadioButtonSingle.setSelected(true);
134         jRadioButtonSingle.setText(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_SingleType")); // NOI18N
135
jRadioButtonSingle.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
136         jRadioButtonSingle.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
137         jRadioButtonSingle.addItemListener(new java.awt.event.ItemListener JavaDoc() {
138             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
139                 jRadioButtonSingleItemStateChanged(evt);
140             }
141         });
142         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
143         gridBagConstraints.gridx = 0;
144         gridBagConstraints.gridy = 3;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
147         add(jRadioButtonSingle, gridBagConstraints);
148         jRadioButtonSingle.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButtonSingle")); // NOI18N
149

150         jTextFieldSize.setColumns(5);
151         jTextFieldSize.setEditable(false);
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 1;
154         gridBagConstraints.gridy = 6;
155         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
157         gridBagConstraints.weightx = 1.0;
158         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
159         add(jTextFieldSize, gridBagConstraints);
160         jTextFieldSize.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jTextFieldSize")); // NOI18N
161

162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 1;
164         gridBagConstraints.gridy = 0;
165         gridBagConstraints.gridwidth = 3;
166         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
168         add(jComboBoxFormName, gridBagConstraints);
169         jComboBoxFormName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jComboBoxFormName")); // NOI18N
170

171         jLabelFormName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_FormName_mnem").charAt(0));
172         jLabelFormName.setLabelFor(jComboBoxFormName);
173         jLabelFormName.setText(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_FormName")); // NOI18N
174
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 0;
176         gridBagConstraints.gridy = 0;
177         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
178         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
179         add(jLabelFormName, gridBagConstraints);
180
181         jLabel2.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_PropertyType_mnem").charAt(0));
182         jLabel2.setLabelFor(jComboBoxPropertyType);
183         jLabel2.setText(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_PropertyType")); // NOI18N
184
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
185         gridBagConstraints.gridx = 0;
186         gridBagConstraints.gridy = 2;
187         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
188         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
189         add(jLabel2, gridBagConstraints);
190
191         jComboBoxPropertyType.setEditable(true);
192         jComboBoxPropertyType.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "java.lang.String", "int", "byte", "long", "float", "double", "boolean", "char", "java.lang.Integer", "java.lang.Byte", "java.lang.Long", "java.lang.Float", "java.lang.Double", "java.lang.Boolean", "java.lang.Char" }));
193         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
194         gridBagConstraints.gridx = 1;
195         gridBagConstraints.gridy = 2;
196         gridBagConstraints.gridwidth = 2;
197         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
198         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
199         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 0);
200         add(jComboBoxPropertyType, gridBagConstraints);
201         jComboBoxPropertyType.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jComboBoxPropertyType")); // NOI18N
202

203         jLabelInitValue.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_InitValue_mnem").charAt(0));
204         jLabelInitValue.setLabelFor(jTextFieldInitValue);
205         jLabelInitValue.setText(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_InitValue")); // NOI18N
206
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
207         gridBagConstraints.gridx = 0;
208         gridBagConstraints.gridy = 4;
209         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
210         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 20, 12, 0);
211         add(jLabelInitValue, gridBagConstraints);
212
213         jLabelSize.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_Size_mnem").charAt(0));
214         jLabelSize.setLabelFor(jTextFieldSize);
215         jLabelSize.setText(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_Size")); // NOI18N
216
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
217         gridBagConstraints.gridx = 0;
218         gridBagConstraints.gridy = 6;
219         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 20, 0, 0);
221         add(jLabelSize, gridBagConstraints);
222
223         buttonGroup1.add(jRadioButtonArray);
224         jRadioButtonArray.setMnemonic(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_ArrayType_mnem").charAt(0));
225         jRadioButtonArray.setText(org.openide.util.NbBundle.getMessage(AddFormPropertyPanel.class, "LBL_ArrayType")); // NOI18N
226
jRadioButtonArray.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
227         jRadioButtonArray.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
228         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
229         gridBagConstraints.gridx = 0;
230         gridBagConstraints.gridy = 5;
231         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
232         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
233         add(jRadioButtonArray, gridBagConstraints);
234         jRadioButtonArray.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButtonArray")); // NOI18N
235

236         jTextFieldInitValue.setColumns(30);
237         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
238         gridBagConstraints.gridx = 1;
239         gridBagConstraints.gridy = 4;
240         gridBagConstraints.gridwidth = 3;
241         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
242         gridBagConstraints.weightx = 1.0;
243         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 0);
244         add(jTextFieldInitValue, gridBagConstraints);
245         jTextFieldInitValue.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jTextFieldInitValue")); // NOI18N
246

247         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
248         gridBagConstraints.gridx = 2;
249         gridBagConstraints.gridy = 6;
250         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
251         gridBagConstraints.weightx = 2.0;
252         add(jPanel1, gridBagConstraints);
253
254         jButton1.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSM_BrowseClasses").charAt(0));
255         jButton1.setText(bundle.getString("B_BROWSE")); // NOI18N
256
jButton1.setEnabled(false);
257         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
258             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
259                 jButton1ActionPerformed(evt);
260             }
261         });
262         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
263         gridBagConstraints.gridx = 3;
264         gridBagConstraints.gridy = 2;
265         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
266         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 12, 0);
267         add(jButton1, gridBagConstraints);
268         jButton1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jbBrowseClass")); // NOI18N
269

270         getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_AddFormPropertyPanel")); // NOI18N
271
}// </editor-fold>//GEN-END:initComponents
272

273     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
274
SwingUtilities.invokeLater(new Runnable JavaDoc() {
275             public void run() {
276 //TODO: RETOUCHE
277
// FQNSearch.showFastOpen((JTextComponent)jComboBoxPropertyType.getEditor().getEditorComponent());
278
}
279         });
280
281     }//GEN-LAST:event_jButton1ActionPerformed
282

283     private void jRadioButtonSingleItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButtonSingleItemStateChanged
284
// TODO add your handling code here:
285
jTextFieldSize.setEditable(!jRadioButtonSingle.isSelected());
286     }//GEN-LAST:event_jRadioButtonSingleItemStateChanged
287

288     
289     // Variables declaration - do not modify//GEN-BEGIN:variables
290
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
291     private javax.swing.JButton JavaDoc jButton1;
292     private javax.swing.JComboBox JavaDoc jComboBoxFormName;
293     private javax.swing.JComboBox JavaDoc jComboBoxPropertyType;
294     private javax.swing.JLabel JavaDoc jLabel2;
295     private javax.swing.JLabel JavaDoc jLabelFormName;
296     private javax.swing.JLabel JavaDoc jLabelInitValue;
297     private javax.swing.JLabel JavaDoc jLabelPropertyName;
298     private javax.swing.JLabel JavaDoc jLabelSize;
299     private javax.swing.JPanel JavaDoc jPanel1;
300     private javax.swing.JRadioButton JavaDoc jRadioButtonArray;
301     private javax.swing.JRadioButton JavaDoc jRadioButtonSingle;
302     private javax.swing.JTextField JavaDoc jTextFieldInitValue;
303     private javax.swing.JTextField JavaDoc jTextFieldPropertyName;
304     private javax.swing.JTextField JavaDoc jTextFieldSize;
305     // End of variables declaration//GEN-END:variables
306

307     public String JavaDoc getFormName() {
308         return (String JavaDoc)jComboBoxFormName.getSelectedItem();
309     }
310     
311     public String JavaDoc getPropertyName() {
312         String JavaDoc name = jTextFieldPropertyName.getText().trim();
313         return name.length()==0?null:name;
314     }
315     
316     public String JavaDoc getPropertyType() {
317         javax.swing.text.Document JavaDoc doc = ((JTextComponent JavaDoc)jComboBoxPropertyType.getEditor().getEditorComponent()).getDocument();
318         try {
319             String JavaDoc propType = doc.getText(0,doc.getLength());
320             return propType==null?null:(isArray()?propType+"[]":propType); //NOi18N
321
} catch (javax.swing.text.BadLocationException JavaDoc ex) {
322             return null;
323         }
324     }
325     
326     public boolean isArray() {
327         return jRadioButtonArray.isSelected();
328     }
329     
330     public String JavaDoc getInitValue() {
331         return jTextFieldInitValue.getText().trim();
332     }
333      
334     public String JavaDoc getArraySize() {
335         String JavaDoc text = jTextFieldSize.getText().trim();
336         try {
337             Integer JavaDoc size = new Integer JavaDoc(text);
338             return text;
339         } catch (NumberFormatException JavaDoc ex) {
340             return null;
341         }
342     }
343 }
344
Popular Tags