KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > client > EditPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * @author Ana von Klopp
22  */

23
24 /*
25  * TO DO FOR THIS CLASS:
26  *
27  * For PUT requests, the only option on the data panel should be to
28  * upload a file.
29  *
30  * For POST requests, the user should be able to choose between
31  * uploading a file or editing parameters.
32  *
33  */

34
35 package org.netbeans.modules.web.monitor.client;
36
37 import java.awt.Dialog JavaDoc;
38 import java.awt.Dimension JavaDoc;
39 import java.awt.event.*;
40
41 import java.io.IOException JavaDoc;
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 JavaDoc implements
62     ActionListener, ChangeListener {
63
64     // Code to get the displaying of the tabbed panels correct.
65
//
66
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 JavaDoc tabD = new Dimension JavaDoc(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     // Do we need this to close it?
84
private Dialog JavaDoc dialog = null;
85     private DialogDescriptor editDialog = null;
86     
87     private JButton sendButton;
88     private JButton okButton;
89     private JButton cancelButton;
90
91     /* These buttons were used for the feature that allows the user to
92      * specify whether the browser's cookie should be used or whether
93      * to replace it. In 3.6 ("Promotion B"), it is not
94      * possible to configure the monitor to use user-specified
95      * cookies, but I leave the method, in case it becomes possible in
96      * the future. Basically, we can no longer set the cookie on the
97      * server side (the Servlet APIs does not provide any method for
98      * doing this) but we could technically tell the browser that
99      * issues the replay request to send another cookie (the APIs for
100      * that are not there now). If so, the feature can be
101      * reintroduced.
102      *
103      * See also (PENDING) for other changes required to reintroduce
104      * this feature.
105      */

106     //private JToggleButton browserCookieButton, savedCookieButton;
107
//private static boolean useBrowserCookie = true;
108

109     final static String JavaDoc METHOD = "method"; //NOI18N
110
final static String JavaDoc GET = "GET"; //NOI18N
111
final static String JavaDoc POST = "POST"; //NOI18N
112
final static String JavaDoc PUT = "PUT"; //NOI18N
113

114     private static EditPanel instance = null;
115
116     static void displayEditPanel(TransactionNode node) {
117     MonitorData md = null;
118         // We retrieve the data from the file system, not from the
119
// cache
120
md = Controller.getInstance().getMonitorData((TransactionNode)node,
121                                                      false, // from file
122
false); // don't cache
123
if (md == null) {
124         // We couldn't get the data.
125
String JavaDoc 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     //useBrowserCookie = MonitorAction.getController().getUseBrowserCookie();
138
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     // Housekeeping
175
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 JavaDoc[] options = {
189         //createSessionButtonPanel(),
190
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"), //NOI18N
201
this);
202         
203     dialog = DialogDisplayer.getDefault().createDialog(editDialog);
204     dialog.pack();
205     dialog.setVisible(true);
206     }
207     
208
209     /**
210      * Handle user input...
211      */

212
213     public void actionPerformed(ActionEvent e) {
214     
215     String JavaDoc str = new String JavaDoc();
216         Object JavaDoc 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 JavaDoc 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         // Notify the user that there is no host
237

238         Object JavaDoc[] options = {
239                     okButton
240 // NbBundle.getBundle(EditPanel.class).getString("MON_OK"),
241
};
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 JavaDoc ioe) {
256         // Notify the user that the server is not running
257
Object JavaDoc[] options = {
258             NbBundle.getBundle(EditPanel.class).getString("MON_OK"),
259         };
260
261         Object JavaDoc[] 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     /**
282      * Listens to events from the tab pane, displays different
283      * categories of data accordingly.
284      */

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     // Button used by the dialog descriptor
311
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 } // EditPanel
324
Popular Tags