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: * EditPanelCookies.java
044: *
045: *
046: * Created: Fri Feb 9 2001
047: *
048: * @author Ana von Klopp
049: * @version
050: */
051:
052: /**
053: * Contains the Cookie sub-panel for the EditPanel
054: */package org.netbeans.modules.web.monitor.client;
055:
056: import java.awt.event.ActionEvent;
057: import java.awt.event.ActionListener;
058: import java.util.ResourceBundle;
059: import java.util.StringTokenizer;
060: import java.util.Vector;
061: import javax.swing.JButton;
062: import javax.swing.JScrollPane;
063: import javax.swing.ListSelectionModel;
064: import javax.swing.event.ListSelectionEvent;
065: import javax.swing.event.ListSelectionListener;
066: import javax.swing.event.TableModelEvent;
067: import javax.swing.event.TableModelListener;
068: import org.openide.util.NbBundle;
069: import org.openide.DialogDisplayer;
070: import org.openide.NotifyDescriptor;
071:
072: import org.netbeans.modules.web.monitor.data.*;
073:
074: class EditPanelCookies extends DataDisplay {
075:
076: private final static boolean debug = false;
077:
078: private DisplayTable cookieTable = null;
079: private MonitorData monitorData = null;
080: private boolean setCookies = false;
081:
082: //
083: // Widgets
084: //
085: JButton newCookieB;
086: JButton editCookieB;
087: JButton deleteCookieB;
088:
089: EditPanelCookies() {
090: super ();
091: }
092:
093: //
094: // Redesign this, inefficient.
095: //
096: void redisplayData() {
097: setData(monitorData);
098: this .revalidate();
099: this .repaint();
100: }
101:
102: // We're treating these as if they are all strings at the
103: // moment. In reality they can be of different types, though maybe
104: // that does not matter...
105: void setData(MonitorData md) {
106:
107: this .monitorData = md;
108:
109: setCookieTable();
110:
111: this .removeAll();
112:
113: // Cookies
114: String msg = NbBundle.getBundle(EditPanelCookies.class)
115: .getString("MON_Cookies_4");
116:
117: int gridy = -1;
118: int fullGridWidth = java.awt.GridBagConstraints.REMAINDER;
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: addGridBagComponent(this , createSortButtonLabel(msg,
126: cookieTable, NbBundle.getBundle(EditPanelCookies.class)
127: .getString("MON_Cookies_Mnemonic").charAt(0),
128: NbBundle.getBundle(EditPanelCookies.class).getString(
129: "ACS_MON_CookiesA11yDesc")), 0, ++gridy, 1, 1,
130: 0, 0, java.awt.GridBagConstraints.WEST,
131: java.awt.GridBagConstraints.NONE, labelInsets, 0, 0);
132:
133: JScrollPane scrollpane = new JScrollPane(cookieTable);
134: addGridBagComponent(this , scrollpane, 0, ++gridy,
135: fullGridWidth, 1, 1.0, 1.0,
136: java.awt.GridBagConstraints.WEST,
137: //java.awt.GridBagConstraints.HORIZONTAL,
138: java.awt.GridBagConstraints.BOTH, tableInsets, 0, 0);
139:
140: newCookieB = new JButton(NbBundle.getBundle(
141: EditPanelCookies.class).getString("MON_New_cookie"));
142: newCookieB.setMnemonic(NbBundle.getBundle(
143: EditPanelCookies.class).getString(
144: "MON_New_cookie_Mnemonic").charAt(0));
145: newCookieB.setToolTipText(NbBundle.getBundle(
146: EditPanelCookies.class).getString(
147: "ACS_MON_New_cookieA11yDesc"));
148: newCookieB.addActionListener(new ActionListener() {
149: public void actionPerformed(ActionEvent e) {
150: String title = NbBundle.getBundle(
151: EditPanelCookies.class).getString(
152: "MON_New_cookie");
153: ParamEditor pe = new ParamEditor("",
154: "", //NOI18N
155: ParamEditor.Editable.BOTH,
156: ParamEditor.Condition.COOKIE, title);
157:
158: if (debug)
159: log(" Now showing dialog");// NOI18N
160:
161: pe.showDialog();
162:
163: if (debug)
164: log(" Dialog closed"); // NOI18N
165:
166: if (pe.getDialogOK()) {
167:
168: if (debug)
169: log(" Dialog returned OK"); // NOI18N
170: String name = pe.getName();
171: String value = pe.getValue();
172: if (debug)
173: log(name + " " + value); //NOI18N
174: monitorData.getRequestData().addCookie(name, value);
175: redisplayData();
176: }
177: }
178: });
179:
180: deleteCookieB = new JButton(NbBundle.getBundle(
181: EditPanelCookies.class).getString("MON_Delete_cookie"));
182: deleteCookieB.setMnemonic(NbBundle.getBundle(
183: EditPanelCookies.class).getString(
184: "MON_Delete_cookie_Mnemonic").charAt(0));
185: deleteCookieB.setToolTipText(NbBundle.getBundle(
186: EditPanelCookies.class).getString(
187: "MON_New_cookie_Mnemonic"));
188:
189: deleteCookieB.addActionListener(new ActionListener() {
190:
191: public void actionPerformed(ActionEvent e) {
192:
193: int numRows = cookieTable.getRowCount();
194: StringBuffer buf = new StringBuffer(NbBundle.getBundle(
195: EditPanelCookies.class).getString(
196: "MON_Confirm_Delete_Cookies"));
197: buf.append("\n"); // NOI18N
198:
199: for (int i = 0; i < numRows; ++i) {
200:
201: if (cookieTable.isRowSelected(i)) {
202: buf.append(cookieTable.getValueAt(i, 0));
203: buf.append(" "); // NOI18N
204: buf.append(cookieTable.getValueAt(i, 1));
205: buf.append("\n"); // NOI18N
206: }
207: }
208:
209: showConfirmDialog(buf.toString());
210: if (setCookies) {
211:
212: for (int i = 0; i < numRows; ++i) {
213: if (cookieTable.isRowSelected(i)) {
214:
215: if (debug)
216: log(" deleting cookie " + //NOI18N
217: String.valueOf(i));
218:
219: String name = (String) cookieTable
220: .getValueAt(i, 0);
221: String value = (String) cookieTable
222: .getValueAt(i, 1);
223:
224: if (debug)
225: log(name + ":" + value); //NOI18N
226: monitorData.getRequestData().deleteCookie(
227: name, value);
228: }
229: }
230: redisplayData();
231: }
232: }
233: });
234:
235: int gridx = -1;
236: addGridBagComponent(this , createGlue(), ++gridx, ++gridy, 1, 1,
237: 1.0, 0, java.awt.GridBagConstraints.WEST,
238: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
239: addGridBagComponent(this , newCookieB, ++gridx, gridy, 1, 1, 0,
240: 0, java.awt.GridBagConstraints.EAST,
241: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
242:
243: addGridBagComponent(this , deleteCookieB, ++gridx, gridy, 1, 1,
244: 0, 0, java.awt.GridBagConstraints.EAST,
245: java.awt.GridBagConstraints.NONE, buttonInsets, 0, 0);
246:
247: setEnablings();
248:
249: this .setMaximumSize(this .getPreferredSize());
250: this .repaint();
251: }
252:
253: void showConfirmDialog(String msg) {
254:
255: Object[] options = { NotifyDescriptor.OK_OPTION,
256: NotifyDescriptor.CANCEL_OPTION };
257:
258: NotifyDescriptor confirmDialog = new NotifyDescriptor(
259: (Object) msg, NbBundle
260: .getBundle(EditPanelCookies.class).getString(
261: "MON_Confirmation_Required"),
262: NotifyDescriptor.OK_CANCEL_OPTION,
263: NotifyDescriptor.QUESTION_MESSAGE, options,
264: NotifyDescriptor.CANCEL_OPTION);
265:
266: DialogDisplayer.getDefault().notify(confirmDialog);
267: if (confirmDialog.getValue().equals(NotifyDescriptor.OK_OPTION))
268: setCookies = true;
269: else
270: setCookies = false;
271: }
272:
273: void showErrorDialog() {
274:
275: Object[] options = { NotifyDescriptor.OK_OPTION };
276:
277: NotifyDescriptor errorDialog = new NotifyDescriptor(
278: (Object) NbBundle.getBundle(EditPanelCookies.class)
279: .getString("MON_Bad_cookie"), NbBundle
280: .getBundle(EditPanelCookies.class).getString(
281: "MON_Invalid_input"),
282: NotifyDescriptor.DEFAULT_OPTION,
283: NotifyDescriptor.ERROR_MESSAGE, options,
284: NotifyDescriptor.OK_OPTION);
285:
286: DialogDisplayer.getDefault().notify(errorDialog);
287: }
288:
289: void setEnablings() {
290: // Always enable the Add button.
291: newCookieB.setEnabled(true);
292:
293: // The delete row button is enabled if any rows are selected.
294: int selectedRows[] = cookieTable.getSelectedRows();
295: deleteCookieB.setEnabled(selectedRows.length > 0);
296: }
297:
298: void setCookieTable() {
299:
300: Param[] params = monitorData.getRequestData()
301: .getCookiesAsParams();
302: cookieTable = new DisplayTable(params, DisplayTable.COOKIES,
303: true);
304:
305: cookieTable.getAccessibleContext().setAccessibleName(
306: NbBundle.getBundle(EditPanelCookies.class).getString(
307: "ACS_MON_CookiesTableA11yName"));
308: cookieTable.setToolTipText(NbBundle.getBundle(
309: EditPanelCookies.class).getString(
310: "ACS_MON_CookiesTableA11yDesc"));
311:
312: ListSelectionModel selma = cookieTable.getSelectionModel();
313: selma.addListSelectionListener(new ListSelectionListener() {
314: public void valueChanged(ListSelectionEvent evt) {
315: if (debug)
316: log(" list selection event"); // NOI18N
317: setEnablings();
318: }
319: });
320:
321: cookieTable.addTableModelListener(new TableModelListener() {
322: public void tableChanged(TableModelEvent evt) {
323: if (debug)
324: log(" table model changed"); //NOI18N
325: updateCookieHeader();
326: }
327: });
328: }
329:
330: void updateCookieHeader() {
331:
332: if (debug)
333: log("updateCookieHeader()"); //NOI18N
334: int numRows = cookieTable.getRowCount();
335: if (debug)
336: log("Number of rows is: " + // NOI18N
337: String.valueOf(numRows));
338: if (numRows == 0) {
339: monitorData.getRequestData().setCookieHeader(""); //NOI18N
340: return;
341: }
342: StringBuffer buf = new StringBuffer();
343: for (int i = 0; i < numRows; ++i) {
344: if (i > 0)
345: buf.append(";"); //NOI18N
346: buf.append(cookieTable.getValueAt(i, 0));
347: buf.append("="); //NOI18N
348: buf.append(cookieTable.getValueAt(i, 1));
349: }
350: monitorData.getRequestData().setCookieHeader(buf.toString());
351: if (debug)
352: log(" new cookie string is " + buf.toString()); //NOI18N
353: }
354:
355: public void repaint() {
356: super .repaint();
357: //if (editPanel != null)
358: //editPanel.repaint();
359: }
360:
361: void log(String s) {
362: System.out.println("EditPanelCookies::" + s);//NOI18N
363: }
364:
365: } // EditPanelCookies
|