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: * NameValueCellEditor.java
044: *
045: *
046: * Created: Thursday Feb 15
047: *
048: * @author Simran Gleason
049: * @author Ana von Klopp
050: * @version
051: */package org.netbeans.modules.web.monitor.client;
052:
053: import javax.swing.*;
054: import javax.swing.table.TableModel;
055: import java.awt.event.*;
056: import java.util.*;
057: import java.awt.Color;
058: import java.awt.Component;
059: import java.awt.Container;
060: import java.awt.Dialog;
061: import java.awt.Dimension;
062: import java.awt.Insets;
063: import java.awt.GridBagConstraints;
064: import java.awt.GridBagLayout;
065: import java.awt.event.*;
066: import org.openide.util.HelpCtx;
067:
068: import org.openide.util.NbBundle;
069:
070: /* Should this one get the events from the Param editor? MAO, far
071: * Param editorn vara non-modal? */
072: public class NameValueCellEditor extends DefaultCellEditor {
073:
074: private final static boolean debug = false;
075: private static String editNameAndValueTitle;
076: private static String editValueOnlyTitle;
077:
078: private JTable table;
079: private Object[][] data;
080: private boolean nameEditable;
081: private int row;
082: private int type;
083:
084: public static NameValueCellEditor createCellEditor(JTable table,
085: Object data[][], boolean nameEditable, int row,
086: final int type) {
087:
088: JButton b = new JButton(NbBundle.getMessage(
089: NameValueCellEditor.class, "MON_Edit_dots")); // NOI18N
090: if (type == DisplayTable.UNEDITABLE)
091: b.setToolTipText(NbBundle.getMessage(
092: NameValueCellEditor.class, "MON_DisplayValue"));
093: else
094: b.setToolTipText(NbBundle.getMessage(
095: NameValueCellEditor.class, "MON_EditAttribute"));
096: final NameValueCellEditor ed = new NameValueCellEditor(b,
097: table, data, nameEditable, row, type);
098:
099: b.addActionListener(new ActionListener() {
100: public void actionPerformed(ActionEvent evt) {
101: ed.showParamEditor();
102: }
103: });
104:
105: return ed;
106: }
107:
108: public NameValueCellEditor(JButton b, JTable table,
109: Object data[][], boolean nameEditable, int row, int type) {
110: super (new JCheckBox());
111: editorComponent = b;
112: setClickCountToStart(1);
113:
114: this .table = table;
115: this .data = data;
116: this .nameEditable = nameEditable;
117: this .row = row;
118: this .type = type;
119: }
120:
121: protected void fireEditingStopped() {
122: super .fireEditingStopped();
123: }
124:
125: public Object getCellEditorValue() {
126: return NbBundle.getMessage(NameValueCellEditor.class,
127: "MON_Edit_dots");
128: }
129:
130: public Component getTableCellEditorComponent(JTable table,
131: Object value, boolean isSelected, int row, int column) {
132: ((JButton) editorComponent).setText(value.toString());
133: return editorComponent;
134: }
135:
136: public void showParamEditor() {
137:
138: int currentRow = table.getSelectedRow();
139: TableModel model = table.getModel();
140: String name = (String) model.getValueAt(currentRow, 0);
141: String value = (String) model.getValueAt(currentRow, 1);
142:
143: ParamEditor.Condition condition = ParamEditor.Condition.NONE;
144: ParamEditor.Editable editable = ParamEditor.Editable.BOTH;
145: String title = null;
146:
147: if (debug)
148: System.out.println("type = " + String.valueOf(type)); //NOI18N
149:
150: if (type == DisplayTable.UNEDITABLE) {
151: editable = ParamEditor.Editable.NEITHER;
152: title = NbBundle.getMessage(NameValueCellEditor.class,
153: "MON_ParamValue");
154: } else if (type == DisplayTable.HEADERS) {
155: title = NbBundle.getMessage(NameValueCellEditor.class,
156: "MON_Edit_header");
157: condition = ParamEditor.Condition.HEADER;
158: } else if (type == DisplayTable.PARAMS)
159: title = NbBundle.getMessage(NameValueCellEditor.class,
160: "MON_Edit_param");
161: else if (type == DisplayTable.REQUEST) {
162: editable = ParamEditor.Editable.VALUE;
163: title = NbBundle.getMessage(NameValueCellEditor.class,
164: "MON_Edit_request");
165: condition = ParamEditor.Condition.VALUE;
166: } else if (type == DisplayTable.COOKIES) {
167: title = NbBundle.getMessage(NameValueCellEditor.class,
168: "MON_Edit_cookie");
169: condition = ParamEditor.Condition.COOKIE;
170: } else if (type == DisplayTable.SERVER) {
171: title = NbBundle.getMessage(NameValueCellEditor.class,
172: "MON_Edit_server");
173: condition = ParamEditor.Condition.VALUE;
174: editable = ParamEditor.Editable.VALUE;
175: }
176: // This should not happen
177: else
178: title = NbBundle.getMessage(NameValueCellEditor.class,
179: "MON_Edit_value");
180:
181: ParamEditor pe = new ParamEditor(name, value, editable,
182: condition, title);
183:
184: pe.showDialog();
185:
186: if (debug)
187: System.out.println("NameValueCellEditor::has " + //NOI18N
188: pe.getName() + " " + pe.getValue());//NOI18N
189:
190: if ((type > DisplayTable.UNEDITABLE) && pe.getDialogOK()) {
191: if (debug)
192: System.out.println("Updating the model");//NOI18N
193:
194: if (nameEditable) {
195: model.setValueAt(pe.getName(), currentRow, 0);
196: if (debug)
197: System.out.println("Updated the name");//NOI18N
198: }
199: model.setValueAt(pe.getValue(), currentRow, 1);
200: if (debug)
201: System.out.println("Updated the value");//NOI18N
202: }
203: }
204: } // NameValueCellEditor
|