1 19 20 package org.netbeans.modules.web.struts.wizards; 21 22 import javax.swing.DefaultListModel ; 23 import javax.swing.ListSelectionModel ; 24 import javax.swing.event.ListDataEvent ; 25 import javax.swing.event.ListDataListener ; 26 import javax.swing.table.AbstractTableModel ; 27 import org.openide.WizardDescriptor; 28 29 import org.openide.util.NbBundle; 30 31 public class FormBeanPropertiesPanelVisual extends javax.swing.JPanel implements WizardDescriptor.Panel { 32 33 private PropertiesTableModel model; 34 35 38 public FormBeanPropertiesPanelVisual() { 39 initComponents(); 40 initTable(); 41 42 } 44 45 private void initTable() { 46 model = new PropertiesTableModel(); 47 jTableProperties.setModel(model); 48 jTableProperties.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 49 52 jTableProperties.setRowHeight(jTableProperties.getFontMetrics(jTableProperties.getFont()).getHeight() + 4); 53 jTableProperties.getParent().setBackground(jTableProperties.getBackground()); 54 } 55 56 public DefaultListModel getTableModel() { 57 return model.getDefaultListModel(); 58 } 59 60 public void removeChangeListener(javax.swing.event.ChangeListener l) { 61 } 62 63 public void addChangeListener(javax.swing.event.ChangeListener l) { 64 } 65 66 public void storeSettings(Object settings) { 67 } 68 69 public void readSettings(Object settings) { 70 } 71 72 public org.openide.util.HelpCtx getHelp() { 73 return null; 74 } 75 76 public java.awt.Component getComponent() { 77 return this; 78 } 79 80 84 89 private void initComponents() { 91 java.awt.GridBagConstraints gridBagConstraints; 92 93 jScrollPane1 = new javax.swing.JScrollPane (); 94 jTableProperties = new javax.swing.JTable (); 95 jButtonAdd = new javax.swing.JButton (); 96 jButtonRemove = new javax.swing.JButton (); 97 jLabel1 = new javax.swing.JLabel (); 98 99 setLayout(new java.awt.GridBagLayout ()); 100 101 jTableProperties.setModel(new javax.swing.table.DefaultTableModel ( 102 new Object [][] { 103 {null, null, null, null}, 104 {null, null, null, null}, 105 {null, null, null, null}, 106 {null, null, null, null} 107 }, 108 new String [] { 109 "Title 1", "Title 2", "Title 3", "Title 4" 110 } 111 )); 112 jScrollPane1.setViewportView(jTableProperties); 113 114 gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridx = 0; 116 gridBagConstraints.gridy = 1; 117 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 118 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 119 gridBagConstraints.weightx = 1.0; 120 gridBagConstraints.weighty = 1.0; 121 add(jScrollPane1, gridBagConstraints); 122 123 jButtonAdd.setMnemonic(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_AddButton_LabelMnemonic").charAt(0)); 124 jButtonAdd.setText(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_AddButton")); 125 jButtonAdd.addActionListener(new java.awt.event.ActionListener () { 126 public void actionPerformed(java.awt.event.ActionEvent evt) { 127 jButtonAddActionPerformed(evt); 128 } 129 }); 130 131 gridBagConstraints = new java.awt.GridBagConstraints (); 132 gridBagConstraints.gridx = 1; 133 gridBagConstraints.gridy = 1; 134 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 135 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 136 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 137 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 138 add(jButtonAdd, gridBagConstraints); 139 140 jButtonRemove.setMnemonic(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_RemoveButton_LabelMnemonic").charAt(0)); 141 jButtonRemove.setText(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_RemoveButton")); 142 jButtonRemove.addActionListener(new java.awt.event.ActionListener () { 143 public void actionPerformed(java.awt.event.ActionEvent evt) { 144 jButtonRemoveActionPerformed(evt); 145 } 146 }); 147 148 gridBagConstraints = new java.awt.GridBagConstraints (); 149 gridBagConstraints.gridx = 1; 150 gridBagConstraints.gridy = 2; 151 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 152 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 153 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 154 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 155 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 156 add(jButtonRemove, gridBagConstraints); 157 158 jLabel1.setLabelFor(jTableProperties); 159 jLabel1.setText(org.openide.util.NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_Properties")); 160 gridBagConstraints = new java.awt.GridBagConstraints (); 161 gridBagConstraints.gridx = 0; 162 gridBagConstraints.gridy = 0; 163 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 164 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 165 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 166 add(jLabel1, gridBagConstraints); 167 168 } 169 171 private void jButtonRemoveActionPerformed(java.awt.event.ActionEvent evt) { int index = jTableProperties.getSelectedRow(); 173 if (index != -1) 174 model.getDefaultListModel().remove(index); 175 } 177 private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) { model.addItem(new FormBeanProperty()); 179 } 181 182 private javax.swing.JButton jButtonAdd; 184 private javax.swing.JButton jButtonRemove; 185 private javax.swing.JLabel jLabel1; 186 private javax.swing.JScrollPane jScrollPane1; 187 private javax.swing.JTable jTableProperties; 188 190 207 222 225 public static final class PropertiesTableModel extends AbstractTableModel implements ListDataListener { 226 227 private DefaultListModel model; 228 229 public PropertiesTableModel() { 230 model = new DefaultListModel (); 231 model.addListDataListener(this); 232 } 233 234 public DefaultListModel getDefaultListModel() { 235 return model; 236 } 237 238 public int getColumnCount() { 239 return 2; 240 } 241 242 public int getRowCount() { 243 return model.size(); 244 } 245 246 public String getColumnName(int column) { 247 switch (column) { 248 case 0: 249 return NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_PropertiesTableHeader_Property"); case 1: 251 return NbBundle.getMessage(FormBeanPropertiesPanelVisual.class, "LBL_PropertiesTableHeader_Value"); } 253 return ""; } 255 256 public Class getColumnClass(int columnIndex) { 257 if (columnIndex == 2) 258 return Boolean .class; 259 else 260 return String .class; 261 } 262 263 public boolean isCellEditable(int rowIndex, int columnIndex) { 264 return true; 265 } 266 267 public Object getValueAt(int row, int column) { 268 FormBeanProperty item = getItem(row); 269 switch (column) { 270 case 0: return item.getProperty(); 271 case 1: return item.getType(); 272 } 273 return ""; 274 } 275 276 public void setValueAt(Object value, int row, int column) { 277 FormBeanProperty item = getItem(row); 278 switch (column) { 279 case 0: item.setProperty((String ) value);break; 280 case 1: item.setType((String ) value); 281 } 282 } 283 284 public void clear(){ 285 model.clear(); 286 } 287 288 public void contentsChanged(ListDataEvent e) { 289 fireTableRowsUpdated(e.getIndex0(), e.getIndex1()); 290 } 291 292 public void intervalAdded(ListDataEvent e) { 293 fireTableRowsInserted(e.getIndex0(), e.getIndex1()); 294 } 295 296 public void intervalRemoved(ListDataEvent e) { 297 fireTableRowsDeleted(e.getIndex0(), e.getIndex1()); 298 } 299 300 private FormBeanProperty getItem(int index) { 301 return (FormBeanProperty) model.get(index); 302 } 303 304 public void addItem(FormBeanProperty item){ 305 model.addElement(item); 306 } 307 } 308 } 309 | Popular Tags |