01: /* AbstractListModel.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Aug 18 15:19:43 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul;
20:
21: import java.util.List;
22: import java.util.LinkedList;
23: import java.util.Iterator;
24:
25: import org.zkoss.io.Serializables;
26:
27: import org.zkoss.zk.ui.UiException;
28:
29: import org.zkoss.zul.event.ListDataEvent;
30: import org.zkoss.zul.event.ListDataListener;
31:
32: /**
33: * A skeletal implementation for {@link ListModel}.
34: *
35: * @author tomyeh
36: */
37: abstract public class AbstractListModel implements ListModel,
38: java.io.Serializable {
39: private transient List _listeners = new LinkedList();
40:
41: /** Fires a {@link ListDataEvent} for all registered listener
42: * (thru {@link #addListDataListener}.
43: *
44: * <p>Note: you can invoke this method only in an event listener.
45: */
46: protected void fireEvent(int type, int index0, int index1) {
47: final ListDataEvent evt = new ListDataEvent(this , type, index0,
48: index1);
49: for (Iterator it = _listeners.iterator(); it.hasNext();)
50: ((ListDataListener) it.next()).onChange(evt);
51: }
52:
53: //-- ListModel --//
54: public void addListDataListener(ListDataListener l) {
55: if (l == null)
56: throw new NullPointerException();
57: _listeners.add(l);
58: }
59:
60: public void removeListDataListener(ListDataListener l) {
61: _listeners.remove(l);
62: }
63:
64: //Serializable//
65: private synchronized void writeObject(java.io.ObjectOutputStream s)
66: throws java.io.IOException {
67: s.defaultWriteObject();
68:
69: Serializables.smartWrite(s, _listeners);
70: }
71:
72: private synchronized void readObject(java.io.ObjectInputStream s)
73: throws java.io.IOException, ClassNotFoundException {
74: s.defaultReadObject();
75:
76: _listeners = new LinkedList();
77: Serializables.smartRead(s, _listeners);
78: }
79: }
|