Lines 25-36
Link Here
|
25 |
|
25 |
|
26 |
/** |
26 |
/** |
27 |
* |
27 |
* |
28 |
* Abstract implementation of {@link IObservableList}, based on an underlying regular list. |
28 |
* Abstract implementation of {@link IObservableList}, based on an underlying |
|
|
29 |
* regular list. |
29 |
* <p> |
30 |
* <p> |
30 |
* This class is thread safe. All state accessing methods must be invoked from |
31 |
* This class is thread safe. All state accessing methods must be invoked from |
31 |
* the {@link Realm#isCurrent() current realm}. Methods for adding and removing |
32 |
* the {@link Realm#isCurrent() current realm}. Methods for adding and removing |
32 |
* listeners may be invoked from any thread. |
33 |
* listeners may be invoked from any thread. |
33 |
* </p> |
34 |
* </p> |
|
|
35 |
* |
34 |
* @since 1.0 |
36 |
* @since 1.0 |
35 |
* |
37 |
* |
36 |
*/ |
38 |
*/ |
Lines 40-51
Link Here
|
40 |
protected List wrappedList; |
42 |
protected List wrappedList; |
41 |
|
43 |
|
42 |
/** |
44 |
/** |
43 |
* Stale state of the list. Access must occur in the current realm. |
45 |
* Stale state of the list. Access must occur in the current realm. |
44 |
*/ |
46 |
*/ |
45 |
private boolean stale = false; |
47 |
private boolean stale = false; |
46 |
|
48 |
|
47 |
private Object elementType; |
49 |
private Object elementType; |
48 |
|
50 |
|
|
|
51 |
/** |
52 |
* needed for deserialization |
53 |
*/ |
54 |
protected ObservableList() { |
55 |
super(Realm.getDefault()); |
56 |
} |
57 |
|
49 |
protected ObservableList(List wrappedList, Object elementType) { |
58 |
protected ObservableList(List wrappedList, Object elementType) { |
50 |
this(Realm.getDefault(), wrappedList, elementType); |
59 |
this(Realm.getDefault(), wrappedList, elementType); |
51 |
} |
60 |
} |
Lines 60-66
Link Here
|
60 |
addListener(ListChangeEvent.TYPE, listener); |
69 |
addListener(ListChangeEvent.TYPE, listener); |
61 |
} |
70 |
} |
62 |
|
71 |
|
63 |
public synchronized void removeListChangeListener(IListChangeListener listener) { |
72 |
public synchronized void removeListChangeListener( |
|
|
73 |
IListChangeListener listener) { |
64 |
removeListener(ListChangeEvent.TYPE, listener); |
74 |
removeListener(ListChangeEvent.TYPE, listener); |
65 |
} |
75 |
} |
66 |
|
76 |
|
Lines 69-75
Link Here
|
69 |
super.fireChange(); |
79 |
super.fireChange(); |
70 |
fireEvent(new ListChangeEvent(this, diff)); |
80 |
fireEvent(new ListChangeEvent(this, diff)); |
71 |
} |
81 |
} |
72 |
|
82 |
|
73 |
public boolean contains(Object o) { |
83 |
public boolean contains(Object o) { |
74 |
getterCalled(); |
84 |
getterCalled(); |
75 |
return wrappedList.contains(o); |
85 |
return wrappedList.contains(o); |
Lines 133-177
Link Here
|
133 |
getterCalled(); |
143 |
getterCalled(); |
134 |
return wrappedList.toString(); |
144 |
return wrappedList.toString(); |
135 |
} |
145 |
} |
136 |
|
146 |
|
137 |
/** |
147 |
/** |
138 |
* @TrackedGetter |
148 |
* @TrackedGetter |
139 |
*/ |
149 |
*/ |
140 |
public Object get(int index) { |
150 |
public Object get(int index) { |
141 |
getterCalled(); |
151 |
getterCalled(); |
142 |
return wrappedList.get(index); |
152 |
return wrappedList.get(index); |
143 |
} |
153 |
} |
144 |
|
154 |
|
145 |
/** |
155 |
/** |
146 |
* @TrackedGetter |
156 |
* @TrackedGetter |
147 |
*/ |
157 |
*/ |
148 |
public int indexOf(Object o) { |
158 |
public int indexOf(Object o) { |
149 |
getterCalled(); |
159 |
getterCalled(); |
150 |
return wrappedList.indexOf(o); |
160 |
return wrappedList.indexOf(o); |
151 |
} |
161 |
} |
152 |
|
162 |
|
153 |
/** |
163 |
/** |
154 |
* @TrackedGetter |
164 |
* @TrackedGetter |
155 |
*/ |
165 |
*/ |
156 |
public int lastIndexOf(Object o) { |
166 |
public int lastIndexOf(Object o) { |
157 |
getterCalled(); |
167 |
getterCalled(); |
158 |
return wrappedList.lastIndexOf(o); |
168 |
return wrappedList.lastIndexOf(o); |
159 |
} |
169 |
} |
160 |
|
170 |
|
161 |
// List Iterators |
171 |
// List Iterators |
162 |
|
172 |
|
163 |
/** |
173 |
/** |
164 |
* @TrackedGetter |
174 |
* @TrackedGetter |
165 |
*/ |
175 |
*/ |
166 |
public ListIterator listIterator() { |
176 |
public ListIterator listIterator() { |
167 |
return listIterator(0); |
177 |
return listIterator(0); |
168 |
} |
178 |
} |
169 |
|
179 |
|
170 |
/** |
180 |
/** |
171 |
* @TrackedGetter |
181 |
* @TrackedGetter |
172 |
*/ |
182 |
*/ |
173 |
public ListIterator listIterator(int index) { |
183 |
public ListIterator listIterator(int index) { |
174 |
getterCalled(); |
184 |
getterCalled(); |
175 |
final ListIterator wrappedIterator = wrappedList.listIterator(index); |
185 |
final ListIterator wrappedIterator = wrappedList.listIterator(index); |
176 |
return new ListIterator() { |
186 |
return new ListIterator() { |
177 |
|
187 |
|
Lines 211-235
Link Here
|
211 |
throw new UnsupportedOperationException(); |
221 |
throw new UnsupportedOperationException(); |
212 |
} |
222 |
} |
213 |
}; |
223 |
}; |
214 |
} |
224 |
} |
215 |
|
|
|
216 |
|
225 |
|
217 |
public List subList(int fromIndex, int toIndex) { |
226 |
public List subList(int fromIndex, int toIndex) { |
218 |
getterCalled(); |
227 |
getterCalled(); |
219 |
return wrappedList.subList(fromIndex, toIndex); |
228 |
return wrappedList.subList(fromIndex, toIndex); |
220 |
} |
229 |
} |
221 |
|
230 |
|
222 |
protected void getterCalled() { |
231 |
protected void getterCalled() { |
223 |
ObservableTracker.getterCalled(this); |
232 |
ObservableTracker.getterCalled(this); |
224 |
} |
233 |
} |
225 |
|
234 |
|
226 |
public Object set(int index, Object element) { |
235 |
public Object set(int index, Object element) { |
227 |
throw new UnsupportedOperationException(); |
236 |
throw new UnsupportedOperationException(); |
228 |
} |
237 |
} |
229 |
|
238 |
|
230 |
public Object remove(int index) { |
239 |
public Object remove(int index) { |
231 |
throw new UnsupportedOperationException(); |
240 |
throw new UnsupportedOperationException(); |
232 |
} |
241 |
} |
233 |
|
242 |
|
234 |
public boolean add(Object o) { |
243 |
public boolean add(Object o) { |
235 |
throw new UnsupportedOperationException(); |
244 |
throw new UnsupportedOperationException(); |
Lines 238-251
Link Here
|
238 |
public void add(int index, Object element) { |
247 |
public void add(int index, Object element) { |
239 |
throw new UnsupportedOperationException(); |
248 |
throw new UnsupportedOperationException(); |
240 |
} |
249 |
} |
241 |
|
250 |
|
242 |
public boolean addAll(Collection c) { |
251 |
public boolean addAll(Collection c) { |
243 |
throw new UnsupportedOperationException(); |
252 |
throw new UnsupportedOperationException(); |
244 |
} |
253 |
} |
245 |
|
254 |
|
246 |
public boolean addAll(int index, Collection c) { |
255 |
public boolean addAll(int index, Collection c) { |
247 |
throw new UnsupportedOperationException(); |
256 |
throw new UnsupportedOperationException(); |
248 |
} |
257 |
} |
249 |
|
258 |
|
250 |
public boolean remove(Object o) { |
259 |
public boolean remove(Object o) { |
251 |
throw new UnsupportedOperationException(); |
260 |
throw new UnsupportedOperationException(); |
Lines 264-270
Link Here
|
264 |
} |
273 |
} |
265 |
|
274 |
|
266 |
/** |
275 |
/** |
267 |
* Returns the stale state. Must be invoked from the current realm. |
276 |
* Returns the stale state. Must be invoked from the current realm. |
268 |
* |
277 |
* |
269 |
* @return stale state |
278 |
* @return stale state |
270 |
*/ |
279 |
*/ |
Lines 274-280
Link Here
|
274 |
} |
283 |
} |
275 |
|
284 |
|
276 |
/** |
285 |
/** |
277 |
* Sets the stale state. Must be invoked from the current realm. |
286 |
* Sets the stale state. Must be invoked from the current realm. |
278 |
* |
287 |
* |
279 |
* @param stale |
288 |
* @param stale |
280 |
* The stale state to list. This will fire a stale event if the |
289 |
* The stale state to list. This will fire a stale event if the |
Lines 292-307
Link Here
|
292 |
} |
301 |
} |
293 |
|
302 |
|
294 |
protected void fireChange() { |
303 |
protected void fireChange() { |
295 |
throw new RuntimeException("fireChange should not be called, use fireListChange() instead"); //$NON-NLS-1$ |
304 |
throw new RuntimeException( |
|
|
305 |
"fireChange should not be called, use fireListChange() instead"); //$NON-NLS-1$ |
296 |
} |
306 |
} |
297 |
|
307 |
|
298 |
/* (non-Javadoc) |
308 |
/* |
|
|
309 |
* (non-Javadoc) |
310 |
* |
299 |
* @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() |
311 |
* @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose() |
300 |
*/ |
312 |
*/ |
301 |
public synchronized void dispose() { |
313 |
public synchronized void dispose() { |
302 |
super.dispose(); |
314 |
super.dispose(); |
303 |
} |
315 |
} |
304 |
|
316 |
|
305 |
public Object getElementType() { |
317 |
public Object getElementType() { |
306 |
return elementType; |
318 |
return elementType; |
307 |
} |
319 |
} |