001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /**
043: * EditPanelRequest.java
044: *
045: *
046: * Created: Fri Feb 9 2001
047: *
048: * @author Ana von Klopp
049: * @author Simran Gleason
050: * @version
051: */
052:
053: /**
054: * Contains the Request sub-panel for the EditPanel
055: */package org.netbeans.modules.web.monitor.client;
056:
057: import java.awt.event.*;
058: import javax.swing.event.TableModelEvent;
059: import javax.swing.event.TableModelListener;
060: import java.util.ResourceBundle;
061: import java.util.Hashtable;
062: import org.openide.util.NbBundle;
063: import org.netbeans.modules.web.monitor.data.*;
064:
065: class EditPanelRequest extends DataDisplay {
066:
067: private final static boolean debug = false;
068:
069: private static final String[] methodChoices = { EditPanel.GET,
070: EditPanel.POST, EditPanel.PUT };
071:
072: private DisplayTable requestTable = null;
073: private MonitorData monitorData = null;
074:
075: EditPanelRequest() {
076: super ();
077: }
078:
079: // Redesign this. It is inefficient and prevents us from
080: // maintaining the sorting state
081: void redisplayData() {
082: setData(monitorData);
083: }
084:
085: void setData(MonitorData md) {
086:
087: this .monitorData = md;
088: if (debug)
089: log("setData()"); // NOI18N
090: setRequestTable();
091:
092: this .removeAll();
093:
094: int gridy = -1;
095: int fullGridWidth = java.awt.GridBagConstraints.REMAINDER;
096:
097: addGridBagComponent(this , createTopSpacer(), 0, ++gridy,
098: fullGridWidth, 1, 0, 0,
099: java.awt.GridBagConstraints.WEST,
100: java.awt.GridBagConstraints.NONE, topSpacerInsets, 0, 0);
101:
102: addGridBagComponent(this , createHeaderLabel(NbBundle.getBundle(
103: EditPanelRequest.class).getString("MON_Request_19"),
104: NbBundle.getBundle(EditPanelRequest.class).getString(
105: "MON_Request_19_Mnemonic").charAt(0), NbBundle
106: .getBundle(EditPanelRequest.class).getString(
107: "ACS_MON_Request_19A11yDesc"),
108: requestTable), 0, ++gridy, fullGridWidth, 1, 0, 0,
109: java.awt.GridBagConstraints.WEST,
110: java.awt.GridBagConstraints.NONE, labelInsets, 0, 0);
111:
112: addGridBagComponent(this , requestTable, 0, ++gridy,
113: fullGridWidth, 1, 1.0, 0,
114: java.awt.GridBagConstraints.NORTHWEST,
115: java.awt.GridBagConstraints.HORIZONTAL, tableInsets, 0,
116: 0);
117:
118: addGridBagComponent(this , createGlue(), 0, ++gridy, 1, 1, 1.0,
119: 1.0, java.awt.GridBagConstraints.WEST,
120: java.awt.GridBagConstraints.BOTH, zeroInsets, 0, 0);
121:
122: int gridx = -1;
123: addGridBagComponent(this , createGlue(), ++gridx, ++gridy, 1, 1,
124: 1.0, 0, java.awt.GridBagConstraints.WEST,
125: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
126:
127: // Housekeeping
128: this .setMaximumSize(this .getPreferredSize());
129: this .repaint();
130: }
131:
132: void setRequestTable() {
133:
134: String[] requestCategories = {
135: NbBundle.getBundle(EditPanelRequest.class).getString(
136: "MON_Request_URI"),
137: NbBundle.getBundle(EditPanelRequest.class).getString(
138: "MON_Method"),
139: NbBundle.getBundle(EditPanelRequest.class).getString(
140: "MON_Protocol") };
141:
142: requestTable = new DisplayTable(requestCategories,
143: DisplayTable.REQUEST);
144:
145: RequestData rd = monitorData.getRequestData();
146: requestTable.setValueAt(rd.getAttributeValue("uri"), 0, 1); //NOI18N
147: requestTable.setValueAt(rd.getAttributeValue(EditPanel.METHOD),
148: 1, 1);
149: requestTable.setValueAt(rd.getAttributeValue("protocol"), 2, 1); // NOI18N
150:
151: javax.swing.JComboBox box = requestTable.setChoices(1, 1,
152: methodChoices, false);
153: box.getAccessibleContext().setAccessibleName(
154: requestCategories[1]);
155: box.getAccessibleContext().setAccessibleDescription(
156: NbBundle.getMessage(EditPanelRequest.class,
157: "ACS_MON_RequestMethod"));
158: requestTable.getAccessibleContext().setAccessibleName(
159: NbBundle.getBundle(EditPanelRequest.class).getString(
160: "ACS_MON_RequestTable_19A11yName"));
161: requestTable.setToolTipText(NbBundle.getBundle(
162: EditPanelRequest.class).getString(
163: "ACS_MON_RequestTable_19A11yDesc"));
164:
165: requestTable.addTableModelListener(new TableModelListener() {
166: public void tableChanged(TableModelEvent evt) {
167:
168: if (debug)
169: log("tableChanged"); //NOI18N
170:
171: RequestData rd = monitorData.getRequestData();
172:
173: // The query panel depends on the value of the
174: // method attribute.
175: String method = rd.getAttributeValue(EditPanel.METHOD);
176: String newMethod = (String) requestTable.getValueAt(1,
177: 1);
178: if (method != null && !method.equals(newMethod)) {
179: rd.setAttributeValue(EditPanel.METHOD, newMethod);
180:
181: if (method.equals(EditPanel.GET)
182: && newMethod.equals(EditPanel.POST)) {
183:
184: // Set the query string to null if we got
185: // parameters from it, o/w leave it as is
186: try {
187: String queryString = rd
188: .getAttributeValue("queryString"); //NOI18N
189: Hashtable ht = javax.servlet.http.HttpUtils
190: .parseQueryString(queryString);
191: rd.setAttributeValue("queryString", ""); //NOI18N
192: } catch (Exception ex) {
193: }
194:
195: } else if (method.equals(EditPanel.POST)
196: && newMethod.equals(EditPanel.GET)) {
197: Util.addParametersToQuery(rd);
198: }
199: }
200:
201: //
202: // Set the rest...
203: //
204: String uri = (String) requestTable.getValueAt(0, 1);
205: uri = uri.trim();
206:
207: String protocol = (String) requestTable
208: .getValueAt(2, 1);
209: protocol = protocol.trim();
210: rd.setAttributeValue("uri", uri); //NOI18N
211: rd.setAttributeValue("protocol", protocol); //NOI18N
212: }
213: });
214: }
215:
216: public void repaint() {
217: super .repaint();
218: //if (editPanel != null)
219: // editPanel.repaint();
220: }
221:
222: void log(String s) {
223: System.out.println("EditPanelRequest::" + s); //NOI18N
224: }
225:
226: } // EditPanelRequest
|