1 19 20 package org.netbeans.modules.web.struts.dialogs; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 import javax.swing.AbstractButton ; 25 import javax.swing.DefaultComboBoxModel ; 26 import javax.swing.SwingUtilities ; 27 import javax.swing.text.JTextComponent ; 28 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 38 public class AddFormPropertyPanel extends javax.swing.JPanel implements ValidatingPanel { 39 StrutsConfigDataObject config; 40 41 public AddFormPropertyPanel(StrutsConfigDataObject config, String targetFormName) { 42 this.config=config; 43 initComponents(); 44 List beans = StrutsConfigUtilities.getAllFormBeansInModule(config); 45 DefaultComboBoxModel model = (DefaultComboBoxModel )jComboBoxFormName.getModel(); 46 Iterator iter = beans.iterator(); 47 while (iter.hasNext()) { 48 String name=((FormBean)iter.next()).getAttributeValue("name"); 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 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 [] getStateChangeComponents() { 74 return new AbstractButton [] {jRadioButtonSingle}; 75 } 76 77 public JTextComponent [] getDocumentChangeComponents() { 78 return new JTextComponent []{jTextFieldPropertyName, jTextFieldSize, (JTextComponent )jComboBoxPropertyType.getEditor().getEditorComponent()}; 79 } 80 81 86 private void initComponents() { 88 java.awt.GridBagConstraints gridBagConstraints; 89 90 buttonGroup1 = new javax.swing.ButtonGroup (); 91 jLabelPropertyName = new javax.swing.JLabel (); 92 jTextFieldPropertyName = new javax.swing.JTextField (); 93 jRadioButtonSingle = new javax.swing.JRadioButton (); 94 jTextFieldSize = new javax.swing.JTextField (); 95 jComboBoxFormName = new javax.swing.JComboBox (); 96 jLabelFormName = new javax.swing.JLabel (); 97 jLabel2 = new javax.swing.JLabel (); 98 jComboBoxPropertyType = new javax.swing.JComboBox (); 99 jLabelInitValue = new javax.swing.JLabel (); 100 jLabelSize = new javax.swing.JLabel (); 101 jRadioButtonArray = new javax.swing.JRadioButton (); 102 jTextFieldInitValue = new javax.swing.JTextField (); 103 jPanel1 = new javax.swing.JPanel (); 104 jButton1 = new javax.swing.JButton (); 105 106 setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11)); 107 setLayout(new java.awt.GridBagLayout ()); 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")); gridBagConstraints = new java.awt.GridBagConstraints (); 113 gridBagConstraints.gridx = 0; 114 gridBagConstraints.gridy = 1; 115 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 116 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 117 add(jLabelPropertyName, gridBagConstraints); 118 119 jTextFieldPropertyName.setColumns(30); 120 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 12, 5, 0); 127 add(jTextFieldPropertyName, gridBagConstraints); 128 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle"); jTextFieldPropertyName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jTextFieldPropertyName")); 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")); jRadioButtonSingle.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 136 jRadioButtonSingle.setMargin(new java.awt.Insets (0, 0, 0, 0)); 137 jRadioButtonSingle.addItemListener(new java.awt.event.ItemListener () { 138 public void itemStateChanged(java.awt.event.ItemEvent evt) { 139 jRadioButtonSingleItemStateChanged(evt); 140 } 141 }); 142 gridBagConstraints = new java.awt.GridBagConstraints (); 143 gridBagConstraints.gridx = 0; 144 gridBagConstraints.gridy = 3; 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 146 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 147 add(jRadioButtonSingle, gridBagConstraints); 148 jRadioButtonSingle.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButtonSingle")); 150 jTextFieldSize.setColumns(5); 151 jTextFieldSize.setEditable(false); 152 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 12, 5, 0); 159 add(jTextFieldSize, gridBagConstraints); 160 jTextFieldSize.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jTextFieldSize")); 162 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 12, 5, 0); 168 add(jComboBoxFormName, gridBagConstraints); 169 jComboBoxFormName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jComboBoxFormName")); 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")); gridBagConstraints = new java.awt.GridBagConstraints (); 175 gridBagConstraints.gridx = 0; 176 gridBagConstraints.gridy = 0; 177 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 178 gridBagConstraints.insets = new java.awt.Insets (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")); gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridx = 0; 186 gridBagConstraints.gridy = 2; 187 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 188 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 189 add(jLabel2, gridBagConstraints); 190 191 jComboBoxPropertyType.setEditable(true); 192 jComboBoxPropertyType.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "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 (); 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 (0, 12, 12, 0); 200 add(jComboBoxPropertyType, gridBagConstraints); 201 jComboBoxPropertyType.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jComboBoxPropertyType")); 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")); gridBagConstraints = new java.awt.GridBagConstraints (); 207 gridBagConstraints.gridx = 0; 208 gridBagConstraints.gridy = 4; 209 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 210 gridBagConstraints.insets = new java.awt.Insets (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")); gridBagConstraints = new java.awt.GridBagConstraints (); 217 gridBagConstraints.gridx = 0; 218 gridBagConstraints.gridy = 6; 219 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 220 gridBagConstraints.insets = new java.awt.Insets (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")); jRadioButtonArray.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 227 jRadioButtonArray.setMargin(new java.awt.Insets (0, 0, 0, 0)); 228 gridBagConstraints = new java.awt.GridBagConstraints (); 229 gridBagConstraints.gridx = 0; 230 gridBagConstraints.gridy = 5; 231 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 232 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 233 add(jRadioButtonArray, gridBagConstraints); 234 jRadioButtonArray.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButtonArray")); 236 jTextFieldInitValue.setColumns(30); 237 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 12, 12, 0); 244 add(jTextFieldInitValue, gridBagConstraints); 245 jTextFieldInitValue.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jTextFieldInitValue")); 247 gridBagConstraints = new java.awt.GridBagConstraints (); 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")); jButton1.setEnabled(false); 257 jButton1.addActionListener(new java.awt.event.ActionListener () { 258 public void actionPerformed(java.awt.event.ActionEvent evt) { 259 jButton1ActionPerformed(evt); 260 } 261 }); 262 gridBagConstraints = new java.awt.GridBagConstraints (); 263 gridBagConstraints.gridx = 3; 264 gridBagConstraints.gridy = 2; 265 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; 266 gridBagConstraints.insets = new java.awt.Insets (0, 6, 12, 0); 267 add(jButton1, gridBagConstraints); 268 jButton1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jbBrowseClass")); 270 getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_AddFormPropertyPanel")); } 273 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { SwingUtilities.invokeLater(new Runnable () { 275 public void run() { 276 } 279 }); 280 281 } 283 private void jRadioButtonSingleItemStateChanged(java.awt.event.ItemEvent evt) { jTextFieldSize.setEditable(!jRadioButtonSingle.isSelected()); 286 } 288 289 private javax.swing.ButtonGroup buttonGroup1; 291 private javax.swing.JButton jButton1; 292 private javax.swing.JComboBox jComboBoxFormName; 293 private javax.swing.JComboBox jComboBoxPropertyType; 294 private javax.swing.JLabel jLabel2; 295 private javax.swing.JLabel jLabelFormName; 296 private javax.swing.JLabel jLabelInitValue; 297 private javax.swing.JLabel jLabelPropertyName; 298 private javax.swing.JLabel jLabelSize; 299 private javax.swing.JPanel jPanel1; 300 private javax.swing.JRadioButton jRadioButtonArray; 301 private javax.swing.JRadioButton jRadioButtonSingle; 302 private javax.swing.JTextField jTextFieldInitValue; 303 private javax.swing.JTextField jTextFieldPropertyName; 304 private javax.swing.JTextField jTextFieldSize; 305 307 public String getFormName() { 308 return (String )jComboBoxFormName.getSelectedItem(); 309 } 310 311 public String getPropertyName() { 312 String name = jTextFieldPropertyName.getText().trim(); 313 return name.length()==0?null:name; 314 } 315 316 public String getPropertyType() { 317 javax.swing.text.Document doc = ((JTextComponent )jComboBoxPropertyType.getEditor().getEditorComponent()).getDocument(); 318 try { 319 String propType = doc.getText(0,doc.getLength()); 320 return propType==null?null:(isArray()?propType+"[]":propType); } catch (javax.swing.text.BadLocationException ex) { 322 return null; 323 } 324 } 325 326 public boolean isArray() { 327 return jRadioButtonArray.isSelected(); 328 } 329 330 public String getInitValue() { 331 return jTextFieldInitValue.getText().trim(); 332 } 333 334 public String getArraySize() { 335 String text = jTextFieldSize.getText().trim(); 336 try { 337 Integer size = new Integer (text); 338 return text; 339 } catch (NumberFormatException ex) { 340 return null; 341 } 342 } 343 } 344 | Popular Tags |