1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import java.util.List ; 23 import javax.swing.table.AbstractTableModel ; 25 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 26 27 public abstract class DDBeanTableModel extends AbstractTableModel 28 { 29 private List children; 30 private CommonDDBean parent; 31 32 protected abstract String [] getColumnNames(); 33 34 protected CommonDDBean getParent() { 35 return parent; 36 } 37 38 protected List getChildren() { 39 return children; 40 } 41 42 public int getColumnCount() 43 { 44 return getColumnNames().length; 45 } 46 47 48 public int getRowCount() 49 { 50 if (children != null) 51 { 52 return (children.size()); 53 } 54 else 55 { 56 return (0); 57 } 58 } 59 60 61 public String getColumnName(int column) 62 { 63 return getColumnNames()[column]; 64 } 65 66 public boolean isCellEditable(int row, int column) 67 { 68 return (false); 69 } 70 71 public int getRowWithValue(int column, Object value) 72 { 73 for(int row = 0; row < getRowCount(); row++) 74 { 75 Object obj = getValueAt(row, column); 76 if (obj.equals(value)) 77 { 78 return (row); 79 } 80 } 81 82 return (-1); 83 } 84 85 public abstract CommonDDBean addRow(Object [] values); 86 87 public abstract void editRow(int row, Object [] values); 88 89 public abstract void removeRow(int row); 90 91 public void setData(CommonDDBean parent,CommonDDBean[] children) { 92 this.parent = parent; 93 this.children = new java.util.ArrayList (); 94 if (children==null) return; 95 for(int i=0;i<children.length;i++) 96 this.children.add(children[i]); 97 fireTableDataChanged(); 98 } 99 100 } | Popular Tags |