KickJava   Java API By Example, From Geeks To Geeks.

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


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  * NameValueCellEditor.java
22  *
23  *
24  * Created: Thursday Feb 15
25  *
26  * @author Simran Gleason
27  * @author Ana von Klopp
28  * @version
29  */

30
31
32 package org.netbeans.modules.web.monitor.client;
33
34 import javax.swing.*;
35 import javax.swing.table.TableModel JavaDoc;
36 import java.awt.event.*;
37 import java.util.*;
38 import java.awt.Color JavaDoc;
39 import java.awt.Component JavaDoc;
40 import java.awt.Container JavaDoc;
41 import java.awt.Dialog JavaDoc;
42 import java.awt.Dimension JavaDoc;
43 import java.awt.Insets JavaDoc;
44 import java.awt.GridBagConstraints JavaDoc;
45 import java.awt.GridBagLayout JavaDoc;
46 import java.awt.event.*;
47 import org.openide.util.HelpCtx;
48
49 import org.openide.util.NbBundle;
50
51 /* Should this one get the events from the Param editor? MAO, far
52  * Param editorn vara non-modal? */

53 public class NameValueCellEditor extends DefaultCellEditor {
54
55     private final static boolean debug = false;
56     private static String JavaDoc editNameAndValueTitle;
57     private static String JavaDoc editValueOnlyTitle;
58
59     private JTable table;
60     private Object JavaDoc[][] data;
61     private boolean nameEditable;
62     private int row;
63     private int type;
64
65     public static NameValueCellEditor createCellEditor(JTable table,
66                                Object JavaDoc data [][],
67                                boolean nameEditable,
68                                int row, final int type) {
69
70     JButton b = new JButton(NbBundle.getMessage(NameValueCellEditor.class, "MON_Edit_dots")); // NOI18N
71
if(type == DisplayTable.UNEDITABLE)
72         b.setToolTipText(NbBundle.getMessage(NameValueCellEditor.class, "MON_DisplayValue")) ;
73     else
74         b.setToolTipText(NbBundle.getMessage(NameValueCellEditor.class, "MON_EditAttribute")) ;
75     final NameValueCellEditor ed = new NameValueCellEditor(b,
76                                    table,
77                                    data,
78                                    nameEditable,
79                                    row, type);
80
81     b.addActionListener(new ActionListener() {
82         public void actionPerformed(ActionEvent evt) {
83         ed.showParamEditor();
84         }
85     });
86
87     return ed;
88     }
89
90                     
91     public NameValueCellEditor(JButton b,
92                    JTable table,
93                    Object JavaDoc data [][],
94                    boolean nameEditable,
95                    int row,
96                    int type) {
97     super(new JCheckBox());
98     editorComponent = b;
99     setClickCountToStart(1);
100
101     this.table = table;
102     this.data = data;
103     this.nameEditable = nameEditable;
104     this.row = row;
105     this.type = type;
106     }
107
108     
109     protected void fireEditingStopped() {
110     super.fireEditingStopped();
111     }
112     
113     public Object JavaDoc getCellEditorValue() {
114     return NbBundle.getMessage(NameValueCellEditor.class, "MON_Edit_dots");
115     }
116  
117     public Component JavaDoc getTableCellEditorComponent(JTable table,
118                          Object JavaDoc value,
119                          boolean isSelected,
120                          int row,
121                          int column) {
122     ((JButton)editorComponent).setText(value.toString());
123     return editorComponent;
124     }
125
126
127     public void showParamEditor() {
128
129     int currentRow = table.getSelectedRow();
130     TableModel JavaDoc model = table.getModel();
131     String JavaDoc name = (String JavaDoc)model.getValueAt(currentRow, 0);
132     String JavaDoc value = (String JavaDoc)model.getValueAt(currentRow, 1);
133
134     ParamEditor.Condition condition = ParamEditor.Condition.NONE;
135     ParamEditor.Editable editable = ParamEditor.Editable.BOTH;
136     String JavaDoc title = null;
137     
138     if(debug)
139         System.out.println("type = " + String.valueOf(type)); //NOI18N
140

141     if(type == DisplayTable.UNEDITABLE) {
142         editable = ParamEditor.Editable.NEITHER;
143         title = NbBundle.getMessage(NameValueCellEditor.class,
144                     "MON_ParamValue");
145     }
146     else if(type == DisplayTable.HEADERS) {
147         title = NbBundle.getMessage(NameValueCellEditor.class,
148                     "MON_Edit_header");
149         condition = ParamEditor.Condition.HEADER;
150     }
151     else if(type == DisplayTable.PARAMS)
152         title = NbBundle.getMessage(NameValueCellEditor.class,
153                     "MON_Edit_param");
154     else if(type == DisplayTable.REQUEST) {
155         editable = ParamEditor.Editable.VALUE;
156         title = NbBundle.getMessage(NameValueCellEditor.class,
157                     "MON_Edit_request");
158         condition = ParamEditor.Condition.VALUE;
159     }
160     else if(type == DisplayTable.COOKIES) {
161         title = NbBundle.getMessage(NameValueCellEditor.class,
162                     "MON_Edit_cookie");
163         condition = ParamEditor.Condition.COOKIE;
164     }
165     else if(type == DisplayTable.SERVER) {
166         title = NbBundle.getMessage(NameValueCellEditor.class,
167                     "MON_Edit_server");
168         condition = ParamEditor.Condition.VALUE;
169         editable = ParamEditor.Editable.VALUE;
170     }
171     // This should not happen
172
else
173         title = NbBundle.getMessage(NameValueCellEditor.class, "MON_Edit_value");
174     
175
176
177     ParamEditor pe = new ParamEditor(name, value, editable, condition,
178                      title);
179
180     pe.showDialog();
181
182     if(debug)
183         System.out.println("NameValueCellEditor::has " + //NOI18N
184
pe.getName() + " " + pe.getValue());//NOI18N
185

186     if ((type > DisplayTable.UNEDITABLE) && pe.getDialogOK()) {
187         if(debug) System.out.println("Updating the model");//NOI18N
188

189         if (nameEditable) {
190         model.setValueAt(pe.getName(), currentRow, 0);
191         if(debug) System.out.println("Updated the name");//NOI18N
192
}
193         model.setValueAt(pe.getValue(), currentRow, 1);
194         if(debug) System.out.println("Updated the value");//NOI18N
195
}
196     }
197 } // NameValueCellEditor
198
Popular Tags