comparison org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/AbstractConcurrentModel.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 org.eclipse.jface.viewers.deferred.AbstractConcurrentModel;
14
15 import org.eclipse.jface.viewers.deferred.IConcurrentModel;
16 import org.eclipse.jface.viewers.deferred.IConcurrentModelListener;
17
18 import org.eclipse.core.runtime.ListenerList;
19
20 import java.lang.all;
21 import java.util.Set;
22
23 /**
24 * Abstract base class for all IConcurrentModel implementations. Clients should
25 * subclass this class instead of implementing IConcurrentModel directly.
26 *
27 * @since 3.1
28 */
29 public abstract class AbstractConcurrentModel :
30 IConcurrentModel {
31
32 private ListenerList listeners;
33
34 public this(){
35 listeners = new ListenerList();
36 }
37
38 /* (non-Javadoc)
39 * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#addListener(org.eclipse.jface.viewers.deferred.IConcurrentContentProviderListener)
40 */
41 public void addListener(IConcurrentModelListener listener) {
42 listeners.add(cast(Object)listener);
43 }
44
45 /**
46 * Fires an add notification to all listeners
47 *
48 * @param added objects added to the set
49 */
50 protected final void fireAdd(Object[] added) {
51 Object[] listenerArray = listeners.getListeners();
52
53 for (int i = 0; i < listenerArray.length; i++) {
54 IConcurrentModelListener next = cast(IConcurrentModelListener) listenerArray[i];
55
56 next.add(added);
57 }
58 }
59
60 /**
61 * Fires a remove notification to all listeners
62 *
63 * @param removed objects removed from the set
64 */
65 protected final void fireRemove(Object[] removed) {
66 Object[] listenerArray = listeners.getListeners();
67
68 for (int i = 0; i < listenerArray.length; i++) {
69 IConcurrentModelListener next = cast(IConcurrentModelListener) listenerArray[i];
70
71 next.remove(removed);
72 }
73 }
74
75 /**
76 * Fires an update notification to all listeners
77 *
78 * @param updated objects that have changed
79 */
80 protected final void fireUpdate(Object[] updated) {
81 Object[] listenerArray = listeners.getListeners();
82
83 for (int i = 0; i < listenerArray.length; i++) {
84 IConcurrentModelListener next = cast(IConcurrentModelListener) listenerArray[i];
85
86 next.update(updated);
87 }
88 }
89
90 /**
91 * Returns the array of listeners for this model
92 *
93 * @return the array of listeners for this model
94 */
95 protected final IConcurrentModelListener[] getListeners() {
96 Object[] l = listeners.getListeners();
97 IConcurrentModelListener[] result = new IConcurrentModelListener[l.length];
98
99 for (int i = 0; i < l.length; i++) {
100 result[i] = cast(IConcurrentModelListener)l[i];
101 }
102
103 return result;
104 }
105
106 /* (non-Javadoc)
107 * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#removeListener(org.eclipse.jface.viewers.deferred.IConcurrentContentProviderListener)
108 */
109 public void removeListener(IConcurrentModelListener listener) {
110 listeners.remove(cast(Object)listener);
111 }
112 }