1 19 20 23 24 34 35 package org.netbeans.modules.web.monitor.client; 36 37 import java.awt.Dialog ; 38 import java.awt.Dimension ; 39 import java.awt.event.*; 40 41 import java.io.IOException ; 42 43 import java.net.*; 44 import java.text.*; 45 46 import javax.swing.*; 47 import javax.swing.event.*; 48 49 import java.util.*; 50 51 import org.openide.ErrorManager; 52 import org.openide.DialogDescriptor; 53 import org.openide.DialogDisplayer; 54 import org.openide.NotifyDescriptor; 55 import org.openide.util.HelpCtx; 56 import org.openide.util.NbBundle; 57 58 import org.netbeans.modules.web.monitor.data.*; 59 60 61 class EditPanel extends javax.swing.JPanel implements 62 ActionListener, ChangeListener { 63 64 private int displayType = 0; 67 private static final int DISPLAY_TYPE_QUERY = 0; 68 private static final int DISPLAY_TYPE_REQUEST = 1; 69 private static final int DISPLAY_TYPE_COOKIES = 2; 70 private static final int DISPLAY_TYPE_SERVER = 3; 71 private static final int DISPLAY_TYPE_HEADERS = 4; 72 73 private transient Dimension tabD = new Dimension (450,280); 74 75 private EditPanelQuery queryPanel; 76 private EditPanelRequest requestPanel; 77 private EditPanelCookies cookiesPanel; 78 private EditPanelServer serverPanel; 79 private EditPanelHeaders headersPanel; 80 81 private MonitorData monitorData = null; 82 83 private Dialog dialog = null; 85 private DialogDescriptor editDialog = null; 86 87 private JButton sendButton; 88 private JButton okButton; 89 private JButton cancelButton; 90 91 106 109 final static String METHOD = "method"; final static String GET = "GET"; final static String POST = "POST"; final static String PUT = "PUT"; 114 private static EditPanel instance = null; 115 116 static void displayEditPanel(TransactionNode node) { 117 MonitorData md = null; 118 md = Controller.getInstance().getMonitorData((TransactionNode)node, 121 false, false); if (md == null) { 124 String msg = NbBundle.getMessage(EditPanel.class, "MSG_NoMonitorData"); 126 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, msg); 127 return; 128 } 129 130 if(md.getRequestData().getAttributeValue(METHOD).equals(POST)) 131 Util.removeParametersFromQuery(md.getRequestData()); 132 133 md.getRequestData().deleteCookie("jsessionid"); 134 135 if(instance == null) instance = new EditPanel(); 136 137 instance.showDialog(md); 139 } 140 141 static synchronized EditPanel getInstance() { 142 if(instance == null) instance = new EditPanel(); 143 return instance; 144 } 145 146 private EditPanel() { 147 148 createDialogButtons(); 149 150 this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 151 152 queryPanel = new EditPanelQuery(); 153 requestPanel = new EditPanelRequest(); 154 cookiesPanel = new EditPanelCookies(); 155 serverPanel = new EditPanelServer(); 156 headersPanel = new EditPanelHeaders(); 157 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EditPanel.class,"ACS_MON_Replay_panel")); 158 JTabbedPane tabs = new JTabbedPane(); 159 tabs.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanel.class).getString("ACS_MON_Replay_tabsName")); 160 tabs.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(EditPanel.class).getString("ACS_MON_Replay_tabsDesc")); 161 162 tabs.setPreferredSize(tabD); 163 tabs.addTab(NbBundle.getBundle(EditPanel.class).getString("MON_Query_Panel_Tab"), queryPanel); 164 tabs.addTab(NbBundle.getBundle(EditPanel.class).getString("MON_Request_Panel_Tab"), 165 requestPanel); 166 tabs.addTab(NbBundle.getBundle(EditPanel.class).getString("MON_Cookies_Panel_Tab"), cookiesPanel); 167 tabs.addTab(NbBundle.getBundle(EditPanel.class).getString("MON_Server_Panel_Tab"), serverPanel); 168 tabs.addTab(NbBundle.getBundle(EditPanel.class).getString("MON_Headers_Panel_Tab"), headersPanel); 169 tabs.addChangeListener(this); 170 171 this.add(tabs); 172 this.add(Box.createGlue()); 173 this.add(Box.createVerticalStrut(5)); 174 this.setMaximumSize(this.getPreferredSize()); 176 } 177 178 void showDialog(MonitorData md) { 179 180 this.monitorData = md; 181 182 queryPanel.setData(monitorData); 183 requestPanel.setData(monitorData); 184 cookiesPanel.setData(monitorData); 185 serverPanel.setData(monitorData); 186 headersPanel.setData(monitorData); 187 188 Object [] options = { 189 sendButton, 191 cancelButton, 192 }; 193 194 editDialog = new DialogDescriptor(this, 195 NbBundle.getBundle(EditPanel.class).getString("MON_EditReplay_panel"), 196 false, 197 options, 198 options[0], 199 DialogDescriptor.BOTTOM_ALIGN, 200 new HelpCtx("monitor_resend"), this); 202 203 dialog = DialogDisplayer.getDefault().createDialog(editDialog); 204 dialog.pack(); 205 dialog.setVisible(true); 206 } 207 208 209 212 213 public void actionPerformed(ActionEvent e) { 214 215 String str = new String (); 216 Object value = editDialog.getValue(); 217 if (value == null) 218 return; 219 if (value instanceof JButton) 220 str = ((JButton)value).getText(); 221 else 222 str = value.toString(); 223 if(str.equals(NbBundle.getBundle(EditPanel.class).getString("MON_Send"))) { 224 225 String method = 226 monitorData.getRequestData().getAttributeValue(METHOD); 227 228 if(method.equals(GET)) 229 Util.composeQueryString(monitorData.getRequestData()); 230 231 try { 232 MonitorAction.getController().replayTransaction(monitorData); 233 dialog.dispose(); 234 } 235 catch(UnknownHostException uhe) { 236 238 Object [] options = { 239 okButton 240 }; 242 243 NotifyDescriptor noServerDialog = 244 new NotifyDescriptor 245 (NbBundle.getMessage(EditPanel.class, "MON_Exec_server_wrong", monitorData.getServerName()), 246 NbBundle.getBundle(EditPanel.class).getString("MON_Exec_server"), 247 NotifyDescriptor.DEFAULT_OPTION, 248 NotifyDescriptor.INFORMATION_MESSAGE, 249 options, 250 options[0]); 251 DialogDisplayer.getDefault().notify(noServerDialog); 252 displayType = DISPLAY_TYPE_SERVER; 253 showData(); 254 } 255 catch(IOException ioe) { 256 Object [] options = { 258 NbBundle.getBundle(EditPanel.class).getString("MON_OK"), 259 }; 260 261 Object [] args = { 262 monitorData.getServerName(), 263 monitorData.getServerPortAsString(), 264 }; 265 266 NotifyDescriptor noServerDialog = 267 new NotifyDescriptor 268 (NbBundle.getMessage(EditPanel.class, "MON_Exec_server_start", args), 269 NbBundle.getBundle(EditPanel.class).getString("MON_Exec_server"), 270 NotifyDescriptor.DEFAULT_OPTION, 271 NotifyDescriptor.INFORMATION_MESSAGE, 272 options, 273 options[0]); 274 DialogDisplayer.getDefault().notify(noServerDialog); 275 } 276 } 277 else if(str.equals(NbBundle.getBundle(EditPanel.class).getString("MON_Cancel"))) 278 dialog.dispose(); 279 } 280 281 285 public void stateChanged(ChangeEvent e) { 286 JTabbedPane p = (JTabbedPane)e.getSource(); 287 displayType = p.getSelectedIndex(); 288 289 showData(); 290 } 291 292 293 void showData() { 294 295 if (displayType == DISPLAY_TYPE_QUERY) 296 queryPanel.setData(monitorData); 297 else if (displayType == DISPLAY_TYPE_REQUEST) 298 requestPanel.setData(monitorData); 299 else if (displayType == DISPLAY_TYPE_COOKIES) 300 cookiesPanel.setData(monitorData); 301 else if (displayType == DISPLAY_TYPE_SERVER) 302 serverPanel.setData(monitorData); 303 else if (displayType == DISPLAY_TYPE_HEADERS) 304 headersPanel.setData(monitorData); 305 } 306 307 308 private void createDialogButtons() { 309 310 sendButton = new JButton(NbBundle.getBundle(EditPanel.class).getString("MON_Send")); 312 sendButton.setMnemonic(NbBundle.getBundle(EditPanel.class).getString("MON_Send_Mnemonic").charAt(0)); 313 sendButton.setToolTipText(NbBundle.getBundle(EditPanel.class).getString("ACS_MON_SendA11yDesc")); 314 315 okButton = new JButton(NbBundle.getBundle(EditPanel.class).getString("MON_OK")); 316 okButton.setMnemonic(NbBundle.getBundle(EditPanel.class).getString("MON_OK_Mnemonic").charAt(0)); 317 okButton.setToolTipText(NbBundle.getBundle(EditPanel.class).getString("ACS_MON_OKA11yDesc")); 318 319 cancelButton = new JButton(NbBundle.getBundle(EditPanel.class).getString("MON_Cancel")); 320 cancelButton.setMnemonic(NbBundle.getBundle(EditPanel.class).getString("MON_Cancel_Mnemonic").charAt(0)); 321 cancelButton.setToolTipText(NbBundle.getBundle(EditPanel.class).getString("ACS_MON_CancelA11yDesc")); 322 } 323 } | Popular Tags |