comparison org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/ObservableMap.d @ 78:0a55d2d5a946

Added file for databinding
author Frank Benoit <benoit@tionex.de>
date Tue, 14 Apr 2009 11:35:29 +0200
parents
children 383ce7bd736b
comparison
equal deleted inserted replaced
76:f05e6e8b2f2d 78:0a55d2d5a946
1 /*******************************************************************************
2 * Copyright (c) 2006, 2007 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 * Brad Reynolds - bug 164653
11 *******************************************************************************/
12
13 module org.eclipse.core.databinding.observable.map.ObservableMap;
14
15 import java.lang.all;
16
17 import java.util.Collection;
18 import java.util.Map;
19 import java.util.Set;
20
21 import org.eclipse.core.databinding.observable.AbstractObservable;
22 import org.eclipse.core.databinding.observable.ObservableTracker;
23 import org.eclipse.core.databinding.observable.Realm;
24
25 /**
26 *
27 * <p>
28 * This class is thread safe. All state accessing methods must be invoked from
29 * the {@link Realm#isCurrent() current realm}. Methods for adding and removing
30 * listeners may be invoked from any thread.
31 * </p>
32 * @since 1.0
33 */
34 public class ObservableMap : AbstractObservable , IObservableMap {
35
36 protected Map wrappedMap;
37
38 private bool stale = false;
39
40 /**
41 * @param wrappedMap
42 */
43 public this(Map wrappedMap) {
44 this(Realm.getDefault(), wrappedMap);
45 }
46
47 /**
48 * @param realm
49 * @param wrappedMap
50 */
51 public this(Realm realm, Map wrappedMap) {
52 super(realm);
53 this.wrappedMap = wrappedMap;
54 }
55
56 public synchronized void addMapChangeListener(IMapChangeListener listener) {
57 addListener(MapChangeEvent.TYPE, listener);
58 }
59
60 public synchronized void removeMapChangeListener(IMapChangeListener listener) {
61 removeListener(MapChangeEvent.TYPE, listener);
62 }
63
64 protected void getterCalled() {
65 ObservableTracker.getterCalled(this);
66 }
67
68 protected void fireMapChange(MapDiff diff) {
69 checkRealm();
70
71 // fire general change event first
72 super.fireChange();
73
74 fireEvent(new MapChangeEvent(this, diff));
75 }
76
77 public bool containsKey(Object key) {
78 getterCalled();
79 return wrappedMap.containsKey(key);
80 }
81
82 public bool containsValue(Object value) {
83 getterCalled();
84 return wrappedMap.containsValue(value);
85 }
86
87 public Set entrySet() {
88 getterCalled();
89 return wrappedMap.entrySet();
90 }
91
92 public Object get(Object key) {
93 getterCalled();
94 return wrappedMap.get(key);
95 }
96
97 public bool isEmpty() {
98 getterCalled();
99 return wrappedMap.isEmpty();
100 }
101
102 public Set keySet() {
103 getterCalled();
104 return wrappedMap.keySet();
105 }
106
107 public int size() {
108 getterCalled();
109 return wrappedMap.size();
110 }
111
112 public Collection values() {
113 getterCalled();
114 return wrappedMap.values();
115 }
116
117 /**
118 * Returns the stale state. Must be invoked from the current realm.
119 *
120 * @return stale state
121 */
122 public bool isStale() {
123 checkRealm();
124 return stale;
125 }
126
127 /**
128 * Sets the stale state. Must be invoked from the current realm.
129 *
130 * @param stale
131 * The stale state to set. This will fire a stale event if the
132 * given bool is true and this observable set was not already
133 * stale.
134 */
135 public void setStale(bool stale) {
136 checkRealm();
137 bool wasStale = this.stale;
138 this.stale = stale;
139 if (!wasStale && stale) {
140 fireStale();
141 }
142 }
143
144 public Object put(Object key, Object value) {
145 throw new UnsupportedOperationException();
146 }
147
148 public Object remove(Object key) {
149 throw new UnsupportedOperationException();
150 }
151
152 public void clear() {
153 throw new UnsupportedOperationException();
154 }
155
156 public void putAll(Map arg0) {
157 throw new UnsupportedOperationException();
158 }
159
160 public synchronized void dispose() {
161 super.dispose();
162 }
163 }