1 19 23 24 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards; 25 26 import org.openide.util.NbBundle; 27 import java.util.ResourceBundle ; 28 import java.util.ArrayList ; 29 import javax.swing.*; 30 import javax.swing.event.ChangeListener ; 31 32 import org.netbeans.modules.j2ee.sun.sunresources.beans.Field; 33 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup; 34 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants; 35 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper; 36 37 42 public class CommonGeneralFinishVisualPanel extends javax.swing.JPanel implements ChangeListener , WS70WizardConstants { 43 44 48 49 public static final String TYPE_EXTERNAL_RESOURCE = "_EXTERNAL"; public static final String TYPE_MAIL_RESOURCE = "_MAIL"; public static final String TYPE_CUSTOM_RESOURCE = "_CUSTOM"; public static final String TYPE_JDBC_RESOURCE = "_JDBC"; 54 protected ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.Bundle"); 56 protected final CommonGeneralFinishPanel panel; 57 protected FieldGroup[] groups; 58 protected int fieldSize; 59 protected ResourceConfigHelper helper; 60 protected String panelType = TYPE_MAIL_RESOURCE; 61 protected ArrayList beans = new ArrayList (); 62 protected boolean createNewResource = false; 63 64 protected javax.swing.JTextArea descriptionTextArea = null; 66 protected javax.swing.JPanel jPanel1[] = null; 67 protected javax.swing.JLabel jLabels[] = null; 68 protected javax.swing.JComponent jFields[] = null; 69 protected Field fields[] = null; 70 protected String resourceName; 71 protected boolean showGroupTitle = false; 72 73 private javax.swing.JPanel jPanel0; 75 private boolean firstTime = true; 76 private int y = 0; 77 private String [] dbVendors; 79 80 81 public CommonGeneralFinishVisualPanel(CommonGeneralFinishPanel panel, FieldGroup[] groups, String panelType) { 82 this.firstTime = true; 83 this.panel = panel; 84 this.helper = panel.getHelper(); 85 this.resourceName = panel.getResourceName(); 86 setFieldGroups(groups); 87 if (groups.length > 1) 88 this.showGroupTitle = true; 89 90 setLayout(new java.awt.GridBagLayout ()); 91 initDescriptionComponent(); 92 93 94 setPanelType(panelType); 95 initComponents(); 96 97 refreshFields(); 98 setName(NbBundle.getMessage(CommonGeneralFinishVisualPanel.class, "TITLE_" + groups[0].getName())); getAccessibleContext().setAccessibleName(bundle.getString("TITLE_" + groups[0].getName())); 101 String a11yDesc = null; 102 if(panelType==TYPE_CUSTOM_RESOURCE){ 103 a11yDesc = WS70WizardConstants.__CustomResource; 104 }else if(panelType==TYPE_MAIL_RESOURCE){ 105 a11yDesc = WS70WizardConstants.__MailResource; 106 }if(panelType==TYPE_EXTERNAL_RESOURCE){ 107 a11yDesc = WS70WizardConstants.__ExternalJndiResource; 108 }if(panelType==TYPE_JDBC_RESOURCE){ 109 a11yDesc = WS70WizardConstants.__JdbcResource; 110 } 111 getAccessibleContext().setAccessibleDescription(bundle.getString(a11yDesc+"_Description")); 112 this.firstTime = false; 113 } 114 115 public void setFieldGroups(FieldGroup[] groups) { 116 this.groups = groups; 117 fieldSize = 0; 118 for (int i = 0; i < groups.length; i++) { 119 fieldSize += groups[i].sizeField(); 120 } 121 } 122 123 128 private void initComponents() { 129 java.awt.GridBagConstraints gridBagConstraints; 130 131 int gap = 0; 132 int itemHeight = 28; 133 if (fieldSize < 6) { 134 itemHeight = 42; 135 gap = 7; 136 } 137 int i = 0; 138 jPanel1 = new JPanel[groups.length]; 139 fields = new Field[fieldSize]; 140 jLabels = new JLabel[fieldSize]; 141 jFields = new JComponent[fieldSize]; 142 143 for (int j = 0; j < groups.length; j++) { 144 if (showGroupTitle) { 145 JLabel label = new JLabel(); 146 label.setText(bundle.getString("LBL_GROUP_" + groups[j].getName())); label.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_LBL_GROUP_" + groups[j].getName() + "A11yDesc")); gridBagConstraints = new java.awt.GridBagConstraints (); 149 gridBagConstraints.gridx = 0; 150 gridBagConstraints.gridy = this.y; this.y++; 151 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 152 gridBagConstraints.ipadx = 0; 153 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 11); 154 add(label, gridBagConstraints); 155 } 156 157 Field[] flds = groups[j].getField(); 158 int size = flds.length; 159 jPanel1[j] = new javax.swing.JPanel (); 160 jPanel1[j].setLayout(new java.awt.GridBagLayout ()); 161 162 int panelWidth = (int)jPanel1[j].getMaximumSize().getWidth(); 164 jPanel1[j].setMaximumSize(new java.awt.Dimension (panelWidth, itemHeight * size)); 165 jPanel1[j].setMinimumSize(new java.awt.Dimension (panelWidth, itemHeight * size)); 166 jPanel1[j].setPreferredSize(new java.awt.Dimension (panelWidth, itemHeight * size)); 167 168 169 for (int k = 0; k < size; k++) { 170 fields[i] = flds[k]; 171 JLabel jLabel = new JLabel(); 172 jLabel.setText(bundle.getString("LBL_" + fields[i].getName())); jLabel.setDisplayedMnemonic(bundle.getString("LBL_" + fields[i].getName() + "_Mnemonic").charAt(0)); gridBagConstraints = new java.awt.GridBagConstraints (); 175 gridBagConstraints.gridx = 0; 176 gridBagConstraints.gridy = k; 177 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 178 gridBagConstraints.ipadx = 0; 179 gridBagConstraints.insets = new java.awt.Insets (2, 12, gap, 0); 180 jLabels[i] = jLabel; 181 jPanel1[j].add(jLabels[i], gridBagConstraints); 182 183 if (FieldHelper.isList(fields[i])) { 184 JComboBox jComboBox = new JComboBox(); 185 jLabel.setLabelFor(jComboBox); 186 jComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ToolTip_" + fields[i].getName())); 187 String tags[] = FieldHelper.getTags(fields[i]); 188 boolean isVendorField = false; 189 if(this.getPanelType()==this.TYPE_JDBC_RESOURCE&& fields[i].getName().equals(__DatabaseVendor)){ 190 Field vendorField = FieldHelper.getField(groups[0], __DatabaseVendor); 191 tags = FieldHelper.getTags(vendorField); 192 dbVendors = FieldHelper.getTags(vendorField); 193 isVendorField = true; 194 } 195 for (int h = 0; h < tags.length; h++) { 196 if(isVendorField){ 197 jComboBox.addItem(bundle.getString("DBVendor_" + tags[h])); }else{ 199 jComboBox.addItem(tags[h]); 200 } 201 } 202 final int index = i; 203 jComboBox.addActionListener(new java.awt.event.ActionListener () { 204 public void actionPerformed(java.awt.event.ActionEvent evt) { 205 jComboBoxActionPerformed(evt, index); 206 } 207 }); 208 gridBagConstraints = new java.awt.GridBagConstraints (); 209 gridBagConstraints.gridx = 1; 210 gridBagConstraints.gridy = k; 211 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 212 gridBagConstraints.insets = new java.awt.Insets (2, 20, gap, 0); 213 gridBagConstraints.weightx = 1.0; 214 jFields[i] = jComboBox; 215 jPanel1[j].add(jComboBox, gridBagConstraints); 216 } else { 217 JTextField jTextField = new JTextField(); 218 jTextField.setText("jTextField1"); jLabel.setLabelFor(jTextField); 220 jTextField.getAccessibleContext().setAccessibleDescription(bundle.getString("ToolTip_" + fields[i].getName())); 221 jTextField.setToolTipText(bundle.getString("ToolTip_" + fields[i].getName())); 223 final int index = i; 227 234 jTextField.addKeyListener(new java.awt.event.KeyAdapter () { 235 public void keyReleased(java.awt.event.KeyEvent evt) { 236 jTextField1KeyReleased(evt, index); 237 } 238 }); 239 gridBagConstraints = new java.awt.GridBagConstraints (); 240 gridBagConstraints.gridx = 1; 241 gridBagConstraints.gridy = k; 242 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 243 gridBagConstraints.insets = new java.awt.Insets (2, 20, gap, 0); 244 gridBagConstraints.weightx = 1.0; 245 jFields[i] = jTextField; 246 jPanel1[j].add(jTextField, gridBagConstraints); 247 } 248 i++; 249 } 250 251 gridBagConstraints = new java.awt.GridBagConstraints (); 252 gridBagConstraints.gridx = 0; 253 gridBagConstraints.gridy = this.y; this.y++; 254 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 255 gridBagConstraints.insets = new java.awt.Insets (5, 0, 10, 11); 256 jPanel1[j].setBorder(new javax.swing.border.EtchedBorder ()); 257 add(jPanel1[j], gridBagConstraints); 258 } 259 } 260 261 private void initDescriptionComponent() { 262 java.awt.GridBagConstraints gridBagConstraints; 263 264 descriptionTextArea = new javax.swing.JTextArea (); 265 descriptionTextArea.setEditable(false); 266 descriptionTextArea.setFont(javax.swing.UIManager.getFont("Label.font")); descriptionTextArea.setText(bundle.getString(this.resourceName + "_Description")); descriptionTextArea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground")); descriptionTextArea.setRequestFocusEnabled(false); 270 descriptionTextArea.setEnabled(false); 271 descriptionTextArea.setOpaque(false); 272 gridBagConstraints = new java.awt.GridBagConstraints (); 273 gridBagConstraints.gridx = 0; 274 gridBagConstraints.gridy = this.y; this.y++; 275 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 276 gridBagConstraints.weightx = 1.0; 277 gridBagConstraints.weighty = 0.0; 278 gridBagConstraints.insets = new java.awt.Insets (12, 12, 20, 11); 279 add(descriptionTextArea, gridBagConstraints); 280 } 281 282 283 284 protected String getPanelType() { 285 return panelType; 286 } 287 288 protected void setPanelType(String type) { 289 this.panelType = type; 290 } 291 292 293 public void stateChanged(final javax.swing.event.ChangeEvent p1) { 294 } 295 296 public boolean createNew() { 297 return createNewResource; 298 } 299 300 public void refreshFields() { 301 ResourceConfigData data = this.helper.getData(); 302 for (int i = 0; i < jFields.length; i++) { 303 String item; 304 if (FieldHelper.isList(fields[i])) { 305 item = (String )((JComboBox)jFields[i]).getSelectedItem(); 306 } else { 307 item = (String )((JTextField)jFields[i]).getText(); 308 } 309 String fieldName = fields[i].getName(); 310 Object value = data.get(fieldName); 311 if (value == null) { 312 value = FieldHelper.getDefaultValue(fields[i]); 313 data.set(fieldName, value); 314 } 315 String val = (String )value; 316 if (!item.equals(val)) { 317 if (FieldHelper.isList(fields[i])) { 318 ((JComboBox)jFields[i]).setSelectedItem(val); 319 } else { 320 ((JTextField)jFields[i]).setText(val); 321 } 322 } 323 } 324 } 325 326 private void jComboBoxActionPerformed(java.awt.event.ActionEvent evt, int index) { 327 ResourceConfigData data = this.helper.getData(); 328 String item = (String )((JComboBox)jFields[index]).getSelectedItem(); 329 int selectedIndex = ((JComboBox)jFields[index]).getSelectedIndex(); 330 String fieldName = fields[index].getName(); 331 332 if(this.getPanelType()==this.TYPE_JDBC_RESOURCE && fieldName.equals(__DatabaseVendor)){ 333 for(int i=0;i<fields.length;i++){ 334 String fname = fields[i].getName(); 335 if(fname.equals(WS70WizardConstants.__DatasourceClassname)){ 336 Field dsField = FieldHelper.getField(groups[0], __DatasourceClassname); 337 String classVal = FieldHelper.getConditionalFieldValue(dsField, dbVendors[selectedIndex]); 338 ((JTextField)jFields[i]).setText(classVal); 339 data.setString(fname, classVal); 340 } 341 } 342 }else{ 343 String val = data.getString(fieldName); 344 if (!item.equals(val)) 345 data.setString(fieldName, item); 346 } 347 } 348 349 private void jTextField1KeyReleased(java.awt.event.KeyEvent evt, int index) { 350 ResourceConfigData data = this.helper.getData(); 351 String item = (String )((JTextField)jFields[index]).getText(); 352 String fieldName = fields[index].getName(); 353 String val = data.getString(fieldName); 354 if (FieldHelper.isInt(fields[index])) { 355 try { 356 Integer.parseInt(item); 357 } catch (NumberFormatException ex) { 358 JOptionPane.showMessageDialog(this, bundle.getString("MSG_NotNumber")); if (val == null || val.length() == 0) 360 val = FieldHelper.getDefaultValue(fields[index]); 361 ((JTextField)jFields[index]).setText(val); 362 return; 363 } 364 } 365 String jLabel = (String )this.jLabels[index].getText(); 366 if (!item.equals(val) && jLabel.equals(bundle.getString("LBL_" + __JndiName)) ) { 368 item = item + data.getTargetFile(); 369 data.setString(fieldName, item); 370 } 371 if (!item.equals(val)){ 372 data.setString(fieldName, item); 373 } 375 panel.fireChangeEvent(); 376 } 377 378 public CommonGeneralFinishVisualPanel setFirstTime(boolean first) { 379 this.firstTime = first; 380 return this; 381 } 382 383 public void initData() { 384 refreshFields(); 385 } 386 387 public void setHelper(ResourceConfigHelper helper){ 388 this.helper = helper; 389 this.helper.getData().setString("jndi-name", helper.getData().getTargetFile()); refreshFields(); 391 } 392 } 393 | Popular Tags |