1 19 20 package org.netbeans.modules.web.struts.dialogs; 21 22 import java.io.IOException ; 23 import java.util.Hashtable ; 24 import javax.swing.SwingUtilities ; 25 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 34 public class AddFormBeanPanel extends javax.swing.JPanel implements ValidatingPanel { 35 36 private StrutsConfigDataObject config; 37 private Hashtable beanNames; 38 39 public AddFormBeanPanel(StrutsConfigDataObject config) { 40 initComponents(); 41 this.config = config; 42 beanNames = null; 43 } 44 45 public String validatePanel() { 46 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 (); 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 ex) { 58 } 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 [] getStateChangeComponents() { 69 return new javax.swing.AbstractButton []{ jRadioButton1 }; 70 } 71 72 public javax.swing.text.JTextComponent [] getDocumentChangeComponents() { 73 return new javax.swing.text.JTextComponent []{TFBeanClass, TFFormName}; 74 } 75 76 81 private void initComponents() { 83 java.awt.GridBagConstraints gridBagConstraints; 84 85 buttonGroup1 = new javax.swing.ButtonGroup (); 86 jLabelFormName = new javax.swing.JLabel (); 87 CBDynamic = new javax.swing.JComboBox (); 88 TFBeanClass = new javax.swing.JTextField (); 89 jButtonBrowse = new javax.swing.JButton (); 90 TFFormName = new javax.swing.JTextField (); 91 jRadioButton1 = new javax.swing.JRadioButton (); 92 jRadioButton2 = new javax.swing.JRadioButton (); 93 94 setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11)); 95 setLayout(new java.awt.GridBagLayout ()); 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")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (new String [] { "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 (); 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 (5, 12, 0, 0); 115 add(CBDynamic, gridBagConstraints); 116 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle"); CBDynamic.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CVBDynamic")); 119 TFBeanClass.setColumns(30); 120 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (5, 12, 0, 0); 126 add(TFBeanClass, gridBagConstraints); 127 TFBeanClass.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_TFBeanClass")); TFBeanClass.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TFBeanClass")); 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")); jButtonBrowse.setEnabled(false); 133 jButtonBrowse.addComponentListener(new java.awt.event.ComponentAdapter () { 134 public void componentHidden(java.awt.event.ComponentEvent evt) { 135 jButtonBrowseComponentHidden(evt); 136 } 137 }); 138 jButtonBrowse.addActionListener(new java.awt.event.ActionListener () { 139 public void actionPerformed(java.awt.event.ActionEvent evt) { 140 jButtonBrowseActionPerformed(evt); 141 } 142 }); 143 gridBagConstraints = new java.awt.GridBagConstraints (); 144 gridBagConstraints.gridx = 2; 145 gridBagConstraints.gridy = 1; 146 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 147 add(jButtonBrowse, gridBagConstraints); 148 jButtonBrowse.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jButtonBrowseClass")); 150 TFFormName.setColumns(30); 151 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (0, 12, 0, 0); 157 add(TFFormName, gridBagConstraints); 158 TFFormName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TFFormName")); 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")); jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 165 jRadioButton1.setMargin(new java.awt.Insets (0, 0, 0, 0)); 166 jRadioButton1.addItemListener(new java.awt.event.ItemListener () { 167 public void itemStateChanged(java.awt.event.ItemEvent evt) { 168 jRadioButton1ItemStateChanged(evt); 169 } 170 }); 171 gridBagConstraints = new java.awt.GridBagConstraints (); 172 gridBagConstraints.gridx = 0; 173 gridBagConstraints.gridy = 1; 174 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 175 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 176 add(jRadioButton1, gridBagConstraints); 177 jRadioButton1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButton1")); 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")); jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 183 jRadioButton2.setMargin(new java.awt.Insets (0, 0, 0, 0)); 184 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 (5, 0, 0, 0); 189 add(jRadioButton2, gridBagConstraints); 190 jRadioButton2.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_jRadioButton2")); 192 getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_AddFormBeanPanel")); } 195 private void jButtonBrowseComponentHidden(java.awt.event.ComponentEvent evt) { } 198 private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent evt) { SwingUtilities.invokeLater(new Runnable () { 200 public void run() { 201 } 204 }); 205 206 } 208 private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent evt) { boolean selected = jRadioButton1.isSelected(); 211 TFBeanClass.setEditable(selected); 212 CBDynamic.setEnabled(!selected); 213 } 215 216 private javax.swing.JComboBox CBDynamic; 218 private javax.swing.JTextField TFBeanClass; 219 private javax.swing.JTextField TFFormName; 220 private javax.swing.ButtonGroup buttonGroup1; 221 private javax.swing.JButton jButtonBrowse; 222 private javax.swing.JLabel jLabelFormName; 223 private javax.swing.JRadioButton jRadioButton1; 224 private javax.swing.JRadioButton jRadioButton2; 225 227 public String getFormBeanClass() { 228 return jRadioButton1.isSelected()?TFBeanClass.getText().trim():(String )CBDynamic.getSelectedItem(); 229 } 230 231 public String getFormName() { 232 return (String )TFFormName.getText().trim(); 233 } 234 235 } 236 | Popular Tags |