comparison org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/CompositeMap.d @ 85:6be48cf9f95c

Work on databinding
author Frank Benoit <benoit@tionex.de>
date Sat, 18 Apr 2009 13:54:50 +0200
parents 383ce7bd736b
children
comparison
equal deleted inserted replaced
84:fcf926c91ca4 85:6be48cf9f95c
48 * @since 1.1 48 * @since 1.1
49 * 49 *
50 */ 50 */
51 public class CompositeMap : ObservableMap { 51 public class CompositeMap : ObservableMap {
52 52
53 private Map valueToElements = new HashMap(); 53 private Map valueToElements;
54 54
55 // adds that need to go through the second map and thus will be picked up by 55 // adds that need to go through the second map and thus will be picked up by
56 // secondMapListener. 56 // secondMapListener.
57 private Set pendingAdds = new HashSet(); 57 private Set pendingAdds;
58 58
59 // Removes that need to go through the second map and thus will be picked up 59 // Removes that need to go through the second map and thus will be picked up
60 // by 60 // by
61 // secondMapListener. Maps from value being removed to key being removed. 61 // secondMapListener. Maps from value being removed to key being removed.
62 private Map pendingRemoves = new HashMap(); 62 private Map pendingRemoves;
63 63
64 // Changes that need to go through the second map and thus will be picked up 64 // Changes that need to go through the second map and thus will be picked up
65 // by 65 // by
66 // secondMapListener. Maps from old value to new value and new value to old 66 // secondMapListener. Maps from old value to new value and new value to old
67 // value. 67 // value.
68 private Map pendingChanges = new HashMap(); 68 private Map pendingChanges;
69 69
70 private IMapChangeListener firstMapListener = new class() IMapChangeListener { 70 private IMapChangeListener firstMapListener;
71 class FirstMapListener : IMapChangeListener {
71 72
72 public void handleMapChange(MapChangeEvent event) { 73 public void handleMapChange(MapChangeEvent event) {
73 MapDiff diff = event.diff; 74 MapDiff diff = event.diff;
74 Set rangeSetAdditions = new HashSet(); 75 Set rangeSetAdditions = new HashSet();
75 Set rangeSetRemovals = new HashSet(); 76 Set rangeSetRemovals = new HashSet();
156 rangeSet.addAndRemove(rangeSetAdditions, rangeSetRemovals); 157 rangeSet.addAndRemove(rangeSetAdditions, rangeSetRemovals);
157 } 158 }
158 } 159 }
159 }; 160 };
160 161
161 private IMapChangeListener secondMapListener = new class() IMapChangeListener { 162 private IMapChangeListener secondMapListener;
163 class SecondMapListener : IMapChangeListener {
162 164
163 public void handleMapChange(MapChangeEvent event) { 165 public void handleMapChange(MapChangeEvent event) {
164 MapDiff diff = event.diff; 166 MapDiff diff = event.diff;
165 final Set adds = new HashSet(); 167 final Set adds = new HashSet();
166 final Set changes = new HashSet(); 168 final Set changes = new HashSet();
276 wrappedSet.addAll(additions); 278 wrappedSet.addAll(additions);
277 fireSetChange(Diffs.createSetDiff(additions, removals)); 279 fireSetChange(Diffs.createSetDiff(additions, removals));
278 } 280 }
279 } 281 }
280 282
281 private WritableSetPlus rangeSet = new WritableSetPlus(); 283 private WritableSetPlus rangeSet;
282 284
283 /** 285 /**
284 * Creates a new composite map. Because the key set of the second map is 286 * Creates a new composite map. Because the key set of the second map is
285 * determined by the value set of the given observable map 287 * determined by the value set of the given observable map
286 * <code>firstMap</code>, it cannot be passed in as an argument. Instead, 288 * <code>firstMap</code>, it cannot be passed in as an argument. Instead,
293 * a factory that creates the second map when given an observable 295 * a factory that creates the second map when given an observable
294 * set representing the value set of <code>firstMap</code>. 296 * set representing the value set of <code>firstMap</code>.
295 */ 297 */
296 public this(IObservableMap firstMap, 298 public this(IObservableMap firstMap,
297 IObservableFactory secondMapFactory) { 299 IObservableFactory secondMapFactory) {
300 valueToElements = new HashMap();
301 pendingAdds = new HashSet();
302 pendingRemoves = new HashMap();
303 pendingChanges = new HashMap();
304 firstMapListener = new FirstMapListener();
305 secondMapListener = new SecondMapListener();
306 rangeSet = new WritableSetPlus();
298 super(firstMap.getRealm(), new HashMap()); 307 super(firstMap.getRealm(), new HashMap());
299 this.firstMap = firstMap; 308 this.firstMap = firstMap;
300 firstMap.addMapChangeListener(firstMapListener); 309 firstMap.addMapChangeListener(firstMapListener);
301 for (Iterator it = firstMap.entrySet().iterator(); it.hasNext();) { 310 for (Iterator it = firstMap.entrySet().iterator(); it.hasNext();) {
302 Map.Entry entry = cast(Entry) it.next(); 311 Map.Entry entry = cast(Entry) it.next();