1 12 13 package org.eclipse.core.databinding.observable.map; 14 15 import java.util.Collection ; 16 import java.util.Map ; 17 import java.util.Set ; 18 19 import org.eclipse.core.databinding.observable.AbstractObservable; 20 import org.eclipse.core.databinding.observable.ObservableTracker; 21 import org.eclipse.core.databinding.observable.Realm; 22 23 32 public class ObservableMap extends AbstractObservable implements IObservableMap { 33 34 protected Map wrappedMap; 35 36 private boolean stale = false; 37 38 41 public ObservableMap(Map wrappedMap) { 42 this(Realm.getDefault(), wrappedMap); 43 } 44 45 49 public ObservableMap(Realm realm, Map wrappedMap) { 50 super(realm); 51 this.wrappedMap = wrappedMap; 52 } 53 54 public synchronized void addMapChangeListener(IMapChangeListener listener) { 55 addListener(MapChangeEvent.TYPE, listener); 56 } 57 58 public synchronized void removeMapChangeListener(IMapChangeListener listener) { 59 removeListener(MapChangeEvent.TYPE, listener); 60 } 61 62 protected void getterCalled() { 63 ObservableTracker.getterCalled(this); 64 } 65 66 protected void fireMapChange(MapDiff diff) { 67 checkRealm(); 68 69 super.fireChange(); 71 72 fireEvent(new MapChangeEvent(this, diff)); 73 } 74 75 public boolean containsKey(Object key) { 76 getterCalled(); 77 return wrappedMap.containsKey(key); 78 } 79 80 public boolean containsValue(Object value) { 81 getterCalled(); 82 return wrappedMap.containsValue(value); 83 } 84 85 public Set entrySet() { 86 getterCalled(); 87 return wrappedMap.entrySet(); 88 } 89 90 public Object get(Object key) { 91 getterCalled(); 92 return wrappedMap.get(key); 93 } 94 95 public boolean isEmpty() { 96 getterCalled(); 97 return wrappedMap.isEmpty(); 98 } 99 100 public Set keySet() { 101 getterCalled(); 102 return wrappedMap.keySet(); 103 } 104 105 public int size() { 106 getterCalled(); 107 return wrappedMap.size(); 108 } 109 110 public Collection values() { 111 getterCalled(); 112 return wrappedMap.values(); 113 } 114 115 120 public boolean isStale() { 121 checkRealm(); 122 return stale; 123 } 124 125 133 public void setStale(boolean stale) { 134 checkRealm(); 135 boolean wasStale = this.stale; 136 this.stale = stale; 137 if (!wasStale && stale) { 138 fireStale(); 139 } 140 } 141 142 public Object put(Object key, Object value) { 143 throw new UnsupportedOperationException (); 144 } 145 146 public Object remove(Object key) { 147 throw new UnsupportedOperationException (); 148 } 149 150 public void clear() { 151 throw new UnsupportedOperationException (); 152 } 153 154 public void putAll(Map arg0) { 155 throw new UnsupportedOperationException (); 156 } 157 158 public synchronized void dispose() { 159 super.dispose(); 160 } 161 } 162 | Popular Tags |