1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common; 26 27 import java.util.ArrayList ; 28 import java.util.Hashtable ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 import java.awt.Component ; 33 34 import javax.swing.JComboBox ; 35 import javax.swing.JTable ; 36 import javax.swing.table.AbstractTableModel ; 37 import javax.swing.table.TableCellRenderer ; 38 39 40 44 public abstract class MethodTableModel extends AbstractTableModel { 45 46 protected List ddMethods; 47 protected List methods; 48 49 50 private Map methodToDDMethodMap; 52 53 54 55 public MethodTableModel(List methods, List ddMethods) { 56 if (methods != null) { 57 this.methods = new ArrayList (); 58 for(int i = 0;i < methods.size(); i++) { 59 this.methods.add(methods.get(i)); 60 } 61 } 62 63 if (ddMethods != null) { 64 this.ddMethods = new ArrayList (); 65 for(int i = 0;i < ddMethods.size(); i++) { 66 this.ddMethods.add(ddMethods.get(i)); 67 } 68 } 69 setMap(); 70 fireTableDataChanged(); 71 } 72 73 74 public void setData(List methods, List ddMethods) { 75 if (methods != null) { 76 this.methods = new ArrayList (); 77 for(int i = 0;i < methods.size(); i++) { 78 this.methods.add(methods.get(i)); 79 } 80 } 81 82 if (ddMethods != null) { 83 this.ddMethods = new ArrayList (); 84 for(int i = 0;i < ddMethods.size(); i++) { 85 this.ddMethods.add(ddMethods.get(i)); 86 } 87 } 88 89 92 setMap(); 93 fireTableDataChanged(); 94 } 95 96 97 public MethodTableModel(List methods) { 98 this(methods, null); 99 } 100 101 102 protected MethodTableModel() { 103 } 104 105 106 public int getColumnCount() { 107 return getColumnNames().length; 108 } 109 110 111 public String getColumnName(int column) { 112 return getColumnNames()[column]; 113 } 114 115 116 public Class getColumnClass(int column) { 117 switch(column){ 118 case 0: { 119 return String .class; 120 } 121 case 1: { 122 return Boolean .class; 123 } 124 default: { 125 return getColumnType(column); 126 } 127 } 128 } 129 130 131 public int getRowCount() { 132 if (methods != null){ 133 return methods.size(); 134 } else { 135 return 0; 136 } 137 } 138 139 140 144 public boolean isCellEditable(int row, int col) { 145 if (col == 0) { 148 return false; 149 } else { 150 return true; 151 } 152 } 153 154 155 public Object getValueAt(int row, int col) { 156 switch(col){ 157 case 0: { 158 Object method = methods.get(row); 160 if(method != null){ 161 return getValueAt(col, method, row); 166 }else{ 167 return null; 168 } 169 } 170 case 1: { 171 if(methodToDDMethodMap != null){ 173 if(methodToDDMethodMap.containsKey(methods.get(row))){ 174 return new Boolean ("true"); } 176 } 177 return new Boolean ("false"); } 179 default: { 180 if(methodToDDMethodMap != null){ 181 Object ddMethod = methodToDDMethodMap.get(methods.get(row)); 182 if(ddMethod != null){ 183 return getDDValueAt(col, ddMethod); 184 } 185 } else return null; 186 } 187 } 188 return null; 189 } 190 191 192 196 public void setValueAt(Object value, int row, int col) { 197 switch(col){ 198 case 0: { 199 } 200 break; 201 case 1: { 202 Object method = methods.get(row); 203 Object ddMethod = null; 204 if(methodToDDMethodMap != null){ 205 ddMethod = methodToDDMethodMap.get(method); 206 } 207 Boolean enable = (Boolean )value; 208 if(enable.toString().equals("true")){ if(ddMethod == null){ 210 enableMethod(method); 211 } 212 }else{ 213 if(ddMethod != null){ 214 disableMethod(method, ddMethod); 215 } 216 } 217 } 218 break; 219 default: { 220 if(methodToDDMethodMap != null){ 221 Object ddMethod = methodToDDMethodMap.get(methods.get(row)); 222 if(ddMethod != null){ 223 setDDValueAt(col, ddMethod, value); 224 } 225 } 226 } 227 break; 228 } 229 fireTableCellUpdated(row, col); 230 } 231 232 233 protected abstract String [] getColumnNames(); 234 235 protected abstract Class getColumnType(int column); 236 237 protected abstract Object getValueAt(int column, Object method, int row); 241 242 protected abstract Object getDDValueAt(int column, Object ddMethod); 243 244 protected abstract void setDDValueAt(int column, Object ddMethod, Object value); 245 246 protected abstract Object getDDMethod(Object method); 247 248 protected abstract void addDDMethod(Object ddMethod); 249 250 protected abstract void removeDDMethod(Object ddMethod); 251 252 protected abstract boolean areEqual(Object ddMethod, Object method); 253 254 255 protected void setMap(){ 256 methodToDDMethodMap = new Hashtable (); 258 if(methods == null) return; 259 Object method = null; 260 if(ddMethods != null){ 261 for(int i=0; i<ddMethods.size(); i++){ 262 Object ddMethod = ddMethods.get(i); 263 method = getMethod(ddMethod, methods); 264 assert(method != null); 265 if(method != null){ 266 methodToDDMethodMap.put(method, ddMethod); 267 } 268 } 269 } 270 } 271 272 273 private void enableMethod(Object method){ 274 Object ddMethod = getDDObject(method); 275 if(methodToDDMethodMap == null){ 276 methodToDDMethodMap = new Hashtable (); 277 } 278 methodToDDMethodMap.put(method, ddMethod); 279 addDDMethod(ddMethod); 280 fireTableDataChanged(); 281 } 282 283 284 private Object getDDObject(Object method){ 285 return getDDMethod(method); 286 } 287 288 289 private void disableMethod(Object method, Object ddMethod){ 290 if(methodToDDMethodMap != null){ 291 methodToDDMethodMap.remove(method); 292 removeDDMethod(ddMethod); 293 } 294 fireTableDataChanged(); 295 } 296 297 298 private Object getMethod(Object ddMethod, List methods){ 299 for(int i=0; i<methods.size(); i++){ 300 if(areEqual(ddMethod, methods.get(i))){ 301 return methods.get(i); 302 } 303 } 304 return null; 305 } 306 307 308 private void printList(List list){ 309 if(list != null){ 310 System.out.println("printList list --" + list); System.out.println("printList list toString -- " + list.toString()); int size = list.size(); 313 for(int i=0; i<size; i++){ 314 System.out.println("printList item no: i -- " + list.get(i)); System.out.println("printList item no: i toSring() -- " + list.get(i).toString()); } 317 } 318 } 319 } 320 | Popular Tags |