1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class SimpleListTableDataModel extends AbstractTableDataModel implements |
35 | |
Serializable |
36 | |
{ |
37 | |
|
38 | |
private static final long serialVersionUID = 1L; |
39 | |
|
40 | |
private List m_arrRows; |
41 | |
|
42 | |
public SimpleListTableDataModel(Object[] arrRows) |
43 | |
{ |
44 | 0 | this(Arrays.asList(arrRows)); |
45 | 0 | } |
46 | |
|
47 | |
public SimpleListTableDataModel(List arrRows) |
48 | 0 | { |
49 | 0 | m_arrRows = arrRows; |
50 | 0 | } |
51 | |
|
52 | |
public SimpleListTableDataModel(Collection arrRows) |
53 | 0 | { |
54 | 0 | m_arrRows = new ArrayList(arrRows); |
55 | 0 | } |
56 | |
|
57 | |
public SimpleListTableDataModel(Iterator objRows) |
58 | 0 | { |
59 | 0 | m_arrRows = new ArrayList(); |
60 | 0 | addAll(m_arrRows, objRows); |
61 | 0 | } |
62 | |
|
63 | |
private void addAll(List arrRows, Iterator objRows) |
64 | |
{ |
65 | 0 | while(objRows.hasNext()) |
66 | 0 | arrRows.add(objRows.next()); |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public int getRowCount() |
73 | |
{ |
74 | 0 | return m_arrRows.size(); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
public Object getRow(int nRow) |
84 | |
{ |
85 | 0 | if (nRow < 0 || nRow >= m_arrRows.size()) |
86 | |
{ |
87 | |
|
88 | 0 | return null; |
89 | |
} |
90 | 0 | return m_arrRows.get(nRow); |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public Iterator getRows(int nFrom, int nTo) |
102 | |
{ |
103 | 0 | return new ArrayIterator(m_arrRows.toArray(), nFrom, nTo); |
104 | |
} |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public Iterator getRows() |
110 | |
{ |
111 | 0 | return m_arrRows.iterator(); |
112 | |
} |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public void addRow(Object objRow) |
121 | |
{ |
122 | 0 | m_arrRows.add(objRow); |
123 | |
|
124 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
125 | 0 | fireTableDataModelEvent(objEvent); |
126 | 0 | } |
127 | |
|
128 | |
public void addRows(Collection arrRows) |
129 | |
{ |
130 | 0 | m_arrRows.addAll(arrRows); |
131 | |
|
132 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
133 | 0 | fireTableDataModelEvent(objEvent); |
134 | 0 | } |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public void removeRow(Object objRow) |
143 | |
{ |
144 | 0 | m_arrRows.remove(objRow); |
145 | |
|
146 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
147 | 0 | fireTableDataModelEvent(objEvent); |
148 | 0 | } |
149 | |
|
150 | |
public void removeRows(Collection arrRows) |
151 | |
{ |
152 | 0 | m_arrRows.removeAll(arrRows); |
153 | |
|
154 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
155 | 0 | fireTableDataModelEvent(objEvent); |
156 | 0 | } |
157 | |
|
158 | |
} |