1 21 package net.mlw.vlh.swing.support; 22 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.List ; 26 27 import org.apache.commons.beanutils.PropertyUtils; 28 29 33 public class DyanBeanTableModel extends AbstractValueListTableModel 34 { 35 private String [] columns = {}; 36 37 private String [] properties = {}; 38 39 private Class [] classes = {}; 40 41 public void addColumn(String title, String property) 42 { 43 addColumn(title, property, Object .class); 44 } 45 46 public void addColumn(String title, String property, Class klass) 47 { 48 List columns = new ArrayList (Arrays.asList(this.columns)); 49 columns.add(title); 50 this.columns = (String []) columns.toArray(new String [] {}); 51 52 List properties = new ArrayList (Arrays.asList(this.properties)); 53 properties.add(property); 54 this.properties = (String []) properties.toArray(new String [] {}); 55 56 List classes = new ArrayList (Arrays.asList(this.classes)); 57 classes.add(klass); 58 this.classes = (Class []) classes.toArray(new Class [] {}); 59 } 60 61 public String getSortPropertyName(int i) 62 { 63 return properties[i]; 64 } 65 66 69 public String getColumnName(int i) 70 { 71 return columns[i]; 72 } 73 74 77 public int getColumnCount() 78 { 79 return columns.length; 80 } 81 82 85 public Object getValueAt(int row, int column) 86 { 87 try 88 { 89 Object bean = list.get(row); 90 if (bean == null) 91 { 92 return null; 93 } 94 return PropertyUtils.getProperty(bean, properties[column]); 95 } 96 catch (Exception e) 97 { 98 return e; 99 } 100 } 101 102 105 public Class getColumnClass(int index) 106 { 107 return classes[index]; 108 } 109 110 } | Popular Tags |