diff options
Diffstat (limited to 'bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/ListProperty.java')
-rw-r--r-- | bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/ListProperty.java | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/ListProperty.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/ListProperty.java index cf9590b4..6a63ca2c 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/ListProperty.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/list/ListProperty.java @@ -18,7 +18,6 @@ import java.util.Collections; import java.util.List; import org.eclipse.core.databinding.observable.Diffs; -import org.eclipse.core.databinding.observable.IObservable; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.databinding.observable.list.IObservableList; import org.eclipse.core.databinding.observable.list.ListDiff; @@ -31,9 +30,13 @@ import org.eclipse.core.internal.databinding.property.ListPropertyDetailValuesLi /** * Abstract implementation of IListProperty. * + * @param <S> + * type of the source object + * @param <E> + * type of the elements in the list * @since 1.2 */ -public abstract class ListProperty implements IListProperty { +public abstract class ListProperty<S, E> implements IListProperty<S, E> { /** * By default, this method returns <code>Collections.EMPTY_LIST</code> in @@ -49,9 +52,9 @@ public abstract class ListProperty implements IListProperty { * * @since 1.3 */ - public List getList(Object source) { + public List<E> getList(S source) { if (source == null) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } return Collections.unmodifiableList(doGetList(source)); } @@ -63,12 +66,12 @@ public abstract class ListProperty implements IListProperty { * the property source * @return a List with the current contents of the source's list property * @noreference This method is not intended to be referenced by clients. - * @since 1.3 + * @since 1.5 */ - protected List doGetList(Object source) { - IObservableList observable = observe(source); + protected List<E> doGetList(S source) { + IObservableList<E> observable = observe(source); try { - return new ArrayList(observable); + return new ArrayList<E>(observable); } finally { observable.dispose(); } @@ -77,7 +80,7 @@ public abstract class ListProperty implements IListProperty { /** * @since 1.3 */ - public final void setList(Object source, List list) { + public final void setList(S source, List<E> list) { if (source != null) { doSetList(source, list); } @@ -90,17 +93,17 @@ public abstract class ListProperty implements IListProperty { * the property source * @param list * the new list - * @since 1.3 + * @since 1.5 * @noreference This method is not intended to be referenced by clients. */ - protected void doSetList(Object source, List list) { + protected void doSetList(S source, List<E> list) { doUpdateList(source, Diffs.computeListDiff(doGetList(source), list)); } /** * @since 1.3 */ - public final void updateList(Object source, ListDiff diff) { + public final void updateList(S source, ListDiff<E> diff) { if (source != null) { doUpdateList(source, diff); } @@ -115,8 +118,8 @@ public abstract class ListProperty implements IListProperty { * a diff describing the change * @since 1.3 */ - protected void doUpdateList(Object source, ListDiff diff) { - IObservableList observable = observe(source); + protected void doUpdateList(S source, ListDiff<E> diff) { + IObservableList<E> observable = observe(source); try { diff.applyTo(observable); } finally { @@ -124,32 +127,35 @@ public abstract class ListProperty implements IListProperty { } } - public IObservableList observe(Object source) { + public IObservableList<E> observe(S source) { return observe(Realm.getDefault(), source); } - public IObservableFactory listFactory() { - return new IObservableFactory() { - public IObservable createObservable(Object target) { + public IObservableFactory<S, IObservableList<E>> listFactory() { + return new IObservableFactory<S, IObservableList<E>>() { + public IObservableList<E> createObservable(S target) { return observe(target); } }; } - public IObservableFactory listFactory(final Realm realm) { - return new IObservableFactory() { - public IObservable createObservable(Object target) { + public IObservableFactory<S, IObservableList<E>> listFactory( + final Realm realm) { + return new IObservableFactory<S, IObservableList<E>>() { + public IObservableList<E> createObservable(S target) { return observe(realm, target); } }; } - public IObservableList observeDetail(IObservableValue master) { + public <U extends S> IObservableList<E> observeDetail( + IObservableValue<U> master) { return MasterDetailObservables.detailList(master, listFactory(master.getRealm()), getElementType()); } - public final IListProperty values(IValueProperty detailValue) { - return new ListPropertyDetailValuesList(this, detailValue); + public final <T> IListProperty<S, T> values( + IValueProperty<? super E, T> detailValue) { + return new ListPropertyDetailValuesList<S, E, T>(this, detailValue); } } |