KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > databinding > observable > Observables


1 /*******************************************************************************
2  * Copyright (c) 2006 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  ******************************************************************************/

11
12 package org.eclipse.core.databinding.observable;
13
14 import java.util.List JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.core.databinding.observable.list.IListChangeListener;
18 import org.eclipse.core.databinding.observable.list.IObservableList;
19 import org.eclipse.core.databinding.observable.list.ObservableList;
20 import org.eclipse.core.databinding.observable.set.IObservableSet;
21 import org.eclipse.core.databinding.observable.set.ISetChangeListener;
22 import org.eclipse.core.databinding.observable.set.ObservableSet;
23 import org.eclipse.core.internal.databinding.observable.EmptyObservableList;
24 import org.eclipse.core.internal.databinding.observable.EmptyObservableSet;
25 import org.eclipse.core.internal.databinding.observable.ProxyObservableSet;
26 import org.eclipse.core.internal.databinding.observable.UnmodifiableObservableList;
27
28 /**
29  * Contains static methods to operate on or return
30  * {@link IObservable Observables}.
31  *
32  * @since 3.2
33  */

34 public class Observables {
35     /**
36      * @param list
37      * @return list Returns an unmodifiable view of the provided
38      * <code>list</code>.
39      */

40     public static IObservableList unmodifiableObservableList(
41             IObservableList list) {
42         if (list == null) {
43             throw new IllegalArgumentException JavaDoc(
44                     "Parameter " + list + " was null."); //$NON-NLS-1$ //$NON-NLS-2$
45
}
46
47         return new UnmodifiableObservableList(list);
48     }
49
50     /**
51      * Returns an empty observable list. The returned list continues to work
52      * after it has been disposed of and can be disposed of multiple times.
53      *
54      * @return an empty observable list.
55      */

56     public static IObservableList emptyObservableList() {
57         return new EmptyObservableList(Realm.getDefault());
58     }
59
60     /**
61      * Returns an empty observable list. The returned list continues to work
62      * after it has been disposed of and can be disposed of multiple times.
63      *
64      * @param realm
65      * @return an empty observable list.
66      */

67     public static IObservableList emptyObservableList(Realm realm) {
68         return new EmptyObservableList(realm);
69     }
70
71     /**
72      * Returns an empty observable set. The returned set continues to work after
73      * it has been disposed of and can be disposed of multiple times.
74      *
75      * @return an empty observable set.
76      */

77     public static IObservableSet emptyObservableSet() {
78         return new EmptyObservableSet(Realm.getDefault());
79     }
80
81     /**
82      * Returns an empty observable set. The returned set continues to work after
83      * it has been disposed of and can be disposed of multiple times.
84      *
85      * @param realm
86      * @return an empty observable set.
87      */

88     public static IObservableSet emptyObservableSet(Realm realm) {
89         return new EmptyObservableSet(realm);
90     }
91
92     /**
93      * @param set
94      * @return Returns an observableSet backed by the given set
95      */

96     public static IObservableSet staticObservableSet(Set JavaDoc set) {
97         return new ObservableSet(Realm.getDefault(), set, Object JavaDoc.class) {
98             public void addChangeListener(IChangeListener listener) {
99             }
100
101             public void addStaleListener(IStaleListener listener) {
102             }
103
104             public void addSetChangeListener(ISetChangeListener listener) {
105             }
106         };
107     }
108
109     /**
110      * @param realm
111      * @param set
112      * @return Returns an observableSet backed by the given set
113      */

114     public static IObservableSet staticObservableSet(Realm realm, Set JavaDoc set) {
115         return new ObservableSet(realm, set, Object JavaDoc.class) {
116             public void addChangeListener(IChangeListener listener) {
117             }
118
119             public void addStaleListener(IStaleListener listener) {
120             }
121
122             public void addSetChangeListener(ISetChangeListener listener) {
123             }
124         };
125     }
126
127     /**
128      * Returns an observable set that contains the same elements as the given
129      * set, and fires the same events as the given set, but can be disposed of
130      * without disposing of the wrapped set.
131      *
132      * @param target
133      * the set to wrap
134      * @return a proxy observable set
135      */

136     public static IObservableSet proxyObservableSet(IObservableSet target) {
137         return new ProxyObservableSet(target);
138     }
139
140     /**
141      * @param list
142      * @return an observable list that never fires events
143      */

144     public static IObservableList staticObservableList(List JavaDoc list) {
145         return staticObservableList(Realm.getDefault(), list);
146     }
147
148     /**
149      * @param realm
150      * @param list
151      * @return an observable list that never fires events
152      */

153     public static IObservableList staticObservableList(Realm realm, List JavaDoc list) {
154         return new ObservableList(realm, list, Object JavaDoc.class) {
155             public void addChangeListener(IChangeListener listener) {
156             }
157
158             public void addStaleListener(IStaleListener listener) {
159             }
160
161             public void addListChangeListener(IListChangeListener listener) {
162             }
163         };
164     }
165 }
166
Popular Tags