Mercurial > projects > dwt-addons
annotate dwtx/jface/viewers/deferred/SetModel.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 04b47443bb01 |
children |
rev | line source |
---|---|
10 | 1 /******************************************************************************* |
2 * Copyright (c) 2004, 2006 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.SetModel; | |
14 | |
15 import dwtx.jface.viewers.deferred.AbstractConcurrentModel; | |
16 import dwtx.jface.viewers.deferred.IConcurrentModelListener; | |
17 | |
18 | |
19 import dwtx.core.runtime.Assert; | |
20 | |
21 import dwt.dwthelper.utils; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
22 import dwtx.dwtxhelper.Collection; |
10 | 23 |
24 /** | |
25 * Trivial implementation of an <code>IConcurrentModel</code>. Implements | |
26 * an unordered set of elements that fires off change notifications whenever | |
27 * elements are added or removed from the set. All notifications are sent | |
28 * synchronously. | |
29 * | |
30 * @since 3.1 | |
31 */ | |
32 public class SetModel : AbstractConcurrentModel { | |
33 | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
34 private HashSet data; |
10 | 35 |
36 public this(){ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
37 data = new HashSet(); |
10 | 38 } |
39 | |
40 /** | |
41 * Return the contents of the model. | |
42 * @return the array of elements | |
43 * | |
44 */ | |
45 public Object[] getElements() { | |
46 return data.toArray(); | |
47 } | |
48 | |
49 /** | |
50 * Sets the contents to the given array of elements | |
51 * | |
52 * @param newContents new contents of this set | |
53 */ | |
54 public void set(Object[] newContents) { | |
55 // Assert.isNotNull(newContents); | |
56 data.clear(); | |
57 for (int i = 0; i < newContents.length; i++) { | |
58 Object object = newContents[i]; | |
59 | |
60 data.add(object); | |
61 } | |
62 | |
63 IConcurrentModelListener[] listeners = getListeners(); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
64 for (int i = 0; i < listeners.length; i++) { |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
65 IConcurrentModelListener listener = listeners[i]; |
10 | 66 listener.setContents(newContents); |
67 } | |
68 } | |
69 | |
70 /** | |
71 * Empties the set | |
72 */ | |
73 public void clear() { | |
74 Object[] removed = data.toArray(); | |
75 data.clear(); | |
76 fireRemove(removed); | |
77 } | |
78 | |
79 /** | |
80 * Adds the given elements to the set | |
81 * | |
82 * @param toAdd elements to add | |
83 */ | |
84 public void addAll(Object[] toAdd) { | |
85 // Assert.isNotNull(toAdd); | |
86 for (int i = 0; i < toAdd.length; i++) { | |
87 Object object = toAdd[i]; | |
88 | |
89 data.add(object); | |
90 } | |
91 | |
92 fireAdd(toAdd); | |
93 } | |
94 | |
95 /** | |
96 * Adds the given elements to the set. Duplicate elements are ignored. | |
97 * | |
98 * @param toAdd elements to add | |
99 */ | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
10
diff
changeset
|
100 public void addAll(Collection toAdd) { |
10 | 101 Assert.isNotNull(cast(Object)toAdd); |
102 addAll(toAdd.toArray()); | |
103 } | |
104 | |
105 /** | |
106 * Fires a change notification for all elements in the given array | |
107 * | |
108 * @param changed array of elements that have changed | |
109 */ | |
110 public void changeAll(Object[] changed) { | |
111 // Assert.isNotNull(changed); | |
112 fireUpdate(changed); | |
113 } | |
114 | |
115 /** | |
116 * Removes all of the given elements from the set. | |
117 * | |
118 * @param toRemove elements to remove | |
119 */ | |
120 public void removeAll(Object[] toRemove) { | |
121 // Assert.isNotNull(toRemove); | |
122 for (int i = 0; i < toRemove.length; i++) { | |
123 Object object = toRemove[i]; | |
124 | |
125 data.remove(object); | |
126 } | |
127 | |
128 fireRemove(toRemove); | |
129 } | |
130 | |
131 /* (non-Javadoc) | |
132 * @see dwtx.jface.viewers.deferred.IConcurrentModel#requestUpdate(dwtx.jface.viewers.deferred.IConcurrentModelListener) | |
133 */ | |
134 public void requestUpdate(IConcurrentModelListener listener) { | |
135 Assert.isNotNull(cast(Object)listener); | |
136 listener.setContents(getElements()); | |
137 } | |
138 } |