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