KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
23 import java.util.Hashtable JavaDoc;
24 import javax.swing.SwingUtilities JavaDoc;
25 //import org.netbeans.modules.j2ee.common.FQNSearch;
26
import org.netbeans.modules.web.struts.StrutsConfigDataObject;
27 import org.netbeans.modules.web.struts.config.model.FormBean;
28 import org.openide.util.NbBundle;
29
30 /**
31  *
32  * @author Milan Kuchtiak
33  */

34 public class AddFormBeanPanel extends javax.swing.JPanel JavaDoc implements ValidatingPanel {
35
36     private StrutsConfigDataObject config;
37     private Hashtable JavaDoc beanNames;
38     /** Creates new form AddFormBeanPanel */
39     public AddFormBeanPanel(StrutsConfigDataObject config) {
40         initComponents();
41         this.config = config;
42         beanNames = null;
43     }
44
45     public String JavaDoc validatePanel() {
46         //config.getStrutsConfig().getFormBeans().sizeFormBean()
47
if (getFormName().length()==0)
48             return NbBundle.getMessage(AddFormBeanPanel.class,"MSG_EmptyFormName");
49         if (beanNames == null){
50             System.out.println("vytvarim cashe of jmen");
51             beanNames = new Hashtable JavaDoc();
52             try {
53                 FormBean[] beans = config.getStrutsConfig().getFormBeans().getFormBean();
54                 for (int i = 0; i < beans.length; i++){
55                     beanNames.put(beans[i].getAttributeValue("name"), "");
56                 }
57             } catch (IOException JavaDoc ex) {
58                 // don't cashe
59
}
60         }
61         if (beanNames.get(getFormName()) != null)
62             return NbBundle.getMessage(AddFormBeanPanel.class,"MSG_BeanNameDefined");
63         if (jRadioButton1.isSelected() && TFBeanClass.getText().trim().length()==0)
64             return NbBundle.getMessage(AddFormBeanPanel.class,"MSG_EmptyFormBeanClass");
65         return null;
66     }
67
68     public javax.swing.AbstractButton JavaDoc[] getStateChangeComponents() {
69         return new javax.swing.AbstractButton JavaDoc[]{ jRadioButton1 };
70     }
71
72     public javax.swing.text.JTextComponent JavaDoc[] getDocumentChangeComponents() {
73         return new javax.swing.text.JTextComponent JavaDoc[]{TFBeanClass, TFFormName};
74     }
75     
76     /** This method is called from within the constructor to
77      * initialize the form.
78      * WARNING: Do NOT modify this code. The content of this method is
79      * always regenerated by the Form Editor.
80      */

81     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
82
private void initComponents() {
83         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
84
85         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
86         jLabelFormName = new javax.swing.JLabel JavaDoc();
87         CBDynamic = new javax.swing.JComboBox JavaDoc();
88         TFBeanClass = new javax.swing.JTextField JavaDoc();
89         jButtonBrowse = new javax.swing.JButton JavaDoc();
90         TFFormName = new javax.swing.JTextField JavaDoc();
91         jRadioButton1 = new javax.swing.JRadioButton JavaDoc();
92         jRadioButton2 = new javax.swing.JRadioButton JavaDoc();
93
94         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
95         setLayout(new java.awt.GridBagLayout JavaDoc());
96
97         jLabelFormName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_FormName_mnem").charAt(0));
98         jLabelFormName.setLabelFor(TFFormName);
99         jLabelFormName.setText(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_FormName")); // NOI18N
100
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.gridx = 0;
102         gridBagConstraints.gridy = 0;
103         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
104         add(jLabelFormName, gridBagConstraints);
105
106         CBDynamic.setEditable(true);
107         CBDynamic.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "org.apache.struts.action.DynaActionForm", "org.apache.struts.validator.DynaValidatorForm", "org.apache.struts.validator.DynaValidatorActionForm" }));
108         CBDynamic.setEnabled(false);
109         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
110         gridBagConstraints.gridx = 1;
111         gridBagConstraints.gridy = 2;
112         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
113         gridBagConstraints.weightx = 1.0;
114         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
115         add(CBDynamic, gridBagConstraints);
116         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle"); // NOI18N
117
CBDynamic.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CVBDynamic")); // NOI18N
118

119         TFBeanClass.setColumns(30);
120         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
121         gridBagConstraints.gridx = 1;
122         gridBagConstraints.gridy = 1;
123         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124         gridBagConstraints.weightx = 1.0;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
126         add(TFBeanClass, gridBagConstraints);
127         TFBeanClass.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_TFBeanClass")); // NOI18N
128
TFBeanClass.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TFBeanClass")); // NOI18N
129

130         jButtonBrowse.setMnemonic(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_Browse_mnem").charAt(0));
131         jButtonBrowse.setText(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_BrowseButton")); // NOI18N
132
jButtonBrowse.setEnabled(false);
133         jButtonBrowse.addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
134             public void componentHidden(java.awt.event.ComponentEvent JavaDoc evt) {
135                 jButtonBrowseComponentHidden(evt);
136             }
137         });
138         jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
139             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
140                 jButtonBrowseActionPerformed(evt);
141             }
142         });
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridx = 2;
145         gridBagConstraints.gridy = 1;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 0);
147         add(jButtonBrowse, gridBagConstraints);
148         jButtonBrowse.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jButtonBrowseClass")); // NOI18N
149

150         TFFormName.setColumns(30);
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 1;
153         gridBagConstraints.gridy = 0;
154         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
155         gridBagConstraints.weightx = 1.0;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
157         add(TFFormName, gridBagConstraints);
158         TFFormName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TFFormName")); // NOI18N
159

160         buttonGroup1.add(jRadioButton1);
161         jRadioButton1.setMnemonic(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_FormBeanClass_mnem").charAt(0));
162         jRadioButton1.setSelected(true);
163         jRadioButton1.setText(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_FormBeanClass")); // NOI18N
164
jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
165         jRadioButton1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
166         jRadioButton1.addItemListener(new java.awt.event.ItemListener JavaDoc() {
167             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
168                 jRadioButton1ItemStateChanged(evt);
169             }
170         });
171         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
172         gridBagConstraints.gridx = 0;
173         gridBagConstraints.gridy = 1;
174         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
175         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
176         add(jRadioButton1, gridBagConstraints);
177         jRadioButton1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButton1")); // NOI18N
178

179         buttonGroup1.add(jRadioButton2);
180         jRadioButton2.setMnemonic(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_DYNAMIC_mnem").charAt(0));
181         jRadioButton2.setText(org.openide.util.NbBundle.getMessage(AddFormBeanPanel.class, "LBL_DYNAMIC")); // NOI18N
182
jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
183         jRadioButton2.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
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(5, 0, 0, 0);
189         add(jRadioButton2, gridBagConstraints);
190         jRadioButton2.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButton2")); // NOI18N
191

192         getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_AddFormBeanPanel")); // NOI18N
193
}// </editor-fold>//GEN-END:initComponents
194

195     private void jButtonBrowseComponentHidden(java.awt.event.ComponentEvent JavaDoc evt) {//GEN-FIRST:event_jButtonBrowseComponentHidden
196
}//GEN-LAST:event_jButtonBrowseComponentHidden
197

198     private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonBrowseActionPerformed
199
SwingUtilities.invokeLater(new Runnable JavaDoc() {
200             public void run() {
201 //TODO: RETOUCHE
202
// FQNSearch.showFastOpen(TFBeanClass);
203
}
204         });
205
206     }//GEN-LAST:event_jButtonBrowseActionPerformed
207

208     private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged
209
// TODO add your handling code here:
210
boolean selected = jRadioButton1.isSelected();
211         TFBeanClass.setEditable(selected);
212         CBDynamic.setEnabled(!selected);
213     }//GEN-LAST:event_jRadioButton1ItemStateChanged
214

215     
216     // Variables declaration - do not modify//GEN-BEGIN:variables
217
private javax.swing.JComboBox JavaDoc CBDynamic;
218     private javax.swing.JTextField JavaDoc TFBeanClass;
219     private javax.swing.JTextField JavaDoc TFFormName;
220     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
221     private javax.swing.JButton JavaDoc jButtonBrowse;
222     private javax.swing.JLabel JavaDoc jLabelFormName;
223     private javax.swing.JRadioButton JavaDoc jRadioButton1;
224     private javax.swing.JRadioButton JavaDoc jRadioButton2;
225     // End of variables declaration//GEN-END:variables
226

227     public String JavaDoc getFormBeanClass() {
228         return jRadioButton1.isSelected()?TFBeanClass.getText().trim():(String JavaDoc)CBDynamic.getSelectedItem();
229     }
230
231     public String JavaDoc getFormName() {
232         return (String JavaDoc)TFFormName.getText().trim();
233     }
234     
235 }
236
Popular Tags