KickJava   Java API By Example, From Geeks To Geeks.

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


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * EditPanelRequest.java
22  *
23  *
24  * Created: Fri Feb 9 2001
25  *
26  * @author Ana von Klopp
27  * @author Simran Gleason
28  * @version
29  */

30
31 /**
32  * Contains the Request sub-panel for the EditPanel
33  */

34
35 package org.netbeans.modules.web.monitor.client;
36
37 import java.awt.event.*;
38 import javax.swing.event.TableModelEvent JavaDoc;
39 import javax.swing.event.TableModelListener JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41 import java.util.Hashtable JavaDoc;
42 import org.openide.util.NbBundle;
43 import org.netbeans.modules.web.monitor.data.*;
44
45 class EditPanelRequest extends DataDisplay {
46
47     private final static boolean debug = false;
48
49     private static final String JavaDoc [] methodChoices = {
50     EditPanel.GET,
51     EditPanel.POST,
52     EditPanel.PUT
53     };
54
55     private DisplayTable requestTable = null;
56     private MonitorData monitorData = null;
57     
58     EditPanelRequest() {
59     super();
60     }
61     
62     // Redesign this. It is inefficient and prevents us from
63
// maintaining the sorting state
64
void redisplayData() {
65     setData(monitorData);
66     }
67
68     void setData(MonitorData md) {
69
70     this.monitorData = md;
71     if(debug) log("setData()"); // NOI18N
72
setRequestTable();
73
74     this.removeAll();
75     
76     int gridy = -1;
77     int fullGridWidth = java.awt.GridBagConstraints.REMAINDER;
78
79     addGridBagComponent(this, createTopSpacer(), 0, ++gridy,
80                 fullGridWidth, 1, 0, 0,
81                 java.awt.GridBagConstraints.WEST,
82                 java.awt.GridBagConstraints.NONE,
83                 topSpacerInsets,
84                 0, 0);
85
86     addGridBagComponent(this,
87                 createHeaderLabel
88                 (NbBundle.getBundle(EditPanelRequest.class).getString("MON_Request_19"),
89                  NbBundle.getBundle(EditPanelRequest.class).getString("MON_Request_19_Mnemonic").charAt(0),
90                  NbBundle.getBundle(EditPanelRequest.class).getString("ACS_MON_Request_19A11yDesc"),
91                  requestTable),
92                 0, ++gridy,
93                 fullGridWidth, 1, 0, 0,
94                 java.awt.GridBagConstraints.WEST,
95                 java.awt.GridBagConstraints.NONE,
96                 labelInsets,
97                 0, 0);
98
99     addGridBagComponent(this, requestTable, 0, ++gridy,
100                 fullGridWidth, 1, 1.0, 0,
101                 java.awt.GridBagConstraints.NORTHWEST,
102                 java.awt.GridBagConstraints.HORIZONTAL,
103                 tableInsets,
104                 0, 0);
105
106     addGridBagComponent(this, createGlue(), 0, ++gridy,
107                 1, 1, 1.0, 1.0,
108                 java.awt.GridBagConstraints.WEST,
109                 java.awt.GridBagConstraints.BOTH,
110                 zeroInsets,
111                 0, 0);
112
113
114     int gridx = -1;
115     addGridBagComponent(this, createGlue(), ++gridx, ++gridy,
116                 1, 1, 1.0, 0,
117                 java.awt.GridBagConstraints.WEST,
118                 java.awt.GridBagConstraints.NONE,
119                 buttonInsets,
120                 0, 0);
121
122     // Housekeeping
123
this.setMaximumSize(this.getPreferredSize());
124     this.repaint();
125     }
126
127     void setRequestTable() {
128     
129     String JavaDoc[] requestCategories = {
130         NbBundle.getBundle(EditPanelRequest.class).getString("MON_Request_URI"),
131         NbBundle.getBundle(EditPanelRequest.class).getString("MON_Method"),
132         NbBundle.getBundle(EditPanelRequest.class).getString("MON_Protocol")
133     };
134
135     requestTable =
136         new DisplayTable(requestCategories, DisplayTable.REQUEST);
137
138     RequestData rd = monitorData.getRequestData();
139     requestTable.setValueAt(rd.getAttributeValue("uri"), 0,1); //NOI18N
140
requestTable.setValueAt(rd.getAttributeValue(EditPanel.METHOD),1,1);
141     requestTable.setValueAt(rd.getAttributeValue("protocol"), 2,1); // NOI18N
142

143     javax.swing.JComboBox JavaDoc box = requestTable.setChoices(1, 1, methodChoices, false);
144         box.getAccessibleContext().setAccessibleName(requestCategories[1]);
145         box.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EditPanelRequest.class,"ACS_MON_RequestMethod"));
146         requestTable.getAccessibleContext().setAccessibleName(NbBundle.getBundle(EditPanelRequest.class).getString("ACS_MON_RequestTable_19A11yName"));
147         requestTable.setToolTipText(NbBundle.getBundle(EditPanelRequest.class).getString("ACS_MON_RequestTable_19A11yDesc"));
148
149     requestTable.addTableModelListener(new TableModelListener JavaDoc() {
150         public void tableChanged(TableModelEvent JavaDoc evt) {
151
152             if(debug) log("tableChanged"); //NOI18N
153

154             RequestData rd = monitorData.getRequestData();
155
156             // The query panel depends on the value of the
157
// method attribute.
158
String JavaDoc method = rd.getAttributeValue(EditPanel.METHOD);
159             String JavaDoc newMethod = (String JavaDoc)requestTable.getValueAt(1, 1);
160             if (method != null && !method.equals(newMethod)) {
161             rd.setAttributeValue(EditPanel.METHOD, newMethod);
162
163             if(method.equals(EditPanel.GET) && newMethod.equals(EditPanel.POST)) {
164
165                 // Set the query string to null if we got
166
// parameters from it, o/w leave it as is
167
try {
168                 String JavaDoc queryString =
169                     rd.getAttributeValue("queryString"); //NOI18N
170
Hashtable JavaDoc ht =
171                     javax.servlet.http.HttpUtils.parseQueryString(queryString);
172                 rd.setAttributeValue("queryString", ""); //NOI18N
173
}
174                 catch(Exception JavaDoc ex) { }
175
176
177             }
178             else if(method.equals(EditPanel.POST) &&
179                 newMethod.equals(EditPanel.GET)) {
180                 Util.addParametersToQuery(rd);
181             }
182             }
183
184             //
185
// Set the rest...
186
//
187
String JavaDoc uri = (String JavaDoc)requestTable.getValueAt(0,1);
188             uri = uri.trim();
189
190             String JavaDoc protocol = (String JavaDoc)requestTable.getValueAt(2,1);
191             protocol = protocol.trim();
192             rd.setAttributeValue("uri", uri); //NOI18N
193
rd.setAttributeValue("protocol", protocol); //NOI18N
194
}});
195     }
196
197     public void repaint() {
198     super.repaint();
199     //if (editPanel != null)
200
// editPanel.repaint();
201
}
202
203     void log(String JavaDoc s) {
204     System.out.println("EditPanelRequest::" + s); //NOI18N
205
}
206     
207 } // EditPanelRequest
208
Popular Tags