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: * EditPanelQuery.java
044: *
045: *
046: * Created: Mon Feb 5 13:34:46 2001
047: *
048: * @author Ana von Klopp
049: * @author Simran Gleason
050: * @version
051: */
052:
053: /**
054: * Contains the Query sub-panel for the EditPanel
055: */package org.netbeans.modules.web.monitor.client;
056:
057: import java.awt.Component;
058: import java.awt.event.ActionEvent;
059: import java.awt.event.ActionListener;
060: import java.awt.event.FocusEvent;
061: import java.awt.event.FocusListener;
062: import java.util.ResourceBundle;
063: import javax.swing.JButton;
064: import javax.swing.JPanel;
065: import javax.swing.JTextField;
066: import javax.swing.JScrollPane;
067: import javax.swing.ListSelectionModel;
068: import javax.swing.event.ListSelectionEvent;
069: import javax.swing.event.ListSelectionListener;
070: import javax.swing.event.TableModelEvent;
071: import javax.swing.event.TableModelListener;
072:
073: import org.openide.NotifyDescriptor;
074: import org.openide.DialogDisplayer;
075: import org.openide.util.NbBundle;
076:
077: import org.netbeans.modules.web.monitor.data.*;
078:
079: class EditPanelQuery extends DataDisplay {
080:
081: private final static boolean debug = false;
082:
083: private DisplayTable paramTable = null;
084: private MonitorData monitorData = null;
085: private boolean setParams = false;
086:
087: // Widgets
088: JButton newParamB;
089: JButton deleteParamB;
090: JTextField queryStringText;
091: JTextField uploadFileText;
092:
093: EditPanelQuery() {
094: super ();
095: }
096:
097: // Redesign this, inefficient and prevents us from maintaining
098: // sorting state
099: void redisplayData() {
100: if (debug)
101: log("::redisplayData()");
102: setData(monitorData);
103: this .revalidate();
104: this .repaint();
105: }
106:
107: void setData(MonitorData md) {
108:
109: if (debug) {
110: log("setData()"); // NOI18N
111: log("\tMonitor data is:"); // NOI18N
112: log("t" + md.dumpBeanNode()); // NOI18N
113: }
114: this .monitorData = md;
115: this .removeAll();
116:
117: int fullGridWidth = java.awt.GridBagConstraints.REMAINDER;
118: int gridy = -1;
119:
120: addGridBagComponent(this , createTopSpacer(), 0, ++gridy,
121: fullGridWidth, 1, 0, 0,
122: java.awt.GridBagConstraints.WEST,
123: java.awt.GridBagConstraints.NONE, topSpacerInsets, 0, 0);
124:
125: // The query parameters: PENDING
126: //
127: // 1. Get request - add a parameter one at a time. We should not
128: // allow the user to edit the query string.
129: // 2. POST request. Allow the user to edit the query string,
130: // and then there are two cases:
131: // a) add a parameter one at a time
132: // b) add data from file
133: // 3. PUT request. Allow the user to enter data from a file
134: // only. They can edit the query string as well.
135:
136: final RequestData rd = monitorData.getRequestData();
137:
138: String method = rd.getAttributeValue(EditPanel.METHOD);
139: if (EditPanel.POST.equals(method)) {
140: queryStringText = new JTextField(rd
141: .getAttributeValue("queryString")); // NOI18N
142:
143: queryStringText.addFocusListener(new FocusListener() {
144: public void focusGained(FocusEvent evt) {
145: }
146:
147: public void focusLost(FocusEvent evt) {
148: // PENDING - check that this works
149: rd.setAttributeValue("queryString", //NOI18N
150: queryStringText.getText());
151: }
152: });
153:
154: addGridBagComponent(
155: this ,
156: createHeaderLabel(
157: NbBundle.getBundle(EditPanelQuery.class)
158: .getString("MON_Querystring"),
159: NbBundle.getBundle(EditPanelQuery.class)
160: .getString(
161: "MON_Querystring_Mnemonic")
162: .charAt(0),
163: NbBundle
164: .getBundle(EditPanelQuery.class)
165: .getString(
166: "ACS_MON_QuerystringA11yDesc"),
167: paramTable), 0, ++gridy, 1, 1, 0, 0,
168: java.awt.GridBagConstraints.WEST,
169: java.awt.GridBagConstraints.NONE, labelInsets, 0, 0);
170:
171: addGridBagComponent(this , queryStringText, 0, ++gridy,
172: fullGridWidth, 1, 1.0, 0,
173: java.awt.GridBagConstraints.WEST,
174: java.awt.GridBagConstraints.HORIZONTAL,
175: tableInsets, 0, 0);
176: }
177:
178: String msg2 = null;
179: Component msg2Label;
180:
181: if (EditPanel.PUT.equals(method)) {
182: msg2 = NbBundle.getBundle(EditPanelQuery.class).getString(
183: "MON_Upload_File");
184: msg2Label = createDataLabel(msg2);
185: addGridBagComponent(this , msg2Label, 0, ++gridy,
186: fullGridWidth, 1, 0, 0,
187: java.awt.GridBagConstraints.WEST,
188: java.awt.GridBagConstraints.NONE, labelInsets, 0, 0);
189:
190: String uploadFileMsg = NbBundle.getBundle(
191: EditPanelQuery.class).getString(
192: "MON_Upload_File_Not_Supported");
193: uploadFileText = new JTextField(uploadFileMsg);
194: uploadFileText.setEnabled(false);
195: addGridBagComponent(this , uploadFileText, 0, ++gridy,
196: fullGridWidth, 1, 1.0, 0,
197: java.awt.GridBagConstraints.WEST,
198: java.awt.GridBagConstraints.HORIZONTAL,
199: labelInsets, 0, 0);
200: addGridBagComponent(this , createGlue(), 0, ++gridy, 1, 1,
201: 1.0, 1.0, java.awt.GridBagConstraints.WEST,
202: java.awt.GridBagConstraints.BOTH, labelInsets, 0, 0);
203:
204: } else if (method != null) { // GET or POST
205:
206: Param[] params2 = rd.getParam();
207: if (params2 == null)
208: params2 = new Param[0];
209: setParameters(params2);
210: char mnemonic = ' ';
211: String ad = null;
212:
213: if (method.equals(EditPanel.GET)) {
214: msg2 = NbBundle.getBundle(EditPanelQuery.class)
215: .getString("MON_Query_parameters");
216: mnemonic = NbBundle.getBundle(EditPanelQuery.class)
217: .getString("MON_Query_parameters_Mnemonic")
218: .charAt(0);
219: ad = NbBundle.getBundle(EditPanelQuery.class)
220: .getString("ACS_MON_Query_parametersA11yDesc");
221: paramTable
222: .getAccessibleContext()
223: .setAccessibleName(
224: NbBundle
225: .getBundle(EditPanelQuery.class)
226: .getString(
227: "ACS_MON_ParametersTableA11yDesc"));
228: paramTable.setToolTipText(NbBundle.getBundle(
229: EditPanelQuery.class).getString(
230: "ACS_MON_ParametersTableA11yDesc"));
231:
232: } else if (method.equals(EditPanel.POST)) {
233: msg2 = NbBundle.getBundle(EditPanelQuery.class)
234: .getString("MON_Posted_data");
235: mnemonic = NbBundle.getBundle(EditPanelQuery.class)
236: .getString("MON_Posted_data_Mnemonic")
237: .charAt(0);
238: ad = NbBundle.getBundle(EditPanelQuery.class)
239: .getString("ACS_MON_Posted_dataA11yDesc");
240: paramTable
241: .getAccessibleContext()
242: .setAccessibleName(
243: NbBundle
244: .getBundle(EditPanelQuery.class)
245: .getString(
246: "ACS_MON_Posted_dataTableA11yName"));
247: paramTable.setToolTipText(NbBundle.getBundle(
248: EditPanelQuery.class).getString(
249: "ACS_MON_Posted_dataTableA11yDesc"));
250: }
251:
252: msg2Label = createSortButtonLabel(msg2, paramTable,
253: mnemonic, ad);
254:
255: addGridBagComponent(this , msg2Label, 0, ++gridy, 1, 1, 0,
256: 0, java.awt.GridBagConstraints.WEST,
257: java.awt.GridBagConstraints.NONE, labelInsets, 0, 0);
258:
259: gridy = addParamTable(this , params2, gridy);
260: }
261:
262: setEnablings();
263:
264: // Housekeeping
265: this .setMaximumSize(this .getPreferredSize());
266: this .repaint();
267:
268: }
269:
270: private int addParamTable(JPanel panel, Param[] params, int gridy) {
271:
272: JScrollPane scrollpane = new JScrollPane(paramTable);
273:
274: addGridBagComponent(panel, scrollpane, 0, ++gridy,
275: fullGridWidth, 1, 1.0, 1.0,
276: java.awt.GridBagConstraints.WEST,
277: //java.awt.GridBagConstraints.HORIZONTAL,
278: java.awt.GridBagConstraints.BOTH, tableInsets, 0, 0);
279:
280: newParamB = new JButton(NbBundle
281: .getBundle(EditPanelQuery.class).getString(
282: "MON_New_param"));
283: newParamB.setMnemonic(NbBundle.getBundle(EditPanelQuery.class)
284: .getString("MON_New_param_Mnemonic").charAt(0));
285: newParamB.setToolTipText(NbBundle.getBundle(
286: EditPanelQuery.class).getString(
287: "ACS_MON_New_paramA11yDesc"));
288: newParamB.addActionListener(new ActionListener() {
289: public void actionPerformed(ActionEvent e) {
290:
291: String title = NbBundle.getBundle(EditPanelQuery.class)
292: .getString("MON_New_param");
293: ParamEditor pe = new ParamEditor("",
294: "", //NOI18N
295: ParamEditor.Editable.BOTH,
296: ParamEditor.Condition.NONE, title);
297:
298: if (debug)
299: log("Now showing dialog"); // NOI18N
300:
301: pe.showDialog();
302:
303: if (debug)
304: log("Dialog closed"); // NOI18N
305:
306: if (pe.getDialogOK()) {
307:
308: if (debug)
309: log("Dialog returned OK"); // NOI18N
310: String name = pe.getName();
311: String value = pe.getValue();
312: Param newParam = new Param(name, value);
313: monitorData.getRequestData().addParam(newParam);
314: redisplayData();
315: }
316: }
317: });
318:
319: deleteParamB = new JButton(NbBundle.getBundle(
320: EditPanelQuery.class).getString("MON_Delete_param"));
321: deleteParamB.setMnemonic(NbBundle.getBundle(
322: EditPanelQuery.class).getString(
323: "MON_Delete_param_Mnemonic").charAt(0));
324: deleteParamB.setToolTipText(NbBundle.getBundle(
325: EditPanelQuery.class).getString(
326: "ACS_MON_Delete_paramA11yDesc"));
327:
328: deleteParamB.addActionListener(new ActionListener() {
329:
330: public void actionPerformed(ActionEvent e) {
331:
332: int numRows = paramTable.getRowCount();
333: RequestData rd = monitorData.getRequestData();
334:
335: StringBuffer buf = new StringBuffer(NbBundle.getBundle(
336: EditPanelQuery.class).getString(
337: "MON_Confirm_Delete_Params"));
338: buf.append("\n"); //NOI18N
339:
340: for (int i = 0; i < numRows; ++i) {
341:
342: if (paramTable.isRowSelected(i)) {
343: buf.append(paramTable.getValueAt(i, 0));
344: buf.append("="); //NOI18N
345: buf.append(paramTable.getValueAt(i, 1));
346: buf.append("\n"); //NOI18N
347: }
348: }
349:
350: showConfirmDialog(buf.toString());
351:
352: if (setParams) {
353:
354: for (int i = 0; i < numRows; ++i) {
355:
356: if (paramTable.isRowSelected(i)) {
357: String name = (String) paramTable
358: .getValueAt(i, 0);
359: String value = (String) paramTable
360: .getValueAt(i, 1);
361:
362: // Note that we get the params each
363: // time through so that we don't run
364: // into null pointer exceptions.
365: Param[] params2 = rd.getParam();
366: Param param = findParam(params2, name,
367: value);
368: if (param != null)
369: rd.removeParam(param);
370: }
371: }
372: redisplayData();
373: }
374: }
375: });
376: int gridx = -1;
377: addGridBagComponent(this , createGlue(), ++gridx, ++gridy, 1, 1,
378: 1.0, 0, java.awt.GridBagConstraints.WEST,
379: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
380: addGridBagComponent(this , newParamB, ++gridx, gridy, 1, 1, 0,
381: 0, java.awt.GridBagConstraints.EAST,
382: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
383:
384: addGridBagComponent(this , deleteParamB, ++gridx, gridy, 1, 1,
385: 0, 0, java.awt.GridBagConstraints.EAST,
386: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
387: return gridy;
388: }
389:
390: void setEnablings() {
391: //
392: // Always enable the Add button.
393: //
394: newParamB.setEnabled(true);
395:
396: // The delete row button is enabled if any rows are selected.
397: int selectedRows[] = paramTable.getSelectedRows();
398: deleteParamB.setEnabled(selectedRows.length > 0);
399: }
400:
401: void setParameters(Param[] newParams) {
402:
403: paramTable = new DisplayTable(newParams, DisplayTable.PARAMS,
404: true);
405: paramTable.getAccessibleContext().setAccessibleName(
406: NbBundle.getBundle(EditPanelQuery.class).getString(
407: "ACS_MON_QuerystringTableA11yName"));
408: paramTable.setToolTipText(NbBundle.getBundle(
409: EditPanelQuery.class).getString(
410: "ACS_MON_QuerystringTableA11yDesc"));
411:
412: ListSelectionModel selma = paramTable.getSelectionModel();
413: selma.addListSelectionListener(new ListSelectionListener() {
414: public void valueChanged(ListSelectionEvent evt) {
415: if (debug)
416: log("paramTable list selection listener"); // NOI18N
417: setEnablings();
418: }
419: });
420:
421: paramTable.addTableModelListener(new TableModelListener() {
422: public void tableChanged(TableModelEvent evt) {
423: updateParams();
424: }
425: });
426: }
427:
428: void updateParams() {
429: int num = paramTable.getRowCount();
430: RequestData rd = monitorData.getRequestData();
431: Param[] params = rd.getParam();
432:
433: for (int i = 0; i < num; i++) {
434: String name = (String) paramTable.getValueAt(i, 0);
435: name = name.trim();
436: if (name.equals("")) { //NOI18N
437: paramTable.setValueAt(params[i].getName(), i, 0);
438: showErrorDialog();
439: return;
440: }
441: String value = (String) paramTable.getValueAt(i, 1);
442: value = value.trim();
443: params[i].setName(name);
444: params[i].setValue(value);
445: }
446: }
447:
448: void showConfirmDialog(String msg) {
449:
450: Object[] options = { NotifyDescriptor.OK_OPTION,
451: NotifyDescriptor.CANCEL_OPTION };
452:
453: NotifyDescriptor confirmDialog = new NotifyDescriptor(
454: (Object) msg, NbBundle.getBundle(EditPanelQuery.class)
455: .getString("MON_Confirmation_Required"),
456: NotifyDescriptor.OK_CANCEL_OPTION,
457: NotifyDescriptor.QUESTION_MESSAGE, options,
458: NotifyDescriptor.CANCEL_OPTION);
459:
460: DialogDisplayer.getDefault().notify(confirmDialog);
461: if (confirmDialog.getValue().equals(NotifyDescriptor.OK_OPTION))
462: setParams = true;
463: else
464: setParams = false;
465: }
466:
467: void showErrorDialog() {
468:
469: Object[] options = { NotifyDescriptor.OK_OPTION };
470:
471: NotifyDescriptor errorDialog = new NotifyDescriptor(
472: (Object) NbBundle.getBundle(EditPanelQuery.class)
473: .getString("MON_Bad_param"), NbBundle
474: .getBundle(EditPanelQuery.class).getString(
475: "MON_Invalid_input"),
476: NotifyDescriptor.DEFAULT_OPTION,
477: NotifyDescriptor.ERROR_MESSAGE, options,
478: NotifyDescriptor.OK_OPTION);
479:
480: DialogDisplayer.getDefault().notify(errorDialog);
481: }
482:
483: void log(String s) {
484: System.out.println("EditPanelQuery::" + s); //NOI18N
485: }
486:
487: } // EditPanel
|