1 19 20 24 25 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards; 26 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.TableModelEvent ; 29 import javax.swing.event.TableModelListener ; 30 import javax.swing.ListSelectionModel ; 31 import org.openide.util.NbBundle; 32 import java.util.ResourceBundle ; 33 34 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair; 35 36 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup; 37 import org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.WS70WizardConstants; 38 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper; 39 43 public class CommonPropertyVisualPanel extends javax.swing.JPanel implements WS70WizardConstants, TableModelListener { 44 45 private final CommonPropertyPanel panel; 46 private ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.Bundle"); 47 private FieldGroup propertiesGroup; 48 private PropertiesTableModel tableModel; 49 private javax.swing.table.TableColumn propNameColumn; 50 private javax.swing.table.TableColumn propValueColumn; 51 private ResourceConfigHelper helper; 52 53 54 55 public CommonPropertyVisualPanel(CommonPropertyPanel panel) { 56 this.panel = panel; 57 this.helper = panel.getHelper(); 58 this.propertiesGroup = panel.getFieldGroup(__Properties); 59 tableModel = new PropertiesTableModel(this.helper.getData()); 60 initComponents(); 61 propNameColumn = propertyTable.getColumnModel().getColumn(0); 62 setPropTableCellEditor(); 63 tableModel.addTableModelListener(this); 64 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 65 propertyTable.setRowSelectionAllowed(true); 66 67 setName(NbBundle.getMessage(CommonPropertyVisualPanel.class, "TITLE_CommonPropertyPanel")); } 70 71 76 private void initComponents() { 78 java.awt.GridBagConstraints gridBagConstraints; 79 80 descriptionTextArea = new javax.swing.JTextArea (); 81 propertyInfo = new javax.swing.JLabel (); 82 jScrollPane1 = new javax.swing.JScrollPane (); 83 propertyTable = new javax.swing.JTable (); 84 buttonsPane = new javax.swing.JPanel (); 85 addButton = new javax.swing.JButton (); 86 removeButton = new javax.swing.JButton (); 87 88 setLayout(new java.awt.GridBagLayout ()); 89 90 getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("TITLE_CommonPropertyPanel")); 91 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 92 descriptionTextArea.setEditable(false); 93 descriptionTextArea.setLineWrap(true); 94 descriptionTextArea.setText(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 95 descriptionTextArea.setWrapStyleWord(true); 96 descriptionTextArea.setFocusable(false); 97 descriptionTextArea.setOpaque(false); 98 gridBagConstraints = new java.awt.GridBagConstraints (); 99 gridBagConstraints.gridx = 0; 100 gridBagConstraints.gridy = 0; 101 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 102 gridBagConstraints.weightx = 1.0; 103 gridBagConstraints.weighty = 1.0; 104 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 11); 105 add(descriptionTextArea, gridBagConstraints); 106 descriptionTextArea.getAccessibleContext().setAccessibleName(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 107 descriptionTextArea.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 108 109 propertyInfo.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_properties_Mnemonic").charAt(0)); 110 propertyInfo.setLabelFor(propertyTable); 111 propertyInfo.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_properties")); 112 gridBagConstraints = new java.awt.GridBagConstraints (); 113 gridBagConstraints.gridx = 0; 114 gridBagConstraints.gridy = 1; 115 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 116 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 11); 117 add(propertyInfo, gridBagConstraints); 118 propertyInfo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 119 120 jScrollPane1.setPreferredSize(new java.awt.Dimension (descriptionTextArea.getWidth(), this.getHeight())); 121 propertyTable.setModel(tableModel); 122 jScrollPane1.setViewportView(propertyTable); 123 propertyTable.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_AddProperty")); 124 propertyTable.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 125 126 gridBagConstraints = new java.awt.GridBagConstraints (); 127 gridBagConstraints.gridx = 0; 128 gridBagConstraints.gridy = 2; 129 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 130 gridBagConstraints.insets = new java.awt.Insets (10, 12, 10, 11); 131 add(jScrollPane1, gridBagConstraints); 132 jScrollPane1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_AddProperty")); 133 jScrollPane1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 134 135 buttonsPane.setLayout(new java.awt.GridBagLayout ()); 136 137 addButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Add_Mnemonic").charAt(0)); 138 addButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Add")); 139 addButton.addActionListener(new java.awt.event.ActionListener () { 140 public void actionPerformed(java.awt.event.ActionEvent evt) { 141 addButtonActionPerformed(evt); 142 } 143 }); 144 145 gridBagConstraints = new java.awt.GridBagConstraints (); 146 gridBagConstraints.gridx = 0; 147 gridBagConstraints.gridy = 0; 148 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 149 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 12); 150 buttonsPane.add(addButton, gridBagConstraints); 151 addButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_AddButtonA11yDesc")); 152 153 removeButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Remove_Mnemonic").charAt(0)); 154 removeButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_Remove")); 155 removeButton.addActionListener(new java.awt.event.ActionListener () { 156 public void actionPerformed(java.awt.event.ActionEvent evt) { 157 removeButtonActionPerformed(evt); 158 } 159 }); 160 161 gridBagConstraints = new java.awt.GridBagConstraints (); 162 gridBagConstraints.gridx = 0; 163 gridBagConstraints.gridy = 1; 164 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 165 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 166 buttonsPane.add(removeButton, gridBagConstraints); 167 removeButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_RemoveButtonA11yDesc")); 168 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 1; 171 gridBagConstraints.gridy = 2; 172 gridBagConstraints.ipady = 150; 173 add(buttonsPane, gridBagConstraints); 174 buttonsPane.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("LBL_AddProperty")); 175 buttonsPane.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 176 177 } 179 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { propertyTable.editingStopped(new ChangeEvent (this)); 183 ResourceConfigData data = this.helper.getData(); 184 data.addProperty(new NameValuePair()); 185 tableModel.fireTableDataChanged(); 186 } 188 private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { int selectedRow = propertyTable.getSelectedRow(); 191 if (selectedRow != -1) { 192 propertyTable.editingStopped(new ChangeEvent (this)); 194 this.helper.getData().removeProperty(selectedRow); 195 tableModel.fireTableDataChanged(); 196 } 197 } 199 public void tableChanged(TableModelEvent evt) { 200 setPropTableCellEditor(); 201 this.panel.fireChangeEvent(); 202 } 203 204 public void setPropTableCellEditor() { 205 206 javax.swing.JComboBox propNameComboBox = new javax.swing.JComboBox (); 207 208 String [] remainingProperties = null; 209 remainingProperties = FieldHelper.getRemainingFieldNames(propertiesGroup, this.helper.getData().getPropertyNames()); 210 211 for (int i = 0; i < remainingProperties.length; i++) 212 propNameComboBox.addItem(remainingProperties[i]); 213 propNameComboBox.setEditable(true); 214 this.propNameColumn = propertyTable.getColumnModel().getColumn(0); 215 propNameColumn.setCellEditor(new javax.swing.DefaultCellEditor (propNameComboBox)); 216 this.propValueColumn = propertyTable.getColumnModel().getColumn(1); 217 218 javax.swing.DefaultCellEditor editor = new javax.swing.DefaultCellEditor (new javax.swing.JTextField ()); 219 editor.setClickCountToStart(1); 220 propValueColumn.setCellEditor(editor); 221 } 222 223 public void refreshFields() { 224 ResourceConfigData data = this.helper.getData(); 225 ((PropertiesTableModel)propertyTable.getModel()).setData(this.helper.getData()); 226 descriptionTextArea.setText(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", data.getString(__JndiName))); 227 } 228 229 private javax.swing.JButton addButton; 231 private javax.swing.JPanel buttonsPane; 232 private javax.swing.JTextArea descriptionTextArea; 233 private javax.swing.JScrollPane jScrollPane1; 234 private javax.swing.JLabel propertyInfo; 235 private javax.swing.JTable propertyTable; 236 private javax.swing.JButton removeButton; 237 239 public void setInitialFocus(){ 240 new setFocus(addButton); 241 } 242 } 243 | Popular Tags |