Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
SimpleSetTableDataModel |
|
| 1.5714285714285714;1.571 |
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.Collection; |
|
19 | import java.util.Iterator; |
|
20 | import java.util.Set; |
|
21 | ||
22 | import org.apache.tapestry.contrib.table.model.CTableDataModelEvent; |
|
23 | import org.apache.tapestry.contrib.table.model.common.AbstractTableDataModel; |
|
24 | ||
25 | /** |
|
26 | * A minimal set implementation of the |
|
27 | * {@link org.apache.tapestry.contrib.table.model.ITableDataModel} interface. |
|
28 | * |
|
29 | * @author mindbridge |
|
30 | */ |
|
31 | public class SimpleSetTableDataModel extends AbstractTableDataModel implements |
|
32 | Serializable |
|
33 | { |
|
34 | ||
35 | private static final long serialVersionUID = 1L; |
|
36 | ||
37 | private Set m_setRows; |
|
38 | ||
39 | public SimpleSetTableDataModel(Set setRows) |
|
40 | 0 | { |
41 | 0 | m_setRows = setRows; |
42 | 0 | } |
43 | ||
44 | /** |
|
45 | * @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRowCount() |
|
46 | */ |
|
47 | public int getRowCount() |
|
48 | { |
|
49 | 0 | return m_setRows.size(); |
50 | } |
|
51 | ||
52 | /** |
|
53 | * @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRows() |
|
54 | */ |
|
55 | public Iterator getRows() |
|
56 | { |
|
57 | 0 | return m_setRows.iterator(); |
58 | } |
|
59 | ||
60 | /** |
|
61 | * Method addRow. Adds a row object to the model at its end |
|
62 | * |
|
63 | * @param objRow |
|
64 | * the row object to add |
|
65 | */ |
|
66 | public void addRow(Object objRow) |
|
67 | { |
|
68 | 0 | if (m_setRows.contains(objRow)) return; |
69 | 0 | m_setRows.add(objRow); |
70 | ||
71 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
72 | 0 | fireTableDataModelEvent(objEvent); |
73 | 0 | } |
74 | ||
75 | public void addRows(Collection arrRows) |
|
76 | { |
|
77 | 0 | m_setRows.addAll(arrRows); |
78 | ||
79 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
80 | 0 | fireTableDataModelEvent(objEvent); |
81 | 0 | } |
82 | ||
83 | /** |
|
84 | * Method removeRow. Removes a row object from the model |
|
85 | * |
|
86 | * @param objRow |
|
87 | * the row object to remove |
|
88 | */ |
|
89 | public void removeRow(Object objRow) |
|
90 | { |
|
91 | 0 | if (!m_setRows.contains(objRow)) return; |
92 | 0 | m_setRows.remove(objRow); |
93 | ||
94 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
95 | 0 | fireTableDataModelEvent(objEvent); |
96 | 0 | } |
97 | ||
98 | public void removeRows(Collection arrRows) |
|
99 | { |
|
100 | 0 | m_setRows.removeAll(arrRows); |
101 | ||
102 | 0 | CTableDataModelEvent objEvent = new CTableDataModelEvent(); |
103 | 0 | fireTableDataModelEvent(objEvent); |
104 | 0 | } |
105 | ||
106 | } |