/*
* Angkor Web Framework
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package com.tirsen.angkor.beans;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* <!-- $Id: BasicBeanTableModel.java,v 1.2 2002/10/09 21:37:37 tirsen Exp $ -->
* <!-- $Author: tirsen $ -->
* @author Jon Tirs´n (tirsen@users.sourceforge.net)
* @version $Revision: 1.2 $
public class BasicBeanTableModel extends BeanTableModel
{
private List rows;
public BasicBeanTableModel()
}
public BasicBeanTableModel(Class rowClass)
super(rowClass);
protected List getRows()
if (rows == null) throw new IllegalStateException("Tried to access model before initializing rows.");
return rows;
public int getRowCount()
int rowCount = super.getRowCount();
if (rowCount == -1)
if (rows == null)
rowCount = 0;
else
rowCount = getRows().size();
return rowCount;
public void setRow(int row, Object object)
ensureCapable(row);
rows.set(row, object);
* Sets a segment of rows starting at specified startRow.
public void setRows(int startRow, Collection objects)
ensureCapable(startRow + objects.size());
int row = startRow;
for (Iterator iterator = objects.iterator(); iterator.hasNext();)
Object o = (Object) iterator.next();
rows.set(row++, o);
private void ensureCapable(int row)
if (rows == null) rows = new ArrayList(row);
int size = rows.size();
for (int i = size - row; i < size + 1; i++)
rows.add(null);
public void setRows(Object[] rows)
if (rows != null)
this.rows = Arrays.asList(rows);
this.rows = null;
public void setRows(List rows)
this.rows = new ArrayList(rows);
public void setRows(Iterator iterator)
rows = new ArrayList();
while (iterator.hasNext())
rows.add(o);
public void empty()
super.empty();
rows = null;