|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SimpleListTableDataModel.java | 0% | 0% | 0% | 0% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
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 |
* A minimal list implementation of the
|
|
30 |
* {@link org.apache.tapestry.contrib.table.model.ITableDataModel} interface
|
|
31 |
*
|
|
32 |
* @author mindbridge
|
|
33 |
*/
|
|
34 |
public class SimpleListTableDataModel extends AbstractTableDataModel implements Serializable |
|
35 |
{ |
|
36 |
private List m_arrRows;
|
|
37 |
|
|
38 | 0 |
public SimpleListTableDataModel(Object[] arrRows)
|
39 |
{ |
|
40 | 0 |
this(Arrays.asList(arrRows));
|
41 |
} |
|
42 |
|
|
43 | 0 |
public SimpleListTableDataModel(List arrRows)
|
44 |
{ |
|
45 | 0 |
m_arrRows = arrRows; |
46 |
} |
|
47 |
|
|
48 | 0 |
public SimpleListTableDataModel(Collection arrRows)
|
49 |
{ |
|
50 | 0 |
m_arrRows = new ArrayList(arrRows);
|
51 |
} |
|
52 |
|
|
53 | 0 |
public SimpleListTableDataModel(Iterator objRows)
|
54 |
{ |
|
55 | 0 |
m_arrRows = new ArrayList();
|
56 | 0 |
addAll(m_arrRows, objRows); |
57 |
} |
|
58 |
|
|
59 | 0 |
private void addAll(List arrRows, Iterator objRows) |
60 |
{ |
|
61 | 0 |
while (objRows.hasNext())
|
62 | 0 |
arrRows.add(objRows.next()); |
63 |
} |
|
64 |
|
|
65 |
/**
|
|
66 |
* @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRowCount()
|
|
67 |
*/
|
|
68 | 0 |
public int getRowCount() |
69 |
{ |
|
70 | 0 |
return m_arrRows.size();
|
71 |
} |
|
72 |
|
|
73 |
/**
|
|
74 |
* Returns the row element at the given position
|
|
75 |
* @param nRow the index of the element to return
|
|
76 |
*/
|
|
77 | 0 |
public Object getRow(int nRow) |
78 |
{ |
|
79 | 0 |
if (nRow < 0 || nRow >= m_arrRows.size())
|
80 |
{ |
|
81 |
// error message
|
|
82 | 0 |
return null; |
83 |
} |
|
84 | 0 |
return m_arrRows.get(nRow);
|
85 |
} |
|
86 |
|
|
87 |
/**
|
|
88 |
* Returns an Iterator with the elements from the given range
|
|
89 |
* @param nFrom the start of the range (inclusive)
|
|
90 |
* @param nTo the stop of the range (exclusive)
|
|
91 |
*/
|
|
92 | 0 |
public Iterator getRows(int nFrom, int nTo) |
93 |
{ |
|
94 | 0 |
return new ArrayIterator(m_arrRows.toArray(), nFrom, nTo); |
95 |
} |
|
96 |
|
|
97 |
/**
|
|
98 |
* @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRows()
|
|
99 |
*/
|
|
100 | 0 |
public Iterator getRows()
|
101 |
{ |
|
102 | 0 |
return m_arrRows.iterator();
|
103 |
} |
|
104 |
|
|
105 |
/**
|
|
106 |
* Method addRow.
|
|
107 |
* Adds a row object to the model at its end
|
|
108 |
* @param objRow the row object to add
|
|
109 |
*/
|
|
110 | 0 |
public void addRow(Object objRow) |
111 |
{ |
|
112 | 0 |
m_arrRows.add(objRow); |
113 |
|
|
114 | 0 |
CTableDataModelEvent objEvent = new CTableDataModelEvent();
|
115 | 0 |
fireTableDataModelEvent(objEvent); |
116 |
} |
|
117 |
|
|
118 | 0 |
public void addRows(Collection arrRows) |
119 |
{ |
|
120 | 0 |
m_arrRows.addAll(arrRows); |
121 |
|
|
122 | 0 |
CTableDataModelEvent objEvent = new CTableDataModelEvent();
|
123 | 0 |
fireTableDataModelEvent(objEvent); |
124 |
} |
|
125 |
|
|
126 |
/**
|
|
127 |
* Method removeRow.
|
|
128 |
* Removes a row object from the model
|
|
129 |
* @param objRow the row object to remove
|
|
130 |
*/
|
|
131 | 0 |
public void removeRow(Object objRow) |
132 |
{ |
|
133 | 0 |
m_arrRows.remove(objRow); |
134 |
|
|
135 | 0 |
CTableDataModelEvent objEvent = new CTableDataModelEvent();
|
136 | 0 |
fireTableDataModelEvent(objEvent); |
137 |
} |
|
138 |
|
|
139 | 0 |
public void removeRows(Collection arrRows) |
140 |
{ |
|
141 | 0 |
m_arrRows.removeAll(arrRows); |
142 |
|
|
143 | 0 |
CTableDataModelEvent objEvent = new CTableDataModelEvent();
|
144 | 0 |
fireTableDataModelEvent(objEvent); |
145 |
} |
|
146 |
|
|
147 |
} |
|
148 |
|
|