1 19 20 30 31 32 package org.netbeans.modules.web.monitor.client; 33 34 import javax.swing.*; 35 import javax.swing.table.TableModel ; 36 import java.awt.event.*; 37 import java.util.*; 38 import java.awt.Color ; 39 import java.awt.Component ; 40 import java.awt.Container ; 41 import java.awt.Dialog ; 42 import java.awt.Dimension ; 43 import java.awt.Insets ; 44 import java.awt.GridBagConstraints ; 45 import java.awt.GridBagLayout ; 46 import java.awt.event.*; 47 import org.openide.util.HelpCtx; 48 49 import org.openide.util.NbBundle; 50 51 53 public class NameValueCellEditor extends DefaultCellEditor { 54 55 private final static boolean debug = false; 56 private static String editNameAndValueTitle; 57 private static String editValueOnlyTitle; 58 59 private JTable table; 60 private Object [][] data; 61 private boolean nameEditable; 62 private int row; 63 private int type; 64 65 public static NameValueCellEditor createCellEditor(JTable table, 66 Object data [][], 67 boolean nameEditable, 68 int row, final int type) { 69 70 JButton b = new JButton(NbBundle.getMessage(NameValueCellEditor.class, "MON_Edit_dots")); 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 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 getCellEditorValue() { 114 return NbBundle.getMessage(NameValueCellEditor.class, "MON_Edit_dots"); 115 } 116 117 public Component getTableCellEditorComponent(JTable table, 118 Object 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 model = table.getModel(); 131 String name = (String )model.getValueAt(currentRow, 0); 132 String value = (String )model.getValueAt(currentRow, 1); 133 134 ParamEditor.Condition condition = ParamEditor.Condition.NONE; 135 ParamEditor.Editable editable = ParamEditor.Editable.BOTH; 136 String title = null; 137 138 if(debug) 139 System.out.println("type = " + String.valueOf(type)); 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 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 " + pe.getName() + " " + pe.getValue()); 186 if ((type > DisplayTable.UNEDITABLE) && pe.getDialogOK()) { 187 if(debug) System.out.println("Updating the model"); 189 if (nameEditable) { 190 model.setValueAt(pe.getName(), currentRow, 0); 191 if(debug) System.out.println("Updated the name"); } 193 model.setValueAt(pe.getValue(), currentRow, 1); 194 if(debug) System.out.println("Updated the value"); } 196 } 197 } | Popular Tags |