|
Lines 27-41
Link Here
|
| 27 |
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; |
27 |
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; |
| 28 |
import org.eclipse.core.databinding.observable.set.IObservableSet; |
28 |
import org.eclipse.core.databinding.observable.set.IObservableSet; |
| 29 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
29 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
|
|
30 |
import org.eclipse.core.databinding.property.PropertyObservables; |
| 30 |
import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; |
31 |
import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; |
| 31 |
import org.eclipse.core.internal.databinding.beans.BeanObservableMapDecorator; |
32 |
import org.eclipse.core.internal.databinding.beans.BeanObservableMapDecorator; |
| 32 |
import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; |
33 |
import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; |
| 33 |
import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; |
34 |
import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; |
| 34 |
import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; |
|
|
| 35 |
import org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap; |
| 36 |
import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; |
| 37 |
import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; |
| 38 |
import org.eclipse.core.internal.databinding.beans.JavaBeanPropertyObservableMap; |
| 39 |
import org.eclipse.core.runtime.Assert; |
35 |
import org.eclipse.core.runtime.Assert; |
| 40 |
|
36 |
|
| 41 |
/** |
37 |
/** |
|
Lines 83-91
Link Here
|
| 83 |
*/ |
79 |
*/ |
| 84 |
public static IObservableValue observeValue(Realm realm, Object bean, |
80 |
public static IObservableValue observeValue(Realm realm, Object bean, |
| 85 |
String propertyName) { |
81 |
String propertyName) { |
| 86 |
PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), |
82 |
return PropertyObservables.observeValue(realm, bean, BeanProperties |
| 87 |
propertyName); |
83 |
.valueProperty(bean.getClass(), propertyName)); |
| 88 |
return new JavaBeanObservableValue(realm, bean, descriptor); |
|
|
| 89 |
} |
84 |
} |
| 90 |
|
85 |
|
| 91 |
/** |
86 |
/** |
|
Lines 103-111
Link Here
|
| 103 |
*/ |
98 |
*/ |
| 104 |
public static IObservableMap observeMap(IObservableSet domain, |
99 |
public static IObservableMap observeMap(IObservableSet domain, |
| 105 |
Class beanClass, String propertyName) { |
100 |
Class beanClass, String propertyName) { |
| 106 |
PropertyDescriptor descriptor = getPropertyDescriptor(beanClass, |
101 |
return PropertyObservables.observeMap(domain, BeanProperties |
| 107 |
propertyName); |
102 |
.valueProperty(beanClass, propertyName)); |
| 108 |
return new JavaBeanObservableMap(domain, descriptor); |
|
|
| 109 |
} |
103 |
} |
| 110 |
|
104 |
|
| 111 |
/** |
105 |
/** |
|
Lines 124-132
Link Here
|
| 124 |
*/ |
118 |
*/ |
| 125 |
public static IObservableMap observeMap(Realm realm, Object bean, |
119 |
public static IObservableMap observeMap(Realm realm, Object bean, |
| 126 |
String propertyName) { |
120 |
String propertyName) { |
| 127 |
PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), |
121 |
return PropertyObservables.observeMap(realm, bean, BeanProperties |
| 128 |
propertyName); |
122 |
.mapProperty(bean.getClass(), propertyName)); |
| 129 |
return new JavaBeanPropertyObservableMap(realm, bean, descriptor); |
|
|
| 130 |
} |
123 |
} |
| 131 |
|
124 |
|
| 132 |
/** |
125 |
/** |
|
Lines 145-152
Link Here
|
| 145 |
return observeMap(Realm.getDefault(), bean, propertyName); |
138 |
return observeMap(Realm.getDefault(), bean, propertyName); |
| 146 |
} |
139 |
} |
| 147 |
|
140 |
|
| 148 |
/*package*/ static PropertyDescriptor getPropertyDescriptor(Class beanClass, |
141 |
/* package */static PropertyDescriptor getPropertyDescriptor( |
| 149 |
String propertyName) { |
142 |
Class beanClass, String propertyName) { |
| 150 |
BeanInfo beanInfo; |
143 |
BeanInfo beanInfo; |
| 151 |
try { |
144 |
try { |
| 152 |
beanInfo = Introspector.getBeanInfo(beanClass); |
145 |
beanInfo = Introspector.getBeanInfo(beanClass); |
|
Lines 231-239
Link Here
|
| 231 |
* collection-typed named property of the given bean object. The returned |
224 |
* collection-typed named property of the given bean object. The returned |
| 232 |
* list is mutable. When an item is added or removed the setter is invoked |
225 |
* list is mutable. When an item is added or removed the setter is invoked |
| 233 |
* for the list on the parent bean to provide notification to other |
226 |
* for the list on the parent bean to provide notification to other |
| 234 |
* listeners via <code>PropertyChangeEvents</code>. This is done to |
227 |
* listeners via <code>PropertyChangeEvents</code>. This is done to provide |
| 235 |
* provide the same behavior as is expected from arrays as specified in the |
228 |
* the same behavior as is expected from arrays as specified in the bean |
| 236 |
* bean spec in section 7.2. |
229 |
* spec in section 7.2. |
| 237 |
* |
230 |
* |
| 238 |
* @param realm |
231 |
* @param realm |
| 239 |
* the realm |
232 |
* the realm |
|
Lines 242-249
Link Here
|
| 242 |
* @param propertyName |
235 |
* @param propertyName |
| 243 |
* the name of the property |
236 |
* the name of the property |
| 244 |
* @param elementType |
237 |
* @param elementType |
| 245 |
* type of the elements in the list. If <code>null</code> and |
238 |
* type of the elements in the list. If <code>null</code> and the |
| 246 |
* the property is an array the type will be inferred. If |
239 |
* property is an array the type will be inferred. If |
| 247 |
* <code>null</code> and the property type cannot be inferred |
240 |
* <code>null</code> and the property type cannot be inferred |
| 248 |
* element type will be <code>null</code>. |
241 |
* element type will be <code>null</code>. |
| 249 |
* @return an observable list tracking the collection-typed named property |
242 |
* @return an observable list tracking the collection-typed named property |
|
Lines 251-262
Link Here
|
| 251 |
*/ |
244 |
*/ |
| 252 |
public static IObservableList observeList(Realm realm, Object bean, |
245 |
public static IObservableList observeList(Realm realm, Object bean, |
| 253 |
String propertyName, Class elementType) { |
246 |
String propertyName, Class elementType) { |
| 254 |
PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean |
247 |
return PropertyObservables.observeList(realm, bean, BeanProperties |
| 255 |
.getClass(), propertyName); |
248 |
.listProperty(bean.getClass(), propertyName, elementType)); |
| 256 |
elementType = getCollectionElementType(elementType, propertyDescriptor); |
|
|
| 257 |
|
| 258 |
return new JavaBeanObservableList(realm, bean, propertyDescriptor, |
| 259 |
elementType); |
| 260 |
} |
249 |
} |
| 261 |
|
250 |
|
| 262 |
/** |
251 |
/** |
|
Lines 439-449
Link Here
|
| 439 |
|
428 |
|
| 440 |
IObservableValue value = MasterDetailObservables.detailValue(master, |
429 |
IObservableValue value = MasterDetailObservables.detailValue(master, |
| 441 |
valueFactory(realm, propertyName), propertyType); |
430 |
valueFactory(realm, propertyName), propertyType); |
| 442 |
BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( |
431 |
return new BeanObservableValueDecorator(value, master, |
| 443 |
value, master, getValueTypePropertyDescriptor(master, |
432 |
getValueTypePropertyDescriptor(master, propertyName)); |
| 444 |
propertyName)); |
|
|
| 445 |
|
| 446 |
return decorator; |
| 447 |
} |
433 |
} |
| 448 |
|
434 |
|
| 449 |
/** |
435 |
/** |
|
Lines 469-478
Link Here
|
| 469 |
/** |
455 |
/** |
| 470 |
* Helper method for |
456 |
* Helper method for |
| 471 |
* <code>MasterDetailObservables.detailValue(master, valueFactory(realm, |
457 |
* <code>MasterDetailObservables.detailValue(master, valueFactory(realm, |
| 472 |
* propertyName), propertyType)</code>. |
458 |
* propertyName), propertyType)</code>. This method returns an |
| 473 |
* This method returns an {@link IBeanObservable} with a |
459 |
* {@link IBeanObservable} with a {@link PropertyDescriptor} based on the |
| 474 |
* {@link PropertyDescriptor} based on the given master type and property |
460 |
* given master type and property name. |
| 475 |
* name. |
|
|
| 476 |
* |
461 |
* |
| 477 |
* @param realm |
462 |
* @param realm |
| 478 |
* the realm |
463 |
* the realm |
|
Lines 492-506
Link Here
|
| 492 |
* @since 1.1 |
477 |
* @since 1.1 |
| 493 |
*/ |
478 |
*/ |
| 494 |
public static IObservableValue observeDetailValue(Realm realm, |
479 |
public static IObservableValue observeDetailValue(Realm realm, |
| 495 |
IObservableValue master, Class masterType, String propertyName, Class propertyType) { |
480 |
IObservableValue master, Class masterType, String propertyName, |
|
|
481 |
Class propertyType) { |
| 496 |
Assert.isNotNull(masterType, "masterType cannot be null"); //$NON-NLS-1$ |
482 |
Assert.isNotNull(masterType, "masterType cannot be null"); //$NON-NLS-1$ |
| 497 |
IObservableValue value = MasterDetailObservables.detailValue(master, |
483 |
IObservableValue value = MasterDetailObservables.detailValue(master, |
| 498 |
valueFactory(realm, propertyName), propertyType); |
484 |
valueFactory(realm, propertyName), propertyType); |
| 499 |
BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( |
485 |
return new BeanObservableValueDecorator(value, master, |
| 500 |
value, master, getPropertyDescriptor(masterType, |
486 |
getPropertyDescriptor(masterType, propertyName)); |
| 501 |
propertyName)); |
|
|
| 502 |
|
| 503 |
return decorator; |
| 504 |
} |
487 |
} |
| 505 |
|
488 |
|
| 506 |
/** |
489 |
/** |
|
Lines 551-561
Link Here
|
| 551 |
IObservableList observableList = MasterDetailObservables.detailList( |
534 |
IObservableList observableList = MasterDetailObservables.detailList( |
| 552 |
master, listFactory(realm, propertyName, propertyType), |
535 |
master, listFactory(realm, propertyName, propertyType), |
| 553 |
propertyType); |
536 |
propertyType); |
| 554 |
BeanObservableListDecorator decorator = new BeanObservableListDecorator( |
537 |
return new BeanObservableListDecorator(observableList, master, |
| 555 |
observableList, master, getValueTypePropertyDescriptor(master, |
538 |
getValueTypePropertyDescriptor(master, propertyName)); |
| 556 |
propertyName)); |
|
|
| 557 |
|
| 558 |
return decorator; |
| 559 |
} |
539 |
} |
| 560 |
|
540 |
|
| 561 |
/** |
541 |
/** |
|
Lines 599-609
Link Here
|
| 599 |
IObservableSet observableSet = MasterDetailObservables.detailSet( |
579 |
IObservableSet observableSet = MasterDetailObservables.detailSet( |
| 600 |
master, setFactory(realm, propertyName, propertyType), |
580 |
master, setFactory(realm, propertyName, propertyType), |
| 601 |
propertyType); |
581 |
propertyType); |
| 602 |
BeanObservableSetDecorator decorator = new BeanObservableSetDecorator( |
582 |
return new BeanObservableSetDecorator(observableSet, master, |
| 603 |
observableSet, master, getValueTypePropertyDescriptor(master, |
583 |
getValueTypePropertyDescriptor(master, propertyName)); |
| 604 |
propertyName)); |
|
|
| 605 |
|
| 606 |
return decorator; |
| 607 |
} |
584 |
} |
| 608 |
|
585 |
|
| 609 |
/** |
586 |
/** |
|
Lines 642-651
Link Here
|
| 642 |
IObservableValue master, String propertyName) { |
619 |
IObservableValue master, String propertyName) { |
| 643 |
IObservableMap observableMap = MasterDetailObservables.detailMap( |
620 |
IObservableMap observableMap = MasterDetailObservables.detailMap( |
| 644 |
master, mapPropertyFactory(realm, propertyName)); |
621 |
master, mapPropertyFactory(realm, propertyName)); |
| 645 |
BeanObservableMapDecorator decorator = new BeanObservableMapDecorator( |
622 |
return new BeanObservableMapDecorator(observableMap, master, |
| 646 |
observableMap, master, getValueTypePropertyDescriptor(master, |
623 |
getValueTypePropertyDescriptor(master, propertyName)); |
| 647 |
propertyName)); |
|
|
| 648 |
return decorator; |
| 649 |
} |
624 |
} |
| 650 |
|
625 |
|
| 651 |
/** |
626 |
/** |
|
Lines 688-699
Link Here
|
| 688 |
*/ |
663 |
*/ |
| 689 |
public static IObservableSet observeSet(Realm realm, Object bean, |
664 |
public static IObservableSet observeSet(Realm realm, Object bean, |
| 690 |
String propertyName, Class elementType) { |
665 |
String propertyName, Class elementType) { |
| 691 |
PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean |
666 |
return PropertyObservables.observeSet(realm, bean, BeanProperties |
| 692 |
.getClass(), propertyName); |
667 |
.setProperty(bean.getClass(), propertyName, elementType)); |
| 693 |
elementType = getCollectionElementType(elementType, propertyDescriptor); |
|
|
| 694 |
|
| 695 |
return new JavaBeanObservableSet(realm, bean, propertyDescriptor, |
| 696 |
elementType); |
| 697 |
} |
668 |
} |
| 698 |
|
669 |
|
| 699 |
/** |
670 |
/** |
|
Lines 780-796
Link Here
|
| 780 |
* @param propertyName |
751 |
* @param propertyName |
| 781 |
* the name of the property |
752 |
* the name of the property |
| 782 |
* @return a factory for creating {@link IObservableMap} objects |
753 |
* @return a factory for creating {@link IObservableMap} objects |
| 783 |
* |
754 |
* |
| 784 |
* @since 1.1 |
755 |
* @since 1.1 |
| 785 |
*/ |
756 |
*/ |
| 786 |
public static IObservableFactory setToMapFactory(final Class beanClass, final String propertyName) { |
757 |
public static IObservableFactory setToMapFactory(final Class beanClass, |
|
|
758 |
final String propertyName) { |
| 787 |
return new IObservableFactory() { |
759 |
return new IObservableFactory() { |
| 788 |
public IObservable createObservable(Object target) { |
760 |
public IObservable createObservable(Object target) { |
| 789 |
return observeMap((IObservableSet) target, beanClass, propertyName); |
761 |
return observeMap((IObservableSet) target, beanClass, |
|
|
762 |
propertyName); |
| 790 |
} |
763 |
} |
| 791 |
}; |
764 |
}; |
| 792 |
} |
765 |
} |
| 793 |
|
766 |
|
| 794 |
/** |
767 |
/** |
| 795 |
* Returns a factory for creating an observable map. The factory, when |
768 |
* Returns a factory for creating an observable map. The factory, when |
| 796 |
* provided with a bean object, will create an {@link IObservableMap} in the |
769 |
* provided with a bean object, will create an {@link IObservableMap} in the |
|
Lines 830-857
Link Here
|
| 830 |
} |
803 |
} |
| 831 |
|
804 |
|
| 832 |
/** |
805 |
/** |
| 833 |
* @param elementType |
|
|
| 834 |
* can be <code>null</code> |
| 835 |
* @param propertyDescriptor |
| 836 |
* @return type of the items in a collection/array property |
| 837 |
*/ |
| 838 |
/*package*/ static Class getCollectionElementType(Class elementType, |
| 839 |
PropertyDescriptor propertyDescriptor) { |
| 840 |
if (elementType == null) { |
| 841 |
Class propertyType = propertyDescriptor.getPropertyType(); |
| 842 |
elementType = propertyType.isArray() ? propertyType |
| 843 |
.getComponentType() : Object.class; |
| 844 |
} |
| 845 |
|
| 846 |
return elementType; |
| 847 |
} |
| 848 |
|
| 849 |
/** |
| 850 |
* @param observable |
806 |
* @param observable |
| 851 |
* @param propertyName |
807 |
* @param propertyName |
| 852 |
* @return property descriptor or <code>null</code> |
808 |
* @return property descriptor or <code>null</code> |
| 853 |
*/ |
809 |
*/ |
| 854 |
/* package*/ static PropertyDescriptor getValueTypePropertyDescriptor( |
810 |
/* package */static PropertyDescriptor getValueTypePropertyDescriptor( |
| 855 |
IObservableValue observable, String propertyName) { |
811 |
IObservableValue observable, String propertyName) { |
| 856 |
return (observable.getValueType() != null) ? getPropertyDescriptor( |
812 |
return (observable.getValueType() != null) ? getPropertyDescriptor( |
| 857 |
(Class) observable.getValueType(), propertyName) : null; |
813 |
(Class) observable.getValueType(), propertyName) : null; |