1 19 20 package org.netbeans.modules.web.wizards; 21 22 import java.awt.Dimension ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.Insets ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 28 import javax.swing.JButton ; 29 import javax.swing.JLabel ; 30 import javax.swing.JPanel ; 31 import javax.swing.JScrollPane ; 32 import javax.swing.ListSelectionModel ; 33 import javax.swing.event.ListSelectionEvent ; 34 import javax.swing.event.ListSelectionListener ; 35 import javax.swing.event.TableModelEvent ; 36 import javax.swing.event.TableModelListener ; 37 38 39 import org.openide.util.NbBundle; 40 41 45 46 class InitParamPanel extends JPanel implements ActionListener , 47 ListSelectionListener { 48 49 private final static String ADD = "add"; 50 private final static String EDIT = "edit"; 51 private final static String REMOVE = "remove"; 52 private ServletData deployData; 53 private BaseWizardPanel parent; 54 private boolean edited = false; 55 56 private JLabel jLinitparams; 57 private DDTable table; 58 private JButton jBnew; 59 private JButton jBedit; 60 private JButton jBdelete; 61 private JScrollPane scrollP; 62 63 private static final boolean debug = false; 64 65 private static final long serialVersionUID = -5803905591685582710L; 66 67 public InitParamPanel(ServletData deployData, BaseWizardPanel parent) { 68 this.deployData = deployData; 69 this.parent = parent; 70 initComponents (); 71 } 72 73 private void initComponents () { 74 75 setLayout(new java.awt.GridBagLayout ()); 77 78 GridBagConstraints fullRowC = new GridBagConstraints (); 80 fullRowC.gridx = 0; 81 fullRowC.gridy = 0; 82 fullRowC.gridwidth = 2; 83 fullRowC.anchor = GridBagConstraints.WEST; 84 fullRowC.fill = GridBagConstraints.HORIZONTAL; 85 fullRowC.insets = new Insets (4, 0, 4, 60); 86 87 GridBagConstraints bC = new GridBagConstraints (); 89 bC.gridx = 1; 90 bC.gridy = 1; 91 bC.weightx = 0.1; 92 bC.fill = GridBagConstraints.HORIZONTAL; 93 bC.insets = new Insets (4, 20, 4, 60); 94 95 GridBagConstraints tableC = new GridBagConstraints (); 97 tableC.gridx = 0; 98 tableC.gridy = 1; 99 tableC.gridheight = 4; 100 tableC.fill = GridBagConstraints.BOTH; 101 tableC.weightx = 0.9; 102 tableC.weighty = 1.0; 103 tableC.anchor = GridBagConstraints.WEST; 104 tableC.insets = new Insets (4, 0, 4, 0); 105 106 GridBagConstraints fillerC = new GridBagConstraints (); 108 fillerC.gridx = 1; 109 fillerC.gridy = GridBagConstraints.RELATIVE; 110 fillerC.fill = GridBagConstraints.BOTH; 111 fillerC.weighty = 1.0; 112 fillerC.insets = new Insets (4, 0, 4, 0); 113 114 jLinitparams = new JLabel (NbBundle.getMessage(InitParamPanel.class, "LBL_initparamsL")); 117 jLinitparams.setDisplayedMnemonic(NbBundle.getMessage (InitParamPanel.class, "LBL_initparams_mnemonic").charAt(0)); 118 this.add(jLinitparams, fullRowC); 120 121 123 String [] headers = { "paramname", "paramvalue" }; 124 table = new DDTable(headers, 125 "LBL_initparams", 126 Editable.BOTH); 127 128 jLinitparams.setLabelFor(table); 129 130 table.getSelectionModel().addListSelectionListener(this); 132 table.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparams_desc")); table.getAccessibleContext().setAccessibleName(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparams")); 135 136 table.getModel().addTableModelListener(new TableModelListener () { 137 public void tableChanged(TableModelEvent evt) { 138 if(debug) log("\ttable model changed"); updateInitParams(); 140 }}); 144 145 scrollP = new JScrollPane (table); 146 this.add(scrollP, tableC); 147 148 jBnew = new JButton (); 149 jBnew.setText(NbBundle.getMessage(InitParamPanel.class, 150 "LBL_new")); 151 jBnew.setMnemonic(NbBundle.getMessage(InitParamPanel.class, "LBL_new_mnemonic").charAt(0)); 152 jBnew.addActionListener(this); 153 jBnew.setActionCommand(ADD); 154 jBnew.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparam_new")); this.add(jBnew, bC); 156 157 bC.gridy++; 158 jBedit = new JButton (); 159 jBedit.setText(NbBundle.getMessage(InitParamPanel.class, 160 "LBL_edit")); 161 jBedit.setMnemonic(NbBundle.getMessage(InitParamPanel.class, "LBL_edit_mnemonic").charAt(0)); 162 jBedit.addActionListener(this); 163 jBedit.setActionCommand(EDIT); 164 jBedit.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparam_edit")); jBedit.setEnabled(false); 166 this.add(jBedit, bC); 167 168 bC.gridy++; 169 jBdelete = new JButton (); 170 jBdelete.setText(NbBundle.getMessage(InitParamPanel.class, 171 "LBL_delete")); 172 jBdelete.setMnemonic(NbBundle.getMessage(InitParamPanel.class, "LBL_delete_mnemonic").charAt(0)); 173 jBdelete.addActionListener(this); 174 jBdelete.setActionCommand(REMOVE); 175 jBdelete.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(InitParamPanel.class, "ACSD_initparam_delete")); jBdelete.setEnabled(false); 177 this.add(jBdelete, bC); 178 179 this.add(new javax.swing.JPanel (),fillerC); 180 181 } 182 183 public void setEnabled() { 184 185 boolean enable = deployData.makeEntry(); 186 187 jLinitparams.setEnabled(enable); 188 jBnew.setEnabled(enable); 189 if(enable) { 190 if(debug) { 191 log("\tnumRows: " + table.getRowCount()); log("\tselected row: " + table.getSelectedRow()); } 194 ListSelectionModel lsm = table.getSelectionModel(); 195 if (lsm.isSelectionEmpty()) { 196 jBdelete.setEnabled(false); 197 jBedit.setEnabled(false); 198 } 199 else { 200 jBdelete.setEnabled(true); 201 jBedit.setEnabled(true); 202 } 203 } 204 else { 205 jBdelete.setEnabled(false); 206 jBedit.setEnabled(false); 207 } 208 table.setEditable(enable ? Editable.BOTH : Editable.NEITHER); 209 } 210 211 public void actionPerformed(ActionEvent evt) { 212 213 if(debug) log("::actionPerformed()"); int row = -1; 215 if(evt.getSource() instanceof JButton ) { 216 if(evt.getActionCommand() == ADD) { 217 if(debug) log("\tAdding row"); String [] values= { 219 NbBundle.getMessage(InitParamPanel.class, "LBL_paramname"), 220 NbBundle.getMessage(InitParamPanel.class, "LBL_paramvalue"), 221 }; 222 row = table.addRow(values); 223 table.setRowSelectionInterval(row, row); 224 if(debug) log("\tAdded row " + row); 225 } 226 else if (evt.getActionCommand() == REMOVE) { 227 if(debug) log("\tDeleting row"); row = table.getSelectedRow(); 229 table.removeRow(row); 230 setEnabled(); 231 } 232 else if (evt.getActionCommand() == EDIT) { 233 if(debug) log("\tEditing row"); row = table.getSelectedRow(); 236 String name = (String )(table.getValueAt(row, 0)); 237 String value = (String )(table.getValueAt(row, 1)); 238 String title = NbBundle.getMessage(DDTable.class, 239 "LBL_initparams_edit"); TableRowDialog d = 241 new TableRowDialog(name, value, Editable.BOTH, 242 TableRowDialog.Condition.NONE, 243 title); 244 d.showDialog(); 245 if(d.getDialogOK()) { 246 if(debug) log("Dialog is OK"); 247 table.setData(d.getName(), d.getValue(), row); 248 } 249 else 250 table.setData(name, value, row); 251 } 252 scrollP.revalidate(); 253 } 254 } 255 256 public void valueChanged(ListSelectionEvent e) { 257 if(debug) log("::valueChanged()"); if (e.getValueIsAdjusting()) return; 260 setEnabled(); 261 updateInitParams(); 262 } 263 264 private void updateInitParams() { 265 266 if(debug) log("::updateInitParams()"); 267 edited = true; 268 269 if(deployData.makeEntry()) { 270 271 if(debug) { 272 log("\tnumRows: " + table.getRowCount()); log("\tselected row: " + table.getSelectedRow()); } 275 276 int numInitParams = table.getRowCount(); 277 String [][] param = new String [numInitParams][2]; 278 279 if(debug) log("\tnum params " + String.valueOf(numInitParams)); 281 282 boolean isOK = true; 283 for(int i=0; i<numInitParams; ++i) { 284 param[i][0] = (String )(table.getModel().getValueAt(i,0)); 285 if(debug) log("\tname is " + param[i][0]); if(param[i][0].length() == 0) isOK = false; 287 param[i][1] = (String )(table.getModel().getValueAt(i,1)); 288 if(debug) log("\tname is " + param[i][1]); } 290 deployData.setInitParams(param, isOK); 291 parent.fireChangeEvent(); 292 } 293 } 294 295 private void log(String s) { 296 System.out.println("InitParamPanel" + s); 297 } 298 } | Popular Tags |