diff options
author | Matthew Hall | 2009-02-06 23:21:06 +0000 |
---|---|---|
committer | Matthew Hall | 2009-02-06 23:21:06 +0000 |
commit | 89aab203e111f798eb02fdec8be342635e3a6fd9 (patch) | |
tree | 4c1a6845d1813d808ed548ee873f0ff8e71f29e7 /bundles/org.eclipse.core.databinding/src/org/eclipse | |
parent | 42b7af38278d027c54d4035d419366140a66ca0b (diff) | |
download | eclipse.platform.ui-89aab203e111f798eb02fdec8be342635e3a6fd9.tar.gz eclipse.platform.ui-89aab203e111f798eb02fdec8be342635e3a6fd9.tar.xz eclipse.platform.ui-89aab203e111f798eb02fdec8be342635e3a6fd9.zip |
FIXED - bug 263868: [DataBinding] Self-properties implementations for IValueProperty, IListProperty, ISetProperty, IMapProperty
https://bugs.eclipse.org/bugs/show_bug.cgi?id=263868
Diffstat (limited to 'bundles/org.eclipse.core.databinding/src/org/eclipse')
5 files changed, 315 insertions, 1 deletions
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/property/Properties.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/property/Properties.java index 17caa3657c0..391e0aed51e 100644 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/property/Properties.java +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/property/Properties.java @@ -7,16 +7,27 @@ * * Contributors: * Matthew Hall - initial API and implementation (bug 194734) - * Matthew Hall - bug 195222 + * Matthew Hall - bugs 195222, 263868 ******************************************************************************/ package org.eclipse.core.databinding.property; +import java.util.List; import java.util.Map; +import java.util.Set; +import org.eclipse.core.databinding.observable.list.IObservableList; import org.eclipse.core.databinding.observable.map.IObservableMap; import org.eclipse.core.databinding.observable.set.IObservableSet; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.property.list.IListProperty; +import org.eclipse.core.databinding.property.map.IMapProperty; +import org.eclipse.core.databinding.property.set.ISetProperty; import org.eclipse.core.databinding.property.value.IValueProperty; +import org.eclipse.core.internal.databinding.property.list.SelfListProperty; +import org.eclipse.core.internal.databinding.property.map.SelfMapProperty; +import org.eclipse.core.internal.databinding.property.set.SelfSetProperty; +import org.eclipse.core.internal.databinding.property.value.SelfValueProperty; /** * Contains static methods to operate on or return IProperty objects. @@ -68,4 +79,63 @@ public class Properties { maps[i] = properties[i].observeDetail(domainMap); return maps; } + + /** + * Returns a value property which takes the source object itself as the + * property value. This property may be used to wrap an object in an + * unmodifiable {@link IObservableValue}. + * + * @param valueType + * the value type of the property + * @return a value property which takes the source object itself as the + * property value. + */ + public static IValueProperty selfValue(final Object valueType) { + return new SelfValueProperty(valueType); + } + + /** + * Returns a list property which takes the source object (a {@link List}) as + * the property list. This property may be used to wrap an arbitrary List + * instance in an {@link IObservableList}. + * + * @param elementType + * the element type of the property + * @return a list property which takes the source object (a {@link List}) as + * the property list. + */ + public static IListProperty selfList(final Object elementType) { + return new SelfListProperty(elementType); + } + + /** + * Returns a set property which takes the source object (a {@link Set}) as + * the property set. This property may be used to wrap an arbitrary Set + * instance in an {@link IObservableSet}. + * + * @param elementType + * the element type of the property + * @return a set property which takes the source object (a {@link Set}) as + * the property set. + */ + public static ISetProperty selfSet(final Object elementType) { + return new SelfSetProperty(elementType); + } + + /** + * Returns a map property which takes the source object (a {@link Map}) as + * the property map. This property may be used to wrap an arbitrary Map + * instance in an {@link IObservableMap}. + * + * @param keyType + * the key type of the property + * @param valueType + * the value type of the property + * @return a map property which takes the source object (a {@link Map} as + * the property map. + */ + public static IMapProperty selfMap(final Object keyType, + final Object valueType) { + return new SelfMapProperty(keyType, valueType); + } } diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/list/SelfListProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/list/SelfListProperty.java new file mode 100644 index 00000000000..4817857249f --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/list/SelfListProperty.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 263868) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding.property.list; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.databinding.observable.list.ListDiff; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.list.SimpleListProperty; + +/** + * @since 3.3 + * + */ +public class SelfListProperty extends SimpleListProperty { + private final Object elementType; + + /** + * @param elementType + */ + public SelfListProperty(Object elementType) { + this.elementType = elementType; + } + + public Object getElementType() { + return elementType; + } + + protected List doGetList(Object source) { + // An observable may cache the returned list. We clone the list + // to prevent computed diffs from always being empty. + return new ArrayList((List) source); + } + + protected void doSetList(Object source, List list, ListDiff diff) { + diff.applyTo((List) source); + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + return null; // no listener API + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/map/SelfMapProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/map/SelfMapProperty.java new file mode 100644 index 00000000000..842e876697d --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/map/SelfMapProperty.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 263868) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding.property.map; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.databinding.observable.map.MapDiff; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.map.SimpleMapProperty; + +/** + * @since 3.3 + * + */ +public final class SelfMapProperty extends SimpleMapProperty { + private final Object keyType; + private final Object valueType; + + /** + * @param keyType + * @param valueType + */ + public SelfMapProperty(Object keyType, Object valueType) { + this.keyType = keyType; + this.valueType = valueType; + } + + public Object getKeyType() { + return keyType; + } + + public Object getValueType() { + return valueType; + } + + protected Map doGetMap(Object source) { + // An observable may cache the returned map. We clone the map + // to prevent computed diffs from always being empty. + return new HashMap((Map) source); + } + + protected void doSetMap(Object source, Map map, MapDiff diff) { + diff.applyTo((Map) source); + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + return null; // no listener API + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/set/SelfSetProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/set/SelfSetProperty.java new file mode 100644 index 00000000000..9b923a30998 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/set/SelfSetProperty.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 263868) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding.property.set; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.databinding.observable.set.SetDiff; +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.set.SimpleSetProperty; + +/** + * @since 3.3 + * + */ +public final class SelfSetProperty extends SimpleSetProperty { + private final Object elementType; + + /** + * @param elementType + */ + public SelfSetProperty(Object elementType) { + this.elementType = elementType; + } + + public Object getElementType() { + return elementType; + } + + protected Set doGetSet(Object source) { + // An observable may cache the returned set. We clone the set + // to prevent computed diffs from always being empty. + return new HashSet((Set) source); + } + + protected void doSetSet(Object source, Set set, SetDiff diff) { + diff.applyTo((Set) source); + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + return null; // no listener API + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/value/SelfValueProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/value/SelfValueProperty.java new file mode 100644 index 00000000000..95743acc903 --- /dev/null +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/property/value/SelfValueProperty.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Hall and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Hall - initial API and implementation (bug 263868) + ******************************************************************************/ + +package org.eclipse.core.internal.databinding.property.value; + +import org.eclipse.core.databinding.property.INativePropertyListener; +import org.eclipse.core.databinding.property.ISimplePropertyListener; +import org.eclipse.core.databinding.property.value.SimpleValueProperty; + +/** + * @since 3.3 + * + */ +public final class SelfValueProperty extends SimpleValueProperty { + private final Object valueType; + + /** + * @param valueType + */ + public SelfValueProperty(Object valueType) { + this.valueType = valueType; + } + + public Object getValueType() { + return valueType; + } + + protected Object doGetValue(Object source) { + return source; + } + + protected void doSetValue(Object source, Object value) { + } + + public INativePropertyListener adaptListener( + ISimplePropertyListener listener) { + return null; + } + + protected void doAddListener(Object source, INativePropertyListener listener) { + } + + protected void doRemoveListener(Object source, + INativePropertyListener listener) { + } +}
\ No newline at end of file |