Mercurial > projects > dwt2
annotate org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/Observables.d @ 88:9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 19 Apr 2009 11:10:09 +0200 |
parents | 6be48cf9f95c |
children |
rev | line source |
---|---|
78 | 1 /******************************************************************************* |
2 * Copyright (c) 2006-2008 Cerner 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 * Brad Reynolds - initial API and implementation | |
10 * Matt Carter - bug 212518 (constantObservableValue) | |
11 * Matthew Hall - bugs 208332, 212518, 219909, 184830 | |
12 * Marko Topolnik - bug 184830 | |
13 ******************************************************************************/ | |
14 | |
15 module org.eclipse.core.databinding.observable.Observables; | |
81 | 16 import org.eclipse.core.databinding.observable.IChangeListener; |
17 import org.eclipse.core.databinding.observable.Realm; | |
18 import org.eclipse.core.databinding.observable.IStaleListener; | |
19 import org.eclipse.core.databinding.observable.IObservable; | |
78 | 20 |
21 import java.lang.all; | |
22 | |
23 import java.util.List; | |
24 import java.util.Set; | |
25 | |
26 import org.eclipse.core.databinding.observable.list.IListChangeListener; | |
27 import org.eclipse.core.databinding.observable.list.IObservableList; | |
28 import org.eclipse.core.databinding.observable.list.ObservableList; | |
29 import org.eclipse.core.databinding.observable.map.IObservableMap; | |
30 import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; | |
31 import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; | |
32 import org.eclipse.core.databinding.observable.set.IObservableSet; | |
33 import org.eclipse.core.databinding.observable.set.ISetChangeListener; | |
34 import org.eclipse.core.databinding.observable.set.ObservableSet; | |
35 import org.eclipse.core.databinding.observable.value.IObservableValue; | |
36 import org.eclipse.core.internal.databinding.observable.ConstantObservableValue; | |
37 import org.eclipse.core.internal.databinding.observable.EmptyObservableList; | |
38 import org.eclipse.core.internal.databinding.observable.EmptyObservableSet; | |
39 import org.eclipse.core.internal.databinding.observable.MapEntryObservableValue; | |
40 import org.eclipse.core.internal.databinding.observable.ProxyObservableList; | |
41 import org.eclipse.core.internal.databinding.observable.ProxyObservableSet; | |
42 import org.eclipse.core.internal.databinding.observable.StalenessObservableValue; | |
43 import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableList; | |
44 import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableSet; | |
45 import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableValue; | |
46 import org.eclipse.core.runtime.Assert; | |
47 | |
48 /** | |
49 * Contains static methods to operate on or return | |
50 * {@link IObservable Observables}. | |
51 * | |
52 * @since 1.0 | |
53 */ | |
54 public class Observables { | |
55 /** | |
56 * Returns an unmodifiable observable value backed by the given observable | |
57 * value. | |
58 * | |
59 * @param value | |
60 * the value to wrap in an unmodifiable value | |
61 * @return an unmodifiable observable value backed by the given observable | |
62 * value | |
63 * @since 1.1 | |
64 */ | |
65 public static IObservableValue unmodifiableObservableValue( | |
66 IObservableValue value) { | |
85 | 67 Assert.isNotNull(cast(Object)value, "Argument 'value' cannot be null"); //$NON-NLS-1$ |
78 | 68 return new UnmodifiableObservableValue(value); |
69 } | |
70 | |
71 /** | |
72 * Returns an observable value with the given constant value. | |
73 * | |
74 * @param realm | |
75 * the observable's realm | |
76 * @param value | |
77 * the observable's constant value | |
78 * @param valueType | |
79 * the observable's value type | |
80 * @return an immutable observable value with the given constant value | |
81 * @since 1.1 | |
82 */ | |
83 public static IObservableValue constantObservableValue(Realm realm, | |
84 Object value, Object valueType) { | |
85 return new ConstantObservableValue(realm, value, valueType); | |
86 } | |
87 | |
88 /** | |
89 * Returns an observable value with the given constant value. | |
90 * | |
91 * @param realm | |
92 * the observable's realm | |
93 * @param value | |
94 * the observable's constant value | |
95 * @return an immutable observable value with the given constant value | |
96 * @since 1.1 | |
97 */ | |
98 public static IObservableValue constantObservableValue(Realm realm, | |
99 Object value) { | |
100 return constantObservableValue(realm, value, null); | |
101 } | |
102 | |
103 /** | |
104 * Returns an observable value with the given constant value. | |
105 * | |
106 * @param value | |
107 * the observable's constant value | |
108 * @param valueType | |
109 * the observable's value type | |
110 * @return an immutable observable value with the given constant value | |
111 * @since 1.1 | |
112 */ | |
113 public static IObservableValue constantObservableValue(Object value, | |
114 Object valueType) { | |
115 return constantObservableValue(Realm.getDefault(), value, valueType); | |
116 } | |
117 | |
118 /** | |
119 * Returns an observable value with the given constant value. | |
120 * | |
121 * @param value | |
122 * the observable's constant value | |
123 * @return an immutable observable value with the given constant value | |
124 * @since 1.1 | |
125 */ | |
126 public static IObservableValue constantObservableValue(Object value) { | |
127 return constantObservableValue(Realm.getDefault(), value, null); | |
128 } | |
129 | |
130 /** | |
131 * Returns an unmodifiable observable list backed by the given observable | |
132 * list. | |
133 * | |
134 * @param list | |
135 * the list to wrap in an unmodifiable list | |
136 * @return an unmodifiable observable list backed by the given observable | |
137 * list | |
138 */ | |
139 public static IObservableList unmodifiableObservableList( | |
140 IObservableList list) { | |
141 if (list is null) { | |
142 throw new IllegalArgumentException("List parameter cannot be null."); //$NON-NLS-1$ | |
143 } | |
144 | |
145 return new UnmodifiableObservableList(list); | |
146 } | |
147 | |
148 /** | |
149 * Returns an unmodifiable observable set backed by the given observable | |
150 * set. | |
151 * | |
152 * @param set | |
153 * the set to wrap in an unmodifiable set | |
154 * @return an unmodifiable observable set backed by the given observable set | |
155 * @since 1.1 | |
156 */ | |
157 public static IObservableSet unmodifiableObservableSet(IObservableSet set) { | |
158 if (set is null) { | |
159 throw new IllegalArgumentException("Set parameter cannot be null"); //$NON-NLS-1$ | |
160 } | |
161 | |
162 return new UnmodifiableObservableSet(set); | |
163 } | |
164 | |
165 /** | |
166 * Returns an empty observable list. The returned list continues to work | |
167 * after it has been disposed of and can be disposed of multiple times. | |
168 * | |
169 * @return an empty observable list. | |
170 */ | |
171 public static IObservableList emptyObservableList() { | |
172 return emptyObservableList(Realm.getDefault(), null); | |
173 } | |
174 | |
175 /** | |
176 * Returns an empty observable list of the given element type. The returned | |
177 * list continues to work after it has been disposed of and can be disposed | |
178 * of multiple times. | |
179 * | |
180 * @param elementType | |
181 * the element type of the returned list | |
182 * @return an empty observable list | |
183 * @since 1.1 | |
184 */ | |
185 public static IObservableList emptyObservableList(Object elementType) { | |
186 return emptyObservableList(Realm.getDefault(), elementType); | |
187 } | |
188 | |
189 /** | |
190 * Returns an empty observable list belonging to the given realm. The | |
191 * returned list continues to work after it has been disposed of and can be | |
192 * disposed of multiple times. | |
193 * | |
194 * @param realm | |
195 * the realm of the returned list | |
196 * @return an empty observable list. | |
197 */ | |
198 public static IObservableList emptyObservableList(Realm realm) { | |
199 return emptyObservableList(realm, null); | |
200 } | |
201 | |
202 /** | |
203 * Returns an empty observable list of the given element type and belonging | |
204 * to the given realm. The returned list continues to work after it has been | |
205 * disposed of and can be disposed of multiple times. | |
206 * | |
207 * @param realm | |
208 * the realm of the returned list | |
209 * @param elementType | |
210 * the element type of the returned list | |
211 * @return an empty observable list | |
212 * @since 1.1 | |
213 */ | |
214 public static IObservableList emptyObservableList(Realm realm, | |
215 Object elementType) { | |
216 return new EmptyObservableList(realm, elementType); | |
217 } | |
218 | |
219 /** | |
220 * Returns an empty observable set. The returned set continues to work after | |
221 * it has been disposed of and can be disposed of multiple times. | |
222 * | |
223 * @return an empty observable set. | |
224 */ | |
225 public static IObservableSet emptyObservableSet() { | |
226 return emptyObservableSet(Realm.getDefault(), null); | |
227 } | |
228 | |
229 /** | |
230 * Returns an empty observable set of the given element type. The returned | |
231 * set continues to work after it has been disposed of and can be disposed | |
232 * of multiple times. | |
233 * | |
234 * @param elementType | |
235 * the element type of the returned set | |
236 * @return an empty observable set | |
237 * @since 1.1 | |
238 */ | |
239 public static IObservableSet emptyObservableSet(Object elementType) { | |
240 return emptyObservableSet(Realm.getDefault(), elementType); | |
241 } | |
242 | |
243 /** | |
244 * Returns an empty observable set belonging to the given realm. The | |
245 * returned set continues to work after it has been disposed of and can be | |
246 * disposed of multiple times. | |
247 * | |
248 * @param realm | |
249 * the realm of the returned set | |
250 * @return an empty observable set. | |
251 */ | |
252 public static IObservableSet emptyObservableSet(Realm realm) { | |
253 return emptyObservableSet(realm, null); | |
254 } | |
255 | |
256 /** | |
257 * Returns an empty observable set of the given element type and belonging | |
258 * to the given realm. The returned set continues to work after it has been | |
259 * disposed of and can be disposed of multiple times. | |
260 * | |
261 * @param realm | |
262 * the realm of the returned set | |
263 * @param elementType | |
264 * the element type of the returned set | |
265 * @return an empty observable set | |
266 * @since 1.1 | |
267 */ | |
268 public static IObservableSet emptyObservableSet(Realm realm, | |
269 Object elementType) { | |
270 return new EmptyObservableSet(realm, elementType); | |
271 } | |
272 | |
273 /** | |
274 * Returns an observable set backed by the given set. | |
275 * | |
276 * @param set | |
277 * the set to wrap in an IObservableSet | |
278 * @return an observable set backed by the given set | |
279 */ | |
280 public static IObservableSet staticObservableSet(Set set) { | |
88
9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
281 return staticObservableSet(Realm.getDefault(), set, Class.fromType!(Object)); |
78 | 282 } |
283 | |
284 /** | |
285 * Returns an observable set of the given element type, backed by the given | |
286 * set. | |
287 * | |
288 * @param set | |
289 * the set to wrap in an IObservableSet | |
290 * @param elementType | |
291 * the element type of the returned set | |
292 * @return Returns an observable set backed by the given unchanging set | |
293 * @since 1.1 | |
294 */ | |
295 public static IObservableSet staticObservableSet(Set set, Object elementType) { | |
296 return staticObservableSet(Realm.getDefault(), set, elementType); | |
297 } | |
298 | |
299 /** | |
300 * Returns an observable set belonging to the given realm, backed by the | |
301 * given set. | |
302 * | |
303 * @param realm | |
304 * the realm of the returned set | |
305 * @param set | |
306 * the set to wrap in an IObservableSet | |
307 * @return an observable set backed by the given unchanging set | |
308 */ | |
309 public static IObservableSet staticObservableSet(Realm realm, Set set) { | |
88
9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
310 return staticObservableSet(realm, set, Class.fromType!(Object)); |
78 | 311 } |
312 | |
313 /** | |
314 * Returns an observable set of the given element type and belonging to the | |
315 * given realm, backed by the given set. | |
316 * | |
317 * @param realm | |
318 * the realm of the returned set | |
319 * @param set | |
320 * the set to wrap in an IObservableSet | |
321 * @param elementType | |
322 * the element type of the returned set | |
323 * @return an observable set backed by the given set | |
324 * @since 1.1 | |
325 */ | |
326 public static IObservableSet staticObservableSet(Realm realm, Set set, | |
327 Object elementType) { | |
328 return new class(realm, set, elementType) ObservableSet { | |
85 | 329 this(Realm r, Set s, Object e ){ super(r, s, e);} |
78 | 330 public void addChangeListener(IChangeListener listener) { |
331 } | |
332 | |
333 public void addStaleListener(IStaleListener listener) { | |
334 } | |
335 | |
336 public void addSetChangeListener(ISetChangeListener listener) { | |
337 } | |
338 }; | |
339 } | |
340 | |
341 /** | |
342 * Returns an observable set that contains the same elements as the given | |
343 * set, and fires the same events as the given set, but can be disposed of | |
344 * without disposing of the wrapped set. | |
345 * | |
346 * @param target | |
347 * the set to wrap | |
348 * @return a disposable proxy for the given observable set | |
349 */ | |
350 public static IObservableSet proxyObservableSet(IObservableSet target) { | |
351 return new ProxyObservableSet(target); | |
352 } | |
353 | |
354 /** | |
355 * Returns an observable list that contains the same elements as the given | |
356 * list, and fires the same events as the given list, but can be disposed of | |
357 * without disposing of the wrapped list. | |
358 * | |
359 * @param target | |
360 * the list to wrap | |
361 * @return a disposable proxy for the given observable list | |
362 * @since 1.1 | |
363 */ | |
364 public static IObservableList proxyObservableList(IObservableList target) { | |
365 return new ProxyObservableList(target); | |
366 } | |
367 | |
368 /** | |
369 * Returns an observable list backed by the given list. | |
370 * | |
371 * @param list | |
372 * the list to wrap in an IObservableList | |
373 * @return an observable list backed by the given unchanging list | |
374 */ | |
375 public static IObservableList staticObservableList(List list) { | |
88
9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
376 return staticObservableList(Realm.getDefault(), list, Class.fromType!(Object)); |
78 | 377 } |
378 | |
379 /** | |
380 * Returns an observable list of the given element type, backed by the given | |
381 * list. | |
382 * | |
383 * @param list | |
384 * the list to wrap in an IObservableList | |
385 * @param elementType | |
386 * the element type of the returned list | |
387 * @return an observable list backed by the given unchanging list | |
388 * @since 1.1 | |
389 */ | |
390 public static IObservableList staticObservableList(List list, | |
391 Object elementType) { | |
392 return staticObservableList(Realm.getDefault(), list, elementType); | |
393 } | |
394 | |
395 /** | |
396 * Returns an observable list belonging to the given realm, backed by the | |
397 * given list. | |
398 * | |
399 * @param realm | |
400 * the realm of the returned list | |
401 * @param list | |
402 * the list to wrap in an IObservableList | |
403 * @return an observable list backed by the given unchanging list | |
404 */ | |
405 public static IObservableList staticObservableList(Realm realm, List list) { | |
88
9e0ab372d5d8
Revert from TypeInfo/ClassInfo to java.lang.Class
Frank Benoit <benoit@tionex.de>
parents:
85
diff
changeset
|
406 return staticObservableList(realm, list, Class.fromType!(Object)); |
78 | 407 } |
408 | |
409 /** | |
410 * Returns an observable list of the given element type and belonging to the | |
411 * given realm, backed by the given list. | |
412 * | |
413 * @param realm | |
414 * the realm of the returned list | |
415 * @param list | |
416 * the list to wrap in an IObservableList | |
417 * @param elementType | |
418 * the element type of the returned list | |
419 * @return an observable list backed by the given unchanging list | |
420 * @since 1.1 | |
421 */ | |
422 public static IObservableList staticObservableList(Realm realm, List list, | |
423 Object elementType) { | |
424 return new class(realm, list, elementType) ObservableList { | |
85 | 425 this(Realm r, List s, Object e ){ super(r, s, e);} |
78 | 426 public void addChangeListener(IChangeListener listener) { |
427 } | |
428 | |
429 public void addStaleListener(IStaleListener listener) { | |
430 } | |
431 | |
432 public void addListChangeListener(IListChangeListener listener) { | |
433 } | |
434 }; | |
435 } | |
436 | |
437 /** | |
438 * Returns an observable value of type <code>Boolean.TYPE</code> which | |
439 * tracks whether the given observable is stale. | |
440 * | |
441 * @param observable | |
442 * the observable to track | |
443 * @return an observable value which tracks whether the given observable is | |
444 * stale | |
445 * | |
446 * @since 1.1 | |
447 */ | |
448 public static IObservableValue observeStale(IObservable observable) { | |
449 return new StalenessObservableValue(observable); | |
450 } | |
451 | |
452 /** | |
453 * Returns an observable value that tracks changes to the value of an | |
454 * observable map's entry specified by its key. | |
455 * <p> | |
456 * The state where the key does not exist in the map is equivalent to the | |
457 * state where the key exists and its value is <code>null</code>. The | |
458 * transition between these two states is not considered a value change and | |
459 * no event is fired. | |
460 * | |
461 * @param map | |
462 * the observable map whose entry will be tracked. | |
463 * @param key | |
464 * the key identifying the map entry to track. | |
465 * @param valueType | |
466 * the type of the value. May be <code>null</code>, meaning | |
467 * the value is untyped. | |
468 * @return an observable value that tracks the value associated with the | |
469 * specified key in the given map | |
470 * @since 1.1 | |
471 */ | |
472 public static IObservableValue observeMapEntry(IObservableMap map, | |
473 Object key, Object valueType) { | |
474 return new MapEntryObservableValue(map, key, valueType); | |
475 } | |
476 | |
477 /** | |
478 * Returns a factory for creating obervable values tracking the value of the | |
479 * {@link IObservableMap observable map} entry identified by a particular | |
480 * key. | |
481 * | |
482 * @param map | |
483 * the observable map whose entry will be tracked. | |
484 * @param valueType | |
485 * the type of the value. May be <code>null</code>, meaning | |
486 * the value is untyped. | |
487 * @return a factory for creating observable values tracking the value of | |
488 * the observable map entry identified by a particular key object. | |
489 * @since 1.1 | |
490 */ | |
491 public static IObservableFactory mapEntryValueFactory( | |
492 IObservableMap map, Object valueType) { | |
85 | 493 return new class(map, valueType) IObservableFactory { |
78 | 494 IObservableMap map_; |
495 Object valueType_; | |
496 this(IObservableMap a, Object b){ | |
497 map_=a; valueType_=b; | |
498 } | |
499 public IObservable createObservable(Object key) { | |
500 return observeMapEntry(map_, key, valueType_); | |
501 } | |
502 }; | |
503 } | |
504 | |
505 /** | |
506 * Helper method for <code>MasterDetailObservables.detailValue(master, | |
507 * mapEntryValueFactory(map, valueType), valueType)</code>. | |
508 * | |
509 * @param map | |
510 * the observable map whose entry will be tracked. | |
511 * @param master | |
512 * the observable value that identifies which map entry to track. | |
513 * @param valueType | |
514 * the type of the value. May be <code>null</code>, meaning | |
515 * the value is untyped. | |
516 * @return an observable value tracking the current value of the specified | |
517 * key in the given map an observable value that tracks the current | |
518 * value of the named property for the current value of the master | |
519 * observable value | |
520 * @since 1.1 | |
521 */ | |
522 public static IObservableValue observeDetailMapEntry(IObservableMap map, | |
523 IObservableValue master, Object valueType) { | |
524 return MasterDetailObservables.detailValue(master, | |
525 mapEntryValueFactory(map, valueType), valueType); | |
526 } | |
527 } |