1 | // Copyright 2004-2007 Jean-Francois Poilpret |
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 net.sourceforge.hivegui.table; |
16 | |
17 | import java.util.ArrayList; |
18 | import java.util.List; |
19 | |
20 | /** |
21 | * @author Jean-Francois Poilpret |
22 | */ |
23 | public abstract class AbstractDataListModel<T> implements DataListModel<T> |
24 | { |
25 | public void addDataListModelListener(DataListModelListener listener) |
26 | { |
27 | _listeners.add(listener); |
28 | } |
29 | |
30 | public void removeDataListModelListener(DataListModelListener listener) |
31 | { |
32 | _listeners.remove(listener); |
33 | } |
34 | |
35 | protected void fireModelReset() |
36 | { |
37 | for (DataListModelListener listener: _listeners) |
38 | { |
39 | listener.modelReset(); |
40 | } |
41 | } |
42 | |
43 | protected void fireRowsAdded(int begin, int end) |
44 | { |
45 | for (DataListModelListener listener: _listeners) |
46 | { |
47 | listener.rowsAdded(begin, end); |
48 | } |
49 | } |
50 | |
51 | protected void fireRowsModified(int begin, int end) |
52 | { |
53 | for (DataListModelListener listener: _listeners) |
54 | { |
55 | listener.rowsModified(begin, end); |
56 | } |
57 | } |
58 | |
59 | protected void fireRowModified(int source, int destination) |
60 | { |
61 | // The order in which listeners are called must be guaranteed (ie, in |
62 | // the order of registration through addDataListModelListener()) |
63 | for (DataListModelListener listener: _listeners) |
64 | { |
65 | listener.rowModified(source, destination); |
66 | } |
67 | } |
68 | |
69 | protected void fireRowsRemoved(int begin, int end) |
70 | { |
71 | for (DataListModelListener listener: _listeners) |
72 | { |
73 | listener.rowsRemoved(begin, end); |
74 | } |
75 | } |
76 | |
77 | final protected List<DataListModelListener> _listeners = |
78 | new ArrayList<DataListModelListener>(); |
79 | } |