01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jface.viewers.deferred;
11:
12: import org.eclipse.core.runtime.ListenerList;
13:
14: /**
15: * Abstract base class for all IConcurrentModel implementations. Clients should
16: * subclass this class instead of implementing IConcurrentModel directly.
17: *
18: * @since 3.1
19: */
20: public abstract class AbstractConcurrentModel implements
21: IConcurrentModel {
22:
23: private ListenerList listeners = new ListenerList();
24:
25: /* (non-Javadoc)
26: * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#addListener(org.eclipse.jface.viewers.deferred.IConcurrentContentProviderListener)
27: */
28: public void addListener(IConcurrentModelListener listener) {
29: listeners.add(listener);
30: }
31:
32: /**
33: * Fires an add notification to all listeners
34: *
35: * @param added objects added to the set
36: */
37: protected final void fireAdd(Object[] added) {
38: Object[] listenerArray = listeners.getListeners();
39:
40: for (int i = 0; i < listenerArray.length; i++) {
41: IConcurrentModelListener next = (IConcurrentModelListener) listenerArray[i];
42:
43: next.add(added);
44: }
45: }
46:
47: /**
48: * Fires a remove notification to all listeners
49: *
50: * @param removed objects removed from the set
51: */
52: protected final void fireRemove(Object[] removed) {
53: Object[] listenerArray = listeners.getListeners();
54:
55: for (int i = 0; i < listenerArray.length; i++) {
56: IConcurrentModelListener next = (IConcurrentModelListener) listenerArray[i];
57:
58: next.remove(removed);
59: }
60: }
61:
62: /**
63: * Fires an update notification to all listeners
64: *
65: * @param updated objects that have changed
66: */
67: protected final void fireUpdate(Object[] updated) {
68: Object[] listenerArray = listeners.getListeners();
69:
70: for (int i = 0; i < listenerArray.length; i++) {
71: IConcurrentModelListener next = (IConcurrentModelListener) listenerArray[i];
72:
73: next.update(updated);
74: }
75: }
76:
77: /**
78: * Returns the array of listeners for this model
79: *
80: * @return the array of listeners for this model
81: */
82: protected final IConcurrentModelListener[] getListeners() {
83: Object[] l = listeners.getListeners();
84: IConcurrentModelListener[] result = new IConcurrentModelListener[l.length];
85:
86: for (int i = 0; i < l.length; i++) {
87: result[i] = (IConcurrentModelListener) l[i];
88: }
89:
90: return result;
91: }
92:
93: /* (non-Javadoc)
94: * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#removeListener(org.eclipse.jface.viewers.deferred.IConcurrentContentProviderListener)
95: */
96: public void removeListener(IConcurrentModelListener listener) {
97: listeners.remove(listener);
98: }
99: }
|