KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > table > model > simple > SimpleSetTableDataModel


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 JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Set JavaDoc;
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 Serializable JavaDoc
32 {
33     private static final long serialVersionUID = 1L;
34     
35     private Set JavaDoc m_setRows;
36
37     public SimpleSetTableDataModel(Set JavaDoc setRows)
38     {
39         m_setRows = setRows;
40     }
41
42     /**
43      * @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRowCount()
44      */

45     public int getRowCount()
46     {
47         return m_setRows.size();
48     }
49
50     /**
51      * @see org.apache.tapestry.contrib.table.model.ITableDataModel#getRows()
52      */

53     public Iterator JavaDoc getRows()
54     {
55         return m_setRows.iterator();
56     }
57
58     /**
59      * Method addRow.
60      * Adds a row object to the model at its end
61      * @param objRow the row object to add
62      */

63     public void addRow(Object JavaDoc objRow)
64     {
65         if (m_setRows.contains(objRow)) return;
66         m_setRows.add(objRow);
67
68         CTableDataModelEvent objEvent = new CTableDataModelEvent();
69         fireTableDataModelEvent(objEvent);
70     }
71
72     public void addRows(Collection JavaDoc arrRows)
73     {
74         m_setRows.addAll(arrRows);
75
76         CTableDataModelEvent objEvent = new CTableDataModelEvent();
77         fireTableDataModelEvent(objEvent);
78     }
79
80     /**
81      * Method removeRow.
82      * Removes a row object from the model
83      * @param objRow the row object to remove
84      */

85     public void removeRow(Object JavaDoc objRow)
86     {
87         if (!m_setRows.contains(objRow)) return;
88         m_setRows.remove(objRow);
89
90         CTableDataModelEvent objEvent = new CTableDataModelEvent();
91         fireTableDataModelEvent(objEvent);
92     }
93
94     public void removeRows(Collection JavaDoc arrRows)
95     {
96         m_setRows.removeAll(arrRows);
97
98         CTableDataModelEvent objEvent = new CTableDataModelEvent();
99         fireTableDataModelEvent(objEvent);
100     }
101
102 }
103
Popular Tags