1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards; 26 27 import org.openide.util.NbBundle; 28 import javax.swing.table.TableColumn ; 29 import javax.swing.event.ChangeEvent ; 30 import javax.swing.event.TableModelListener ; 31 import javax.swing.ListSelectionModel ; 32 import java.util.ResourceBundle ; 33 34 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair; 35 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup; 36 import org.netbeans.modules.j2ee.sun.sunresources.beans.Field; 37 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard; 38 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants; 39 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroupHelper; 40 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper; 41 42 46 public class CPPropertiesPanelVisualPanel extends javax.swing.JPanel implements WizardConstants, TableModelListener { 47 48 52 private final CPPropertiesPanelPanel panel; 53 private ResourceConfigHelper helper; 54 private FieldGroup generalGroup, propertiesGroup; 55 private Field dsField, typeField; 56 57 58 public CPPropertiesPanelVisualPanel(CPPropertiesPanelPanel panel, ResourceConfigHelper helper, Wizard wizardInfo) { 59 this.panel = panel; 60 this.helper = helper; 61 this.tableModel = new PropertiesTableModel(this.helper.getData()); 62 63 initComponents(); 64 setName(NbBundle.getMessage(CPPropertiesPanelVisualPanel.class, "TITLE_ConnPoolWizardPanel_properties")); 67 this.generalGroup = FieldGroupHelper.getFieldGroup(wizardInfo, __General); 68 this.propertiesGroup = FieldGroupHelper.getFieldGroup(wizardInfo, __Properties); 69 this.dsField = FieldHelper.getField(generalGroup, __DatasourceClassname); 70 71 setPropTableCellEditor(); 72 this.tableModel.addTableModelListener(this); 73 this.jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 74 75 String dsClassName = this.helper.getData().getString(__DatasourceClassname); 76 if (dsClassName.length() == 0) 77 dsClassName = FieldHelper.getDefaultValue(dsField); 78 classNameField.setText(dsClassName); 79 80 this.typeField = FieldHelper.getField(generalGroup, __ResType); 81 String resType = this.helper.getData().getString(__ResType); 82 if (resType.length() == 0) 83 resType = FieldHelper.getDefaultValue(typeField); 84 resTypeField.setText(resType); 85 } 86 87 92 private void initComponents() { 94 java.awt.GridBagConstraints gridBagConstraints; 95 96 jPanel1 = new javax.swing.JPanel (); 97 classNameField = new javax.swing.JTextField (); 98 classNameLabel = new javax.swing.JLabel (); 99 resTypeLabel = new javax.swing.JLabel (); 100 resTypeField = new javax.swing.JTextField (); 101 descField = new javax.swing.JTextField (); 102 descLabel = new javax.swing.JLabel (); 103 jScrollPane1 = new javax.swing.JScrollPane (); 104 jTable1 = new javax.swing.JTable (); 105 tableButtonsPane = new javax.swing.JPanel (); 106 addButton = new javax.swing.JButton (); 107 removeButton = new javax.swing.JButton (); 108 descriptionTextArea = new javax.swing.JTextArea (); 109 jLabel1 = new javax.swing.JLabel (); 110 111 setLayout(new java.awt.GridBagLayout ()); 112 113 getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("TITLE_ConnPoolWizardPanel_properties")); 114 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("CPPropertyPanel_Description")); 115 jPanel1.setLayout(new java.awt.GridBagLayout ()); 116 117 classNameField.setText(this.helper.getData().getString(__DatasourceClassname)); 118 classNameField.addActionListener(new java.awt.event.ActionListener () { 119 public void actionPerformed(java.awt.event.ActionEvent evt) { 120 classNameFieldActionPerformed(evt); 121 } 122 }); 123 classNameField.addKeyListener(new java.awt.event.KeyAdapter () { 124 public void keyReleased(java.awt.event.KeyEvent evt) { 125 classNameFieldKeyReleased(evt); 126 } 127 }); 128 129 gridBagConstraints = new java.awt.GridBagConstraints (); 130 gridBagConstraints.gridx = 1; 131 gridBagConstraints.gridy = 0; 132 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 133 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 134 jPanel1.add(classNameField, gridBagConstraints); 135 classNameField.getAccessibleContext().setAccessibleName(this.helper.getData().getString(__DatasourceClassname)); 136 classNameField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_datasource-classnamefieldA11yDesc")); 137 138 classNameLabel.setDisplayedMnemonic(bundle.getString("LBL_datasource-classname_Mnemonic").charAt(0)); 139 classNameLabel.setLabelFor(classNameField); 140 classNameLabel.setText(bundle.getString("LBL_datasource-classname")); 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.gridx = 0; 143 gridBagConstraints.gridy = 0; 144 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 145 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 146 jPanel1.add(classNameLabel, gridBagConstraints); 147 classNameLabel.getAccessibleContext().setAccessibleDescription(bundle.getString("ToolTip_datasource-classname")); 148 149 resTypeLabel.setDisplayedMnemonic(bundle.getString("LBL_res-type_Mnemonic").charAt(0)); 150 resTypeLabel.setLabelFor(resTypeField); 151 resTypeLabel.setText(bundle.getString("LBL_res-type")); 152 gridBagConstraints = new java.awt.GridBagConstraints (); 153 gridBagConstraints.gridx = 0; 154 gridBagConstraints.gridy = 1; 155 gridBagConstraints.ipadx = 43; 156 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 157 jPanel1.add(resTypeLabel, gridBagConstraints); 158 resTypeLabel.getAccessibleContext().setAccessibleName(bundle.getString("LBL_res-type")); 159 resTypeLabel.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_res-typefieldA11yDesc")); 160 161 resTypeField.setEditable(false); 162 resTypeField.setText("jTextField2"); 163 resTypeField.setFocusable(false); 164 gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.gridx = 1; 166 gridBagConstraints.gridy = 1; 167 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 168 gridBagConstraints.weightx = 1.0; 169 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 170 jPanel1.add(resTypeField, gridBagConstraints); 171 resTypeField.getAccessibleContext().setAccessibleName(bundle.getString("LBL_res-type")); 172 resTypeField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_res-typefieldA11yDesc")); 173 174 descField.addActionListener(new java.awt.event.ActionListener () { 175 public void actionPerformed(java.awt.event.ActionEvent evt) { 176 descFieldActionPerformed(evt); 177 } 178 }); 179 descField.addKeyListener(new java.awt.event.KeyAdapter () { 180 public void keyReleased(java.awt.event.KeyEvent evt) { 181 descFieldKeyReleased(evt); 182 } 183 }); 184 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridx = 1; 187 gridBagConstraints.gridy = 2; 188 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 189 gridBagConstraints.weightx = 1.0; 190 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 191 jPanel1.add(descField, gridBagConstraints); 192 193 descLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_description_Mnemonic").charAt(0)); 194 descLabel.setLabelFor(descField); 195 descLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_description")); 196 gridBagConstraints = new java.awt.GridBagConstraints (); 197 gridBagConstraints.gridx = 0; 198 gridBagConstraints.gridy = 2; 199 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 200 gridBagConstraints.ipadx = 49; 201 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 202 jPanel1.add(descLabel, gridBagConstraints); 203 descLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_description")); 204 descLabel.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ToolTip_description")); 205 206 gridBagConstraints = new java.awt.GridBagConstraints (); 207 gridBagConstraints.gridx = 0; 208 gridBagConstraints.gridy = 1; 209 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 210 gridBagConstraints.weightx = 1.0; 211 gridBagConstraints.weighty = 1.0; 212 add(jPanel1, gridBagConstraints); 213 jPanel1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("TITLE_ConnPoolWizardPanel_properties")); 214 jPanel1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("CPPropertyPanel_Description")); 215 216 jScrollPane1.setPreferredSize(new java.awt.Dimension (453, 17)); 217 jTable1.setModel(tableModel); 218 jScrollPane1.setViewportView(jTable1); 219 jTable1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 220 jTable1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 221 222 gridBagConstraints = new java.awt.GridBagConstraints (); 223 gridBagConstraints.gridx = 0; 224 gridBagConstraints.gridy = 3; 225 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 226 gridBagConstraints.insets = new java.awt.Insets (10, 12, 10, 11); 227 add(jScrollPane1, gridBagConstraints); 228 jScrollPane1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 229 jScrollPane1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 230 231 tableButtonsPane.setLayout(new java.awt.GridBagLayout ()); 232 233 addButton.setMnemonic(bundle.getString("LBL_Add_Mnemonic").charAt(0)); 234 addButton.setText(bundle.getString("LBL_Add")); 235 addButton.addActionListener(new java.awt.event.ActionListener () { 236 public void actionPerformed(java.awt.event.ActionEvent evt) { 237 addButtonActionPerformed(evt); 238 } 239 }); 240 241 gridBagConstraints = new java.awt.GridBagConstraints (); 242 gridBagConstraints.gridx = 0; 243 gridBagConstraints.gridy = 0; 244 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 245 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 246 tableButtonsPane.add(addButton, gridBagConstraints); 247 addButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_AddButtonA11yDesc")); 248 249 removeButton.setMnemonic(bundle.getString("LBL_Remove_Mnemonic").charAt(0)); 250 removeButton.setText(bundle.getString("LBL_Remove")); 251 removeButton.addActionListener(new java.awt.event.ActionListener () { 252 public void actionPerformed(java.awt.event.ActionEvent evt) { 253 removeButtonActionPerformed(evt); 254 } 255 }); 256 257 gridBagConstraints = new java.awt.GridBagConstraints (); 258 gridBagConstraints.gridx = 0; 259 gridBagConstraints.gridy = 1; 260 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 261 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 262 tableButtonsPane.add(removeButton, gridBagConstraints); 263 removeButton.getAccessibleContext().setAccessibleName(bundle.getString("LBL_Remove")); 264 removeButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_RemoveButtonA11yDesc")); 265 266 gridBagConstraints = new java.awt.GridBagConstraints (); 267 gridBagConstraints.gridx = 1; 268 gridBagConstraints.gridy = 2; 269 gridBagConstraints.gridheight = 2; 270 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 271 gridBagConstraints.ipady = 100; 272 add(tableButtonsPane, gridBagConstraints); 273 tableButtonsPane.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 274 tableButtonsPane.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 275 276 descriptionTextArea.setEditable(false); 277 descriptionTextArea.setText(bundle.getString("CPPropertyPanel_Description")); 278 descriptionTextArea.setOpaque(false); 279 gridBagConstraints = new java.awt.GridBagConstraints (); 280 gridBagConstraints.gridx = 0; 281 gridBagConstraints.gridy = 0; 282 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 283 gridBagConstraints.weightx = 1.0; 284 gridBagConstraints.weighty = 1.0; 285 gridBagConstraints.insets = new java.awt.Insets (0, 0, 1, 0); 286 add(descriptionTextArea, gridBagConstraints); 287 descriptionTextArea.getAccessibleContext().setAccessibleName(bundle.getString("CPPropertyPanel_Description")); 288 descriptionTextArea.getAccessibleContext().setAccessibleDescription(bundle.getString("CPPropertyPanel_Description")); 289 290 jLabel1.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties_Mnemonic").charAt(0)); 291 jLabel1.setLabelFor(jTable1); 292 jLabel1.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 293 gridBagConstraints = new java.awt.GridBagConstraints (); 294 gridBagConstraints.gridx = 0; 295 gridBagConstraints.gridy = 2; 296 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 297 add(jLabel1, gridBagConstraints); 298 299 } 300 302 private void classNameFieldKeyReleased(java.awt.event.KeyEvent evt) { ResourceConfigData data = this.helper.getData(); 305 String value = data.getString(__DatasourceClassname); 306 String newValue = classNameField.getText(); 307 if (!value.equals(newValue)) { 308 this.helper.getData().setString(__DatasourceClassname, newValue); 309 } 311 this.panel.fireChangeEvent(this); 312 } 314 private void descFieldKeyReleased(java.awt.event.KeyEvent evt) { ResourceConfigData data = this.helper.getData(); 317 String value = data.getString(__Description); 318 String newValue = descField.getText(); 319 if (!value.equals(newValue)) { 320 this.helper.getData().setString(__Description, newValue); 321 } 323 this.panel.fireChangeEvent(this); 324 } 326 private void descFieldActionPerformed(java.awt.event.ActionEvent evt) { ResourceConfigData data = this.helper.getData(); 329 String item = descField.getText(); 330 Object value = data.get(__Description); 331 if (!item.equals((String )value)){ 332 data.setString(__Description, item); 333 } 334 335 this.panel.fireChangeEvent(this); 336 if((this.getRootPane().getDefaultButton() != null) && (this.getRootPane().getDefaultButton().isEnabled())){ 337 this.getRootPane().getDefaultButton().doClick(); 338 } 339 } 341 private void classNameFieldActionPerformed(java.awt.event.ActionEvent evt) { ResourceConfigData data = this.helper.getData(); 344 String item = classNameField.getText(); 345 Object value = data.get(__DatasourceClassname); 346 if (value == null) 347 value = FieldHelper.getDefaultValue(dsField); 348 if (!item.equals((String )value)) 349 data.setString(__DatasourceClassname, item); 350 351 this.panel.fireChangeEvent(this); 352 if((this.getRootPane().getDefaultButton() != null) && (this.getRootPane().getDefaultButton().isEnabled())){ 353 this.getRootPane().getDefaultButton().doClick(); 354 } 355 } 357 private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { int selectedRow = jTable1.getSelectedRow(); 360 if (selectedRow != -1) { 361 jTable1.editingStopped(new ChangeEvent (this)); 363 this.helper.getData().removeProperty(selectedRow); 364 tableModel.fireTableDataChanged(); 365 } 366 } 368 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { jTable1.editingStopped(new ChangeEvent (this)); 372 ResourceConfigData data = this.helper.getData(); 373 data.addProperty(new NameValuePair()); 374 tableModel.fireTableDataChanged(); 375 } 377 public void tableChanged(javax.swing.event.TableModelEvent e) { 378 setPropTableCellEditor(); 379 this.panel.fireChangeEvent(this); 380 } 381 382 public void setPropTableCellEditor() { 383 javax.swing.JComboBox propNameComboBox = new javax.swing.JComboBox (); 384 String [] remainingProperties = FieldHelper.getRemainingFieldNames(propertiesGroup, this.helper.getData().getPropertyNames()); 385 for (int i = 0; i < remainingProperties.length; i++) 386 propNameComboBox.addItem(remainingProperties[i]); 387 388 this.nameColumn = jTable1.getColumnModel().getColumn(0); 389 propNameComboBox.setEditable(true); 390 this.nameColumn.setCellEditor(new javax.swing.DefaultCellEditor (propNameComboBox)); 391 this.valueColumn = jTable1.getColumnModel().getColumn(1); 392 393 javax.swing.DefaultCellEditor editor = new javax.swing.DefaultCellEditor (new javax.swing.JTextField ()); 394 editor.setClickCountToStart(1); 395 this.valueColumn.setCellEditor(editor); 396 } 397 398 public void refreshFields() { 399 ResourceConfigData data = this.helper.getData(); 400 String item = classNameField.getText(); 401 String val = data.getString(__DatasourceClassname); 402 if (!item.equals(val)) 403 classNameField.setText(val); 404 405 item = resTypeField.getText(); 406 val = data.getString(__ResType); 407 if (!item.equals(val)) 408 resTypeField.setText(val); 409 ((PropertiesTableModel)jTable1.getModel()).setData(this.helper.getData()); 410 } 411 412 public void setInitialFocus(){ 413 new setFocus(classNameField); 414 } 415 private javax.swing.JButton addButton; 417 private javax.swing.JTextField classNameField; 418 private javax.swing.JLabel classNameLabel; 419 private javax.swing.JTextField descField; 420 private javax.swing.JLabel descLabel; 421 private javax.swing.JTextArea descriptionTextArea; 422 private javax.swing.JLabel jLabel1; 423 private javax.swing.JPanel jPanel1; 424 private javax.swing.JScrollPane jScrollPane1; 425 private javax.swing.JTable jTable1; 426 private javax.swing.JButton removeButton; 427 private javax.swing.JTextField resTypeField; 428 private javax.swing.JLabel resTypeLabel; 429 private javax.swing.JPanel tableButtonsPane; 430 private ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.Bundle"); private PropertiesTableModel tableModel; 433 private TableColumn nameColumn; 434 private TableColumn valueColumn; 435 436 } 437 438 | Popular Tags |