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 40 44 public class MailPropertyVisualPanel extends javax.swing.JPanel implements WizardConstants, TableModelListener { 45 46 private final MailPropertyPanel panel; 47 private FieldGroup generalGroup; 48 private FieldGroup propertiesGroup; 49 private PropertiesTableModel tableModel; 50 private ResourceConfigHelper helper; 51 private javax.swing.table.TableColumn propNameColumn; 52 private javax.swing.table.TableColumn propValueColumn; 53 54 55 public MailPropertyVisualPanel(MailPropertyPanel panel) { 56 this.panel = panel; 57 this.helper = panel.getHelper(); 58 this.generalGroup = panel.getFieldGroup(__General); 59 this.propertiesGroup = panel.getFieldGroup(__Properties); 60 61 tableModel = new PropertiesTableModel(this.helper.getData()); 62 initComponents(); 63 setPropTableCellEditor(); 64 tableModel.addTableModelListener(this); 65 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 66 propertyTable.setRowSelectionAllowed(true); 67 68 setName(NbBundle.getMessage(MailPropertyVisualPanel.class, "TITLE_MailPropertyPanel")); 71 } 72 73 78 private void initComponents() { 80 java.awt.GridBagConstraints gridBagConstraints; 81 82 descriptionTextArea = new javax.swing.JTextArea (); 83 propertyInfo = new javax.swing.JLabel (); 84 jScrollPane1 = new javax.swing.JScrollPane (); 85 propertyTable = new javax.swing.JTable (); 86 buttonsPane = new javax.swing.JPanel (); 87 addButton = new javax.swing.JButton (); 88 removeButton = new javax.swing.JButton (); 89 90 setLayout(new java.awt.GridBagLayout ()); 91 92 setMinimumSize(new java.awt.Dimension (627, 305)); 93 setPreferredSize(new java.awt.Dimension (627, 305)); 94 getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("TITLE_MailPropertyPanel")); 95 getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("MailPropertyPanel_Description")); 96 descriptionTextArea.setEditable(false); 97 descriptionTextArea.setLineWrap(true); 98 descriptionTextArea.setText(NbBundle.getMessage(MailPropertyVisualPanel.class, "MailPropertyPanel_Description", this.helper.getData().getString(__JndiName))); 99 descriptionTextArea.setWrapStyleWord(true); 100 descriptionTextArea.setMinimumSize(new java.awt.Dimension (500, 17)); 101 descriptionTextArea.setOpaque(false); 102 descriptionTextArea.setPreferredSize(new java.awt.Dimension (500, 17)); 103 gridBagConstraints = new java.awt.GridBagConstraints (); 104 gridBagConstraints.gridx = 0; 105 gridBagConstraints.gridy = 0; 106 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 107 gridBagConstraints.weightx = 1.0; 108 gridBagConstraints.weighty = 1.0; 109 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 11); 110 add(descriptionTextArea, gridBagConstraints); 111 descriptionTextArea.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("MailPropertyPanel_Description")); 112 descriptionTextArea.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("MailPropertyPanel_Description")); 113 114 propertyInfo.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties_Mnemonic").charAt(0)); 115 propertyInfo.setLabelFor(propertyTable); 116 propertyInfo.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 117 gridBagConstraints = new java.awt.GridBagConstraints (); 118 gridBagConstraints.gridx = 0; 119 gridBagConstraints.gridy = 1; 120 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 121 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 11); 122 add(propertyInfo, gridBagConstraints); 123 propertyInfo.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 124 propertyInfo.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableMail_A11yDesc")); 125 126 jScrollPane1.setPreferredSize(new java.awt.Dimension (453, 17)); 127 propertyTable.setModel(tableModel); 128 jScrollPane1.setViewportView(propertyTable); 129 propertyTable.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_AddProperty")); 130 propertyTable.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableMail_A11yDesc")); 131 132 gridBagConstraints = new java.awt.GridBagConstraints (); 133 gridBagConstraints.gridx = 0; 134 gridBagConstraints.gridy = 2; 135 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 136 gridBagConstraints.insets = new java.awt.Insets (10, 12, 10, 11); 137 add(jScrollPane1, gridBagConstraints); 138 jScrollPane1.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 139 jScrollPane1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableMail_A11yDesc")); 140 141 buttonsPane.setLayout(new java.awt.GridBagLayout ()); 142 143 addButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Add_Mnemonic").charAt(0)); 144 addButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Add")); 145 addButton.addActionListener(new java.awt.event.ActionListener () { 146 public void actionPerformed(java.awt.event.ActionEvent evt) { 147 addButtonActionPerformed(evt); 148 } 149 }); 150 151 gridBagConstraints = new java.awt.GridBagConstraints (); 152 gridBagConstraints.gridx = 0; 153 gridBagConstraints.gridy = 0; 154 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 155 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 12); 156 buttonsPane.add(addButton, gridBagConstraints); 157 addButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_AddButtonA11yDesc")); 158 159 removeButton.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Remove_Mnemonic").charAt(0)); 160 removeButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_Remove")); 161 removeButton.addActionListener(new java.awt.event.ActionListener () { 162 public void actionPerformed(java.awt.event.ActionEvent evt) { 163 removeButtonActionPerformed(evt); 164 } 165 }); 166 167 gridBagConstraints = new java.awt.GridBagConstraints (); 168 gridBagConstraints.gridx = 0; 169 gridBagConstraints.gridy = 1; 170 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 171 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 12); 172 buttonsPane.add(removeButton, gridBagConstraints); 173 removeButton.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_RemoveButtonA11yDesc")); 174 175 gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridx = 1; 177 gridBagConstraints.gridy = 2; 178 gridBagConstraints.ipady = 150; 179 add(buttonsPane, gridBagConstraints); 180 buttonsPane.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("LBL_properties")); 181 buttonsPane.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/ide/sunresources/wizards/Bundle").getString("ACS_propTableMail_A11yDesc")); 182 183 } 184 186 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { propertyTable.editingStopped(new ChangeEvent (this)); 190 ResourceConfigData data = this.helper.getData(); 191 data.addProperty(new NameValuePair()); 192 tableModel.fireTableDataChanged(); 193 } 195 private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { int selectedRow = propertyTable.getSelectedRow(); 198 if (selectedRow != -1) { 199 propertyTable.editingStopped(new ChangeEvent (this)); 201 this.helper.getData().removeProperty(selectedRow); 202 tableModel.fireTableDataChanged(); 203 } 204 } 206 public void tableChanged(TableModelEvent evt) { 207 setPropTableCellEditor(); 208 this.panel.fireChange(evt.getSource()); 209 } 210 211 public void setPropTableCellEditor() { 212 javax.swing.JComboBox propNameComboBox = new javax.swing.JComboBox (); 213 String [] remainingProperties = FieldHelper.getRemainingFieldNames(propertiesGroup, this.helper.getData().getPropertyNames()); 214 215 for (int i = 0; i < remainingProperties.length; i++) 216 propNameComboBox.addItem(remainingProperties[i]); 217 propNameComboBox.setEditable(true); 218 this.propNameColumn = propertyTable.getColumnModel().getColumn(0); 219 propNameColumn.setCellEditor(new javax.swing.DefaultCellEditor (propNameComboBox)); 220 this.propValueColumn = propertyTable.getColumnModel().getColumn(1); 221 222 javax.swing.DefaultCellEditor editor = new javax.swing.DefaultCellEditor (new javax.swing.JTextField ()); 223 editor.setClickCountToStart(1); 224 propValueColumn.setCellEditor(editor); 225 } 226 227 public void refreshFields() { 228 ResourceConfigData data = this.helper.getData(); 229 ((PropertiesTableModel)propertyTable.getModel()).setData(this.helper.getData()); 230 descriptionTextArea.setText(NbBundle.getMessage(MailPropertyVisualPanel.class, "MailPropertyPanel_Description", data.getString(__JndiName))); } 232 233 private javax.swing.JButton addButton; 235 private javax.swing.JPanel buttonsPane; 236 private javax.swing.JTextArea descriptionTextArea; 237 private javax.swing.JScrollPane jScrollPane1; 238 private javax.swing.JLabel propertyInfo; 239 private javax.swing.JTable propertyTable; 240 private javax.swing.JButton removeButton; 241 243 public void setInitialFocus(){ 244 new setFocus(addButton); 245 } 246 } 247 | Popular Tags |