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