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