1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.sunresources.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.sunresources.beans.WizardConstants; 38 import org.netbeans.modules.j2ee.sun.sunresources.beans.FieldHelper; 39 43 public class CommonPropertyVisualPanel extends javax.swing.JPanel implements WizardConstants, TableModelListener { 44 45 private final CommonPropertyPanel panel; 46 private ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.j2ee.sun.ide.sunresources.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(JmsPropertyVisualPanel.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 setMinimumSize(new java.awt.Dimension (627, 305)); 91 setPreferredSize(new java.awt.Dimension (627, 305)); 92 getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("TITLE_CommonPropertyPanel")); 93 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 94 descriptionTextArea.setEditable(false); 95 descriptionTextArea.setLineWrap(true); 96 descriptionTextArea.setText(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 97 descriptionTextArea.setWrapStyleWord(true); 98 descriptionTextArea.setFocusable(false); 99 descriptionTextArea.setMinimumSize(new java.awt.Dimension (500, 17)); 100 descriptionTextArea.setOpaque(false); 101 descriptionTextArea.setPreferredSize(new java.awt.Dimension (500, 17)); 102 gridBagConstraints = new java.awt.GridBagConstraints (); 103 gridBagConstraints.gridx = 0; 104 gridBagConstraints.gridy = 0; 105 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 106 gridBagConstraints.weightx = 1.0; 107 gridBagConstraints.weighty = 1.0; 108 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 11); 109 add(descriptionTextArea, gridBagConstraints); 110 descriptionTextArea.getAccessibleContext().setAccessibleName(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 111 descriptionTextArea.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 112 113 propertyInfo.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties_Mnemonic").charAt(0)); 114 propertyInfo.setLabelFor(propertyTable); 115 propertyInfo.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 116 gridBagConstraints = new java.awt.GridBagConstraints (); 117 gridBagConstraints.gridx = 0; 118 gridBagConstraints.gridy = 1; 119 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 120 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 11); 121 add(propertyInfo, gridBagConstraints); 122 propertyInfo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 123 124 jScrollPane1.setPreferredSize(new java.awt.Dimension (453, 17)); 125 propertyTable.setModel(tableModel); 126 jScrollPane1.setViewportView(propertyTable); 127 propertyTable.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_AddProperty")); 128 propertyTable.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 129 130 gridBagConstraints = new java.awt.GridBagConstraints (); 131 gridBagConstraints.gridx = 0; 132 gridBagConstraints.gridy = 2; 133 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 134 gridBagConstraints.insets = new java.awt.Insets (10, 12, 10, 11); 135 add(jScrollPane1, gridBagConstraints); 136 jScrollPane1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_AddProperty")); 137 jScrollPane1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 138 139 buttonsPane.setLayout(new java.awt.GridBagLayout ()); 140 141 addButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Add_Mnemonic").charAt(0)); 142 addButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Add")); 143 addButton.addActionListener(new java.awt.event.ActionListener () { 144 public void actionPerformed(java.awt.event.ActionEvent evt) { 145 addButtonActionPerformed(evt); 146 } 147 }); 148 149 gridBagConstraints = new java.awt.GridBagConstraints (); 150 gridBagConstraints.gridx = 0; 151 gridBagConstraints.gridy = 0; 152 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 153 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 12); 154 buttonsPane.add(addButton, gridBagConstraints); 155 addButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_AddButtonA11yDesc")); 156 157 removeButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Remove_Mnemonic").charAt(0)); 158 removeButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Remove")); 159 removeButton.addActionListener(new java.awt.event.ActionListener () { 160 public void actionPerformed(java.awt.event.ActionEvent evt) { 161 removeButtonActionPerformed(evt); 162 } 163 }); 164 165 gridBagConstraints = new java.awt.GridBagConstraints (); 166 gridBagConstraints.gridx = 0; 167 gridBagConstraints.gridy = 1; 168 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 169 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 170 buttonsPane.add(removeButton, gridBagConstraints); 171 removeButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_RemoveButtonA11yDesc")); 172 173 gridBagConstraints = new java.awt.GridBagConstraints (); 174 gridBagConstraints.gridx = 1; 175 gridBagConstraints.gridy = 2; 176 gridBagConstraints.ipady = 150; 177 add(buttonsPane, gridBagConstraints); 178 buttonsPane.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_AddProperty")); 179 buttonsPane.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableCommon_A11yDesc")); 180 181 } 182 184 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { propertyTable.editingStopped(new ChangeEvent (this)); 188 ResourceConfigData data = this.helper.getData(); 189 data.addProperty(new NameValuePair()); 190 tableModel.fireTableDataChanged(); 191 } 193 private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { int selectedRow = propertyTable.getSelectedRow(); 196 if (selectedRow != -1) { 197 propertyTable.editingStopped(new ChangeEvent (this)); 199 this.helper.getData().removeProperty(selectedRow); 200 tableModel.fireTableDataChanged(); 201 } 202 } 204 public void tableChanged(TableModelEvent evt) { 205 setPropTableCellEditor(); 206 this.panel.fireChange(evt.getSource()); 207 } 208 209 public void setPropTableCellEditor() { 210 211 javax.swing.JComboBox propNameComboBox = new javax.swing.JComboBox (); 212 213 String [] remainingProperties = null; 214 remainingProperties = FieldHelper.getRemainingFieldNames(propertiesGroup, this.helper.getData().getPropertyNames()); 215 216 for (int i = 0; i < remainingProperties.length; i++) 217 propNameComboBox.addItem(remainingProperties[i]); 218 propNameComboBox.setEditable(true); 219 this.propNameColumn = propertyTable.getColumnModel().getColumn(0); 220 propNameColumn.setCellEditor(new javax.swing.DefaultCellEditor (propNameComboBox)); 221 this.propValueColumn = propertyTable.getColumnModel().getColumn(1); 222 223 javax.swing.DefaultCellEditor editor = new javax.swing.DefaultCellEditor (new javax.swing.JTextField ()); 224 editor.setClickCountToStart(1); 225 propValueColumn.setCellEditor(editor); 226 } 227 228 public void refreshFields() { 229 ResourceConfigData data = this.helper.getData(); 230 ((PropertiesTableModel)propertyTable.getModel()).setData(this.helper.getData()); 231 descriptionTextArea.setText(NbBundle.getMessage(CommonPropertyVisualPanel.class, "CommonPropertyPanel_Description", data.getString(__JndiName))); 232 } 233 234 private javax.swing.JButton addButton; 236 private javax.swing.JPanel buttonsPane; 237 private javax.swing.JTextArea descriptionTextArea; 238 private javax.swing.JScrollPane jScrollPane1; 239 private javax.swing.JLabel propertyInfo; 240 private javax.swing.JTable propertyTable; 241 private javax.swing.JButton removeButton; 242 244 public void setInitialFocus(){ 245 new setFocus(addButton); 246 } 247 } 248 | Popular Tags |