1 19 20 29 30 33 34 package org.netbeans.modules.web.monitor.client; 35 36 import java.awt.event.ActionEvent ; 37 import java.awt.event.ActionListener ; 38 import java.util.ResourceBundle ; 39 import java.util.StringTokenizer ; 40 import java.util.Vector ; 41 import javax.swing.JButton ; 42 import javax.swing.JScrollPane ; 43 import javax.swing.ListSelectionModel ; 44 import javax.swing.event.ListSelectionEvent ; 45 import javax.swing.event.ListSelectionListener ; 46 import javax.swing.event.TableModelEvent ; 47 import javax.swing.event.TableModelListener ; 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 EditPanelCookies extends DataDisplay { 55 56 private final static boolean debug = false; 57 58 private DisplayTable cookieTable = null; 59 private MonitorData monitorData = null; 60 private boolean setCookies = false; 61 62 JButton newCookieB; 66 JButton editCookieB; 67 JButton deleteCookieB; 68 69 EditPanelCookies() { 70 super(); 71 } 72 73 void redisplayData() { 77 setData(monitorData); 78 this.revalidate(); 79 this.repaint(); 80 } 81 82 void setData(MonitorData md) { 86 87 this.monitorData = md; 88 89 setCookieTable(); 90 91 this.removeAll(); 92 93 String msg = NbBundle.getBundle(EditPanelCookies.class).getString("MON_Cookies_4"); 95 96 int gridy = -1; 97 int fullGridWidth = java.awt.GridBagConstraints.REMAINDER; 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 addGridBagComponent(this, createSortButtonLabel(msg, cookieTable, NbBundle.getBundle(EditPanelCookies.class).getString("MON_Cookies_Mnemonic").charAt(0), NbBundle.getBundle(EditPanelCookies.class).getString("ACS_MON_CookiesA11yDesc")), 0, ++gridy, 107 1, 1, 0, 0, 108 java.awt.GridBagConstraints.WEST, 109 java.awt.GridBagConstraints.NONE, 110 labelInsets, 111 0, 0); 112 113 JScrollPane scrollpane = new JScrollPane (cookieTable); 114 addGridBagComponent(this, scrollpane, 0, ++gridy, 115 fullGridWidth, 1, 1.0, 1.0, 116 java.awt.GridBagConstraints.WEST, 117 java.awt.GridBagConstraints.BOTH, 119 tableInsets, 120 0, 0); 121 122 newCookieB = new JButton (NbBundle.getBundle(EditPanelCookies.class).getString("MON_New_cookie")); 123 newCookieB.setMnemonic(NbBundle.getBundle(EditPanelCookies.class).getString("MON_New_cookie_Mnemonic").charAt(0)); 124 newCookieB.setToolTipText(NbBundle.getBundle(EditPanelCookies.class).getString("ACS_MON_New_cookieA11yDesc")); 125 newCookieB.addActionListener(new ActionListener () { 126 public void actionPerformed(ActionEvent e) { 127 String title = NbBundle.getBundle(EditPanelCookies.class).getString("MON_New_cookie"); 128 ParamEditor pe = new ParamEditor("", "", ParamEditor.Editable.BOTH, 130 ParamEditor.Condition.COOKIE, 131 title); 132 133 if(debug) log(" Now showing dialog"); 135 pe.showDialog(); 136 137 if(debug) log(" Dialog closed"); 139 if (pe.getDialogOK()) { 140 141 if(debug) log(" Dialog returned OK"); String name = pe.getName(); 143 String value = pe.getValue(); 144 if(debug) log(name + " " + value); monitorData.getRequestData().addCookie(name,value); 146 redisplayData(); 147 } 148 }}); 149 150 deleteCookieB = new JButton (NbBundle.getBundle(EditPanelCookies.class).getString("MON_Delete_cookie")); 151 deleteCookieB.setMnemonic(NbBundle.getBundle(EditPanelCookies.class).getString("MON_Delete_cookie_Mnemonic").charAt(0)); 152 deleteCookieB.setToolTipText(NbBundle.getBundle(EditPanelCookies.class).getString("MON_New_cookie_Mnemonic")); 153 154 deleteCookieB.addActionListener(new ActionListener () { 155 156 public void actionPerformed(ActionEvent e) { 157 158 int numRows = cookieTable.getRowCount(); 159 StringBuffer buf = new StringBuffer 160 (NbBundle.getBundle(EditPanelCookies.class).getString("MON_Confirm_Delete_Cookies")); 161 buf.append("\n"); 163 for(int i=0; i<numRows; ++i) { 164 165 if(cookieTable.isRowSelected(i)) { 166 buf.append(cookieTable.getValueAt(i, 0)); 167 buf.append(" "); buf.append(cookieTable.getValueAt(i, 1)); 169 buf.append("\n"); } 171 } 172 173 showConfirmDialog(buf.toString()); 174 if(setCookies) { 175 176 for(int i=0; i<numRows; ++i) { 177 if(cookieTable.isRowSelected(i)) { 178 179 if(debug) log(" deleting cookie " + String.valueOf(i)); 181 182 String name = 183 (String )cookieTable.getValueAt(i, 0); 184 String value = 185 (String )cookieTable.getValueAt(i, 186 1); 187 188 if(debug) log(name + ":" + value); monitorData.getRequestData().deleteCookie(name, value); 190 } 191 } 192 redisplayData(); 193 } 194 }}); 195 196 int gridx = -1; 197 addGridBagComponent(this, createGlue(), ++gridx, ++gridy, 198 1, 1, 1.0, 0, 199 java.awt.GridBagConstraints.WEST, 200 java.awt.GridBagConstraints.NONE, 201 buttonInsets, 202 0, 0); 203 addGridBagComponent(this, newCookieB, ++gridx, gridy, 204 1, 1, 0, 0, 205 java.awt.GridBagConstraints.EAST, 206 java.awt.GridBagConstraints.NONE, 207 buttonInsets, 208 0, 0); 209 210 addGridBagComponent(this, deleteCookieB, ++gridx, gridy, 211 1, 1, 0, 0, 212 java.awt.GridBagConstraints.EAST, 213 java.awt.GridBagConstraints.NONE, 214 buttonInsets, 215 0, 0); 216 217 setEnablings(); 218 219 this.setMaximumSize(this.getPreferredSize()); 220 this.repaint(); 221 } 222 223 void showConfirmDialog(String msg) { 224 225 Object [] options = { NotifyDescriptor.OK_OPTION, 226 NotifyDescriptor.CANCEL_OPTION 227 }; 228 229 NotifyDescriptor confirmDialog = 230 new NotifyDescriptor((Object )msg, 231 NbBundle.getBundle(EditPanelCookies.class).getString("MON_Confirmation_Required"), 232 NotifyDescriptor.OK_CANCEL_OPTION, 233 NotifyDescriptor.QUESTION_MESSAGE, 234 options, 235 NotifyDescriptor.CANCEL_OPTION); 236 237 DialogDisplayer.getDefault().notify(confirmDialog); 238 if(confirmDialog.getValue().equals(NotifyDescriptor.OK_OPTION)) 239 setCookies = true; 240 else 241 setCookies = false; 242 } 243 244 245 void showErrorDialog() { 246 247 Object [] options = { NotifyDescriptor.OK_OPTION }; 248 249 NotifyDescriptor errorDialog = 250 new NotifyDescriptor((Object )NbBundle.getBundle(EditPanelCookies.class).getString("MON_Bad_cookie"), 251 NbBundle.getBundle(EditPanelCookies.class).getString("MON_Invalid_input"), 252 NotifyDescriptor.DEFAULT_OPTION, 253 NotifyDescriptor.ERROR_MESSAGE, 254 options, 255 NotifyDescriptor.OK_OPTION); 256 257 DialogDisplayer.getDefault().notify(errorDialog); 258 } 259 260 261 void setEnablings() { 262 newCookieB.setEnabled(true); 264 265 int selectedRows[] = cookieTable.getSelectedRows(); 267 deleteCookieB.setEnabled(selectedRows.length > 0); 268 } 269 270 void setCookieTable() { 271 272 Param[] params = monitorData.getRequestData().getCookiesAsParams(); 273 cookieTable = new DisplayTable(params, DisplayTable.COOKIES, true); 274 275 cookieTable.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanelCookies.class).getString("ACS_MON_CookiesTableA11yName")); 276 cookieTable.setToolTipText(NbBundle.getBundle(EditPanelCookies.class).getString("ACS_MON_CookiesTableA11yDesc")); 277 278 ListSelectionModel selma = cookieTable.getSelectionModel(); 279 selma.addListSelectionListener(new ListSelectionListener () { 280 public void valueChanged(ListSelectionEvent evt) { 281 if(debug) log(" list selection event"); setEnablings(); 283 } 284 }); 285 286 cookieTable.addTableModelListener(new TableModelListener () { 287 public void tableChanged(TableModelEvent evt) { 288 if(debug) log(" table model changed"); updateCookieHeader(); 290 } 291 }); 292 } 293 294 295 void updateCookieHeader() { 296 297 if(debug) log("updateCookieHeader()"); int numRows = cookieTable.getRowCount(); 299 if(debug) log("Number of rows is: " + String.valueOf(numRows)); 301 if(numRows == 0) { 302 monitorData.getRequestData().setCookieHeader(""); return; 304 } 305 StringBuffer buf = new StringBuffer (); 306 for(int i=0; i<numRows; ++i) { 307 if(i>0) buf.append(";"); buf.append(cookieTable.getValueAt(i,0)); 309 buf.append("="); buf.append(cookieTable.getValueAt(i,1)); 311 } 312 monitorData.getRequestData().setCookieHeader(buf.toString()); 313 if(debug) log(" new cookie string is " + buf.toString()); } 315 316 317 public void repaint() { 318 super.repaint(); 319 } 322 323 void log(String s) { 324 System.out.println("EditPanelCookies::" + s); } 326 327 } 329 330 | Popular Tags |