|
Lines 17-23
Link Here
|
| 17 |
*/ |
17 |
*/ |
| 18 |
package org.eclipse.emf.databinding; |
18 |
package org.eclipse.emf.databinding; |
| 19 |
|
19 |
|
| 20 |
|
|
|
| 21 |
import org.eclipse.core.databinding.observable.IObservable; |
20 |
import org.eclipse.core.databinding.observable.IObservable; |
| 22 |
import org.eclipse.core.databinding.observable.Realm; |
21 |
import org.eclipse.core.databinding.observable.Realm; |
| 23 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
22 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
|
Lines 26-194
Link Here
|
| 26 |
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; |
25 |
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; |
| 27 |
import org.eclipse.core.databinding.observable.set.IObservableSet; |
26 |
import org.eclipse.core.databinding.observable.set.IObservableSet; |
| 28 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
27 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
|
|
28 |
import org.eclipse.emf.common.notify.NotifyingList; |
| 29 |
import org.eclipse.emf.databinding.internal.EWritableList; |
| 29 |
import org.eclipse.emf.ecore.EObject; |
30 |
import org.eclipse.emf.ecore.EObject; |
| 30 |
import org.eclipse.emf.ecore.EStructuralFeature; |
31 |
import org.eclipse.emf.ecore.EStructuralFeature; |
|
|
32 |
import org.eclipse.emf.ecore.resource.Resource; |
| 31 |
|
33 |
|
| 32 |
/** |
34 |
/** |
| 33 |
* PROVISIONAL |
35 |
* PROVISIONAL This API is subject to arbitrary change, including renaming or |
| 34 |
* This API is subject to arbitrary change, including renaming or removal. |
36 |
* removal. |
| 35 |
*/ |
37 |
*/ |
| 36 |
public class EMFObservables |
38 |
public class EMFObservables { |
| 37 |
{ |
39 |
/** |
| 38 |
/** |
40 |
* Returns an observable value for the given feature of the object. |
| 39 |
* Returns an observable value for the given feature of the object. |
41 |
* |
| 40 |
* @param eObject the object to observe. |
42 |
* @param eObject |
| 41 |
* @param eStructuralFeature the feature of the object to observe. |
43 |
* the object to observe. |
| 42 |
* @return an observable value for the given feature of the object. |
44 |
* @param eStructuralFeature |
| 43 |
*/ |
45 |
* the feature of the object to observe. |
| 44 |
public static IObservableValue observeValue(EObject eObject, EStructuralFeature eStructuralFeature) |
46 |
* @return an observable value for the given feature of the object. |
| 45 |
{ |
47 |
*/ |
| 46 |
return new EObjectObservableValue(eObject, eStructuralFeature); |
48 |
public static IObservableValue observeValue(EObject eObject, |
| 47 |
} |
49 |
EStructuralFeature eStructuralFeature) { |
| 48 |
|
50 |
return new EObjectObservableValue(eObject, eStructuralFeature); |
| 49 |
/** |
51 |
} |
| 50 |
* Returns an observable value for the given feature of the object. |
52 |
|
| 51 |
* @param realm the realm in which to observe. |
53 |
/** |
| 52 |
* @param eObject the object to observe. |
54 |
* Returns an observable value for the given feature of the object. |
| 53 |
* @param eStructuralFeature the feature of the object to observe. |
55 |
* |
| 54 |
* @return an observable value for the given feature of the object. |
56 |
* @param realm |
| 55 |
*/ |
57 |
* the realm in which to observe. |
| 56 |
public static IObservableValue observeValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature) |
58 |
* @param eObject |
| 57 |
{ |
59 |
* the object to observe. |
| 58 |
return new EObjectObservableValue(realm, eObject, eStructuralFeature); |
60 |
* @param eStructuralFeature |
| 59 |
} |
61 |
* the feature of the object to observe. |
| 60 |
|
62 |
* @return an observable value for the given feature of the object. |
| 61 |
/** |
63 |
*/ |
| 62 |
* Returns an observable list for the given multi-valued feature of the object. |
64 |
public static IObservableValue observeValue(Realm realm, EObject eObject, |
| 63 |
* @param eObject the object to observe. |
65 |
EStructuralFeature eStructuralFeature) { |
| 64 |
* @param eStructuralFeature the feature of the object to observe. |
66 |
return new EObjectObservableValue(realm, eObject, eStructuralFeature); |
| 65 |
* @return an observable list for the given multi-valued feature of the object. |
67 |
} |
| 66 |
*/ |
68 |
|
| 67 |
public static IObservableList observeList(EObject eObject, EStructuralFeature eStructuralFeature) |
69 |
/** |
| 68 |
{ |
70 |
* Returns an observable list for the given multi-valued feature of the |
| 69 |
return new EObjectObservableList(eObject, eStructuralFeature); |
71 |
* object. |
| 70 |
} |
72 |
* |
| 71 |
|
73 |
* @param eObject |
| 72 |
/** |
74 |
* the object to observe. |
| 73 |
* Returns an observable list for the given multi-valued feature of the object. |
75 |
* @param eStructuralFeature |
| 74 |
* @param realm the realm in which to observe. |
76 |
* the feature of the object to observe. |
| 75 |
* @param eObject the object to observe. |
77 |
* @return an observable list for the given multi-valued feature of the |
| 76 |
* @param eStructuralFeature the feature of the object to observe. |
78 |
* object. |
| 77 |
* @return an observable list for the given multi-valued feature of the object. |
79 |
*/ |
| 78 |
*/ |
80 |
public static IObservableList observeList(EObject eObject, |
| 79 |
public static IObservableList observeList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature) |
81 |
EStructuralFeature eStructuralFeature) { |
| 80 |
{ |
82 |
return new EObjectObservableList(eObject, eStructuralFeature); |
| 81 |
return new EObjectObservableList(realm, eObject, eStructuralFeature); |
83 |
} |
| 82 |
} |
84 |
|
| 83 |
|
85 |
/** |
| 84 |
/** |
86 |
* Returns an observable list for the given multi-valued feature of the |
| 85 |
* Returns an observable map in the default realm |
87 |
* object. |
| 86 |
* tracking the current value of the given feature for each object in the given set. |
88 |
* |
| 87 |
* @param objects the objects to track. |
89 |
* @param realm |
| 88 |
* @param eStructuralFeature the feature for which to track the value. |
90 |
* the realm in which to observe. |
| 89 |
* @return an observable map tracking the current value of the given feature for each object in the given set. |
91 |
* @param eObject |
| 90 |
*/ |
92 |
* the object to observe. |
| 91 |
public static IObservableMap observeMap(IObservableSet objects, EStructuralFeature eStructuralFeature) |
93 |
* @param eStructuralFeature |
| 92 |
{ |
94 |
* the feature of the object to observe. |
| 93 |
return new EObjectObservableMap(objects, eStructuralFeature); |
95 |
* @return an observable list for the given multi-valued feature of the |
| 94 |
} |
96 |
* object. |
| 95 |
|
97 |
*/ |
| 96 |
/** |
98 |
public static IObservableList observeList(Realm realm, EObject eObject, |
| 97 |
* Returns an array of observable maps in the default realm |
99 |
EStructuralFeature eStructuralFeature) { |
| 98 |
* tracking the current value of the given features for each object in the given set. |
100 |
return new EObjectObservableList(realm, eObject, eStructuralFeature); |
| 99 |
* @param objects the objects to track. |
101 |
} |
| 100 |
* @param eStructuralFeatures the features for which to track the value. |
102 |
|
| 101 |
* @return an array of observable maps tracking the current value of the given features for each object in the given set. |
103 |
/** |
| 102 |
*/ |
104 |
* Returns an observable map in the default realm tracking the current value |
| 103 |
public static IObservableMap[] observeMaps(IObservableSet objects, EStructuralFeature[] eStructuralFeatures) |
105 |
* of the given feature for each object in the given set. |
| 104 |
{ |
106 |
* |
| 105 |
IObservableMap[] result = new IObservableMap [eStructuralFeatures.length]; |
107 |
* @param objects |
| 106 |
for (int i = 0; i < eStructuralFeatures.length; i++) |
108 |
* the objects to track. |
| 107 |
{ |
109 |
* @param eStructuralFeature |
| 108 |
result[i] = observeMap(objects, eStructuralFeatures[i]); |
110 |
* the feature for which to track the value. |
| 109 |
} |
111 |
* @return an observable map tracking the current value of the given feature |
| 110 |
return result; |
112 |
* for each object in the given set. |
| 111 |
} |
113 |
*/ |
| 112 |
|
114 |
public static IObservableMap observeMap(IObservableSet objects, |
| 113 |
/** |
115 |
EStructuralFeature eStructuralFeature) { |
| 114 |
* Returns an observable value that tracks the current value of the feature of the current value of the master observable value. |
116 |
return new EObjectObservableMap(objects, eStructuralFeature); |
| 115 |
* @param realm the realm in which to observe. |
117 |
} |
| 116 |
* @param value the master observable value. |
118 |
|
| 117 |
* @param eStructuralFeature the feature for which to track the value. |
119 |
/** |
| 118 |
* @return an observable value that tracks the current value of the named property for the current value of the master observable value |
120 |
* Returns an array of observable maps in the default realm tracking the |
| 119 |
* @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object) |
121 |
* current value of the given features for each object in the given set. |
| 120 |
*/ |
122 |
* |
| 121 |
public static IObservableValue observeDetailValue(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature) |
123 |
* @param objects |
| 122 |
{ |
124 |
* the objects to track. |
| 123 |
return MasterDetailObservables.detailValue(value, valueFactory(realm, eStructuralFeature), eStructuralFeature); |
125 |
* @param eStructuralFeatures |
| 124 |
} |
126 |
* the features for which to track the value. |
| 125 |
|
127 |
* @return an array of observable maps tracking the current value of the |
| 126 |
/** |
128 |
* given features for each object in the given set. |
| 127 |
* Returns a factory for creating observable values |
129 |
*/ |
| 128 |
* tracking the value of the given feature of a particular {@link EObject object}. |
130 |
public static IObservableMap[] observeMaps(IObservableSet objects, |
| 129 |
* @param realm the realm in which to observe. |
131 |
EStructuralFeature[] eStructuralFeatures) { |
| 130 |
* @param eStructuralFeature the feature for which to track the value. |
132 |
IObservableMap[] result = new IObservableMap[eStructuralFeatures.length]; |
| 131 |
* @return an observable factory. |
133 |
for (int i = 0; i < eStructuralFeatures.length; i++) { |
| 132 |
*/ |
134 |
result[i] = observeMap(objects, eStructuralFeatures[i]); |
| 133 |
public static IObservableFactory valueFactory(final Realm realm, final EStructuralFeature eStructuralFeature) |
135 |
} |
| 134 |
{ |
136 |
return result; |
| 135 |
return |
137 |
} |
| 136 |
new IObservableFactory() |
138 |
|
| 137 |
{ |
139 |
/** |
| 138 |
public IObservable createObservable(Object target) |
140 |
* Returns an observable value that tracks the current value of the feature |
| 139 |
{ |
141 |
* of the current value of the master observable value. |
| 140 |
return observeValue(realm, (EObject)target, eStructuralFeature); |
142 |
* |
| 141 |
} |
143 |
* @param realm |
| 142 |
}; |
144 |
* the realm in which to observe. |
| 143 |
} |
145 |
* @param value |
| 144 |
|
146 |
* the master observable value. |
| 145 |
/** |
147 |
* @param eStructuralFeature |
| 146 |
* Returns an observable list that tracks the current value of the feature of the current value of the master observable value. |
148 |
* the feature for which to track the value. |
| 147 |
* @param realm the realm in which to observe. |
149 |
* @return an observable value that tracks the current value of the named |
| 148 |
* @param value the master observable value. |
150 |
* property for the current value of the master observable value |
| 149 |
* @param eStructuralFeature the feature for which to track the value. |
151 |
* @see MasterDetailObservables#detailValue(IObservableValue, |
| 150 |
* @return an observable value that tracks the current value of the named property for the current value of the master observable value |
152 |
* IObservableFactory, Object) |
| 151 |
* @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object) |
153 |
*/ |
| 152 |
*/ |
154 |
public static IObservableValue observeDetailValue(Realm realm, |
| 153 |
public static IObservableList observeDetailList(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature) |
155 |
IObservableValue value, EStructuralFeature eStructuralFeature) { |
| 154 |
{ |
156 |
return MasterDetailObservables.detailValue(value, valueFactory(realm, |
| 155 |
return MasterDetailObservables.detailList(value, listFactory(realm, eStructuralFeature), eStructuralFeature); |
157 |
eStructuralFeature), eStructuralFeature); |
| 156 |
} |
158 |
} |
| 157 |
|
159 |
|
| 158 |
/** |
160 |
/** |
| 159 |
* Returns a factory for creating observable lists |
161 |
* Returns a factory for creating observable values tracking the value of |
| 160 |
* tracking the value of the given feature of a particular {@link EObject object}. |
162 |
* the given feature of a particular {@link EObject object}. |
| 161 |
* @param realm the realm in which to observe. |
163 |
* |
| 162 |
* @param eStructuralFeature the feature for which to track the value. |
164 |
* @param realm |
| 163 |
* @return an observable factory. |
165 |
* the realm in which to observe. |
| 164 |
*/ |
166 |
* @param eStructuralFeature |
| 165 |
public static IObservableFactory listFactory(final Realm realm, final EStructuralFeature eStructuralFeature) |
167 |
* the feature for which to track the value. |
| 166 |
{ |
168 |
* @return an observable factory. |
| 167 |
return |
169 |
*/ |
| 168 |
new IObservableFactory() |
170 |
public static IObservableFactory valueFactory(final Realm realm, |
| 169 |
{ |
171 |
final EStructuralFeature eStructuralFeature) { |
| 170 |
public IObservable createObservable(Object target) |
172 |
return new IObservableFactory() { |
| 171 |
{ |
173 |
public IObservable createObservable(Object target) { |
| 172 |
return observeList(realm, (EObject)target, eStructuralFeature); |
174 |
return observeValue(realm, (EObject) target, eStructuralFeature); |
| 173 |
} |
175 |
} |
| 174 |
}; |
176 |
}; |
| 175 |
} |
177 |
} |
| 176 |
|
178 |
|
| 177 |
/** |
179 |
/** |
| 178 |
* Returns a factory for creating observable maps |
180 |
* Returns an observable list that tracks the current value of the feature |
| 179 |
* tracking the value of the given feature of a particular {@link EObject object}. |
181 |
* of the current value of the master observable value. |
| 180 |
* @param eStructuralFeature the feature for which to track the value. |
182 |
* |
| 181 |
* @return an observable factory. |
183 |
* @param realm |
| 182 |
*/ |
184 |
* the realm in which to observe. |
| 183 |
public static IObservableFactory mapFactory(final EStructuralFeature eStructuralFeature) |
185 |
* @param value |
| 184 |
{ |
186 |
* the master observable value. |
| 185 |
return |
187 |
* @param eStructuralFeature |
| 186 |
new IObservableFactory() |
188 |
* the feature for which to track the value. |
| 187 |
{ |
189 |
* @return an observable value that tracks the current value of the named |
| 188 |
public IObservable createObservable(Object target) |
190 |
* property for the current value of the master observable value |
| 189 |
{ |
191 |
* @see MasterDetailObservables#detailList(IObservableValue, |
| 190 |
return observeMap((IObservableSet)target, eStructuralFeature); |
192 |
* IObservableFactory, Object) |
| 191 |
} |
193 |
*/ |
| 192 |
}; |
194 |
public static IObservableList observeDetailList(Realm realm, |
| 193 |
} |
195 |
IObservableValue value, EStructuralFeature eStructuralFeature) { |
|
|
196 |
return MasterDetailObservables.detailList(value, listFactory(realm, |
| 197 |
eStructuralFeature), eStructuralFeature); |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Returns a factory for creating observable lists tracking the value of the |
| 202 |
* given feature of a particular {@link EObject object}. |
| 203 |
* |
| 204 |
* @param realm |
| 205 |
* the realm in which to observe. |
| 206 |
* @param eStructuralFeature |
| 207 |
* the feature for which to track the value. |
| 208 |
* @return an observable factory. |
| 209 |
*/ |
| 210 |
public static IObservableFactory listFactory(final Realm realm, |
| 211 |
final EStructuralFeature eStructuralFeature) { |
| 212 |
return new IObservableFactory() { |
| 213 |
public IObservable createObservable(Object target) { |
| 214 |
return observeList(realm, (EObject) target, eStructuralFeature); |
| 215 |
} |
| 216 |
}; |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* Returns a factory for creating observable maps tracking the value of the |
| 221 |
* given feature of a particular {@link EObject object}. |
| 222 |
* |
| 223 |
* @param eStructuralFeature |
| 224 |
* the feature for which to track the value. |
| 225 |
* @return an observable factory. |
| 226 |
*/ |
| 227 |
public static IObservableFactory mapFactory( |
| 228 |
final EStructuralFeature eStructuralFeature) { |
| 229 |
return new IObservableFactory() { |
| 230 |
public IObservable createObservable(Object target) { |
| 231 |
return observeMap((IObservableSet) target, eStructuralFeature); |
| 232 |
} |
| 233 |
}; |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* Returns an observable for the resource contents ( |
| 238 |
* {@link Resource#getContents()}) |
| 239 |
* |
| 240 |
* @param resource |
| 241 |
* the resources the content should be observed |
| 242 |
* @return an observable list |
| 243 |
*/ |
| 244 |
public static IObservableList observeResourceContents(Resource resource) { |
| 245 |
return new EWritableList<EObject>((NotifyingList<EObject>) resource.getContents()); |
| 246 |
} |
| 194 |
} |
247 |
} |