1 15 package org.apache.tapestry.contrib.table.model.simple; 16 17 import java.io.Serializable ; 18 import java.util.ArrayList ; 19 import java.util.Arrays ; 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.apache.tapestry.contrib.table.model.CTableDataModelEvent; 25 import org.apache.tapestry.contrib.table.model.common.AbstractTableDataModel; 26 import org.apache.tapestry.contrib.table.model.common.ArrayIterator; 27 28 34 public class SimpleListTableDataModel extends AbstractTableDataModel implements Serializable 35 { 36 private static final long serialVersionUID = 1L; 37 38 private List m_arrRows; 39 40 public SimpleListTableDataModel(Object [] arrRows) 41 { 42 this(Arrays.asList(arrRows)); 43 } 44 45 public SimpleListTableDataModel(List arrRows) 46 { 47 m_arrRows = arrRows; 48 } 49 50 public SimpleListTableDataModel(Collection arrRows) 51 { 52 m_arrRows = new ArrayList (arrRows); 53 } 54 55 public SimpleListTableDataModel(Iterator objRows) 56 { 57 m_arrRows = new ArrayList (); 58 addAll(m_arrRows, objRows); 59 } 60 61 private void addAll(List arrRows, Iterator objRows) 62 { 63 while (objRows.hasNext()) 64 arrRows.add(objRows.next()); 65 } 66 67 70 public int getRowCount() 71 { 72 return m_arrRows.size(); 73 } 74 75 79 public Object getRow(int nRow) 80 { 81 if (nRow < 0 || nRow >= m_arrRows.size()) 82 { 83 return null; 85 } 86 return m_arrRows.get(nRow); 87 } 88 89 94 public Iterator getRows(int nFrom, int nTo) 95 { 96 return new ArrayIterator(m_arrRows.toArray(), nFrom, nTo); 97 } 98 99 102 public Iterator getRows() 103 { 104 return m_arrRows.iterator(); 105 } 106 107 112 public void addRow(Object objRow) 113 { 114 m_arrRows.add(objRow); 115 116 CTableDataModelEvent objEvent = new CTableDataModelEvent(); 117 fireTableDataModelEvent(objEvent); 118 } 119 120 public void addRows(Collection arrRows) 121 { 122 m_arrRows.addAll(arrRows); 123 124 CTableDataModelEvent objEvent = new CTableDataModelEvent(); 125 fireTableDataModelEvent(objEvent); 126 } 127 128 133 public void removeRow(Object objRow) 134 { 135 m_arrRows.remove(objRow); 136 137 CTableDataModelEvent objEvent = new CTableDataModelEvent(); 138 fireTableDataModelEvent(objEvent); 139 } 140 141 public void removeRows(Collection arrRows) 142 { 143 m_arrRows.removeAll(arrRows); 144 145 CTableDataModelEvent objEvent = new CTableDataModelEvent(); 146 fireTableDataModelEvent(objEvent); 147 } 148 149 } 150 | Popular Tags |