1 19 20 30 31 34 package org.netbeans.modules.web.monitor.client; 35 36 import java.awt.Component ; 37 import java.awt.event.ActionEvent ; 38 import java.awt.event.ActionListener ; 39 import java.awt.event.FocusEvent ; 40 import java.awt.event.FocusListener ; 41 import java.util.ResourceBundle ; 42 import javax.swing.JButton ; 43 import javax.swing.JPanel ; 44 import javax.swing.JTextField ; 45 import javax.swing.JScrollPane ; 46 import javax.swing.ListSelectionModel ; 47 import javax.swing.event.ListSelectionEvent ; 48 import javax.swing.event.ListSelectionListener ; 49 import javax.swing.event.TableModelEvent ; 50 import javax.swing.event.TableModelListener ; 51 52 import org.openide.NotifyDescriptor; 53 import org.openide.DialogDisplayer; 54 import org.openide.util.NbBundle; 55 56 import org.netbeans.modules.web.monitor.data.*; 57 58 class EditPanelQuery extends DataDisplay { 59 60 private final static boolean debug = false; 61 62 private DisplayTable paramTable = null; 63 private MonitorData monitorData = null; 64 private boolean setParams = false; 65 66 JButton newParamB; 68 JButton deleteParamB; 69 JTextField queryStringText; 70 JTextField uploadFileText; 71 72 EditPanelQuery() { 73 super(); 74 } 75 76 void redisplayData() { 79 if(debug) log("::redisplayData()"); 80 setData(monitorData); 81 this.revalidate(); 82 this.repaint(); 83 } 84 85 void setData(MonitorData md) { 86 87 if(debug) { 88 log("setData()"); log("\tMonitor data is:"); log("t" + md.dumpBeanNode()); } 92 this.monitorData = md; 93 this.removeAll(); 94 95 int fullGridWidth = java.awt.GridBagConstraints.REMAINDER; 96 int gridy = -1; 97 98 99 addGridBagComponent(this, createTopSpacer(), 0, ++gridy, 100 fullGridWidth, 1, 0, 0, 101 java.awt.GridBagConstraints.WEST, 102 java.awt.GridBagConstraints.NONE, 103 topSpacerInsets, 104 0, 0); 105 106 117 final RequestData rd = monitorData.getRequestData(); 118 119 String method = rd.getAttributeValue(EditPanel.METHOD); 120 if (EditPanel.POST.equals(method)) { 121 queryStringText = 122 new JTextField (rd.getAttributeValue("queryString")); 124 queryStringText.addFocusListener(new FocusListener () { 125 public void focusGained(FocusEvent evt) { 126 } 127 public void focusLost(FocusEvent evt) { 128 rd.setAttributeValue("queryString", queryStringText.getText()); 131 } 132 }); 133 134 addGridBagComponent(this, createHeaderLabel(NbBundle.getBundle(EditPanelQuery.class).getString("MON_Querystring"), NbBundle.getBundle(EditPanelQuery.class).getString("MON_Querystring_Mnemonic").charAt(0), NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_QuerystringA11yDesc"), paramTable), 135 0, ++gridy, 136 1, 1, 0, 0, 137 java.awt.GridBagConstraints.WEST, 138 java.awt.GridBagConstraints.NONE, 139 labelInsets, 140 0, 0); 141 142 addGridBagComponent(this, queryStringText, 0, ++gridy, 143 fullGridWidth, 1, 1.0, 0, 144 java.awt.GridBagConstraints.WEST, 145 java.awt.GridBagConstraints.HORIZONTAL, 146 tableInsets, 147 0, 0); 148 } 149 150 String msg2 = null; 151 Component msg2Label; 152 153 if (EditPanel.PUT.equals(method)) { 154 msg2 = NbBundle.getBundle(EditPanelQuery.class).getString("MON_Upload_File"); 155 msg2Label = createDataLabel(msg2); 156 addGridBagComponent(this, msg2Label, 0, ++gridy, 157 fullGridWidth, 1, 0, 0, 158 java.awt.GridBagConstraints.WEST, 159 java.awt.GridBagConstraints.NONE, 160 labelInsets, 161 0, 0); 162 163 164 String uploadFileMsg = NbBundle.getBundle(EditPanelQuery.class).getString("MON_Upload_File_Not_Supported"); 165 uploadFileText = new JTextField (uploadFileMsg); 166 uploadFileText.setEnabled(false); 167 addGridBagComponent(this, uploadFileText, 0, ++gridy, 168 fullGridWidth, 1, 1.0, 0, 169 java.awt.GridBagConstraints.WEST, 170 java.awt.GridBagConstraints.HORIZONTAL, 171 labelInsets, 172 0, 0); 173 addGridBagComponent(this, createGlue(), 0, ++gridy, 174 1, 1, 1.0, 1.0, 175 java.awt.GridBagConstraints.WEST, 176 java.awt.GridBagConstraints.BOTH, 177 labelInsets, 178 0, 0); 179 180 } else if (method != null) { 182 Param[] params2 = rd.getParam(); 183 if (params2 == null) params2 = new Param[0]; 184 setParameters(params2); 185 char mnemonic = ' '; 186 String ad = null; 187 188 if(method.equals(EditPanel.GET)) { 189 msg2 = NbBundle.getBundle(EditPanelQuery.class).getString("MON_Query_parameters"); 190 mnemonic = NbBundle.getBundle(EditPanelQuery.class).getString("MON_Query_parameters_Mnemonic").charAt(0); 191 ad = NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_Query_parametersA11yDesc"); 192 paramTable.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_ParametersTableA11yDesc")); 193 paramTable.setToolTipText(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_ParametersTableA11yDesc")); 194 195 } else if(method.equals(EditPanel.POST)) { 196 msg2 = NbBundle.getBundle(EditPanelQuery.class).getString("MON_Posted_data"); 197 mnemonic = NbBundle.getBundle(EditPanelQuery.class).getString("MON_Posted_data_Mnemonic").charAt(0); 198 ad = NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_Posted_dataA11yDesc"); 199 paramTable.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_Posted_dataTableA11yName")); 200 paramTable.setToolTipText(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_Posted_dataTableA11yDesc")); 201 } 202 203 msg2Label = createSortButtonLabel(msg2, paramTable, mnemonic, ad); 204 205 addGridBagComponent(this, msg2Label, 0, ++gridy, 206 1, 1, 0, 0, 207 java.awt.GridBagConstraints.WEST, 208 java.awt.GridBagConstraints.NONE, 209 labelInsets, 210 0, 0); 211 212 gridy = addParamTable(this, params2, gridy); 213 } 214 215 setEnablings(); 216 217 this.setMaximumSize(this.getPreferredSize()); 219 this.repaint(); 220 221 } 222 223 private int addParamTable(JPanel panel, Param[] params, int gridy) { 224 225 JScrollPane scrollpane = new JScrollPane (paramTable); 226 227 addGridBagComponent(panel, scrollpane, 0, ++gridy, 228 fullGridWidth, 1, 1.0, 1.0, 229 java.awt.GridBagConstraints.WEST, 230 java.awt.GridBagConstraints.BOTH, 232 tableInsets, 233 0, 0); 234 235 newParamB = new JButton (NbBundle.getBundle(EditPanelQuery.class).getString("MON_New_param")); 236 newParamB.setMnemonic(NbBundle.getBundle(EditPanelQuery.class).getString("MON_New_param_Mnemonic").charAt(0)); 237 newParamB.setToolTipText(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_New_paramA11yDesc")); 238 newParamB.addActionListener(new ActionListener () { 239 public void actionPerformed(ActionEvent e) { 240 241 String title = NbBundle.getBundle(EditPanelQuery.class).getString("MON_New_param"); 242 ParamEditor pe = new ParamEditor("", "", ParamEditor.Editable.BOTH, 244 ParamEditor.Condition.NONE, 245 title); 246 247 if(debug) log("Now showing dialog"); 249 pe.showDialog(); 250 251 if(debug) log("Dialog closed"); 253 if (pe.getDialogOK()) { 254 255 if(debug) log("Dialog returned OK"); String name = pe.getName(); 257 String value = pe.getValue(); 258 Param newParam = new Param(name, value); 259 monitorData.getRequestData().addParam(newParam); 260 redisplayData(); 261 } 262 }}); 263 264 deleteParamB = new JButton (NbBundle.getBundle(EditPanelQuery.class).getString("MON_Delete_param")); 265 deleteParamB.setMnemonic(NbBundle.getBundle(EditPanelQuery.class).getString("MON_Delete_param_Mnemonic").charAt(0)); 266 deleteParamB.setToolTipText(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_Delete_paramA11yDesc")); 267 268 deleteParamB.addActionListener(new ActionListener () { 269 270 public void actionPerformed(ActionEvent e) { 271 272 int numRows = paramTable.getRowCount(); 273 RequestData rd = monitorData.getRequestData(); 274 275 StringBuffer buf = new StringBuffer 276 (NbBundle.getBundle(EditPanelQuery.class).getString("MON_Confirm_Delete_Params")); 277 buf.append("\n"); 279 for(int i=0; i<numRows; ++i) { 280 281 if(paramTable.isRowSelected(i)) { 282 buf.append(paramTable.getValueAt(i, 0)); 283 buf.append("="); buf.append(paramTable.getValueAt(i, 1)); 285 buf.append("\n"); } 287 } 288 289 showConfirmDialog(buf.toString()); 290 291 if(setParams) { 292 293 for(int i=0; i<numRows; ++i) { 294 295 if(paramTable.isRowSelected(i)) { 296 String name = 297 (String )paramTable.getValueAt(i, 0); 298 String value = 299 (String )paramTable.getValueAt(i, 1); 300 301 Param[] params2 = rd.getParam(); 305 Param param = findParam(params2, name, value); 306 if (param != null) 307 rd.removeParam(param); 308 } 309 } 310 redisplayData(); 311 } 312 }}); 313 int gridx = -1; 314 addGridBagComponent(this, createGlue(), ++gridx, ++gridy, 315 1, 1, 1.0, 0, 316 java.awt.GridBagConstraints.WEST, 317 java.awt.GridBagConstraints.NONE, 318 buttonInsets, 319 0, 0); 320 addGridBagComponent(this, newParamB, ++gridx, gridy, 321 1, 1, 0, 0, 322 java.awt.GridBagConstraints.EAST, 323 java.awt.GridBagConstraints.NONE, 324 buttonInsets, 325 0, 0); 326 327 addGridBagComponent(this, deleteParamB, ++gridx, gridy, 328 1, 1, 0, 0, 329 java.awt.GridBagConstraints.EAST, 330 java.awt.GridBagConstraints.NONE, 331 buttonInsets, 332 0, 0); 333 return gridy; 334 } 335 336 void setEnablings() { 337 newParamB.setEnabled(true); 341 342 int selectedRows[] = paramTable.getSelectedRows(); 344 deleteParamB.setEnabled(selectedRows.length > 0); 345 } 346 347 void setParameters(Param[] newParams) { 348 349 paramTable = new DisplayTable(newParams, DisplayTable.PARAMS, true); 350 paramTable.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_QuerystringTableA11yName")); 351 paramTable.setToolTipText(NbBundle.getBundle(EditPanelQuery.class).getString("ACS_MON_QuerystringTableA11yDesc")); 352 353 ListSelectionModel selma = paramTable.getSelectionModel(); 354 selma.addListSelectionListener(new ListSelectionListener () { 355 public void valueChanged(ListSelectionEvent evt) { 356 if(debug) log("paramTable list selection listener"); setEnablings(); 358 } 359 }); 360 361 paramTable.addTableModelListener(new TableModelListener () { 362 public void tableChanged(TableModelEvent evt) { 363 updateParams(); 364 } 365 }); 366 } 367 368 369 void updateParams() { 370 int num = paramTable.getRowCount(); 371 RequestData rd = monitorData.getRequestData(); 372 Param[] params = rd.getParam(); 373 374 for(int i=0; i < num; i++) { 375 String name = (String )paramTable.getValueAt(i, 0); 376 name = name.trim(); 377 if(name.equals("")) { paramTable.setValueAt(params[i].getName(), i, 0); 379 showErrorDialog(); 380 return; 381 } 382 String value = (String )paramTable.getValueAt(i, 1); 383 value = value.trim(); 384 params[i].setName(name); 385 params[i].setValue(value); 386 } 387 } 388 389 void showConfirmDialog(String msg) { 390 391 Object [] options = { NotifyDescriptor.OK_OPTION, 392 NotifyDescriptor.CANCEL_OPTION 393 }; 394 395 NotifyDescriptor confirmDialog = 396 new NotifyDescriptor((Object )msg, 397 NbBundle.getBundle(EditPanelQuery.class).getString("MON_Confirmation_Required"), 398 NotifyDescriptor.OK_CANCEL_OPTION, 399 NotifyDescriptor.QUESTION_MESSAGE, 400 options, 401 NotifyDescriptor.CANCEL_OPTION); 402 403 DialogDisplayer.getDefault().notify(confirmDialog); 404 if(confirmDialog.getValue().equals(NotifyDescriptor.OK_OPTION)) 405 setParams = true; 406 else 407 setParams = false; 408 } 409 410 void showErrorDialog() { 411 412 Object [] options = { NotifyDescriptor.OK_OPTION }; 413 414 NotifyDescriptor errorDialog = 415 new NotifyDescriptor((Object )NbBundle.getBundle(EditPanelQuery.class).getString("MON_Bad_param"), 416 NbBundle.getBundle(EditPanelQuery.class).getString("MON_Invalid_input"), 417 NotifyDescriptor.DEFAULT_OPTION, 418 NotifyDescriptor.ERROR_MESSAGE, 419 options, 420 NotifyDescriptor.OK_OPTION); 421 422 DialogDisplayer.getDefault().notify(errorDialog); 423 } 424 425 426 void log(String s) { 427 System.out.println("EditPanelQuery::" + s); } 429 430 } | Popular Tags |