1 19 20 30 31 34 35 package org.netbeans.modules.web.monitor.client; 36 37 import java.awt.event.ActionEvent ; 38 import java.awt.event.ActionListener ; 39 import java.util.ResourceBundle ; 40 import javax.swing.JButton ; 41 import javax.swing.JScrollPane ; 42 import javax.swing.ListSelectionModel ; 43 import javax.swing.event.ListSelectionEvent ; 44 import javax.swing.event.ListSelectionListener ; 45 import javax.swing.event.TableModelEvent ; 46 import javax.swing.event.TableModelListener ; 47 48 import org.openide.util.NbBundle; 49 import org.openide.DialogDisplayer; 50 import org.openide.NotifyDescriptor; 51 52 import org.netbeans.modules.web.monitor.data.*; 53 54 class EditPanelHeaders extends DataDisplay { 55 56 private final static boolean debug = false; 57 58 private DisplayTable headerTable = null; 59 private MonitorData monitorData = null; 60 private boolean setParams = false; 61 62 JButton newHeaderB; 66 JButton editHeaderB; 67 JButton deleteHeaderB; 68 69 EditPanelHeaders() { 70 super(); 71 } 72 73 void redisplayData() { 76 setData(monitorData); 77 this.revalidate(); 78 this.repaint(); 79 } 80 81 void setData(MonitorData md) { 82 83 this.monitorData = md; 84 setHeaderTable(); 85 if(debug) log("setData()"); 87 this.removeAll(); 88 89 int gridy = -1; 90 int fullGridWidth = java.awt.GridBagConstraints.REMAINDER; 91 92 93 addGridBagComponent(this, createTopSpacer(), 0, ++gridy, 94 fullGridWidth, 1, 0, 0, 95 java.awt.GridBagConstraints.WEST, 96 java.awt.GridBagConstraints.NONE, 97 topSpacerInsets, 98 0, 0); 99 100 String msg = NbBundle.getBundle(EditPanelHeaders.class).getString("MON_HTTP_Headers"); 101 addGridBagComponent(this, createSortButtonLabel(msg, headerTable, NbBundle.getBundle(EditPanelHeaders.class).getString("MON_HTTP_Headers_2_Mnemonic").charAt(0), NbBundle.getBundle(EditPanelHeaders.class).getString("ACS_MON_HTTP_HeadersA11yDesc")), 0, ++gridy, 102 1, 1, 0, 0, 103 java.awt.GridBagConstraints.WEST, 104 java.awt.GridBagConstraints.NONE, 105 labelInsets, 106 0, 0); 107 108 JScrollPane scrollpane = new JScrollPane (headerTable); 109 addGridBagComponent(this, scrollpane, 0, ++gridy, 110 fullGridWidth, 1, 1.0, 1.0, 111 java.awt.GridBagConstraints.WEST, 112 java.awt.GridBagConstraints.BOTH, 114 tableInsets, 115 0, 0); 116 117 newHeaderB = new JButton (NbBundle.getBundle(EditPanelHeaders.class).getString("MON_New_header")); 118 newHeaderB.setMnemonic(NbBundle.getBundle(EditPanelHeaders.class).getString("MON_New_header_Mnemonic").charAt(0)); 119 newHeaderB.setToolTipText(NbBundle.getBundle(EditPanelHeaders.class).getString("ACS_MON_New_headerA11yDesc")); 120 newHeaderB.addActionListener(new ActionListener () { 121 public void actionPerformed(ActionEvent e) { 122 String title = NbBundle.getBundle(EditPanelHeaders.class).getString("MON_New_header"); 123 ParamEditor pe = new ParamEditor("", "", ParamEditor.Editable.BOTH, 125 ParamEditor.Condition.HEADER, 126 title); 127 128 if(debug) log("Now showing dialog"); 130 pe.showDialog(); 131 132 if(debug) log("Dialog closed"); 134 if (pe.getDialogOK()) { 135 136 if(debug) log("Dialog returned OK"); 138 String name = pe.getName(); 139 int status = 0; 140 141 if(name.equalsIgnoreCase("cookie")) 142 status = monitorData.getRequestData().addCookie(pe.getValue()); 143 else 144 status = monitorData.getRequestData().getHeaders().addParam(pe.getName(), pe.getValue()); 145 146 if(debug) 147 log("Headers are " + monitorData.getRequestData().getHeaders().toString()); 149 157 redisplayData(); 158 } 159 }}); 160 161 deleteHeaderB = new JButton (NbBundle.getBundle(EditPanelHeaders.class).getString("MON_Delete_header")); 162 deleteHeaderB.setMnemonic(NbBundle.getBundle(EditPanelHeaders.class).getString("MON_Delete_header_Mnemonic").charAt(0)); 163 deleteHeaderB.setToolTipText(NbBundle.getBundle(EditPanelHeaders.class).getString("MON_New_header_Mnemonic")); 164 165 deleteHeaderB.addActionListener(new ActionListener () { 166 167 public void actionPerformed(ActionEvent e) { 168 169 int numRows = headerTable.getRowCount(); 170 171 StringBuffer buf = new StringBuffer 172 (NbBundle.getBundle(EditPanelHeaders.class).getString("MON_Confirm_Delete_Headers")); 173 buf.append("\n"); 175 for(int i=0; i<numRows; ++i) { 176 177 if(headerTable.isRowSelected(i)) { 178 buf.append(headerTable.getValueAt(i, 0)); 179 buf.append(" "); buf.append(headerTable.getValueAt(i, 1)); 181 buf.append("\n"); } 183 } 184 185 showConfirmDialog(buf.toString()); 186 187 if(setParams) { 188 189 Headers hd = monitorData.getRequestData().getHeaders(); 190 191 for(int i=0; i<numRows; ++i) { 192 if(headerTable.isRowSelected(i)) { 193 194 String name = 195 (String )headerTable.getValueAt(i, 0); 196 String value = 197 (String )headerTable.getValueAt(i, 1); 198 199 Param[] myParams = hd.getParam(); 203 Param param = findParam(myParams, name, value); 204 if (param != null) 205 hd.removeParam(param); 206 } 207 } 208 redisplayData(); 209 } 210 }}); 211 212 int gridx = -1; 213 addGridBagComponent(this, createGlue(), ++gridx, ++gridy, 214 1, 1, 1.0, 0, 215 java.awt.GridBagConstraints.WEST, 216 java.awt.GridBagConstraints.NONE, 217 buttonInsets, 218 0, 0); 219 addGridBagComponent(this, newHeaderB, ++gridx, gridy, 220 1, 1, 0, 0, 221 java.awt.GridBagConstraints.EAST, 222 java.awt.GridBagConstraints.NONE, 223 buttonInsets, 224 0, 0); 225 226 addGridBagComponent(this, deleteHeaderB, ++gridx, gridy, 227 1, 1, 0, 0, 228 java.awt.GridBagConstraints.EAST, 229 java.awt.GridBagConstraints.NONE, 230 buttonInsets, 231 0, 0); 232 233 setEnablings(); 234 235 this.setMaximumSize(this.getPreferredSize()); 236 this.repaint(); 237 } 238 239 240 241 242 void showConfirmDialog(String msg) { 243 244 Object [] options = { NotifyDescriptor.OK_OPTION, 245 NotifyDescriptor.CANCEL_OPTION 246 }; 247 248 NotifyDescriptor confirmDialog = 249 new NotifyDescriptor((Object )msg, 250 NbBundle.getBundle(EditPanelHeaders.class).getString("MON_Confirmation_Required"), 251 NotifyDescriptor.OK_CANCEL_OPTION, 252 NotifyDescriptor.QUESTION_MESSAGE, 253 options, 254 NotifyDescriptor.CANCEL_OPTION); 255 256 DialogDisplayer.getDefault().notify(confirmDialog); 257 if(confirmDialog.getValue().equals(NotifyDescriptor.OK_OPTION)) 258 setParams = true; 259 else 260 setParams = false; 261 } 262 263 264 void showErrorDialog() { 265 266 Object [] options = { NotifyDescriptor.OK_OPTION }; 267 268 NotifyDescriptor errorDialog = 269 new NotifyDescriptor((Object )NbBundle.getBundle(EditPanelHeaders.class).getString("MON_Bad_header"), 270 NbBundle.getBundle(EditPanelHeaders.class).getString("MON_Invalid_input"), 271 NotifyDescriptor.DEFAULT_OPTION, 272 NotifyDescriptor.ERROR_MESSAGE, 273 options, 274 NotifyDescriptor.OK_OPTION); 275 276 DialogDisplayer.getDefault().notify(errorDialog); 277 } 278 279 280 void setEnablings() { 281 282 newHeaderB.setEnabled(true); 284 285 int selectedRows[] = headerTable.getSelectedRows(); 287 deleteHeaderB.setEnabled(selectedRows.length > 0); 288 } 289 290 void setHeaderTable() { 291 292 Param[] params = monitorData.getRequestData().getHeaders().getParam(); 293 if(params == null) params = new Param[0]; 294 295 headerTable = 296 new DisplayTable(params, DisplayTable.HEADERS, true); 297 headerTable.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanelHeaders.class).getString("ACS_MON_HTTP_HeadersTableA11yName")); 298 headerTable.setToolTipText(NbBundle.getBundle(EditPanelHeaders.class).getString("ACS_MON_HTTP_HeadersTableA11yDesc")); 299 300 301 ListSelectionModel selma = headerTable.getSelectionModel(); 302 selma.addListSelectionListener(new ListSelectionListener () { 303 public void valueChanged(ListSelectionEvent evt) { 304 if(debug) log("got list selection event"); setEnablings(); 306 } 307 }); 308 309 headerTable.addTableModelListener(new TableModelListener () { 310 public void tableChanged(TableModelEvent evt) { 311 312 if(debug) 313 log("got table changed event"); updateHeaders(); 315 } 316 }); 317 } 318 319 private void updateHeaders() { 320 321 int num = headerTable.getRowCount(); 322 Headers hd = monitorData.getRequestData().getHeaders(); 323 Param[] params = hd.getParam(); 324 325 boolean inputOK = true; 326 327 for(int i=0; i < num; i++) { 328 String name = (String )headerTable.getValueAt(i, 0); 329 name = name.trim(); 330 331 if(debug) 332 log("Name is " + name); 334 if(name.equals("")) { headerTable.setValueAt(params[i].getName(), i, 0); 336 inputOK = false; 337 } 338 String value = (String )headerTable.getValueAt(i, 1); 339 value = value.trim(); 340 341 if(debug) 342 log("Value is " + value); 344 if(value.equals("")) { headerTable.setValueAt(params[i].getValue(), i, 1); 346 inputOK = false; 347 } 348 349 if(!inputOK) { 350 showErrorDialog(); 351 return; 352 } 353 params[i].setName(name); 354 params[i].setValue(value); 355 } 356 } 357 358 public void repaint() { 359 super.repaint(); 360 } 363 364 void log(String s) { 365 System.out.println("EditPanelHeaders::" + s); } 367 368 369 } 371 | Popular Tags |