|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008 Matthew Hall 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 |
* Matthew Hall - initial API and implementation (bug 194734) |
| 10 |
******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.core.databinding.property; |
| 13 |
|
| 14 |
import org.eclipse.core.databinding.observable.IObservable; |
| 15 |
import org.eclipse.core.databinding.observable.Realm; |
| 16 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
| 17 |
import org.eclipse.core.databinding.observable.map.IObservableMap; |
| 18 |
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; |
| 19 |
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; |
| 20 |
import org.eclipse.core.databinding.observable.set.IObservableSet; |
| 21 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
| 22 |
import org.eclipse.core.databinding.property.list.IListProperty; |
| 23 |
import org.eclipse.core.databinding.property.map.IMapProperty; |
| 24 |
import org.eclipse.core.databinding.property.set.ISetProperty; |
| 25 |
import org.eclipse.core.databinding.property.value.IValueProperty; |
| 26 |
import org.eclipse.core.internal.databinding.observable.PropertyObservableList; |
| 27 |
import org.eclipse.core.internal.databinding.observable.PropertyObservableMap; |
| 28 |
import org.eclipse.core.internal.databinding.observable.PropertyObservableSet; |
| 29 |
import org.eclipse.core.internal.databinding.observable.PropertyObservableValue; |
| 30 |
import org.eclipse.core.internal.databinding.observable.masterdetail.ListValuePropertyObservableList; |
| 31 |
import org.eclipse.core.internal.databinding.observable.masterdetail.MapValuePropertyObservableMap; |
| 32 |
import org.eclipse.core.internal.databinding.observable.masterdetail.SetValuePropertyObservableMap; |
| 33 |
|
| 34 |
/** |
| 35 |
* A factory for creating observables observing properties of source objects |
| 36 |
* |
| 37 |
* @since 1.2 |
| 38 |
*/ |
| 39 |
public class PropertyObservables { |
| 40 |
/** |
| 41 |
* Returns an observable value on the default realm that tracks the given |
| 42 |
* property of the source object. |
| 43 |
* |
| 44 |
* @param source |
| 45 |
* the property value |
| 46 |
* @param property |
| 47 |
* the value property to observe |
| 48 |
* @return an observable value on the default realm that tracks the given |
| 49 |
* property of the source object. |
| 50 |
* @since 1.2 |
| 51 |
*/ |
| 52 |
public static IObservableValue observeValue(Object source, |
| 53 |
IValueProperty property) { |
| 54 |
return observeValue(Realm.getDefault(), source, property); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Returns an observable value on the given realm that tracks the given |
| 59 |
* property of the source object |
| 60 |
* |
| 61 |
* @param realm |
| 62 |
* the realm |
| 63 |
* @param source |
| 64 |
* the property source |
| 65 |
* @param property |
| 66 |
* the value property observe |
| 67 |
* @return an observable value that tracks the given property of the source |
| 68 |
* object |
| 69 |
* @since 1.2 |
| 70 |
*/ |
| 71 |
public static IObservableValue observeValue(Realm realm, Object source, |
| 72 |
IValueProperty property) { |
| 73 |
return new PropertyObservableValue(realm, source, property); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Returns a factory for creating observable values on the default realm |
| 78 |
* tracking the given property of a particular source object |
| 79 |
* |
| 80 |
* @param property |
| 81 |
* the property to observe |
| 82 |
* @return a factory for creating observable values on the default realm |
| 83 |
* tracking the given property of a particular source object |
| 84 |
*/ |
| 85 |
public static IObservableFactory valueFactory(IValueProperty property) { |
| 86 |
return valueFactory(Realm.getDefault(), property); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Returns a factory for creating observable values on the given realm |
| 91 |
* tracking the given property of a particular source object |
| 92 |
* |
| 93 |
* @param realm |
| 94 |
* the realm |
| 95 |
* @param property |
| 96 |
* the property to observe |
| 97 |
* @return a factory for creating observable values on the given realm |
| 98 |
* tracking the given property of a particular source object |
| 99 |
*/ |
| 100 |
public static IObservableFactory valueFactory(final Realm realm, |
| 101 |
final IValueProperty property) { |
| 102 |
return new IObservableFactory() { |
| 103 |
public IObservable createObservable(Object target) { |
| 104 |
return observeValue(realm, target, property); |
| 105 |
} |
| 106 |
}; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Returns an observable value on the master observable's realm which tracks |
| 111 |
* the given property of the current value of <code>master</code>. |
| 112 |
* |
| 113 |
* @param master |
| 114 |
* the master observable |
| 115 |
* @param property |
| 116 |
* the property to observe |
| 117 |
* @return an observable value which tracks the given property of the |
| 118 |
* current value of <code>master</code>. |
| 119 |
*/ |
| 120 |
public static IObservableValue observeDetailValue(IObservableValue master, |
| 121 |
IValueProperty property) { |
| 122 |
return MasterDetailObservables.detailValue(master, valueFactory(master |
| 123 |
.getRealm(), property), property.getValueType()); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Returns an observable set on the default realm that tracks the given |
| 128 |
* property of the source object |
| 129 |
* |
| 130 |
* @param source |
| 131 |
* the property source |
| 132 |
* @param property |
| 133 |
* the property to observe |
| 134 |
* @return an observable set on the default realm that tracks the given |
| 135 |
* property of the source object |
| 136 |
*/ |
| 137 |
public static IObservableSet observeSet(Object source, ISetProperty property) { |
| 138 |
return observeSet(Realm.getDefault(), source, property); |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Returns an observable set on the given realm that tracks the given |
| 143 |
* property of the source object |
| 144 |
* |
| 145 |
* @param realm |
| 146 |
* the realm |
| 147 |
* @param source |
| 148 |
* the property source |
| 149 |
* @param property |
| 150 |
* the property to observe |
| 151 |
* @return an observable set on the given realm that tracks the given |
| 152 |
* property of the source object |
| 153 |
*/ |
| 154 |
public static IObservableSet observeSet(Realm realm, Object source, |
| 155 |
ISetProperty property) { |
| 156 |
return new PropertyObservableSet(realm, source, property); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Returns a factory for creating observable sets on the default realm |
| 161 |
* tracking the given property of a particular source object |
| 162 |
* |
| 163 |
* @param property |
| 164 |
* the property to be observed |
| 165 |
* @return a factory for creating observable sets on the default realm |
| 166 |
* tracking the given property of a particular source object |
| 167 |
*/ |
| 168 |
public static IObservableFactory setFactory(ISetProperty property) { |
| 169 |
return setFactory(Realm.getDefault(), property); |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Returns a factory for creating obervable sets on the given realm tracking |
| 174 |
* the given property of a particular source object |
| 175 |
* |
| 176 |
* @param realm |
| 177 |
* the realm |
| 178 |
* @param property |
| 179 |
* the property to be observed |
| 180 |
* @return a factory for creating obervable sets on the given realm tracking |
| 181 |
* the given property of a particular source object |
| 182 |
*/ |
| 183 |
public static IObservableFactory setFactory(final Realm realm, |
| 184 |
final ISetProperty property) { |
| 185 |
return new IObservableFactory() { |
| 186 |
public IObservable createObservable(Object target) { |
| 187 |
return observeSet(realm, target, property); |
| 188 |
} |
| 189 |
}; |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Returns an observable set on the master observable's realm which tracks |
| 194 |
* the given property of the current value of <code>master</code>. |
| 195 |
* |
| 196 |
* @param master |
| 197 |
* the master observable |
| 198 |
* @param property |
| 199 |
* the property to observe |
| 200 |
* @return an observable set on the given realm which tracks the given |
| 201 |
* property of the current value of <code>master</code>. |
| 202 |
*/ |
| 203 |
public static IObservableSet observeDetailSet(IObservableValue master, |
| 204 |
ISetProperty property) { |
| 205 |
return MasterDetailObservables.detailSet(master, setFactory(master |
| 206 |
.getRealm(), property), property.getElementType()); |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Returns an observable list on the default realm that tracks the given |
| 211 |
* property of the source object |
| 212 |
* |
| 213 |
* @param source |
| 214 |
* the property source |
| 215 |
* @param property |
| 216 |
* the property to observe |
| 217 |
* @return an observable list on the default realm that tracks the given |
| 218 |
* property of the source object |
| 219 |
*/ |
| 220 |
public static IObservableList observeList(Object source, |
| 221 |
IListProperty property) { |
| 222 |
return observeList(Realm.getDefault(), source, property); |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Returns an observable list on the given realm that tracks the given |
| 227 |
* property of the source object |
| 228 |
* |
| 229 |
* @param realm |
| 230 |
* the realm |
| 231 |
* @param source |
| 232 |
* the property source |
| 233 |
* @param property |
| 234 |
* the property to observe |
| 235 |
* @return an observable list on the given realm that tracks the given |
| 236 |
* property of the source object |
| 237 |
*/ |
| 238 |
public static IObservableList observeList(Realm realm, Object source, |
| 239 |
IListProperty property) { |
| 240 |
return new PropertyObservableList(realm, source, property); |
| 241 |
} |
| 242 |
|
| 243 |
/** |
| 244 |
* Returns a factory for creating observable lists on the default realm |
| 245 |
* tracking the given property of a particular source object |
| 246 |
* |
| 247 |
* @param property |
| 248 |
* the property to be observed |
| 249 |
* @return an observable value factory on |
| 250 |
*/ |
| 251 |
public static IObservableFactory listFactory(IListProperty property) { |
| 252 |
return listFactory(Realm.getDefault(), property); |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Returns a factory for creating obervable lists on the given realm |
| 257 |
* tracking the given property of a particular source object |
| 258 |
* |
| 259 |
* @param realm |
| 260 |
* the realm |
| 261 |
* @param property |
| 262 |
* the property to be observed |
| 263 |
* @return an observable value factory on |
| 264 |
*/ |
| 265 |
public static IObservableFactory listFactory(final Realm realm, |
| 266 |
final IListProperty property) { |
| 267 |
return new IObservableFactory() { |
| 268 |
public IObservable createObservable(Object target) { |
| 269 |
return observeList(realm, target, property); |
| 270 |
} |
| 271 |
}; |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* Returns an observable list on the master observable's realm which tracks |
| 276 |
* the given property of the current value of <code>master</code>. |
| 277 |
* |
| 278 |
* @param master |
| 279 |
* the master observable |
| 280 |
* @param property |
| 281 |
* the property to observe |
| 282 |
* @return an observable list on the given realm which tracks the given |
| 283 |
* property of the current value of <code>master</code>. |
| 284 |
*/ |
| 285 |
public static IObservableList observeDetailList(IObservableValue master, |
| 286 |
IListProperty property) { |
| 287 |
return MasterDetailObservables.detailList(master, listFactory(master |
| 288 |
.getRealm(), property), property.getElementType()); |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Returns an observable list on the master observable's realm which tracks |
| 293 |
* the given property of each element of <code>master</code>. |
| 294 |
* |
| 295 |
* @param master |
| 296 |
* the master observable |
| 297 |
* @param property |
| 298 |
* the property to observe on each element in the master |
| 299 |
* observable |
| 300 |
* @return an observable |
| 301 |
*/ |
| 302 |
public static IObservableList observeDetailValues(IObservableList master, |
| 303 |
IValueProperty property) { |
| 304 |
return new ListValuePropertyObservableList(master, property); |
| 305 |
} |
| 306 |
|
| 307 |
/** |
| 308 |
* Returns an observable map on the default realm which tracks the given |
| 309 |
* property of the source object |
| 310 |
* |
| 311 |
* @param source |
| 312 |
* the property source |
| 313 |
* @param property |
| 314 |
* the property to observe |
| 315 |
* @return an observable map on the default realm which tracks the given |
| 316 |
* property of the source object |
| 317 |
*/ |
| 318 |
public static IObservableMap observeMap(Object source, IMapProperty property) { |
| 319 |
return observeMap(Realm.getDefault(), source, property); |
| 320 |
} |
| 321 |
|
| 322 |
/** |
| 323 |
* Returns an observable map on the given realm which tracks the given |
| 324 |
* property of the source object |
| 325 |
* |
| 326 |
* @param realm |
| 327 |
* the realm |
| 328 |
* @param source |
| 329 |
* the property source |
| 330 |
* @param property |
| 331 |
* the property to observe |
| 332 |
* @return an observable map on the given realm which tracks the given |
| 333 |
* property of the source object |
| 334 |
*/ |
| 335 |
public static IObservableMap observeMap(Realm realm, Object source, |
| 336 |
IMapProperty property) { |
| 337 |
return new PropertyObservableMap(realm, source, property); |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* Returns an observable map on the master observable's realm tracking the |
| 342 |
* current values of the given property for the elements in the given set. |
| 343 |
* |
| 344 |
* @param keySet |
| 345 |
* the master observable |
| 346 |
* @param valueProperty |
| 347 |
* the property to observe on each element of the master |
| 348 |
* observable |
| 349 |
* @return an observable map that tracks the current value of the given |
| 350 |
* property for the elements in the given set. |
| 351 |
*/ |
| 352 |
public static IObservableMap observeDetailValues(IObservableSet keySet, |
| 353 |
IValueProperty valueProperty) { |
| 354 |
return new SetValuePropertyObservableMap(keySet, valueProperty); |
| 355 |
} |
| 356 |
|
| 357 |
/** |
| 358 |
* Returns an observable map on the master observable's realm which tracks |
| 359 |
* the current values of the given property for the entry values in the |
| 360 |
* given map. |
| 361 |
* |
| 362 |
* @param map |
| 363 |
* the master observable |
| 364 |
* @param valueProperty |
| 365 |
* the property to observe on each entry value in the master |
| 366 |
* observable |
| 367 |
* @return an observable map on the master observable's realm which tracks |
| 368 |
* the current value of the given property for the elements in the |
| 369 |
* given map's values collection |
| 370 |
*/ |
| 371 |
public static IObservableMap observeDetailValues(IObservableMap map, |
| 372 |
IValueProperty valueProperty) { |
| 373 |
return new MapValuePropertyObservableMap(map, valueProperty); |
| 374 |
} |
| 375 |
} |