1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.beans;
9
10 import java.util.ArrayList;
11 import java.util.Arrays;
12 import java.util.Collection;
13 import java.util.Iterator;
14 import java.util.List;
15
16 /***
17 * <!-- $Id: BasicBeanTableModel.java,v 1.2 2002/10/09 21:37:37 tirsen Exp $ -->
18 * <!-- $Author: tirsen $ -->
19 *
20 * @author Jon Tirs´n (tirsen@users.sourceforge.net)
21 * @version $Revision: 1.2 $
22 */
23 public class BasicBeanTableModel extends BeanTableModel
24 {
25 private List rows;
26
27 public BasicBeanTableModel()
28 {
29 }
30
31 public BasicBeanTableModel(Class rowClass)
32 {
33 super(rowClass);
34 }
35
36 protected List getRows()
37 {
38 if (rows == null) throw new IllegalStateException("Tried to access model before initializing rows.");
39 return rows;
40 }
41
42 public int getRowCount()
43 {
44 int rowCount = super.getRowCount();
45 if (rowCount == -1)
46 {
47 if (rows == null)
48 rowCount = 0;
49 else
50 rowCount = getRows().size();
51 }
52 return rowCount;
53 }
54
55 public void setRow(int row, Object object)
56 {
57 ensureCapable(row);
58 rows.set(row, object);
59 }
60
61 /***
62 * Sets a segment of rows starting at specified startRow.
63 */
64 public void setRows(int startRow, Collection objects)
65 {
66 ensureCapable(startRow + objects.size());
67 int row = startRow;
68 for (Iterator iterator = objects.iterator(); iterator.hasNext();)
69 {
70 Object o = (Object) iterator.next();
71 rows.set(row++, o);
72 }
73 }
74
75 private void ensureCapable(int row)
76 {
77 if (rows == null) rows = new ArrayList(row);
78 int size = rows.size();
79 for (int i = size - row; i < size + 1; i++)
80 {
81 rows.add(null);
82 }
83 }
84
85 public void setRows(Object[] rows)
86 {
87 if (rows != null)
88 this.rows = Arrays.asList(rows);
89 else
90 this.rows = null;
91 }
92
93 public void setRows(List rows)
94 {
95 this.rows = new ArrayList(rows);
96 }
97
98 public void setRows(Iterator iterator)
99 {
100 rows = new ArrayList();
101 while (iterator.hasNext())
102 {
103 Object o = (Object) iterator.next();
104 rows.add(o);
105 }
106 }
107
108 public void empty()
109 {
110 super.empty();
111 rows = null;
112 }
113 }
This page was automatically generated by Maven