| 1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common; 26 27 33 34 import java.util.ArrayList ; 35 import java.util.List ; 36 37 import javax.swing.table.AbstractTableModel ; 38 39 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 40 41 42 public abstract class BeanTableModel extends AbstractTableModel { 43 44 private List children; 45 private Object parent; 46 47 48 public int getColumnCount() { 50 return getColumnNames().length; 51 } 52 53 54 public int getRowCount() { 55 if (children != null){ 56 return children.size(); 57 } else { 58 return 0; 59 } 60 } 61 62 63 public String getColumnName(int column) { 64 return getColumnNames()[column]; 65 } 66 67 68 public boolean isCellEditable(int row, int column) { 69 return false; 70 } 71 72 73 protected abstract String [] getColumnNames(); 75 76 public abstract Object addRow(Object [] values); 77 78 public abstract void editRow(int row, Object [] values); 79 80 public abstract void removeRow(int row); 81 82 public abstract boolean alreadyExists(Object [] values); 83 84 public abstract Object [] getValues(int row); 85 86 87 public void setData(Object parent, CommonDDBean[] children) { 88 this.parent = parent; 89 this.children = new ArrayList (); 90 91 if (children == null) { 92 return; 93 } 94 95 for(int i = 0;i < children.length; i++) { 96 this.children.add(children[i]); 97 } 98 99 fireTableDataChanged(); 100 } 101 102 103 public int getRowWithValue(int column, Object value) { 104 for(int row = 0, max = getRowCount(); row < max; row++) { 105 Object obj = getValueAt(row, column); 106 if (obj.equals(value)) { 107 return row; 108 } 109 } 110 return -1; 111 } 112 113 114 protected Object getParent() { 115 return parent; 116 } 117 118 119 protected List getChildren() { 120 return children; 121 } 122 } 123 | Popular Tags |