diff --git a/bundles/org.eclipse.core.databinding.beans/.settings/.api_filters b/bundles/org.eclipse.core.databinding.beans/.settings/.api_filters index a0654db314b..d8141c4e01b 100644 --- a/bundles/org.eclipse.core.databinding.beans/.settings/.api_filters +++ b/bundles/org.eclipse.core.databinding.beans/.settings/.api_filters @@ -1,5 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.eclipse.core.databinding.beans/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.databinding.beans/META-INF/MANIFEST.MF index e21652b1da0..4b2493bbcc3 100644 --- a/bundles/org.eclipse.core.databinding.beans/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.core.databinding.beans/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.core.databinding.beans -Bundle-Version: 1.8.0.qualifier +Bundle-Version: 1.9.0.qualifier Bundle-ClassPath: . Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeanProperties.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeanProperties.java deleted file mode 100644 index 601661b0863..00000000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeanProperties.java +++ /dev/null @@ -1,410 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2016 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 194734) - * Matthew Hall - bug 195222, 247997, 261843, 264307 - * Lars Vogel - Bug 488364 - ******************************************************************************/ - -package org.eclipse.core.databinding.beans; - -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.List; - -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.beans.AnonymousBeanListProperty; -import org.eclipse.core.internal.databinding.beans.AnonymousBeanMapProperty; -import org.eclipse.core.internal.databinding.beans.AnonymousBeanSetProperty; -import org.eclipse.core.internal.databinding.beans.AnonymousBeanValueProperty; -import org.eclipse.core.internal.databinding.beans.BeanListProperty; -import org.eclipse.core.internal.databinding.beans.BeanListPropertyDecorator; -import org.eclipse.core.internal.databinding.beans.BeanMapProperty; -import org.eclipse.core.internal.databinding.beans.BeanMapPropertyDecorator; -import org.eclipse.core.internal.databinding.beans.BeanPropertyHelper; -import org.eclipse.core.internal.databinding.beans.BeanSetProperty; -import org.eclipse.core.internal.databinding.beans.BeanSetPropertyDecorator; -import org.eclipse.core.internal.databinding.beans.BeanValueProperty; -import org.eclipse.core.internal.databinding.beans.BeanValuePropertyDecorator; - -/** - * A factory for creating properties for Java objects that conform to the - * JavaBean - * specification for bound properties. - * - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546822 for more - * information. It has been replaced by the class - * {@link org.eclipse.core.databinding.beans.typed.BeanProperties}. - * That class creates typed property objects, while this class - * creates raw property objects. - * - * @since 1.2 - */ -@Deprecated -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class BeanProperties { - /** - * Returns a value property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains null. - * - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @return a value property for the given property name of an arbitrary bean - * class. - */ - public static IBeanValueProperty value(String propertyName) { - return value(null, propertyName, null); - } - - /** - * Returns a value property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains null. - * - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param valueType - * the value type of the returned value property - * @return a value property for the given property name of an arbitrary bean - * class. - */ - public static IBeanValueProperty value(String propertyName, Class valueType) { - return value(null, propertyName, valueType); - } - - /** - * Returns a value property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @return a value property for the given property name of the given bean - * class. - */ - public static IBeanValueProperty value(Class beanClass, String propertyName) { - return value(beanClass, propertyName, null); - } - - /** - * Returns a value property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param valueType - * the value type of the returned value property - * @return a value property for the given property name of the given bean - * class. - */ - public static IBeanValueProperty value(Class beanClass, String propertyName, Class valueType) { - String[] propertyNames = split(propertyName); - if (propertyNames.length > 1) - valueType = null; - - PropertyDescriptor propertyDescriptor; - IValueProperty property; - if (beanClass == null) { - propertyDescriptor = null; - property = new AnonymousBeanValueProperty(propertyNames[0], - valueType); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyNames[0]); - property = new BeanValueProperty(propertyDescriptor, valueType); - } - - IBeanValueProperty beanProperty = new BeanValuePropertyDecorator( - property, propertyDescriptor); - for (int i = 1; i < propertyNames.length; i++) { - beanProperty = beanProperty.value(propertyNames[i]); - } - return beanProperty; - } - - private static String[] split(String propertyName) { - if (propertyName.indexOf('.') == -1) - return new String[] { propertyName }; - List propertyNames = new ArrayList(); - int index; - while ((index = propertyName.indexOf('.')) != -1) { - propertyNames.add(propertyName.substring(0, index)); - propertyName = propertyName.substring(index + 1); - } - propertyNames.add(propertyName); - return (String[]) propertyNames - .toArray(new String[propertyNames.size()]); - } - - /** - * Returns a value property array for the given property names of the given - * bean class. - * - * @param beanClass - * the bean class - * @param propertyNames - * defines the property names. May be nested e.g. "parent.name" - * @return a value property array for the given property names of the given - * bean class. - */ - public static IBeanValueProperty[] values(Class beanClass, String... propertyNames) { - IBeanValueProperty[] properties = new IBeanValueProperty[propertyNames.length]; - for (int i = 0; i < properties.length; i++) - properties[i] = value(beanClass, propertyNames[i], null); - return properties; - } - - /** - * Returns a value property array for the given property names of an - * arbitrary bean class. - * - * @param propertyNames - * defines the property names. May be nested e.g. "parent.name" - * @return a value property array for the given property names of the given - * bean class. - */ - public static IBeanValueProperty[] values(String... propertyNames) { - return values(null, propertyNames); - } - - /** - * Returns a set property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty set. - * - * @param propertyName - * the property name - * @return a set property for the given property name of an arbitrary bean - * class. - */ - public static IBeanSetProperty set(String propertyName) { - return set(null, propertyName, null); - } - - /** - * Returns a set property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty set. - * - * @param propertyName - * the property name - * @param elementType - * the element type of the returned set property - * @return a set property for the given property name of an arbitrary bean - * class. - */ - public static IBeanSetProperty set(String propertyName, Class elementType) { - return set(null, propertyName, elementType); - } - - /** - * Returns a set property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @return a set property for the given property name of the given bean - * class. - */ - public static IBeanSetProperty set(Class beanClass, String propertyName) { - return set(beanClass, propertyName, null); - } - - /** - * Returns a set property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @param elementType - * the element type of the returned set property - * @return a set property for the given property name of the given bean - * class. - */ - public static IBeanSetProperty set(Class beanClass, String propertyName, - Class elementType) { - PropertyDescriptor propertyDescriptor; - ISetProperty property; - if (beanClass == null) { - propertyDescriptor = null; - property = new AnonymousBeanSetProperty(propertyName, elementType); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyName); - property = new BeanSetProperty(propertyDescriptor, elementType); - } - return new BeanSetPropertyDecorator(property, propertyDescriptor); - } - - /** - * Returns a list property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty list. - * - * @param propertyName - * the property name - * @return a list property for the given property name of an arbitrary bean - * class. - */ - public static IBeanListProperty list(String propertyName) { - return list(null, propertyName, null); - } - - /** - * Returns a list property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty list. - * - * @param propertyName - * the property name - * @param elementType - * the element type of the returned list property - * @return a list property for the given property name of the given bean - * class. - */ - public static IBeanListProperty list(String propertyName, Class elementType) { - return list(null, propertyName, elementType); - } - - /** - * Returns a list property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @return a list property for the given property name of the given bean - * class. - */ - public static IBeanListProperty list(Class beanClass, String propertyName) { - return list(beanClass, propertyName, null); - } - - /** - * Returns a list property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @param elementType - * the element type of the returned list property - * @return a list property for the given property name of the given bean - * class. - */ - public static IBeanListProperty list(Class beanClass, String propertyName, - Class elementType) { - PropertyDescriptor propertyDescriptor; - IListProperty property; - if (beanClass == null) { - propertyDescriptor = null; - property = new AnonymousBeanListProperty(propertyName, elementType); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyName); - property = new BeanListProperty(propertyDescriptor, elementType); - } - return new BeanListPropertyDecorator(property, propertyDescriptor); - } - - /** - * Returns a map property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty map. - * - * @param propertyName - * the property name - * @return a map property for the given property name of an arbitrary bean - * class. - */ - public static IBeanMapProperty map(String propertyName) { - return map(null, propertyName, null, null); - } - - /** - * Returns a map property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty map. - * - * @param propertyName - * the property name - * @param keyType - * the key type for the returned map property - * @param valueType - * the value type for the returned map property - * @return a map property for the given property name of an arbitrary bean - * class. - */ - public static IBeanMapProperty map(String propertyName, Class keyType, Class valueType) { - return map(null, propertyName, keyType, valueType); - } - - /** - * Returns a map property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @return a map property for the given property name of the given bean - * class. - */ - public static IBeanMapProperty map(Class beanClass, String propertyName) { - return map(beanClass, propertyName, null, null); - } - - /** - * Returns a map property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @param keyType - * the key type for the returned map property - * @param valueType - * the value type for the returned map property - * @return a map property for the given property name of the given bean - * class. - */ - public static IBeanMapProperty map(Class beanClass, String propertyName, Class keyType, Class valueType) { - PropertyDescriptor propertyDescriptor; - IMapProperty property; - if (beanClass == null) { - propertyDescriptor = null; - property = new AnonymousBeanMapProperty(propertyName, keyType, - valueType); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyName); - property = new BeanMapProperty(propertyDescriptor, keyType, - valueType); - } - return new BeanMapPropertyDecorator(property, propertyDescriptor); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeansObservables.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeansObservables.java deleted file mode 100644 index 4d3b4a61007..00000000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeansObservables.java +++ /dev/null @@ -1,1018 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brad Reynolds - bugs 164268, 171616, 147515 - * Matthew Hall - bug 221704, 234686, 246625, 226289, 246782, 194734, - * 195222, 247997 - * Thomas Kratz - bug 213787 - * Lars Vogel - Bug 443399 - *******************************************************************************/ -package org.eclipse.core.databinding.beans; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableMapDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; -import org.eclipse.core.internal.databinding.beans.BeanPropertyHelper; -import org.eclipse.core.internal.databinding.beans.Util; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -/** - * A factory for creating observable objects of Java objects that conform to the - * JavaBean - * specification for bound properties. - * - * @since 1.1 - * - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546820 for more - * information. Use BeanProperties instead. - */ -@Deprecated -@SuppressWarnings({ "rawtypes", "unchecked" }) -final public class BeansObservables { - - /** - * - */ - public static final boolean DEBUG = true; - - /** - * Returns an observable value in the default realm tracking the current - * value of the named property of the given bean. - * - * @param bean - * the object - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value tracking the current value of the named - * property of the given bean - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableValue observeValue(Object bean, String propertyName) { - return observeValue(Realm.getDefault(), bean, propertyName); - } - - /** - * Returns an observable value in the given realm tracking the current value - * of the named property of the given bean. - * - * @param realm - * the realm - * @param bean - * the object - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value tracking the current value of the named - * property of the given bean - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableValue observeValue(Realm realm, Object bean, - String propertyName) { - return BeanProperties.value((Class) bean.getClass(), propertyName).observe(realm, bean); - } - - /** - * Returns an observable map in the given observable set's realm tracking - * the current values of the named property for the beans in the given set. - * Elements in the set which do not have the named property will have null - * values, and attempts to {@link IObservableMap#put(Object, Object) put} - * values to these elements will be ignored. - * - * @param domain - * the set of bean objects - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable map tracking the current values of the named - * property for the beans in the given domain set - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap observeMap(IObservableSet domain, - String propertyName) { - return BeanProperties.value(propertyName).observeDetail(domain); - } - - /** - * Returns an observable map in the given observable set's realm tracking - * the current values of the named property for the beans in the given set. - * - * @param domain - * the set of bean objects - * @param beanClass - * the common base type of bean objects that may be in the set - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable map tracking the current values of the named - * property for the beans in the given domain set - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap observeMap(IObservableSet domain, - Class beanClass, String propertyName) { - return BeanProperties.value(beanClass, propertyName).observeDetail( - domain); - } - - /** - * Returns an observable map in the given realm tracking the map-typed named - * property of the given bean object. - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable map tracking the map-typed named property of the - * given bean object - * @since 1.1 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Realm realm, Object bean, - String propertyName) { - return observeMap(realm, bean, propertyName, null, null); - } - - /** - * Returns an observable map in the given realm tracking the map-typed named - * property of the given bean object. - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @param keyType - * the element type of the observable map's key set, or - * null if untyped - * @param valueType - * the element type of the observable map's values collection, or - * null if untyped - * @return an observable map tracking the map-typed named property of the - * given bean object - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Realm realm, Object bean, - String propertyName, Class keyType, Class valueType) { - return BeanProperties.map(bean.getClass(), propertyName, keyType, - valueType).observe(realm, bean); - } - - /** - * Returns an observable map in the default realm tracking the map-typed - * named property of the given bean object. - * - * @param bean - * the bean object - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable map tracking the map-typed named property of the - * given bean object - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Object bean, String propertyName) { - return observeMap(Realm.getDefault(), bean, propertyName, null, null); - } - - /** - * Returns an observable map in the default realm tracking the map-typed - * named property of the given bean object. - * - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @param keyType - * the element type of the observable map's key set, or - * null if untyped - * @param valueType - * the element type of the observable map's values collection, or - * null if untyped - * @return an observable map tracking the map-typed named property of the - * given bean object - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Object bean, String propertyName, - Class keyType, Class valueType) { - return observeMap(Realm.getDefault(), bean, propertyName, keyType, - valueType); - } - - /** - * Returns an array of observable maps in the given observable set's realm - * tracking the current values of the named properties for the beans in the - * given set. Elements in the set which do not have the named property will - * have null values, and attempts to - * {@link IObservableMap#put(Object, Object) put} values to these elements - * will be ignored. - * - * @param domain - * the set of objects - * @param propertyNames - * the array of property names. May be nested e.g. "parent.name" - * @return an array of observable maps tracking the current values of the - * named propertys for the beans in the given domain set - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap[] observeMaps(IObservableSet domain, - String[] propertyNames) { - IObservableMap[] result = new IObservableMap[propertyNames.length]; - for (int i = 0; i < propertyNames.length; i++) { - result[i] = observeMap(domain, propertyNames[i]); - } - return result; - } - - /** - * Returns an array of observable maps in the given observable set's realm - * tracking the current values of the named properties for the beans in the - * given set. - * - * @param domain - * the set of objects - * @param beanClass - * the common base type of objects that may be in the set - * @param propertyNames - * the array of property names. May be nested e.g. "parent.name" - * @return an array of observable maps tracking the current values of the - * named propertys for the beans in the given domain set - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap[] observeMaps(IObservableSet domain, - Class beanClass, String[] propertyNames) { - IObservableMap[] result = new IObservableMap[propertyNames.length]; - for (int i = 0; i < propertyNames.length; i++) { - result[i] = observeMap(domain, beanClass, propertyNames[i]); - } - return result; - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. - * - * @param realm - * the realm - * @param bean - * the object - * @param propertyName - * the name of the collection-typed property - * @return an observable list tracking the collection-typed named property - * of the given bean object - * @see #observeList(Realm, Object, String, Class) - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableList observeList(Realm realm, Object bean, - String propertyName) { - return observeList(realm, bean, propertyName, null); - } - - /** - * Returns an observable list in the default realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. - * - * @param bean - * the object - * @param propertyName - * the name of the collection-typed property - * @return an observable list tracking the collection-typed named property - * of the given bean object - * @see #observeList(Realm, Object, String, Class) - * @since 1.2 - */ - public static IObservableList observeList(Object bean, String propertyName) { - return observeList(Realm.getDefault(), bean, propertyName); - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. When an item is added or removed the setter is invoked - * for the list on the parent bean to provide notification to other - * listeners via PropertyChangeEvents. This is done to provide - * the same behavior as is expected from arrays as specified in the bean - * spec in section 7.2. - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the list. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable list tracking the collection-typed named property - * of the given bean object - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableList observeList(Realm realm, Object bean, - String propertyName, Class elementType) { - return BeanProperties.list(bean.getClass(), propertyName, elementType) - .observe(realm, bean); - } - - /** - * Returns an observable list in the default realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. When an item is added or removed the setter is invoked - * for the list on the parent bean to provide notification to other - * listeners via PropertyChangeEvents. This is done to provide - * the same behavior as is expected from arrays as specified in the bean - * spec in section 7.2. - * - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the list. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable list tracking the collection-typed named property - * of the given bean object - * @since 1.2 - */ - public static IObservableList observeList(Object bean, String propertyName, - Class elementType) { - return observeList(Realm.getDefault(), bean, propertyName, elementType); - } - - /** - * Returns an observable set in the given realm tracking the - * collection-typed named property of the given bean object - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @return an observable set tracking the collection-typed named property of - * the given bean object - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Realm realm, Object bean, - String propertyName) { - return observeSet(realm, bean, propertyName, null); - } - - /** - * Returns an observable set in the default realm tracking the - * collection-typed named property of the given bean object - * - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @return an observable set tracking the collection-typed named property of - * the given bean object - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Object bean, String propertyName) { - return observeSet(Realm.getDefault(), bean, propertyName); - } - - /** - * Returns a factory for creating observable values in the given realm, - * tracking the given property of a particular bean object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value factory - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory valueFactory(final Realm realm, - final String propertyName) { - return BeanProperties.value(propertyName).valueFactory(realm); - } - - /** - * Returns a factory for creating observable values in the current default - * realm, tracking the given property of a particular bean object - * - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value factory - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory valueFactory(String propertyName) { - return valueFactory(Realm.getDefault(), propertyName); - } - - /** - * Returns a factory for creating observable lists in the given realm, - * tracking the given property of a particular bean object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @param elementType the element type of the returned list property - * @return an observable list factory - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory listFactory(final Realm realm, - final String propertyName, final Class elementType) { - return BeanProperties.list(propertyName, elementType) - .listFactory(realm); - } - - /** - * Returns a factory for creating observable lists in the current default - * realm, tracking the given property of a particular bean object - * - * @param propertyName - * the name of the property - * @param elementType the element type of the returned list property - * @return an observable list factory - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory listFactory(String propertyName, - Class elementType) { - return listFactory(Realm.getDefault(), propertyName, elementType); - } - - /** - * Returns a factory for creating observable sets in the given realm, - * tracking the given property of a particular bean object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @return an observable set factory - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory setFactory(final Realm realm, - final String propertyName) { - return BeanProperties.set(propertyName).setFactory(realm); - } - - /** - * Returns a factory for creating observable sets in the current default - * realm, tracking the given property of a particular bean object - * - * @param propertyName - * the name of the property - * @return an observable set factory - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory setFactory(String propertyName) { - return setFactory(Realm.getDefault(), propertyName); - } - - /** - * Helper method for - * MasterDetailObservables.detailValue(master, valueFactory(realm, - propertyName), propertyType) - * - * @param realm the realm - * @param master the observable value to track - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @param propertyType - * can be null - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - * - * @deprecated Use - * {@link #observeDetailValue(IObservableValue, String, Class)} - * instead - */ - @Deprecated - public static IObservableValue observeDetailValue(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - warnIfDifferentRealms(realm, master.getRealm()); - - IObservableValue value = MasterDetailObservables.detailValue( - master, - BeanProperties.value(propertyName, propertyType).valueFactory( - realm), propertyType); - return new BeanObservableValueDecorator(value, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /* package */static void warnIfDifferentRealms(Realm detailRealm, - Realm masterRealm) { - if (!Util.equals(detailRealm, masterRealm)) { - Throwable throwable = new Throwable(); - throwable.fillInStackTrace(); - String message = "Detail realm (" + detailRealm //$NON-NLS-1$ - + ") not equal to master realm (" //$NON-NLS-1$ - + masterRealm + ")"; //$NON-NLS-1$ - Policy.getLog().log( - new Status(IStatus.WARNING, Policy.JFACE_DATABINDING, - message, throwable)); - } - } - - /** - * Helper method for - * MasterDetailObservables.detailValue(master, valueFactory(master.getRealm(), propertyName), propertyType) - * - * @param master the master observable value - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @param propertyType - * can be null - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableValue observeDetailValue(IObservableValue master, - String propertyName, Class propertyType) { - Class beanClass = null; - if (master.getValueType() instanceof Class) - beanClass = (Class) master.getValueType(); - return observeDetailValue(master, beanClass, propertyName, propertyType); - } - - /** - * Helper method for - * MasterDetailObservables.detailValue(master, valueFactory(realm, - * propertyName), propertyType). This method returns an - * {@link IBeanObservable} with a {@link PropertyDescriptor} based on the - * given master type and property name. - * - * @param realm - * the realm - * @param master - * the master observable value, for example tracking the - * selection in a list - * @param masterType - * the type of the master observable value - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param propertyType - * can be null - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - * @since 1.1 - * @deprecated Use - * {@link #observeDetailValue(IObservableValue, Class, String, Class)} - * instead. - */ - @Deprecated - public static IObservableValue observeDetailValue(Realm realm, - IObservableValue master, Class masterType, String propertyName, - Class propertyType) { - warnIfDifferentRealms(realm, master.getRealm()); - Assert.isNotNull(masterType, "masterType cannot be null"); //$NON-NLS-1$ - IObservableValue value = MasterDetailObservables.detailValue(master, - BeanProperties.value(masterType, propertyName, propertyType) - .valueFactory(realm), propertyType); - return new BeanObservableValueDecorator(value, - BeanPropertyHelper.getPropertyDescriptor(masterType, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailValue(master, valueFactory(master.getRealm(), propertyName), propertyType) - * . This method returns an {@link IBeanObservable} with a - * {@link PropertyDescriptor} based on the given master type and property - * name. - * - * @param master - * the master observable value, for example tracking the - * selection in a list - * @param masterType - * the type of the master observable value - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param propertyType - * can be null - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableValue observeDetailValue(IObservableValue master, - Class masterType, String propertyName, Class propertyType) { - return BeanProperties.value(masterType, propertyName, propertyType) - .observeDetail(master); - } - - /** - * Helper method for - * MasterDetailObservables.detailList(master, listFactory(realm, - propertyName, propertyType), propertyType) - * - * @param realm the realm - * @param master the observable value to track - * @param propertyName the property name - * @param propertyType - * can be null - * @return an observable list that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @deprecated Use - * {@link #observeDetailList(IObservableValue, String, Class)} - * instead - */ - @Deprecated - public static IObservableList observeDetailList(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - warnIfDifferentRealms(realm, master.getRealm()); - IObservableList observableList = MasterDetailObservables.detailList( - master, BeanProperties.list(propertyName, propertyType) - .listFactory(realm), propertyType); - return new BeanObservableListDecorator(observableList, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailList(master, listFactory(master.getRealm(), propertyName, propertyType), propertyType) - * - * @param master the master observable value - * @param propertyName the property name - * @param propertyType - * can be null - * @return an observable list that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableList observeDetailList(IObservableValue master, - String propertyName, Class propertyType) { - Class beanClass = null; - if (master.getValueType() instanceof Class) - beanClass = (Class) master.getValueType(); - return BeanProperties.list(beanClass, propertyName, propertyType) - .observeDetail(master); - } - - /** - * Helper method for - * MasterDetailObservables.detailSet(master, setFactory(realm, - propertyName), propertyType) - * - * @param realm the realm - * @param master the observable value - * @param propertyName the property name - * @param propertyType - * can be null - * @return an observable set that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @deprecated Use - * {@link #observeDetailSet(IObservableValue, String, Class)} - * instead. - */ - @Deprecated - public static IObservableSet observeDetailSet(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - warnIfDifferentRealms(realm, master.getRealm()); - - IObservableSet observableSet = MasterDetailObservables.detailSet( - master, BeanProperties.set(propertyName, propertyType) - .setFactory(realm), propertyType); - return new BeanObservableSetDecorator(observableSet, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailSet(master, setFactory(master.getRealm(), propertyName), propertyType) - * - * @param master the observable value - * @param propertyName the property name - * @param propertyType - * can be null - * @return an observable set that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableSet observeDetailSet(IObservableValue master, - String propertyName, Class propertyType) { - Class beanClass = null; - if (master.getValueType() instanceof Class) - beanClass = (Class) master.getValueType(); - return BeanProperties.set(beanClass, propertyName, propertyType) - .observeDetail(master); - } - - /** - * Helper method for - * MasterDetailObservables.detailMap(master, mapFactory(realm, propertyName)) - * - * @param realm - * the realm - * @param master the observable value - * @param propertyName name of the property - * @return an observable map that tracks the map-type named property for the - * current value of the master observable value. - * @since 1.1 - * @deprecated Use {@link #observeDetailMap(IObservableValue, String)} - * instead - */ - @Deprecated - public static IObservableMap observeDetailMap(Realm realm, - IObservableValue master, String propertyName) { - warnIfDifferentRealms(realm, master.getRealm()); - IObservableMap observableMap = MasterDetailObservables.detailMap( - master, BeanProperties.map(propertyName).mapFactory(realm)); - return new BeanObservableMapDecorator(observableMap, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailMap(master, mapFactory(master.getRealm(), propertyName)) - * - * @param master the observable value - * @param propertyName the property name - * @return an observable map that tracks the map-type named property for the - * current value of the master observable value. - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableMap observeDetailMap(IObservableValue master, - String propertyName) { - Class beanClass = null; - if (master.getValueType() instanceof Class) - beanClass = (Class) master.getValueType(); - return BeanProperties.map(beanClass, propertyName) - .observeDetail(master); - } - - /** - * Returns an observable set in the given realm tracking the - * collection-typed named property of the given bean object. The returned - * set is mutable. When an item is added or removed the setter is invoked - * for the set on the parent bean to provide notification to other listeners - * via PropertyChangeEvents. This is done to provide the same - * behavior as is expected from arrays as specified in the bean spec in - * section 7.2. - * - * @param realm - * the realm - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable set tracking the collection-typed named property of - * the given bean object - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Realm realm, Object bean, - String propertyName, Class elementType) { - return BeanProperties.set(bean.getClass(), propertyName, elementType) - .observe(realm, bean); - } - - /** - * Returns an observable set in the current default realm tracking the - * collection-typed named property of the given bean object. The returned - * set is mutable. When an item is added or removed the setter is invoked - * for the set on the parent bean to provide notification to other listeners - * via PropertyChangeEvents. This is done to provide the same - * behavior as is expected from arrays as specified in the bean spec in - * section 7.2. - * - * @param bean - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable set tracking the collection-typed named property of - * the given bean object - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Object bean, String propertyName, - Class elementType) { - return observeSet(Realm.getDefault(), bean, propertyName, elementType); - } - - /** - * Returns a factory for creating observable sets in the given realm, - * tracking the given property of a particular bean object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return a factory for creating observable sets in the given realm, - * tracking the given property of a particular bean object - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory setFactory(final Realm realm, - final String propertyName, final Class elementType) { - return BeanProperties.set(propertyName, elementType).setFactory(realm); - } - - /** - * Returns a factory for creating observable sets in the current default - * realm, tracking the given property of a particular bean object - * - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return a factory for creating observable sets in the given realm, - * tracking the given property of a particular bean object - * @since 1.2 - */ - public static IObservableFactory setFactory(String propertyName, - Class elementType) { - return setFactory(Realm.getDefault(), propertyName, elementType); - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with an {@link IObservableSet}, will create an - * {@link IObservableMap} in the same realm as the underlying set that - * tracks the current values of the named property for the beans in the - * given set. - * - * @param beanClass - * the common base type of bean objects that may be in the set - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return a factory for creating {@link IObservableMap} objects - * - * @since 1.1 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory setToMapFactory(final Class beanClass, - final String propertyName) { - return target -> observeMap((IObservableSet) target, beanClass, propertyName); - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with a bean object, will create an {@link IObservableMap} in the - * given realm that tracks the map-typed named property for the specified - * bean. - * - * @param realm - * the realm assigned to observables created by the returned - * factory. - * @param propertyName - * the name of the property - * @return a factory for creating {@link IObservableMap} objects. - * @since 1.1 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory mapPropertyFactory(final Realm realm, - final String propertyName) { - return BeanProperties.map(propertyName).mapFactory(realm); - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with a bean object, will create an {@link IObservableMap} in the - * current default realm that tracks the map-typed named property for the - * specified bean. - * - * @param propertyName - * the name of the property - * @return a factory for creating {@link IObservableMap} objects. - * @since 1.2 - * - * @deprecated use BeanProperties instead - */ - @Deprecated - public static IObservableFactory mapPropertyFactory(String propertyName) { - return mapPropertyFactory(Realm.getDefault(), propertyName); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoObservables.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoObservables.java deleted file mode 100644 index b1216d32893..00000000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoObservables.java +++ /dev/null @@ -1,889 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2015 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 221704, 234686, 246625, 226289, 246782, 194734, - * 195222, 247997 - *******************************************************************************/ - -package org.eclipse.core.databinding.beans; - -import java.beans.PropertyChangeEvent; - -import org.eclipse.core.databinding.beans.typed.PojoProperties; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableMapDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; -import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; -import org.eclipse.core.internal.databinding.beans.BeanPropertyHelper; - -/** - * A factory for creating observable objects for POJOs (plain old java objects) - * that conform to idea of an object with getters and setters but does not - * provide {@link PropertyChangeEvent property change events} on change. This - * factory is identical to {@link BeansObservables} except for this fact. - * - * @since 1.1 - * - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546820 for more - * information. Use PojoProperties instead. - */ -@Deprecated -@SuppressWarnings({ "rawtypes", "unchecked" }) -final public class PojoObservables { - - /** - * Returns an observable value in the default realm tracking the current - * value of the named property of the given pojo. - * - * @param pojo - * the object - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value tracking the current value of the named - * property of the given pojo - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableValue observeValue(Object pojo, String propertyName) { - return observeValue(Realm.getDefault(), pojo, propertyName); - } - - /** - * Returns an observable value in the given realm tracking the current value - * of the named property of the given pojo. - * - * @param realm - * the realm - * @param pojo - * the object - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value tracking the current value of the named - * property of the given pojo - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableValue observeValue(Realm realm, Object pojo, String propertyName) { - return PojoProperties.value((Class) pojo.getClass(), propertyName).observe(realm, pojo); - } - - /** - * Returns an observable map in the given observable set's realm tracking - * the current values of the named property for the beans in the given set. - * Elements in the set which do not have the named property will have null - * values, and attempts to {@link IObservableMap#put(Object, Object) put} - * values to these elements will be ignored. - * - * @param domain - * the set of bean objects - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable map tracking the current values of the named - * property for the beans in the given domain set - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeMap(IObservableSet domain, - String propertyName) { - return PojoProperties.value(propertyName).observeDetail(domain); - } - - /** - * Returns an observable map in the given observable set's realm tracking - * the current values of the named property for the pojos in the given set. - * - * @param domain - * the set of pojo objects - * @param pojoClass - * the common base type of pojo objects that may be in the set - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable map tracking the current values of the named - * property for the pojos in the given domain set - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeMap(IObservableSet domain, - Class pojoClass, String propertyName) { - return PojoProperties.value(pojoClass, propertyName).observeDetail( - domain); - } - - /** - * Returns an array of observable maps in the given observable set's realm - * tracking the current values of the named properties for the beans in the - * given set. Elements in the set which do not have the named property will - * have null values, and attempts to - * {@link IObservableMap#put(Object, Object) put} values to these elements - * will be ignored. - * - * @param domain - * the set of objects - * @param propertyNames - * the array of property names. May be nested e.g. "parent.name" - * @return an array of observable maps tracking the current values of the - * named propertys for the beans in the given domain set - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap[] observeMaps(IObservableSet domain, - String[] propertyNames) { - IObservableMap[] result = new IObservableMap[propertyNames.length]; - for (int i = 0; i < propertyNames.length; i++) { - result[i] = observeMap(domain, propertyNames[i]); - } - return result; - } - - /** - * Returns an array of observable maps in the given observable set's realm - * tracking the current values of the named propertys for the pojos in the - * given set. - * - * @param domain - * the set of objects - * @param pojoClass - * the common base type of objects that may be in the set - * @param propertyNames - * the array of property names. May be nested e.g. "parent.name" - * @return an array of observable maps tracking the current values of the - * named propertys for the pojos in the given domain set - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap[] observeMaps(IObservableSet domain, - Class pojoClass, String[] propertyNames) { - IObservableMap[] result = new IObservableMap[propertyNames.length]; - for (int i = 0; i < propertyNames.length; i++) { - result[i] = observeMap(domain, pojoClass, propertyNames[i]); - } - return result; - } - - /** - * Returns an observable map in the given realm tracking the map-typed named - * property of the given pojo object. - * - * @param realm - * the realm - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @return an observable map tracking the map-typed named property of the - * given pojo object - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Realm realm, Object pojo, - String propertyName) { - return observeMap(realm, pojo, propertyName, null, null); - } - - /** - * Returns an observable map in the given realm tracking the map-typed named - * property of the given pojo object. - * - * @param realm - * the realm - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @param keyType - * the element type of the observable map's key set, or - * null if untyped - * @param valueType - * the element type of the observable map's values collection, or - * null if untyped - * @return an observable map tracking the map-typed named property of the - * given pojo object - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Realm realm, Object pojo, - String propertyName, Class keyType, Class valueType) { - return PojoProperties.map(pojo.getClass(), propertyName, keyType, - valueType).observe(realm, pojo); - } - - /** - * Returns an observable map in the default realm tracking the map-typed - * named property of the given pojo object. - * - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @return an observable map tracking the map-typed named property of the - * given pojo object - * @since 1.2 - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Object pojo, String propertyName) { - return observeMap(Realm.getDefault(), pojo, propertyName, null, null); - } - - /** - * Returns an observable map in the default realm tracking the map-typed - * named property of the given pojo object. - * - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @param keyType - * the element type of the observable map's key set, or - * null if untyped - * @param valueType - * the element type of the observable map's values collection, or - * null if untyped - * @return an observable map tracking the map-typed named property of the - * given pojo object - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeMap(Object pojo, String propertyName, - Class keyType, Class valueType) { - return observeMap(Realm.getDefault(), pojo, propertyName, keyType, - valueType); - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given pojo object. The returned - * list is mutable. - * - * @param realm - * the realm - * @param pojo - * the object - * @param propertyName - * the name of the collection-typed property - * @return an observable list tracking the collection-typed named property - * of the given pojo object - * @see #observeList(Realm, Object, String, Class) - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableList observeList(Realm realm, Object pojo, - String propertyName) { - return observeList(realm, pojo, propertyName, null); - } - - /** - * Returns an observable list in the default realm tracking the - * collection-typed named property of the given pojo object. The returned - * list is mutable. - * - * @param pojo - * the object - * @param propertyName - * the name of the collection-typed property - * @return an observable list tracking the collection-typed named property - * of the given pojo object - * @see #observeList(Realm, Object, String, Class) - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableList observeList(Object pojo, String propertyName) { - return observeList(Realm.getDefault(), pojo, propertyName); - } - - /** - * Returns an observable list in the given realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. When an item is added or removed the setter is invoked - * for the list on the parent bean to provide notification to other - * listeners via PropertyChangeEvents. This is done to provide - * the same behavior as is expected from arrays as specified in the bean - * spec in section 7.2. - * - * @param realm - * the realm - * @param pojo - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the list. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable list tracking the collection-typed named property - * of the given bean object - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableList observeList(Realm realm, Object pojo, - String propertyName, Class elementType) { - return PojoProperties.list(pojo.getClass(), propertyName, elementType) - .observe(realm, pojo); - } - - /** - * Returns an observable list in the default realm tracking the - * collection-typed named property of the given bean object. The returned - * list is mutable. When an item is added or removed the setter is invoked - * for the list on the parent bean to provide notification to other - * listeners via PropertyChangeEvents. This is done to provide - * the same behavior as is expected from arrays as specified in the bean - * spec in section 7.2. - * - * @param pojo - * the bean object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the list. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable list tracking the collection-typed named property - * of the given bean object - * @since 1.2 - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableList observeList(Object pojo, String propertyName, - Class elementType) { - return observeList(Realm.getDefault(), pojo, propertyName, elementType); - } - - /** - * Returns an observable set in the given realm tracking the - * collection-typed named property of the given pojo object. - * - * @param realm - * the realm - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @return an observable set tracking the collection-typed named property of - * the given pojo object - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Realm realm, Object pojo, - String propertyName) { - return observeSet(realm, pojo, propertyName, null); - } - - /** - * Returns an observable set in the default realm tracking the - * collection-typed named property of the given pojo object. - * - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @return an observable set tracking the collection-typed named property of - * the given pojo object - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Object pojo, String propertyName) { - return observeSet(Realm.getDefault(), pojo, propertyName); - } - - /** - * Returns an observable set in the given realm tracking the - * collection-typed named property of the given pojo object. - * - * @param realm - * the realm - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable set that tracks the current value of the named - * property for given pojo object - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Realm realm, Object pojo, - String propertyName, Class elementType) { - return PojoProperties.set(pojo.getClass(), propertyName, elementType) - .observe(realm, pojo); - } - - /** - * Returns an observable set in the default realm, tracking the - * collection-typed named property of the given pojo object. - * - * @param pojo - * the pojo object - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable set that tracks the current value of the named - * property for given pojo object - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableSet observeSet(Object pojo, String propertyName, - Class elementType) { - return observeSet(Realm.getDefault(), pojo, propertyName, elementType); - } - - /** - * Returns a factory for creating observable values in the given realm, - * tracking the given property of a particular pojo object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value factory - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory valueFactory(final Realm realm, - final String propertyName) { - return PojoProperties.value(propertyName).valueFactory(realm); - } - - /** - * Returns a factory for creating observable values in the current default - * realm, tracking the given property of a particular pojo object - * - * @param propertyName - * the name of the property. May be nested e.g. "parent.name" - * @return an observable value factory - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory valueFactory(String propertyName) { - return valueFactory(Realm.getDefault(), propertyName); - } - - /** - * Returns a factory for creating observable lists in the given realm, - * tracking the given property of a particular pojo object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @param elementType the element type of the returned list property - * @return an observable list factory - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory listFactory(final Realm realm, - final String propertyName, final Class elementType) { - return PojoProperties.list(propertyName, elementType) - .listFactory(realm); - } - - /** - * Returns a factory for creating observable lists in the current default - * realm, tracking the given property of a particular pojo object - * - * @param propertyName - * the name of the property - * @param elementType the element type of the returned list property - * @return an observable list factory - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory listFactory(String propertyName, - Class elementType) { - return listFactory(Realm.getDefault(), propertyName, elementType); - } - - /** - * Returns a factory for creating observable sets in the given realm, - * tracking the given property of a particular pojo object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @return an observable set factory - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory setFactory(final Realm realm, - final String propertyName) { - return PojoProperties.set(propertyName).setFactory(realm); - } - - /** - * Returns a factory for creating observable sets in the current default - * realm, tracking the given property of a particular pojo object - * - * @param propertyName - * the name of the property - * @return an observable set factory - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory setFactory(String propertyName) { - return setFactory(Realm.getDefault(), propertyName); - } - - /** - * Returns a factory for creating observable set in the given realm, - * tracking the given property of a particular pojo object - * - * @param realm - * the realm to use - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable set factory for creating observable sets - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory setFactory(final Realm realm, - final String propertyName, final Class elementType) { - return PojoProperties.set(propertyName, elementType).setFactory(realm); - } - - /** - * Returns a factory for creating observable set in the current default - * realm, tracking the given property of a particular pojo object - * - * @param propertyName - * the name of the property - * @param elementType - * type of the elements in the set. If null and the - * property is an array the type will be inferred. If - * null and the property type cannot be inferred - * element type will be null. - * @return an observable set factory for creating observable sets - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory setFactory(String propertyName, - Class elementType) { - return setFactory(Realm.getDefault(), propertyName, elementType); - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with a pojo object, will create an {@link IObservableMap} in the - * given realm that tracks the map-typed named property for the specified - * pojo. - * - * @param realm - * the realm assigned to observables created by the returned - * factory. - * @param propertyName - * the name of the property - * @return a factory for creating {@link IObservableMap} objects. - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory mapPropertyFactory(final Realm realm, - final String propertyName) { - return PojoProperties.map(propertyName).mapFactory(realm); - } - - /** - * Returns a factory for creating an observable map. The factory, when - * provided with a pojo object, will create an {@link IObservableMap} in the - * current default realm that tracks the map-typed named property for the - * specified pojo. - * - * @param propertyName - * the name of the property - * @return a factory for creating {@link IObservableMap} objects. - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableFactory mapPropertyFactory(String propertyName) { - return mapPropertyFactory(Realm.getDefault(), propertyName); - } - - /** - * Helper method for - * MasterDetailObservables.detailValue(master, valueFactory(realm, - propertyName), propertyType) - * - * @param realm the realm - * @param master the master observable value - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param propertyType - * can be null - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - * @deprecated Use - * {@link #observeDetailValue(IObservableValue, String, Class)} - * instead - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableValue observeDetailValue(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - BeansObservables.warnIfDifferentRealms(realm, master.getRealm()); - - IObservableValue value = MasterDetailObservables.detailValue( - master, - PojoProperties.value(propertyName, propertyType).valueFactory( - realm), propertyType); - return new BeanObservableValueDecorator(value, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailValue(master, valueFactory(master.getRealm, propertyName), propertyType) - * - * @param master the master observable value - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param propertyType - * can be null - * @return an observable value that tracks the current value of the named - * property for the current value of the master observable value - * - * @see MasterDetailObservables - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableValue observeDetailValue(IObservableValue master, - String propertyName, Class propertyType) { - Class pojoClass = null; - if (master.getValueType() instanceof Class) - pojoClass = (Class) master.getValueType(); - return PojoProperties.value(pojoClass, propertyName, propertyType) - .observeDetail(master); - } - - /** - * Helper method for - * MasterDetailObservables.detailList(master, listFactory(realm, - propertyName, propertyType), propertyType) - * - * @param realm the realm - * @param master the observable value - * @param propertyName name of the property - * @param propertyType - * can be null - * @return an observable list that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @deprecated Use - * {@link #observeDetailList(IObservableValue, String, Class)} - * instead - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableList observeDetailList(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - BeansObservables.warnIfDifferentRealms(realm, master.getRealm()); - IObservableList observableList = MasterDetailObservables.detailList( - master, PojoProperties.list(propertyName, propertyType) - .listFactory(realm), propertyType); - return new BeanObservableListDecorator(observableList, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailList(master, listFactory(master.getRealm(), propertyName, propertyType), propertyType) - * - * @param master the master observable value - * @param propertyName name of the property - * @param propertyType - * can be null - * @return an observable list that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableList observeDetailList(IObservableValue master, - String propertyName, Class propertyType) { - Class pojoClass = null; - if (master.getValueType() instanceof Class) - pojoClass = (Class) master.getValueType(); - return PojoProperties.list(pojoClass, propertyName).observeDetail( - master); - } - - /** - * Helper method for - * MasterDetailObservables.detailSet(master, setFactory(realm, - propertyName), propertyType) - * - * @param realm the realm - * @param master the master observable value - * @param propertyName the property name - * @param propertyType - * can be null - * @return an observable set that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @deprecated Use - * {@link #observeDetailSet(IObservableValue, String, Class)} - * instead. - */ - @Deprecated - public static IObservableSet observeDetailSet(Realm realm, - IObservableValue master, String propertyName, Class propertyType) { - BeansObservables.warnIfDifferentRealms(realm, master.getRealm()); - - IObservableSet observableSet = MasterDetailObservables.detailSet( - master, PojoProperties.set(propertyName, propertyType) - .setFactory(realm), propertyType); - return new BeanObservableSetDecorator(observableSet, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailSet(master, setFactory(master.getRealm(), propertyName), propertyType) - * - * @param master the observable value - * @param propertyName the property name - * @param propertyType - * can be null - * @return an observable set that tracks the named property for the current - * value of the master observable value - * - * @see MasterDetailObservables - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableSet observeDetailSet(IObservableValue master, - String propertyName, Class propertyType) { - Class pojoClass = null; - if (master.getValueType() instanceof Class) - pojoClass = (Class) master.getValueType(); - return PojoProperties.set(pojoClass, propertyName, propertyType) - .observeDetail(master); - } - - /** - * Helper method for - * MasterDetailObservables.detailMap(master, mapFactory(realm, propertyName)) - * - * @param realm the realm - * @param master the observable value - * @param propertyName name of the property - * @return an observable map that tracks the map-type named property for the - * current value of the master observable value. - * @deprecated Use {@link #observeDetailMap(IObservableValue, String)} - * instead - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeDetailMap(Realm realm, - IObservableValue master, String propertyName) { - BeansObservables.warnIfDifferentRealms(realm, master.getRealm()); - IObservableMap observableMap = MasterDetailObservables.detailMap( - master, PojoProperties.map(propertyName).mapFactory(realm)); - return new BeanObservableMapDecorator(observableMap, - BeanPropertyHelper.getValueTypePropertyDescriptor(master, - propertyName)); - } - - /** - * Helper method for - * MasterDetailObservables.detailMap(master, mapFactory(master.getRealm(), propertyName)) - * - * @param master the master observable value - * @param propertyName name of the property - * @return an observable map that tracks the map-type named property for the - * current value of the master observable value. - * @since 1.2 - * - * @deprecated use PojoProperties instead - */ - @Deprecated - public static IObservableMap observeDetailMap(IObservableValue master, - String propertyName) { - Class pojoClass = null; - if (master.getValueType() instanceof Class) - pojoClass = (Class) master.getValueType(); - return PojoProperties.map(pojoClass, propertyName) - .observeDetail(master); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoProperties.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoProperties.java deleted file mode 100644 index 2fbaf0872f5..00000000000 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoProperties.java +++ /dev/null @@ -1,416 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 194734) - * Matthew Hall - bug 195222, 247997, 261843, 264307 - ******************************************************************************/ - -package org.eclipse.core.databinding.beans; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.List; - -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.beans.AnonymousPojoListProperty; -import org.eclipse.core.internal.databinding.beans.AnonymousPojoMapProperty; -import org.eclipse.core.internal.databinding.beans.AnonymousPojoSetProperty; -import org.eclipse.core.internal.databinding.beans.AnonymousPojoValueProperty; -import org.eclipse.core.internal.databinding.beans.BeanPropertyHelper; -import org.eclipse.core.internal.databinding.beans.PojoListProperty; -import org.eclipse.core.internal.databinding.beans.PojoListPropertyDecorator; -import org.eclipse.core.internal.databinding.beans.PojoMapProperty; -import org.eclipse.core.internal.databinding.beans.PojoMapPropertyDecorator; -import org.eclipse.core.internal.databinding.beans.PojoSetProperty; -import org.eclipse.core.internal.databinding.beans.PojoSetPropertyDecorator; -import org.eclipse.core.internal.databinding.beans.PojoValueProperty; -import org.eclipse.core.internal.databinding.beans.PojoValuePropertyDecorator; - -/** - * A factory for creating properties for POJOs (plain old java objects) that - * conform to idea of an object with getters and setters but does not provide - * {@link PropertyChangeEvent property change events} on change. This factory is - * identical to {@link BeanProperties} except for this fact. - * - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546822 for more - * information. It has been replaced by the class - * {@link org.eclipse.core.databinding.beans.typed.PojoProperties}. - * That class creates typed property objects, while this class - * creates raw property objects. - * - * @since 1.2 - */ -@Deprecated -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class PojoProperties { - /** - * Returns a value property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains null. - * - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @return a value property for the given property name of an arbitrary bean - * class. - */ - public static IBeanValueProperty value(String propertyName) { - return value(null, propertyName, null); - } - - /** - * Returns a value property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains null. - * - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param valueType - * the value type of the returned value property - * @return a value property for the given property name of an arbitrary bean - * class. - */ - public static IBeanValueProperty value(String propertyName, Class valueType) { - return value(null, propertyName, valueType); - } - - /** - * Returns a value property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @return a value property for the given property name of the given bean - * class. - */ - public static IBeanValueProperty value(Class beanClass, String propertyName) { - return value(beanClass, propertyName, null); - } - - /** - * Returns a value property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name. May be nested e.g. "parent.name" - * @param valueType - * the value type of the returned value property - * @return a value property for the given property name of the given bean - * class. - */ - public static IBeanValueProperty value(Class beanClass, - String propertyName, Class valueType) { - String[] propertyNames = split(propertyName); - if (propertyNames.length > 1) - valueType = null; - - IValueProperty property; - PropertyDescriptor propertyDescriptor; - if (beanClass == null) { - propertyDescriptor = null; - property = new PojoValuePropertyDecorator( - new AnonymousPojoValueProperty(propertyNames[0], valueType), - null); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyNames[0]); - property = new PojoValueProperty(propertyDescriptor, valueType); - } - - IBeanValueProperty beanProperty = new PojoValuePropertyDecorator( - property, propertyDescriptor); - for (int i = 1; i < propertyNames.length; i++) { - beanProperty = beanProperty.value(propertyNames[i]); - } - return beanProperty; - } - - private static String[] split(String propertyName) { - if (propertyName.indexOf('.') == -1) - return new String[] { propertyName }; - List propertyNames = new ArrayList(); - int index; - while ((index = propertyName.indexOf('.')) != -1) { - propertyNames.add(propertyName.substring(0, index)); - propertyName = propertyName.substring(index + 1); - } - propertyNames.add(propertyName); - return (String[]) propertyNames - .toArray(new String[propertyNames.size()]); - } - - /** - * Returns a value property array for the given property names of the given - * bean class. - * - * @param beanClass - * the bean class - * @param propertyNames - * array of property names. May be nested e.g. "parent.name" - * @return a value property array for the given property names of the given - * bean class. - */ - public static IBeanValueProperty[] values(Class beanClass, - String[] propertyNames) { - IBeanValueProperty[] properties = new IBeanValueProperty[propertyNames.length]; - for (int i = 0; i < properties.length; i++) - properties[i] = value(beanClass, propertyNames[i], null); - return properties; - } - - /** - * Returns a value property array for the given property names of an - * arbitrary bean class. - * - * @param propertyNames - * array of property names. May be nested e.g. "parent.name" - * @return a value property array for the given property names of the given - * bean class. - */ - public static IBeanValueProperty[] values(String... propertyNames) { - return values(null, propertyNames); - } - - /** - * Returns a set property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty set. - * - * @param propertyName - * the property name - * @return a set property for the given property name of an arbitrary bean - * class. - */ - public static IBeanSetProperty set(String propertyName) { - return set(null, propertyName, null); - } - - /** - * Returns a set property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty set. - * - * @param propertyName - * the property name - * @param elementType - * the element type of the returned set property - * @return a set property for the given property name of an arbitrary bean - * class. - */ - public static IBeanSetProperty set(String propertyName, Class elementType) { - return set(null, propertyName, elementType); - } - - /** - * Returns a set property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @return a set property for the given property name of the given bean - * class. - */ - public static IBeanSetProperty set(Class beanClass, String propertyName) { - return set(beanClass, propertyName, null); - } - - /** - * Returns a set property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @param elementType - * the element type of the returned set property - * @return a set property for the given property name of the given bean - * class. - */ - public static IBeanSetProperty set(Class beanClass, String propertyName, - Class elementType) { - PropertyDescriptor propertyDescriptor; - ISetProperty property; - if (beanClass == null) { - propertyDescriptor = null; - property = new AnonymousPojoSetProperty(propertyName, elementType); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyName); - property = new PojoSetProperty(propertyDescriptor, elementType); - } - return new PojoSetPropertyDecorator(property, propertyDescriptor); - } - - /** - * Returns a list property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty list. - * - * @param propertyName - * the property name - * @return a list property for the given property name of an arbitrary bean - * class. - */ - public static IBeanListProperty list(String propertyName) { - return list(null, propertyName, null); - } - - /** - * Returns a list property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty list. - * - * @param propertyName - * the property name - * @param elementType - * the element type of the returned list property - * @return a list property for the given property name of the given bean - * class. - */ - public static IBeanListProperty list(String propertyName, Class elementType) { - return list(null, propertyName, elementType); - } - - /** - * Returns a list property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @return a list property for the given property name of the given bean - * class. - */ - public static IBeanListProperty list(Class beanClass, String propertyName) { - return list(beanClass, propertyName, null); - } - - /** - * Returns a list property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @param elementType - * the element type of the returned list property - * @return a list property for the given property name of the given bean - * class. - */ - public static IBeanListProperty list(Class beanClass, String propertyName, - Class elementType) { - PropertyDescriptor propertyDescriptor; - IListProperty property; - if (beanClass == null) { - propertyDescriptor = null; - property = new AnonymousPojoListProperty(propertyName, elementType); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyName); - property = new PojoListProperty(propertyDescriptor, elementType); - } - return new PojoListPropertyDecorator(property, propertyDescriptor); - } - - /** - * Returns a map property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty map. - * - * @param propertyName - * the property name - * @return a map property for the given property name of an arbitrary bean - * class. - */ - public static IBeanMapProperty map(String propertyName) { - return map(null, propertyName, null, null); - } - - /** - * Returns a map property for the given property name of an arbitrary bean - * class. Objects lacking the named property are treated the same as if the - * property always contains an empty map. - * - * @param propertyName - * the property name - * @param keyType - * the key type for the returned map property - * @param valueType - * the value type for the returned map property - * @return a map property for the given property name of an arbitrary bean - * class. - */ - public static IBeanMapProperty map(String propertyName, Class keyType, - Class valueType) { - return map(null, propertyName, keyType, valueType); - } - - /** - * Returns a map property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @return a map property for the given property name of the given bean - * class. - */ - public static IBeanMapProperty map(Class beanClass, String propertyName) { - return map(beanClass, propertyName, null, null); - } - - /** - * Returns a map property for the given property name of the given bean - * class. - * - * @param beanClass - * the bean class - * @param propertyName - * the property name - * @param keyType - * the key type of the returned map property - * @param valueType - * the value type of the returned map property - * @return a map property for the given property name of the given bean - * class. - */ - public static IBeanMapProperty map(Class beanClass, String propertyName, - Class keyType, Class valueType) { - PropertyDescriptor propertyDescriptor; - IMapProperty property; - if (beanClass == null) { - propertyDescriptor = null; - property = new AnonymousPojoMapProperty(propertyName, keyType, - valueType); - } else { - propertyDescriptor = BeanPropertyHelper.getPropertyDescriptor( - beanClass, propertyName); - property = new PojoMapProperty(propertyDescriptor, keyType, - valueType); - } - return new PojoMapPropertyDecorator(property, propertyDescriptor); - } -} diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/BeanProperties.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/BeanProperties.java index 1453a7a5fbd..1047a347628 100644 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/BeanProperties.java +++ b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/BeanProperties.java @@ -46,11 +46,6 @@ * A factory for creating properties for Java objects that conform to the * JavaBean * specification for bound properties. - *

- * This class is a new version of the deprecated class with the same name in the - * parent package. The difference is that this class returns typed property - * objects. This class is located in its own package to be able to coexist with - * the old version while having the same name. * * @since 1.5 */ diff --git a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/PojoProperties.java b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/PojoProperties.java index 71a55a9c1c8..d9357e4ca30 100644 --- a/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/PojoProperties.java +++ b/bundles/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/typed/PojoProperties.java @@ -47,11 +47,6 @@ * conform to idea of an object with getters and setters but does not provide * {@link PropertyChangeEvent property change events} on change. This factory is * identical to {@link BeanProperties} except for this fact. - *

- * This class is a new version of the deprecated class with the same name in the - * parent package. The difference is that this class returns typed property - * objects. This class is located in its own package to be able to coexist with - * the old version while having the same name. * * @since 1.5 */ diff --git a/bundles/org.eclipse.e4.ui.css.swt/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.css.swt/META-INF/MANIFEST.MF index 05a4067fcef..eaaedbec2bd 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.css.swt/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.e4.ui.css.swt;singleton:=true -Bundle-Version: 0.14.600.qualifier +Bundle-Version: 0.14.700.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF index d852da9e1cf..9112cb74674 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.e4.ui.workbench.renderers.swt;singleton:=true -Bundle-Version: 0.15.600.qualifier +Bundle-Version: 0.15.700.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java index 2ab05a0dab4..28916380b90 100644 --- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java +++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java @@ -904,7 +904,6 @@ public void hideChild(MElementContainer parentElement, MUIElement ch // find the 'stale' tab for this element and dispose it if (tabItem != null && !tabItem.isDisposed()) { - tabItem.setControl(null); tabItem.dispose(); } } diff --git a/bundles/org.eclipse.jface.databinding/.settings/.api_filters b/bundles/org.eclipse.jface.databinding/.settings/.api_filters index b52c3eab383..282dac6193c 100644 --- a/bundles/org.eclipse.jface.databinding/.settings/.api_filters +++ b/bundles/org.eclipse.jface.databinding/.settings/.api_filters @@ -1,5 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF b/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF index b81d4faa3f2..9c22fa76628 100644 --- a/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.jface.databinding/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jface.databinding -Bundle-Version: 1.13.0.qualifier +Bundle-Version: 1.14.0.qualifier Bundle-ClassPath: . Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java deleted file mode 100644 index 467b730cc5d..00000000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java +++ /dev/null @@ -1,604 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2015 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt Carter - bug 170668 - * Brad Reynolds - bug 170848 - * Matthew Hall - bugs 180746, 207844, 245647, 248621, 232917, 194734, - * 195222, 256543, 213893, 262320, 264286, 266563, 306203 - * Michael Krauter - bug 180223 - * Boris Bokowski - bug 245647 - * Tom Schindl - bug 246462 - * Lars Vogel - Bug 327086 - * Jeanderson Candido - Bug 413611 - * Simon Scholz - Bug 449022 - * Eugen Neufeld - bug 461560 - *******************************************************************************/ -package org.eclipse.jface.databinding.swt; - -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.IVetoableValue; -import org.eclipse.core.databinding.observable.value.ValueChangingEvent; -import org.eclipse.jface.databinding.swt.typed.WidgetProperties; -import org.eclipse.jface.internal.databinding.swt.SWTDelayedObservableValueDecorator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Widget; - -/** - * A factory for creating observables for SWT widgets - * - * @since 1.1 - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546820 for more - * information. Use WidgetProperties instead. - */ -@Deprecated -@SuppressWarnings("rawtypes") -public class SWTObservables { - - /** - * Returns the realm representing the UI thread for the given display. - * - * @param display the display to get realm for - * @return the realm representing the UI thread for the given display - * @deprecated please use {@link DisplayRealm#getRealm(Display)} instead. - */ - @Deprecated - public static Realm getRealm(final Display display) { - return DisplayRealm.getRealm(display); - } - - /** - * Returns an observable which delays notification of value change events - * from observable until delay milliseconds have - * elapsed since the last change event, or until a FocusOut event is - * received from the underlying widget (whichever happens first). This - * observable helps to boost performance in situations where an observable - * has computationally expensive listeners (e.g. changing filters in a - * viewer) or many dependencies (master fields with multiple detail fields). - * A common use of this observable is to delay validation of user input - * until the user stops typing in a UI field. - *

- * To notify about pending changes, the returned observable fires a stale - * event when the wrapped observable value fires a change event, and remains - * stale until the delay has elapsed and the value change is fired. A call - * to {@link IObservableValue#getValue() getValue()} while a value change is - * pending will fire the value change immediately, short-circuiting the - * delay. - *

- * Only updates resulting from the observed widget are delayed. Calls directly - * to {@link IObservableValue#setValue} are not, and they cancel pending delayed - * values. - *

- * Note that this observable will not forward {@link ValueChangingEvent} - * events from a wrapped {@link IVetoableValue}. - * - * @param delay - * the delay in milliseconds - * @param observable - * the observable being delayed - * @return an observable which delays notification of value change events - * from observable until delay - * milliseconds have elapsed since the last change event. - * - * @since 1.2 - * @deprecated use WidgetProperties instead - */ - @SuppressWarnings("unchecked") - @Deprecated - public static ISWTObservableValue observeDelayedValue(int delay, ISWTObservableValue observable) { - return new SWTDelayedObservableValueDecorator( - Observables.observeDelayedValue(delay, observable), - observable.getWidget()); - } - - /** - * Returns an observable value tracking the enabled state of the given - * widget. The supported types are: - *

    - *
  • org.eclipse.swt.widgets.Control
  • - *
  • org.eclipse.swt.widgets.Menu
  • - *
  • org.eclipse.swt.widgets.MenuItem
  • - *
  • org.eclipse.swt.widgets.ScrollBar
  • - *
  • org.eclipse.swt.widgets.ToolItem
  • - *
- * - * @param widget - * the widget to observe - * @return an observable value tracking the enabled state of the given - * widget. - * @since 1.5 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeEnabled(Widget widget) { - return WidgetProperties.enabled().observe(widget); - } - - /** - * Returns an observable value tracking the enabled state of the given - * control - * - * @param control - * the control to observe - * @return an observable value tracking the enabled state of the given - * control - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeEnabled(Control control) { - return observeEnabled((Widget) control); - } - - /** - * Returns an observable value tracking the visible state of the given - * control - * - * @param control - * the control to observe - * @return an observable value tracking the visible state of the given - * control - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeVisible(Control control) { - return WidgetProperties.visible().observe(control); - } - - /** - * Returns an observable tracking the tooltip text of the given item. The - * supported types are: - *
    - *
  • org.eclipse.swt.widgets.Control
  • - *
  • org.eclipse.swt.custom.CTabItem
  • - *
  • org.eclipse.swt.widgets.TabItem
  • - *
  • org.eclipse.swt.widgets.TableColumn
  • - *
  • org.eclipse.swt.widgets.ToolItem
  • - *
  • org.eclipse.swt.widgets.TrayItem
  • - *
  • org.eclipse.swt.widgets.TreeColumn
  • - *
- * - * @param widget - * the widget to observe - * @return an observable value tracking the tooltip text of the given item - * - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeTooltipText(Widget widget) { - return WidgetProperties.tooltipText().observe(widget); - } - - /** - * Returns an observable value tracking the tooltip text of the given - * control - * - * @param control - * the control to observe - * @return an observable value tracking the tooltip text of the given - * control - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeTooltipText(Control control) { - return observeTooltipText((Widget) control); - } - - /** - * Returns an observable observing the selection attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Spinner
  • - *
  • org.eclipse.swt.widgets.Button
  • - *
  • org.eclipse.swt.widgets.Combo
  • - *
  • org.eclipse.swt.custom.CCombo
  • - *
  • org.eclipse.swt.widgets.List
  • - *
  • org.eclipse.swt.widgets.MenuItem (since 1.5)
  • - *
  • org.eclipse.swt.widgets.Scale
  • - *
- * - * @param widget - * the widget to observe - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @since 1.5 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeSelection(Widget widget) { - return WidgetProperties.widgetSelection().observe(widget); - } - - /** - * Returns an observable observing the selection attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Button
  • - *
  • org.eclipse.swt.widgets.Combo
  • - *
  • org.eclipse.swt.custom.CCombo
  • - *
  • org.eclipse.swt.widgets.List
  • - *
  • org.eclipse.swt.widgets.Scale
  • - *
  • org.eclipse.swt.widgets.Slider (since 1.5)
  • - *
  • org.eclipse.swt.widgets.Spinner
  • - *
- * - * @param control - * the control to observe - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeSelection(Control control) { - return observeSelection((Widget) control); - } - - /** - * Returns an observable observing the minimum attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Spinner
  • - *
  • org.eclipse.swt.widgets.Slider (since 1.5)
  • - *
  • org.eclipse.swt.widgets.Scale
  • - *
- * - * @param control - * the control to observe - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeMin(Control control) { - return WidgetProperties.minimum().observe(control); - } - - /** - * Returns an observable observing the maximum attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Spinner
  • - *
  • org.eclipse.swt.widgets.Slider (since 1.5)
  • - *
  • org.eclipse.swt.widgets.Scale
  • - *
- * - * @param control - * the control to observe - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeMax(Control control) { - return WidgetProperties.maximum().observe(control); - } - - /** - * Returns an observable observing the text attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Text
  • - *
  • org.eclipse.swt.custom.StyledText (as of 1.3)
  • - *
- * - * @param control - * the control to observe - * @param events - * array of SWT event types to register for change events. May - * include {@link SWT#None}, {@link SWT#Modify}, - * {@link SWT#FocusOut} or {@link SWT#DefaultSelection}. - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeText(Control control, int[] events) { - return WidgetProperties.text(events).observe(control); - } - - /** - * Returns an observable observing the text attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Text
  • - *
  • org.eclipse.swt.custom.StyledText (as of 1.3)
  • - *
- * - * @param control - * the control to observe - * @param event - * event type to register for change events - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeText(Control control, int event) { - return WidgetProperties.text(event).observe(control); - } - - /** - * Returns an observable observing the text attribute of the provided - * widget. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Button (as of 1.3)
  • - *
  • org.eclipse.swt.custom.CCombo
  • - *
  • org.eclipse.swt.custom.CLabel
  • - *
  • org.eclipse.swt.widgets.Combo
  • - *
  • org.eclipse.swt.widgets.Group (as of 1.7)
  • - *
  • org.eclipse.swt.widgets.Item
  • - *
  • org.eclipse.swt.widgets.Label
  • - *
  • org.eclipse.swt.widgets.Link (as of 1.2)
  • - *
  • org.eclipse.swt.widgets.Shell
  • - *
  • org.eclipse.swt.widgets.StyledText (as of 1.3)
  • - *
  • org.eclipse.swt.widgets.Text (as of 1.3)
  • - *
- * - * @param widget - * the widget to observe - * @return observable value - * @throws IllegalArgumentException - * if the type of widget is unsupported - * - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeText(Widget widget) { - return WidgetProperties.text().observe(widget); - } - - /** - * Returns an observable observing the text attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Button (as of 1.3)
  • - *
  • org.eclipse.swt.custom.CCombo
  • - *
  • org.eclipse.swt.custom.CLabel
  • - *
  • org.eclipse.swt.widgets.Combo
  • - *
  • org.eclipse.swt.widgets.Group (as of 1.7)
  • - *
  • org.eclipse.swt.widgets.Label
  • - *
  • org.eclipse.swt.widgets.Link (as of 1.2)
  • - *
  • org.eclipse.swt.widgets.Shell
  • - *
  • org.eclipse.swt.custom.StyledText (as of 1.3)
  • - *
  • org.eclipse.swt.widgets.Text (as of 1.3)
  • - *
- * - * @param control - * the control to observe - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeText(Control control) { - return observeText((Widget) control); - } - - /** - * Returns an observable observing the message attribute of the provided - * widget. the supported types are: - *
    - *
  • org.eclipse.swt.widgets.Text
  • - *
  • org.eclipse.swt.widgets.ToolTip
  • - *
- * - * @param widget - * the widget to observe - * @return an observable observing the message attribute of the provided - * widget. - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeMessage(Widget widget) { - return WidgetProperties.message().observe(widget); - } - - /** - * Returns an observable observing the image attribute of the provided - * widget. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Button
  • - *
  • org.eclipse.swt.custom.CLabel
  • - *
  • org.eclipse.swt.widgets.Item
  • - *
  • org.eclipse.swt.widgets.Label
  • - *
- * - * @param widget - * the widget to observe - * @return observable value - * @throws IllegalArgumentException - * if widget type is unsupported - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeImage(Widget widget) { - return WidgetProperties.image().observe(widget); - } - - /** - * Returns an observable observing the items attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Combo
  • - *
  • org.eclipse.swt.custom.CCombo
  • - *
  • org.eclipse.swt.widgets.List
  • - *
- * - * @param control - * the control to observe - * @return observable list - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static IObservableList observeItems(Control control) { - return WidgetProperties.items().observe(control); - } - - /** - * Returns an observable observing the single selection index attribute of - * the provided control. The supported types are: - *
    - *
  • org.eclipse.swt.widgets.Table
  • - *
  • org.eclipse.swt.widgets.Combo
  • - *
  • org.eclipse.swt.custom.CCombo
  • - *
  • org.eclipse.swt.widgets.List
  • - *
- * - * @param control - * the control to observe - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeSingleSelectionIndex(Control control) { - return WidgetProperties.singleSelectionIndex().observe(control); - } - - /** - * Returns an observable value tracking the foreground color of the given - * control - * - * @param control - * the control to observe - * @return an observable value tracking the foreground color of the given - * control - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeForeground(Control control) { - return WidgetProperties.foreground().observe(control); - } - - /** - * Returns an observable value tracking the background color of the given - * control - * - * @param control - * the control to observe - * @return an observable value tracking the background color of the given - * control - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeBackground(Control control) { - return WidgetProperties.background().observe(control); - } - - /** - * Returns an observable value tracking the font of the given control. - * - * @param control - * the control to observe - * @return an observable value tracking the font of the given control - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeFont(Control control) { - return WidgetProperties.font().observe(control); - } - - /** - * Returns an observable value tracking the size of the given control. - * - * @param control - * the control to observe - * @return an observable value tracking the size of the given control - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeSize(Control control) { - return WidgetProperties.size().observe(control); - } - - /** - * Returns an observable value tracking the location of the given control. - * - * @param control - * the control to observe - * @return an observable value tracking the location of the given control - * @since 1.3 - */ - public static ISWTObservableValue observeLocation(Control control) { - return WidgetProperties.location().observe(control); - } - - /** - * Returns an observable value tracking the focus of the given control. - * - * @param control - * the control to observe - * @return an observable value tracking the focus of the given control - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeFocus(Control control) { - return WidgetProperties.focused().observe(control); - } - - /** - * Returns an observable value tracking the bounds of the given control. - * - * @param control - * the control to observe - * @return an observable value tracking the bounds of the given control - * @since 1.3 - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeBounds(Control control) { - return WidgetProperties.bounds().observe(control); - } - - /** - * Returns an observable observing the editable attribute of the provided - * control. The supported types are: - *
    - *
  • org.eclipse.swt.custom.CCombo (since 1.6)
  • - *
  • org.eclipse.swt.custom.StyledText (since 1.6)
  • - *
  • org.eclipse.swt.widgets.Text
  • - *
- * - * @param control - * the control to observe - * @return observable value - * @throws IllegalArgumentException - * if control type is unsupported - * @deprecated use WidgetProperties instead - */ - @Deprecated - public static ISWTObservableValue observeEditable(Control control) { - return WidgetProperties.editable().observe(control); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/WidgetProperties.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/WidgetProperties.java deleted file mode 100644 index 2bca286c562..00000000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/WidgetProperties.java +++ /dev/null @@ -1,332 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 194734) - * Matthew Hall - bugs 256543, 213893, 262320, 262946, 264286, 266563, 169876, 306203 - * Eugen Neufeld - bug 461560 - * Lars Vogel - Bug 482486 - ******************************************************************************/ - -package org.eclipse.jface.databinding.swt; - -import org.eclipse.jface.internal.databinding.swt.ControlBackgroundProperty; -import org.eclipse.jface.internal.databinding.swt.ControlBoundsProperty; -import org.eclipse.jface.internal.databinding.swt.ControlFocusedProperty; -import org.eclipse.jface.internal.databinding.swt.ControlFontProperty; -import org.eclipse.jface.internal.databinding.swt.ControlForegroundProperty; -import org.eclipse.jface.internal.databinding.swt.ControlLocationProperty; -import org.eclipse.jface.internal.databinding.swt.ControlSizeProperty; -import org.eclipse.jface.internal.databinding.swt.ControlVisibleProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetEditableProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetEnabledProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetImageProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetItemsProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetMaximumProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetMessageProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetMinimumProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetSingleSelectionIndexProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetTextProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetTextWithEventsProperty; -import org.eclipse.jface.internal.databinding.swt.WidgetTooltipTextProperty; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.DateTime; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Slider; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.TabItem; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.swt.widgets.ToolTip; -import org.eclipse.swt.widgets.TrayItem; -import org.eclipse.swt.widgets.TreeColumn; -import org.eclipse.swt.widgets.Widget; - -/** - * A factory for creating properties of SWT {@link Widget widgets}. - * - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546822 for more - * information. It has been replaced by the class - * {@link org.eclipse.jface.databinding.swt.typed.WidgetProperties}. - * That class creates typed property objects, while this class - * creates raw property objects. - * - * @since 1.3 - */ -@Deprecated -@SuppressWarnings({ "rawtypes" }) -public class WidgetProperties { - /** - * Returns a value property for observing the background color of a - * {@link Control}. - * - * @return a value property for observing the background color of a - * {@link Control}. - */ - public static IWidgetValueProperty background() { - return new ControlBackgroundProperty(); - } - - /** - * Returns a value property for observing the bounds of a {@link Control}. - * - * @return a value property for observing the bounds of a {@link Control}. - */ - public static IWidgetValueProperty bounds() { - return new ControlBoundsProperty(); - } - - /** - * Returns a value property for observing the editable state of a - * {@link CCombo} (since 1.6), {@link StyledText} (since 1.6), or - * {@link Text}. - * - * @return a value property for observing the editable state of a - * {@link CCombo}, {@link StyledText}, or {@link Text}. - */ - public static IWidgetValueProperty editable() { - return new WidgetEditableProperty(); - } - - /** - * Returns a value property for observing the enablement state of a - * {@link Control}, {@link Menu} (since 1.5), {@link MenuItem} (since 1.5), - * {@link ScrollBar} (since 1.5) or {@link ToolItem} (since 1.5). - * - * @return a value property for observing the enablement state of a - * {@link Control}, {@link Menu}, {@link MenuItem}, - * {@link ScrollBar} or {@link ToolItem}. - */ - public static IWidgetValueProperty enabled() { - return new WidgetEnabledProperty(); - } - - /** - * Returns a value property for observing the focus state of a - * {@link Control}. - * - * @return a value property for observing the focus state of a - * {@link Control}. - */ - public static IWidgetValueProperty focused() { - return new ControlFocusedProperty(); - } - - /** - * Returns a value property for observing the font of a {@link Control}. - * - * @return a value property for observing the font of a {@link Control}. - */ - public static IWidgetValueProperty font() { - return new ControlFontProperty(); - } - - /** - * Returns a value property for observing the foreground color of a - * {@link Control}. - * - * @return a value property for observing the foreground color of a - * {@link Control}. - */ - public static IWidgetValueProperty foreground() { - return new ControlForegroundProperty(); - } - - /** - * Returns a value property for observing the image of a {@link Button}, - * {@link CLabel}, {@link Item} or {@link Label}. - * - * @return a value property for observing the image of a {@link Button}, - * {@link CLabel}, {@link Item} or {@link Label}. - */ - public static IWidgetValueProperty image() { - return new WidgetImageProperty(); - } - - /** - * Returns a list property for observing the items of a {@link CCombo}, - * {@link Combo} or {@link List}. - * - * @return a list property for observing the items of a {@link CCombo}, - * {@link Combo} or {@link List}. - */ - public static IWidgetListProperty items() { - return new WidgetItemsProperty(); - } - - /** - * Returns a value property for observing the location of a {@link Control}. - * - * @return a value property for observing the location of a {@link Control}. - */ - public static IWidgetValueProperty location() { - return new ControlLocationProperty(); - } - - /** - * Returns a value property for observing the maximum value of a - * {@link Scale}, {@link Slider} (since 1.5) or {@link Spinner}. - * - * @return a value property for observing the maximum value of a - * {@link Scale}, {@link Slider} (since 1.5) or {@link Spinner}. - */ - public static IWidgetValueProperty maximum() { - return new WidgetMaximumProperty(); - } - - /** - * Returns a value property for observing the message of a {@link Text} or - * {@link ToolTip}. - * - * @return a value property for observing the message of a {@link Text} or - * {@link ToolTip}. - */ - public static IWidgetValueProperty message() { - return new WidgetMessageProperty(); - } - - /** - * Returns a value property for observing the minimum value of a - * {@link Scale}, {@link Slider} (since 1.5) or {@link Spinner}. - * - * @return a value property for observing the minimum value of a - * {@link Scale}, {@link Slider} (since 1.5) or {@link Spinner}. - */ - public static IWidgetValueProperty minimum() { - return new WidgetMinimumProperty(); - } - - /** - * Returns a value property for observing the selection state of a - * {@link Button}, {@link CCombo}, {@link Combo}, {@link DateTime}, - * {@link List}, {@link MenuItem} (since 1.5), {@link Scale}, {@link Slider} - * (since 1.5) or {@link Spinner}. - * - * @return a value property for observing the selection state of a - * {@link Button}, {@link CCombo}, {@link Combo}, {@link DateTime}, - * {@link List}, {@link MenuItem}, {@link Scale}, {@link Slider} or - * {@link Spinner}. - */ - public static IWidgetValueProperty selection() { - return new WidgetSelectionProperty(); - } - - /** - * Returns a value property for observing the single selection index of a - * {@link CCombo}, {@link Combo}, {@link List} or {@link Table}. - * - * @return a value property for the single selection index of a SWT Combo. - */ - public static IWidgetValueProperty singleSelectionIndex() { - return new WidgetSingleSelectionIndexProperty(); - } - - /** - * Returns a value property for observing the size of a {@link Control}. - * - * @return a value property for observing the size of a {@link Control}. - */ - public static IWidgetValueProperty size() { - return new ControlSizeProperty(); - } - - /** - * Returns a value property for observing the text of a {@link Button}, - * {@link CCombo}, {@link CLabel}, {@link Combo}, {@link Item}, - * {@link Label}, {@link Link}, {@link Shell}, {@link Group}, - * {@link StyledText} or {@link Text}. - * - * @return a value property for observing the text of a {@link Button}, - * {@link CCombo}, {@link CLabel}, {@link Combo}, {@link Group}, - * {@link Item}, {@link Label}, {@link Link}, {@link Shell}, link - * StyledText} or {@link Text}. - */ - public static IWidgetValueProperty text() { - return new WidgetTextProperty(); - } - - /** - * Returns a value property for observing the text of a {@link StyledText} - * or {@link Text}. - * - * @param event - * the SWT event type to register for change events. May be - * {@link SWT#None}, {@link SWT#Modify}, {@link SWT#FocusOut} or - * {@link SWT#DefaultSelection}. - * - * @return a value property for observing the text of a {@link StyledText} - * or {@link Text}. - */ - public static IWidgetValueProperty text(final int event) { - return text(new int[] { event }); - } - - /** - * Returns a value property for observing the text of a {@link StyledText} - * or {@link Text}. - * - * @param events - * varags of SWT event types to register for change events. May - * include {@link SWT#None}, {@link SWT#Modify}, - * {@link SWT#FocusOut} or {@link SWT#DefaultSelection}. - * - * @return a value property for observing the text of a {@link StyledText} - * or {@link Text}. - */ - public static IWidgetValueProperty text(int... events) { - return new WidgetTextWithEventsProperty(events.clone()); - } - - /** - * Returns a value property for observing the tooltip text of a - * {@link CTabItem}, {@link Control}, {@link TabItem}, {@link TableColumn}, - * {@link ToolItem}, {@link TrayItem} or {@link TreeColumn}. - * - * @return a value property for observing the tooltip text of a - * {@link CTabItem}, {@link Control}, {@link TabItem}, - * {@link TableColumn}, {@link ToolItem}, {@link TrayItem} or - * {@link TreeColumn}. - */ - public static IWidgetValueProperty tooltipText() { - return new WidgetTooltipTextProperty(); - } - - /** - * Returns a value property for observing the visibility state of a - * {@link Control}. - * - * @return a value property for observing the visibility state of a - * {@link Control}. - */ - public static IWidgetValueProperty visible() { - return new ControlVisibleProperty(); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java index 4cc2599b4cb..39102f8c98c 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/typed/WidgetProperties.java @@ -93,11 +93,6 @@ /** * A factory for creating properties of SWT {@link Widget widgets}. - *

- * This class is a new version of the deprecated class with the same name in the - * parent package. The difference is that this class returns typed property - * objects. This class is located in its own package to be able to coexist with - * the old version while having the same name. * * @since 1.9 */ diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewerProperties.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewerProperties.java deleted file mode 100644 index 84fc2379651..00000000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewerProperties.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 194734) - * Matthew Hall - bug 264286 - * Ovidio Mallo - bug 270494 - ******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.jface.internal.databinding.viewers.SelectionProviderMultipleSelectionProperty; -import org.eclipse.jface.internal.databinding.viewers.SelectionProviderSingleSelectionProperty; -import org.eclipse.jface.internal.databinding.viewers.StructuredViewerFiltersProperty; -import org.eclipse.jface.internal.databinding.viewers.ViewerCheckedElementsProperty; -import org.eclipse.jface.internal.databinding.viewers.ViewerInputProperty; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckable; -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; - -/** - * A factory for creating properties of JFace {@link Viewer viewers}. - * - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546822 for more - * information. It has been replaced by the class - * {@link org.eclipse.jface.databinding.viewers.typed.ViewerProperties}. - * That class creates typed property objects, while this class - * creates raw property objects. - * - * @since 1.3 - */ -@Deprecated -@SuppressWarnings({ "rawtypes" }) -public class ViewerProperties { - /** - * Returns a set property for observing the checked elements of a - * {@link CheckboxTableViewer}, {@link CheckboxTreeViewer} or - * {@link ICheckable}. - * - * @param elementType - * the element type of the returned property - * - * @return a set property for observing the checked elements of a - * {@link CheckboxTableViewer}, {@link CheckboxTreeViewer} or - * {@link ICheckable}. - */ - public static IViewerSetProperty checkedElements(Object elementType) { - return new ViewerCheckedElementsProperty(elementType); - } - - /** - * Returns a value property for observing the input of a - * {@link StructuredViewer}. - * - * @return a value property for observing the input of a - * {@link StructuredViewer}. - */ - public static IViewerSetProperty filters() { - return new StructuredViewerFiltersProperty(); - } - - /** - * Returns a value property for observing the input of a {@link Viewer}. - * - * @return a value property for observing the input of a {@link Viewer}. - */ - public static IViewerValueProperty input() { - return new ViewerInputProperty(); - } - - /** - * Returns a list property for observing the multiple selection of an - * {@link ISelectionProvider}. - * - * @return a list property for observing the multiple selection of an - * {@link ISelectionProvider}. - */ - public static IViewerListProperty multipleSelection() { - return new SelectionProviderMultipleSelectionProperty(false); - } - - /** - * Returns a list property for observing the multiple post selection - * of an {@link IPostSelectionProvider}. - * - * @return a list property for observing the multiple post selection - * of an {@link IPostSelectionProvider}. - * - * @since 1.4 - */ - public static IViewerListProperty multiplePostSelection() { - return new SelectionProviderMultipleSelectionProperty(true); - } - - /** - * Returns a value property for observing the single selection of a - * {@link ISelectionProvider}. - * - * @return a value property for observing the single selection of a - * {@link ISelectionProvider}. - */ - public static IViewerValueProperty singleSelection() { - return new SelectionProviderSingleSelectionProperty(false); - } - - /** - * Returns a value property for observing the single post selection - * of a {@link IPostSelectionProvider}. - * - * @return a value property for observing the single post selection - * of a {@link IPostSelectionProvider}. - * - * @since 1.4 - */ - public static IViewerValueProperty singlePostSelection() { - return new SelectionProviderSingleSelectionProperty(true); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.java deleted file mode 100644 index eafcf622b50..00000000000 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2015 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 206839, 124684, 239302, 245647, 194734, 195222, - * 264286 - * Ovidio Mallo - bug 270494 - *******************************************************************************/ - -package org.eclipse.jface.databinding.viewers; - -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.viewers.typed.ViewerProperties; -import org.eclipse.jface.internal.databinding.viewers.ViewerObservableValueDecorator; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckable; -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; - -/** - * Factory methods for creating observables for JFace viewers - * - * @since 1.1 - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546820 for more - * information. Use ViewerProperties instead. - */ -@Deprecated -@SuppressWarnings("rawtypes") -public class ViewersObservables { - private static void checkNull(Object obj) { - if (obj == null) - throw new IllegalArgumentException(); - } - - /** - * Returns an observable which delays notification of value change events - * from observable until delay milliseconds have - * passed since the last change event, or until a FocusOut event is received - * from the underlying viewer control (whichever happens earlier). This - * class helps to delay validation until the user stops changing the value - * (e.g. until a user stops changing a viewer selection). To notify about - * pending changes, the returned observable value will fire a stale event - * when the wrapped observable value fires a change event, but this change - * is being delayed. - * - * @param delay - * the delay in milliseconds - * @param observable - * the observable being delayed - * @return an observable which delays notification of value change events - * from observable until delay - * milliseconds have passed since the last change event. - * - * @since 1.3 - */ - public static IViewerObservableValue observeDelayedValue(int delay, IViewerObservableValue observable) { - return new ViewerObservableValueDecorator<>(Observables.observeDelayedValue(delay, observable), - observable.getViewer()); - } - - /** - * Returns an observable value that tracks the current selection of the - * given selection provider. If the selection provider provides selections - * of type {@link IStructuredSelection}, the observable value will be the - * first element of the structured selection as returned by - * {@link IStructuredSelection#getFirstElement()}. - * - * @param selectionProvider provider to get selection from; not null - * @return the observable value tracking the (single) selection of the given - * selection provider - */ - public static IObservableValue observeSingleSelection( - ISelectionProvider selectionProvider) { - checkNull(selectionProvider); - return ViewerProperties.singleSelection().observe(selectionProvider); - } - - /** - * Returns an observable value that tracks the current post selection - * of the given post selection provider. If the selection provider provides - * selections of type {@link IStructuredSelection}, the observable value - * will be the first element of the structured selection as returned by - * {@link IStructuredSelection#getFirstElement()}. - * - * @param selectionProvider - * The selection provider on which to track the post - * selection. - * @return the observable value tracking the (single) post selection - * of the given post selection provider - * - * @since 1.4 - */ - public static IObservableValue observeSinglePostSelection( - IPostSelectionProvider selectionProvider) { - checkNull(selectionProvider); - return ViewerProperties.singlePostSelection() - .observe(selectionProvider); - } - - /** - * Returns an observable list that tracks the current selection of the given - * selection provider. Assumes that the selection provider provides - * selections of type {@link IStructuredSelection}. Note that the observable - * list will not honor the full contract of java.util.List in - * that it may delete or reorder elements based on what the selection - * provider returns from {@link ISelectionProvider#getSelection()} after - * having called - * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} - * based on the requested change to the observable list. The affected - * methods are add, addAll, and set. - * - * @param selectionProvider provider to get selection from; not null - * @return the observable value tracking the (multi) selection of the given - * selection provider - * - * @since 1.2 - */ - public static IObservableList observeMultiSelection( - ISelectionProvider selectionProvider) { - checkNull(selectionProvider); - return ViewerProperties.multipleSelection().observe(selectionProvider); - } - - /** - * Returns an observable list that tracks the current post selection - * of the given post selection provider. Assumes that the selection provider - * provides selections of type {@link IStructuredSelection}. Note that the - * observable list will not honor the full contract of - * java.util.List in that it may delete or reorder elements - * based on what the selection provider returns from - * {@link ISelectionProvider#getSelection()} after having called - * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} - * based on the requested change to the observable list. The affected - * methods are add, addAll, and set. - * - * @param selectionProvider - * The selection provider on which to track the post - * selection. - * @return the observable value tracking the (multi) post selection - * of the given post selection provider - * - * @since 1.4 - */ - public static IObservableList observeMultiPostSelection( - IPostSelectionProvider selectionProvider) { - checkNull(selectionProvider); - return ViewerProperties.multiplePostSelection().observe( - selectionProvider); - } - - /** - * Returns an observable value that tracks the current selection of the - * given viewer. If the viewer provides selections of type - * {@link IStructuredSelection}, the observable value will be the first - * element of the structured selection as returned by - * {@link IStructuredSelection#getFirstElement()}. - * - * @param viewer - * the viewer - * @return the observable value tracking the (single) selection of the given - * viewer - * @since 1.2 - */ - public static IViewerObservableValue observeSingleSelection(Viewer viewer) { - checkNull(viewer); - return ViewerProperties.singleSelection().observe(viewer); - } - - /** - * Returns an observable value that tracks the current post selection - * of the given structured viewer. If the viewer provides selections of type - * {@link IStructuredSelection}, the observable value will be the first - * element of the structured selection as returned by - * {@link IStructuredSelection#getFirstElement()}. - * - * @param viewer - * The viewer on which to track the post selection. - * @return the observable value tracking the (single) post selection - * of the given structured viewer - * - * @since 1.4 - */ - public static IViewerObservableValue observeSinglePostSelection( - StructuredViewer viewer) { - checkNull(viewer); - return ViewerProperties.singlePostSelection().observe(viewer); - } - - /** - * Returns an observable list that tracks the current selection of the given - * viewer. Assumes that the viewer provides selections of type - * {@link IStructuredSelection}. Note that the observable list will not - * honor the full contract of java.util.List in that it may - * delete or reorder elements based on what the viewer returns from - * {@link ISelectionProvider#getSelection()} after having called - * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} - * based on the requested change to the observable list. The affected - * methods are add, addAll, and set. - * - * @param viewer - * The viewer on which to track the selection. - * @return the observable value tracking the (multi) selection of the given - * selection provider - * - * @since 1.2 - */ - public static IViewerObservableList observeMultiSelection(Viewer viewer) { - checkNull(viewer); - return ViewerProperties.multipleSelection().observe(viewer); - } - - /** - * Returns an observable list that tracks the current post selection - * of the given structured viewer. Assumes that the viewer provides - * selections of type {@link IStructuredSelection}. Note that the observable - * list will not honor the full contract of java.util.List in - * that it may delete or reorder elements based on what the viewer returns - * from {@link ISelectionProvider#getSelection()} after having called - * {@link ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)} - * based on the requested change to the observable list. The affected - * methods are add, addAll, and set. - * - * @param viewer - * The viewer on which to track the post selection. - * @return the observable value tracking the (multi) post selection - * of the given structured viewer - * - * @since 1.4 - */ - public static IViewerObservableList observeMultiPostSelection( - StructuredViewer viewer) { - checkNull(viewer); - return ViewerProperties.multiplePostSelection().observe(viewer); - } - - /** - * Returns an observable value that tracks the input of the given viewer. - *

- * The returned observer is blind to changes in the viewer's input unless - * its {@link IObservableValue#setValue(Object)} method is called directly. - * - * @param viewer - * the viewer to observe - * @return an observable value tracking the input of the given viewer - * @since 1.2 - */ - public static IObservableValue observeInput(Viewer viewer) { - checkNull(viewer); - return ViewerProperties.input().observe(viewer); - } - - /** - * Returns an observable set that tracks the checked elements of the given - * ICheckable. - * - * @param checkable - * {@link ICheckable} containing the checked elements to track - * @param elementType - * element type of the returned set - * @return an observable set tracking the checked elements of the given - * checkable. - * @since 1.2 - */ - public static IObservableSet observeCheckedElements(ICheckable checkable, - Object elementType) { - checkNull(checkable); - return ViewerProperties.checkedElements(elementType).observe(checkable); - } - - /** - * Returns an observable set that tracks the checked elements of the given - * viewer. Assumes that the viewer implements {@link ICheckable}. - * - * @param viewer - * {@link CheckboxTableViewer} containing the checked elements to - * track. - * @param elementType - * element type of the returned set - * @return an observable set that tracks the checked elements of the given - * viewer. - * @since 1.2 - */ - public static IViewerObservableSet observeCheckedElements(CheckboxTableViewer viewer, Object elementType) { - checkNull(viewer); - return ViewerProperties.checkedElements(elementType).observe((Viewer) viewer); - } - - /** - * Returns an observable set that tracks the checked elements of the given - * viewer. Assumes that the viewer implements {@link ICheckable}. - * - * @param viewer - * {@link CheckboxTreeViewer} containing the checked elements to - * track. - * @param elementType - * element type of the returned set - * @return an observable set that tracks the checked elements of the given - * viewer. - * @since 1.2 - */ - public static IViewerObservableSet observeCheckedElements(CheckboxTreeViewer viewer, Object elementType) { - checkNull(viewer); - return ViewerProperties.checkedElements(elementType).observe((Viewer) viewer); - } - - /** - * Returns an observable set that tracks the filters of the given viewer. - * Note that the returned set will not track changes that are made using - * direct API on StructuredViewer (by calling - * {@link StructuredViewer#addFilter(org.eclipse.jface.viewers.ViewerFilter) - * addFilter()}, - * {@link StructuredViewer#removeFilter(org.eclipse.jface.viewers.ViewerFilter) - * removeFilter()}, or - * {@link StructuredViewer#setFilters(org.eclipse.jface.viewers.ViewerFilter[]) - * setFilters()}) -- it is assumed that filters are only changed through the - * returned set. - * - * @param viewer - * viewer containing the filters to be tracked - * @return an observable set that tracks the filters of the given viewer. - * @since 1.3 - */ - public static IViewerObservableSet observeFilters(StructuredViewer viewer) { - checkNull(viewer); - return ViewerProperties.filters().observe((Viewer) viewer); - } -} diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/typed/ViewerProperties.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/typed/ViewerProperties.java index ac6dc02e89a..ae9c64f802a 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/typed/ViewerProperties.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/typed/ViewerProperties.java @@ -35,11 +35,6 @@ /** * A factory for creating properties of JFace {@link Viewer viewers}. - *

- * This class is a new version of the deprecated class with the same name in the - * parent package. The difference is that this class returns typed property - * objects. This class is located in its own package to be able to coexist with - * the old version while having the same name. * * @since 1.9 */ diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java index e6c8a7300b0..c910e469da1 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java @@ -362,58 +362,6 @@ private static GridLayoutFactory getPopupLayout() { */ private String infoText; - /** - * Constructs a new instance of PopupDialog. - * - * @param parent - * The parent shell. - * @param shellStyle - * The shell style. - * @param takeFocusOnOpen - * A boolean indicating whether focus should be - * taken by this popup when it opens. - * @param persistBounds - * A boolean indicating whether the bounds (size - * and location) of the dialog should be persisted - * upon close of the dialog. The bounds can only - * be persisted if the dialog settings for - * persisting the bounds are also specified. If a - * menu action will be provided that allows the - * user to control this feature, then the last - * known value of the user's setting will be used - * instead of this flag. - * @param showDialogMenu - * A boolean indicating whether a menu for moving - * and resizing the popup should be provided. - * @param showPersistActions - * A boolean indicating whether actions allowing - * the user to control the persisting of the - * dialog size and location should be shown in the - * dialog menu. This parameter has no effect if - * showDialogMenu is - * false. - * @param titleText - * Text to be shown in an upper title area, or - * null if there is no title. - * @param infoText - * Text to be shown in a lower info area, or - * null if there is no info area. - * - * @see PopupDialog#getDialogSettings() - * @deprecated As of 3.4, replaced by - * {@link #PopupDialog(Shell, int, boolean, boolean, boolean, boolean, boolean, String, String)} - * - * @noreference Planned for deletion see - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=531913 - */ - @Deprecated - public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, - boolean persistBounds, boolean showDialogMenu, - boolean showPersistActions, String titleText, String infoText) { - this(parent, shellStyle, takeFocusOnOpen, persistBounds, persistBounds, - showDialogMenu, showPersistActions, titleText, infoText, false); - } - /** * Constructs a new instance of PopupDialog. * @@ -1041,27 +989,6 @@ protected void setTitleText(String text) { } } - /** - * Return a boolean indicating whether this dialog will persist its bounds. This - * value is initially set in the dialog's constructor, but can be modified if - * the persist bounds action is shown on the menu and the user has changed its - * value. Subclasses may override this method. - * - * @return true if the dialog's bounds will be persisted, - * false if it will not. - * - * @deprecated As of 3.4, please use {@link #getPersistLocation()} or - * {@link #getPersistSize()} to determine separately whether size or - * location should be persisted. - * - * @noreference Planned for deletion see - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=531913 - */ - @Deprecated - protected boolean getPersistBounds() { - return persistLocation && persistSize; - } - /** * Return a boolean indicating whether this dialog will persist its * location. This value is initially set in the dialog's constructor, but diff --git a/bundles/org.eclipse.ui.workbench/.settings/.api_filters b/bundles/org.eclipse.ui.workbench/.settings/.api_filters new file mode 100644 index 00000000000..e9d3e243b1d --- /dev/null +++ b/bundles/org.eclipse.ui.workbench/.settings/.api_filters @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/WorkbenchObservables.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/WorkbenchObservables.java deleted file mode 100644 index 0bdff9b9efc..00000000000 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/WorkbenchObservables.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2017 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - initial API and implementation - * Lars Vogel - Bug 440810 - * Sergey Prigogin (Google) - *******************************************************************************/ -package org.eclipse.ui.databinding; - -import org.eclipse.core.databinding.observable.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IAdapterManager; -import org.eclipse.core.runtime.Platform; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.IPartService; -import org.eclipse.ui.ISelectionService; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPartReference; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.databinding.typed.WorkbenchProperties; -import org.eclipse.ui.services.IServiceLocator; - -/** - * Factory methods for creating observables for Workbench objects - * - * @since 3.5 - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546820 for more - * information. Use WorkbenchProperties instead. - */ -@Deprecated -public class WorkbenchObservables { - /** - * Returns an observable with values of the given target type. If the wrapped - * observable's value is of the target type, or can be adapted to the target - * type, this is taken as the value of the returned observable, otherwise - * null. - * - * @param master the observable whose value should be adapted - * @param adapter the target type - * @return an observable with values of the given type, or null if - * the current value of the given observable does not adapt to the - * target type - */ - public static IObservableValue observeDetailAdaptedValue(IObservableValue master, Class adapter) { - return observeDetailAdaptedValue(master, adapter, Platform.getAdapterManager()); - } - - /** - * Returns an observable with values of the given target type. If the wrapped - * observable's value is of the target type, or can be adapted to the target - * type, this is taken as the value of the returned observable, otherwise - * null. - * - * @param master the observable whose value should be adapted - * @param adapter the target type - * @param adapterManager the adapter manager used to adapt the master value - * @return an observable with values of the given type, or null if - * the current value of the given observable does not adapt to the - * target type - */ - static IObservableValue observeDetailAdaptedValue(IObservableValue master, Class adapter, - IAdapterManager adapterManager) { - return WorkbenchProperties.adaptedValue(adapter, adapterManager).observeDetail(master); - } - - /** - * Returns an observable value that tracks the post selection of a selection - * service obtained through the given service locator, and adapts the first - * element of that selection to the given target type. - *

- * This method can be used by view or editor implementers to tie into the - * selection service, for example as follows: - *

- * - *
-	 * IObservableValue<IResource> selection = WorkbenchObservables.observeAdaptedSingleSelection(getSite(),
-	 * 		IResource.class);
-	 * 
- * - * - * @param locator a service locator with an available - * {@link ISelectionService} - * @param targetType the target type - * @return an observable value whose value type is the given target type - */ - public static IObservableValue observeAdaptedSingleSelection(IServiceLocator locator, Class targetType) { - ISelectionService selectionService = locator.getService(ISelectionService.class); - Assert.isNotNull(selectionService); - return WorkbenchProperties.singleSelection(null, true).value(WorkbenchProperties.adaptedValue(targetType)) - .observe(selectionService); - } - - /** - * Returns an observable value that tracks the active workbench window for the - * given workbench. - * - * @param workbench the workbench to get the observable for - * @return an observable value that tracks the active workbench window - * @since 3.110 - */ - public static IObservableValue observeActiveWorkbenchWindow(IWorkbench workbench) { - Assert.isNotNull(workbench); - return WorkbenchProperties.activeWindow().observe(workbench); - } - - /** - * Returns an observable value that tracks the active workbench page for the - * given workbench window. - * - * @param window the workbench window to get the observable for - * @return an observable value that tracks the active workbench page - * @since 3.110 - */ - public static IObservableValue observeActiveWorkbenchPage(IWorkbenchWindow window) { - Assert.isNotNull(window); - return WorkbenchProperties.activePage().observe(window); - } - - /** - * Returns an observable value that tracks the active workbench part for the - * given part service. - * - * @param partService the part service to get the observable for, e.g. a - * workbench page - * @return an observable value that tracks the active workbench part - * @since 3.110 - */ - public static IObservableValue observeActivePart(IPartService partService) { - Assert.isNotNull(partService); - return WorkbenchProperties.activePartReference().observe(partService); - } - - /** - * Returns an observable value that tracks the active editor for the given part - * service. - * - * @param partService the part service to get the observable for, e.g. a - * workbench page - * @return an observable value that tracks the active editor - * @since 3.110 - */ - public static IObservableValue observeActiveEditor(IPartService partService) { - final IObservableValue partObservable = observeActivePart(partService); - return ComputedValue.create(() -> { - IWorkbenchPartReference value = partObservable.getValue(); - return value instanceof IEditorReference ? (IEditorReference) value : null; - }); - } - - /** - * Returns an observable value that tracks the editor input for the given - * editor. - * - * @param editor the editor to get the observable for - * @return an observable value that tracks the editor input - * @since 3.110 - */ - public static IObservableValue observeEditorInput(IEditorPart editor) { - Assert.isNotNull(editor); - return WorkbenchProperties.editorInput().observe(editor); - } -} diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/WorkbenchProperties.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/WorkbenchProperties.java deleted file mode 100644 index 7c95cbbd61f..00000000000 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/WorkbenchProperties.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2015 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - initial API and implementation - *******************************************************************************/ -package org.eclipse.ui.databinding; - -import org.eclipse.core.databinding.property.list.IListProperty; -import org.eclipse.core.databinding.property.value.IValueProperty; -import org.eclipse.core.runtime.IAdapterManager; -import org.eclipse.core.runtime.Platform; -import org.eclipse.ui.ISelectionService; - -/** - * Factory methods for creating properties for the Workbench. - * - *

- * Examples: - *

- * - *
- * WorkbenchProperties.singleSelection().observe(getSite().getService(ISelectionService.class))
- * 
- * - * @noreference - * @deprecated This class will be removed in a future release. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=546822 for more - * information. It has been replaced by the class - * {@link org.eclipse.ui.databinding.typed.WorkbenchProperties}. - * That class creates typed property objects, while this class - * creates raw property objects. - * - * @since 3.5 - */ -@Deprecated -@SuppressWarnings("rawtypes") -public class WorkbenchProperties { - /** - * Returns a value property which observes the source object as the adapted - * type, using the platform adapter manager. If the source is of the target - * type, or can be adapted to the target type, this is used as the value of - * property, otherwise null. - * - * @param adapter the adapter class - * @return a value property which observes the source object as the adapted - * type. - */ - public static IValueProperty adaptedValue(Class adapter) { - return adaptedValue(adapter, Platform.getAdapterManager()); - } - - /** - * Returns a value property which observes the source object as the adapted - * type. If the source object is of the target type, or can be adapted to the - * target type, this is used as the value of property, otherwise - * null. - * - * @param adapter the adapter class - * @param adapterManager the adapter manager used to adapt source objects - * @return a value property which observes the source object as the adapted - * type. - */ - static IValueProperty adaptedValue(final Class adapter, final IAdapterManager adapterManager) { - return org.eclipse.ui.databinding.typed.WorkbenchProperties.adaptedValue(adapter, adapterManager); - } - - /** - * Returns a property for observing the first element of a structured selection - * as exposed by {@link ISelectionService}. - * - * @return an observable value - */ - public static IValueProperty singleSelection() { - return singleSelection(null, false); - } - - /** - * Returns a property for observing the first element of a structured selection - * as exposed by {@link ISelectionService}. - * - * @param partId the part id, or null if the selection can - * be from any part - * @param postSelection true if the selection should be delayed for - * keyboard-triggered selections - * - * @return an observable value - */ - public static IValueProperty singleSelection(String partId, boolean postSelection) { - return org.eclipse.ui.databinding.typed.WorkbenchProperties.singleSelection(partId, postSelection); - } - - /** - * Returns a property for observing the elements of a structured selection as - * exposed by {@link ISelectionService}. - * - * @return an observable value - */ - public static IListProperty multipleSelection() { - return multipleSelection(null, false); - } - - /** - * Returns a property for observing the elements of a structured selection as - * exposed by {@link ISelectionService}. - * - * @param partId the part id, or null if the selection can - * be from any part - * @param postSelection true if the selection should be delayed for - * keyboard-triggered selections - * - * @return an observable value - */ - public static IListProperty multipleSelection(String partId, boolean postSelection) { - return org.eclipse.ui.databinding.typed.WorkbenchProperties.multipleSelection(partId, postSelection); - } -} diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/package.html b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/package.html deleted file mode 100644 index 8f650c18949..00000000000 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/package.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - -Package-level Javadoc - - - -APIs for Workbench properties and observables for use with data binding -

Package Specification

-This package provides APIs that provide access to properties of Workbench objects for -use with the data binding framework. - - - diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/typed/WorkbenchProperties.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/typed/WorkbenchProperties.java index db3ae9a1c02..332b2edbabf 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/typed/WorkbenchProperties.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/databinding/typed/WorkbenchProperties.java @@ -48,12 +48,6 @@ * WorkbenchProperties.singleSelection().observe(getSite().getService(ISelectionService.class)) * * - *

- * This class is a new version of the deprecated class with the same name in the - * parent package. The difference is that this class returns typed property - * objects. This class is located in its own package to be able to coexist with - * the old version while having the same name. - * * @since 3.117 */ public class WorkbenchProperties { diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobInfo.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobInfo.java index 3e02270dd72..f490abc6146 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobInfo.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobInfo.java @@ -130,48 +130,6 @@ void clearTaskInfo() { taskInfo = Optional.empty(); } - /** - * Compares the job of the receiver to another job. - * - * @param jobInfo The info we are comparing to - * @return Returns a negative integer, zero, or a positive integer as this - * object is less than, equal to, or greater than the specified object. - */ - private int compareJobs(JobInfo jobInfo) { - Job job2 = jobInfo.getJob(); - - // User jobs have top priority - if (job.isUser()) { - if (!job2.isUser()) { - return -1; - } - } else if (job2.isUser()) { - return 1; - } - - // Show the blocked ones last. - if (isBlocked()) { - if (!jobInfo.isBlocked()) { - return 1; - } - } else if (jobInfo.isBlocked()) { - return -1; - } - - int thisPriority = job.getPriority(); - int otherPriority = job2.getPriority(); - // If equal priority, order by names - if (thisPriority == otherPriority) { - return job.getName().compareTo(job2.getName()); - } - - // order by priority (lower value is higher priority) - if (thisPriority < otherPriority) { - return -1; - } - return 1; - } - // for debugging only @Override public String toString() { @@ -182,34 +140,6 @@ public String toString() { + ")"; //$NON-NLS-1$ } - @Override - public int compareTo(JobTreeElement other) { - if (!(other instanceof JobInfo)) { - return super.compareTo(other); - } - JobInfo element = (JobInfo) other; - - boolean thisCanceled = isCanceled(); - boolean anotherCanceled = element.isCanceled(); - if (thisCanceled && !anotherCanceled) { - // If the receiver is cancelled then it is lowest priority - return 1; - } else if (!thisCanceled && anotherCanceled) { - return -1; - } - - int thisState = getJob().getState(); - int anotherState = element.getJob().getState(); - - // if equal job state, compare other job attributes - if (thisState == anotherState) { - return compareJobs(element); - } - - // ordering by job states, Job.RUNNING should be ordered first - return Integer.compare(anotherState, thisState); - } - /** * Dispose of the receiver. */ diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobSnapshot.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobSnapshot.java new file mode 100644 index 00000000000..3a1bb412f2c --- /dev/null +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobSnapshot.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2022 Joerg Kubitz and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Joerg Kubitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.progress; + +import org.eclipse.core.runtime.jobs.Job; + +/** + * A immutable, comparable Snapshot of a JobTreeElement + */ +public class JobSnapshot implements Comparable { + /** for information only - not to be used for comparison as it is mutable */ + private final JobTreeElement reference; + /** for information only - not to be used for comparison */ + private final int index; + + private final int hashCode; + private final boolean isUser; + private final boolean isBlocked; + private final int priority; + private final String name; + private final boolean isCanceled; + private final int state; + private final String displayString; + + public JobSnapshot(JobTreeElement reference) { + this(reference, 0); + } + public JobSnapshot(JobTreeElement reference, int index) { + this.reference = reference; + this.index = index; + this.hashCode = reference.hashCode(); + this.displayString = reference.getDisplayString(); + + JobInfo jobInfo = (reference instanceof JobInfo) ? (JobInfo) reference : null; + this.isBlocked = jobInfo == null ? false : jobInfo.isBlocked(); + this.isCanceled = jobInfo == null ? false : jobInfo.isCanceled(); + + Job job = jobInfo == null ? null : jobInfo.getJob(); + this.isUser = job == null ? false : job.isUser(); + this.priority = job == null ? 0 : job.getPriority(); + this.name = job == null ? "" : job.getName(); //$NON-NLS-1$ + this.state = job == null ? 0 : job.getState(); + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof JobSnapshot) { + return reference.equals(((JobSnapshot) obj).reference); + } + return false; + } + + @Override + public int compareTo(JobSnapshot other) { + boolean thisCanceled = isCanceled(); + boolean anotherCanceled = other.isCanceled(); + if (thisCanceled && !anotherCanceled) { + // If the receiver is cancelled then it is lowest priority + return 1; + } else if (!thisCanceled && anotherCanceled) { + return -1; + } + + // if equal job state, compare other job attributes + if (getState() != other.getState()) { + // ordering by job states, Job.RUNNING should be ordered first + return Integer.compare(other.getState(), getState()); + } + // User jobs have top priority + if (isUser()) { + if (!other.isUser()) { + return -1; + } + } else if (other.isUser()) { + return 1; + } + + // Show the blocked ones last. + if (isBlocked()) { + if (!other.isBlocked()) { + return 1; + } + } else if (other.isBlocked()) { + return -1; + } + + // If equal priority, order by names + if (getPriority() != other.getPriority()) { + // order by priority (lower value is higher priority) + if (getPriority() < other.getPriority()) { + return -1; + } + return 1; + } + int n = getName().compareTo(other.getName()); + if (n != 0) + return n; + return getDisplayString().compareTo(other.getDisplayString()); + } + + public boolean isUser() { + return isUser; + } + + public boolean isBlocked() { + return isBlocked; + } + + public int getPriority() { + return priority; + } + + public String getName() { + return name; + } + + public boolean isCanceled() { + return isCanceled; + } + + public int getState() { + return state; + } + + public String getDisplayString() { + return displayString; + } + public int getIndex() { + return index; + } + + @Override + public String toString() { + return reference.toString(); + } +} diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobTreeElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobTreeElement.java index d0cee9b6e4f..7820faf2bf3 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobTreeElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/JobTreeElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2015 IBM Corporation and others. + * Copyright (c) 2003, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -19,7 +19,7 @@ /** * The JobTreeElement is the abstract superclass of items displayed in the tree. */ -public abstract class JobTreeElement implements Comparable { +public abstract class JobTreeElement { /** * Returns the parent of this object. * @@ -85,11 +85,6 @@ String getCondensedDisplayString() { */ abstract boolean isJobInfo(); - @Override - public int compareTo(JobTreeElement other) { - return getDisplayString().compareTo(other.getDisplayString()); - } - /** * Returns whether or not this is currently active. * diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManager.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManager.java index 93233494171..5ab83c57179 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManager.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManager.java @@ -638,6 +638,7 @@ void removeListener(IJobProgressManagerListener listener) { * @param info the updated job info */ public void refreshJobInfo(JobInfo info) { + checkForStaleness(info.getJob()); synchronized (pendingUpdatesMutex) { Predicate predicate = listener -> !isNeverDisplaying(info.getJob(), listener.showsDebug()); rememberListenersForJob(info, pendingJobUpdates, predicate); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManagerUtil.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManagerUtil.java index 8256270f808..3d107722c5a 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManagerUtil.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/ProgressManagerUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2019 IBM Corporation and others. + * Copyright (c) 2003, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -51,41 +51,29 @@ public class ProgressManagerUtil { static class ProgressViewerComparator extends ViewerComparator { - private final HashMap lastIndexes = new HashMap<>(); - private final Comparator byIndex = Comparator.comparing(lastIndexes::get, + private final HashMap lastIndexes = new HashMap<>(); + private final Comparator byIndex = Comparator.comparing(lastIndexes::get, Comparator.nullsLast(Integer::compare)); // makes visual sort order stable - @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) - public int compare(Viewer testViewer, Object e1, Object e2) { - return ((Comparable) e1).compareTo(e2); - } - @Override public void sort(final Viewer viewer, Object[] elements) { - /* - * https://bugs.eclipse.org/371354 - * - * JavaSE 7+'s TimSort introduced a breaking change: It now throws a new - * IllegalArgumentException for bad comparators. Workaround is to retry a few - * times. - */ - for (int retries = 3; retries > 0; retries--) { - try { - Arrays.sort(elements, - byIndex.thenComparing((a, b) -> ProgressViewerComparator.this.compare(viewer, a, b))); - lastIndexes.clear(); - for (int i = 0; i < elements.length; i++) { - lastIndexes.put(elements[i], i); - } - return; // success - } catch (IllegalArgumentException e) { - // retry - } + Object[] src = elements.clone(); + // convert to snapshots + JobSnapshot[] snapshots = new JobSnapshot[elements.length]; + for (int i = 0; i < elements.length; i++) { + JobTreeElement jobTreeElement = (JobTreeElement) elements[i]; + snapshots[i] = new JobSnapshot(jobTreeElement, i); + } + // sort + Arrays.sort(snapshots, byIndex.thenComparing(JobSnapshot::compareTo)); + lastIndexes.clear(); + for (int i = 0; i < snapshots.length; i++) { + lastIndexes.put(snapshots[i], i); + } + // convert back + for (int i = 0; i < elements.length; i++) { + elements[i] = src[snapshots[i].getIndex()]; } - - // One last try that will log and throw TimSort's IAE if it happens: - super.sort(viewer, elements); } } diff --git a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF index dfc48220337..05077f05f48 100644 --- a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ui.workbench; singleton:=true -Bundle-Version: 3.126.100.qualifier +Bundle-Version: 3.127.0.qualifier Bundle-ClassPath: . Bundle-Activator: org.eclipse.ui.internal.WorkbenchPlugin Bundle-ActivationPolicy: lazy @@ -18,7 +18,6 @@ Export-Package: org.eclipse.e4.ui.workbench.addons.perspectiveswitcher;x-interna org.eclipse.ui.browser;ui.workbench=split;mandatory:="ui.workbench", org.eclipse.ui.commands, org.eclipse.ui.contexts, - org.eclipse.ui.databinding, org.eclipse.ui.databinding.typed, org.eclipse.ui.dialogs;ui.workbench=split;mandatory:="ui.workbench", org.eclipse.ui.dnd, diff --git a/bundles/org.eclipse.ui/.settings/.api_filters b/bundles/org.eclipse.ui/.settings/.api_filters new file mode 100644 index 00000000000..37e03b5f106 --- /dev/null +++ b/bundles/org.eclipse.ui/.settings/.api_filters @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/releng/org.eclipse.ui.releng/platformUiTools.p2f b/releng/org.eclipse.ui.releng/platformUiTools.p2f index d79fa7f694d..ec06d3f77f3 100644 --- a/releng/org.eclipse.ui.releng/platformUiTools.p2f +++ b/releng/org.eclipse.ui.releng/platformUiTools.p2f @@ -139,22 +139,22 @@ - + - + - + - + diff --git a/tests/org.eclipse.jface.tests.databinding/META-INF/MANIFEST.MF b/tests/org.eclipse.jface.tests.databinding/META-INF/MANIFEST.MF index d768293d816..05ef29c9c27 100644 --- a/tests/org.eclipse.jface.tests.databinding/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.jface.tests.databinding/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jface.tests.databinding -Bundle-Version: 1.11.200.qualifier +Bundle-Version: 1.11.300.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Require-Bundle: org.eclipse.core.databinding;bundle-version="[1.3.0,2.0.0)", diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java deleted file mode 100644 index 9cf7b875da6..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 194734, 264619 - *******************************************************************************/ - -package org.eclipse.core.tests.databinding.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.beans.PojoObservables; -import org.eclipse.core.databinding.beans.typed.PojoProperties; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.property.value.IValueProperty; -import org.eclipse.core.tests.internal.databinding.beans.Bean; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 3.2 - */ -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class PojoObservablesTest extends AbstractDefaultRealmTestCase { - private Bean pojo; - private String propertyName; - - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - - pojo = new Bean(); - propertyName = "value"; - } - - @Test - public void testObserveValue_ReturnsIBeanObservable() throws Exception { - IObservableValue value = PojoObservables.observeValue(pojo, - propertyName); - - assertNotNull(value); - assertTrue(value instanceof IBeanObservable); - } - - @Test - public void testObserveValue_DoesNotAttachListeners() throws Exception { - IObservableValue value = PojoObservables.observeValue(pojo, - propertyName); - - ChangeEventTracker.observe(value); - assertFalse(pojo.hasListeners(propertyName)); - } - - @Test - public void testObservableValueWithRealm_ReturnsIBeanObservable() - throws Exception { - CurrentRealm realm = new CurrentRealm(true); - IObservableValue value = PojoObservables.observeValue(realm, pojo, - propertyName); - - assertNotNull(value); - assertTrue(value instanceof IBeanObservable); - } - - @Test - public void testObservableMap_ReturnsIBeanObservable() throws Exception { - IObservableSet set = new WritableSet(); - set.add(new Bean()); - - IObservableMap map = PojoObservables.observeMap(set, Bean.class, - propertyName); - assertNotNull(map); - assertTrue(map instanceof IBeanObservable); - } - - @Test - public void testObservableMap_DoesNotAttachListeners() throws Exception { - IObservableSet set = new WritableSet(); - set.add(pojo); - - IObservableMap map = PojoObservables.observeMap(set, Bean.class, - propertyName); - assertFalse(pojo.hasListeners(propertyName)); - ChangeEventTracker.observe(map); - assertFalse(pojo.hasListeners(propertyName)); - } - - @Test - public void testObserveMaps_ReturnsMaps() throws Exception { - IObservableSet set = new WritableSet(); - set.add(pojo); - - IObservableMap[] maps = PojoObservables.observeMaps(set, Bean.class, - new String[] { "value", "class" }); - assertEquals(2, maps.length); - } - - @Test - public void testObserveListWithElementType_ReturnsIBeanObservable() - throws Exception { - IObservableList list = PojoObservables.observeList(Realm.getDefault(), - pojo, "list", String.class); - assertTrue(list instanceof IBeanObservable); - } - - @Test - public void testObserveListWithElementType_DoesNotAttachListeners() - throws Exception { - IObservableList observable = PojoObservables.observeList(Realm - .getDefault(), pojo, "list", String.class); - assertFalse(pojo.hasListeners("list")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("list")); - } - - @Test - public void testObserveList_ReturnsIBeanObservable() throws Exception { - IObservableList observable = PojoObservables.observeList(Realm - .getDefault(), pojo, "list"); - assertTrue(observable instanceof IBeanObservable); - } - - @Test - public void testObserveList_DoesNotAttachListeners() throws Exception { - IObservableList observable = PojoObservables.observeList(Realm - .getDefault(), pojo, "list"); - assertFalse(pojo.hasListeners("list")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("list")); - } - - @Test - public void testObserveSetWithElementType_ReturnsIBeanObservable() - throws Exception { - IObservableSet list = PojoObservables.observeSet(Realm.getDefault(), - pojo, "set", String.class); - assertTrue(list instanceof IBeanObservable); - } - - @Test - public void testObserveSetWithElementType_DoesNotAttachListeners() - throws Exception { - IObservableSet observable = PojoObservables.observeSet(Realm - .getDefault(), pojo, "set", String.class); - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } - - @Test - public void testObserveSet_ReturnsIBeanObservable() throws Exception { - IObservableSet list = PojoObservables.observeSet(Realm.getDefault(), - pojo, "set"); - assertTrue(list instanceof IBeanObservable); - } - - @Test - public void testObserveSet_DoesNotAttachListeners() throws Exception { - IObservableSet observable = PojoObservables.observeSet(Realm - .getDefault(), pojo, "set"); - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } - - @Test - public void testValueFactory_DoesNotAttachListeners() throws Exception { - IObservableFactory factory = PojoObservables.valueFactory(Realm - .getDefault(), "value"); - IObservableValue observable = (IObservableValue) factory - .createObservable(pojo); - - assertFalse(pojo.hasListeners("value")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("value")); - } - - @Test - public void testListFactory_DoesNotAttachListeners() throws Exception { - IObservableFactory factory = PojoObservables.listFactory(Realm - .getDefault(), "list", String.class); - IObservableList observable = (IObservableList) factory - .createObservable(pojo); - - assertFalse(pojo.hasListeners("value")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("value")); - } - - @Test - public void testSetFactory_DoesNotAttachListeners() throws Exception { - IObservableFactory factory = PojoObservables.setFactory(Realm - .getDefault(), propertyName); - IObservableSet observable = (IObservableSet) factory - .createObservable(pojo); - - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } - - @Test - public void testSetFactoryWithElementType_DoesNotAttachListeners() - throws Exception { - IObservableFactory factory = PojoObservables.setFactory(Realm - .getDefault(), propertyName, String.class); - IObservableSet observable = (IObservableSet) factory - .createObservable(pojo); - - assertFalse(pojo.hasListeners("set")); - ChangeEventTracker.observe(observable); - assertFalse(pojo.hasListeners("set")); - } - - @Test - public void testObserveDetailValue_ValueType() { - Bean inner = new Bean("string"); - Bean outer = new Bean(inner); - IValueProperty beanProperty = PojoProperties.value("bean"); - IObservableValue beanObservable = beanProperty.observe(outer); - assertEquals(Bean.class, beanObservable.getValueType()); - - IValueProperty valueProperty = PojoProperties.value("value"); - IObservableValue valueObservable = valueProperty - .observeDetail(beanObservable); - assertEquals(String.class, valueObservable.getValueType()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java deleted file mode 100644 index 515f78edcf7..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 208858, 213145, 246625, 194734 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertSame; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.internal.databinding.beans.BeanObservableListDecorator; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.swt.widgets.Display; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 3.3 - */ -public class BeanObservableListDecoratorTest { - private Bean bean; - private PropertyDescriptor propertyDescriptor; - private IObservableList observableList; - private BeanObservableListDecorator decorator; - - @Before - public void setUp() throws Exception { - - bean = new Bean(); - propertyDescriptor = new PropertyDescriptor( - "list", Bean.class,"getList","setList"); - observableList = BeansObservables.observeList( - DisplayRealm.getRealm(Display.getDefault()), bean, "list"); - decorator = new BeanObservableListDecorator(observableList, propertyDescriptor); - } - - @Test - public void testGetDelegate() throws Exception { - assertSame(observableList, decorator.getDecorated()); - } - - @Test - public void testGetObserved() throws Exception { - assertSame(bean, decorator.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertSame(propertyDescriptor, decorator.getPropertyDescriptor()); - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(MutableObservableListContractTest.class, new Delegate()); - suite.addTest(ObservableListContractTest.class, new Delegate()); - - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - @Override - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - final WritableList delegate = new WritableList(realm); - for (int i = 0; i < elementCount; i++) - delegate.add(createElement(delegate)); - return new BeanObservableListDecorator(delegate, null); - } - - private int counter; - - @Override - public Object createElement(IObservableCollection collection) { - return Integer.toString(counter++); - } - - @Override - public void change(IObservable observable) { - IObservableList list = (IObservableList) observable; - list.add(createElement(list)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java deleted file mode 100644 index d605cff7787..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 246625, 194734 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertSame; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.internal.databinding.beans.BeanObservableSetDecorator; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.swt.widgets.Display; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 3.3 - */ -public class BeanObservableSetDecoratorTest { - private PropertyDescriptor propertyDescriptor; - private IObservableSet observableSet; - private BeanObservableSetDecorator decorator; - private Bean bean; - - @Before - public void setUp() throws Exception { - - bean = new Bean(); - propertyDescriptor = new PropertyDescriptor("set", Bean.class); - observableSet = BeansObservables.observeSet(DisplayRealm - .getRealm(Display.getDefault()), bean, "set"); - decorator = new BeanObservableSetDecorator(observableSet, - propertyDescriptor); - } - - @Test - public void testGetDecorated() throws Exception { - assertSame(observableSet, decorator.getDecorated()); - } - - @Test - public void testGetObserved() throws Exception { - assertSame(bean, decorator.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertSame(propertyDescriptor, decorator.getPropertyDescriptor()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java deleted file mode 100644 index 724450ce7a3..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bug 246625, 194734 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertSame; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 3.3 - */ -public class BeanObservableValueDecoratorTest extends AbstractDefaultRealmTestCase { - private Bean bean; - private IObservableValue observableValue; - private BeanObservableValueDecorator decorator; - private PropertyDescriptor propertyDescriptor; - - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - - bean = new Bean(); - propertyDescriptor = new PropertyDescriptor("value", Bean.class); - observableValue = BeansObservables.observeValue(DisplayRealm - .getRealm(Display.getDefault()), bean, "value"); - decorator = new BeanObservableValueDecorator(observableValue, - propertyDescriptor); - } - - @Test - public void testGetDelegate() throws Exception { - assertSame(observableValue, decorator.getDecorated()); - } - - @Test - public void testGetObserved() throws Exception { - assertSame(bean, decorator.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertSame(propertyDescriptor, decorator.getPropertyDescriptor()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java deleted file mode 100644 index 853501f3cb5..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java +++ /dev/null @@ -1,612 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2018 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145, 244098, 246103, 194734, 268688, - * 301774 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.beans.IBeanProperty; -import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 1.1 - */ -public class JavaBeanObservableArrayBasedListTest extends - AbstractDefaultRealmTestCase { - private IObservableList list; - private IBeanObservable beanObservable; - - private PropertyDescriptor propertyDescriptor; - - private Bean bean; - - private String propertyName; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - propertyName = "array"; - propertyDescriptor = ((IBeanProperty) BeanProperties.list(Bean.class, - propertyName)).getPropertyDescriptor(); - bean = new Bean(new Object[0]); - - list = BeansObservables.observeList(DisplayRealm.getRealm(Display - .getDefault()), bean, propertyName); - beanObservable = (IBeanObservable) list; - } - - @Test - public void testGetObserved() throws Exception { - assertSame(bean, beanObservable.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); - } - - @Test - public void testRegistersListenerAfterFirstListenerIsAdded() - throws Exception { - assertFalse(bean.changeSupport.hasListeners(propertyName)); - list.addListChangeListener(new ListChangeEventTracker()); - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testRemovesListenerAfterLastListenerIsRemoved() - throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertTrue(bean.changeSupport.hasListeners(propertyName)); - list.removeListChangeListener(listener); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testFiresListChangeEvents() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setArray(new Bean[] { new Bean() }); - assertEquals(1, listener.count); - } - - @Test - public void testAddAddsElement() throws Exception { - int count = list.size(); - String element = "1"; - - assertEquals(0, count); - list.add(element); - assertEquals(count + 1, list.size()); - assertEquals(element, bean.getArray()[count]); - } - - @Test - public void testAddListChangeEvent() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - String element = "1"; - - list.add(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - - assertSame(list, event.getObservableList()); - assertDiff(event.diff, Collections.EMPTY_LIST, Collections - .singletonList("1")); - } - - @Test - public void testAdd_FiresPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.add("0")); - } - - @Test - public void testAddWithIndex() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - list.add(0, element); - assertEquals(element, bean.getArray()[0]); - } - - @Test - public void testAddAtIndexListChangeEvent() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.add(0, element); - - ListChangeEvent event = listener.event; - assertDiff(event.diff, Collections.EMPTY_LIST, Collections - .singletonList("1")); - } - - @Test - public void testAddAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.add(0, "0")); - } - - @Test - public void testRemove() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, bean.getArray().length); - list.remove(element); - assertEquals(0, bean.getArray().length); - } - - @Test - public void testRemoveListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.singletonList("1"), - Collections.EMPTY_LIST); - } - - @Test - public void testRemovePropertyChangeEvent() throws Exception { - list.add("0"); - - assertPropertyChangeEvent(bean, () -> list.remove("0")); - } - - @Test - public void testRemoveAtIndex() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(element, bean.getArray()[0]); - - list.remove(0); - assertEquals(0, bean.getArray().length); - } - - @Test - public void testRemoveAtIndexListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(0); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.singletonList(element), - Collections.EMPTY_LIST); - } - - @Test - public void testRemoveAtIndexPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, () -> list.remove(0)); - } - - @Test - public void testAddAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - list.addAll(elements); - - assertEquals(2, bean.getArray().length); - } - - @Test - public void testAddAllListChangEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - assertEquals(0, listener.count); - - list.addAll(elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.EMPTY_LIST, Arrays - .asList(new String[] { "1", "2" })); - } - - @Test - public void testAddAllPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.addAll(Arrays.asList(new String[] { "0", "1" }))); - } - - @Test - public void testAddAllAtIndex() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - assertEquals(2, list.size()); - - list.addAll(2, elements); - - assertEquals(4, bean.getArray().length); - assertEquals(elements.get(0), bean.getArray()[0]); - assertEquals(elements.get(1), bean.getArray()[1]); - } - - @Test - public void testAddAllAtIndexListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - - list.addAll(2, elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Arrays.asList(new Object[] { "1", "2" }), Arrays - .asList(new Object[] { "1", "2", "1", "2" })); - } - - @Test - public void testAddAllAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.addAll(0, Arrays.asList(new String[] { "1", "2" }))); - } - - @Test - public void testRemoveAll() throws Exception { - list.addAll(Arrays.asList(new String[] { "1", "2", "3", "4" })); - assertEquals(4, bean.getArray().length); - - list.removeAll(Arrays.asList(new String[] { "2", "4" })); - - assertEquals(2, bean.getArray().length); - assertEquals("1", bean.getArray()[0]); - assertEquals("3", bean.getArray()[1]); - } - - @Test - public void testRemoveAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.removeAll(elements); - - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Arrays - .asList(new Object[] { "1", "2", "1", "2" }), - Collections.EMPTY_LIST); - } - - @Test - public void testRemoveAllPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, () -> list.removeAll(Arrays.asList(new String[] { "0" }))); - } - - @Test - public void testRetainAll() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - assertEquals(4, bean.getArray().length); - - list.retainAll(elements.subList(0, 2)); - assertEquals(2, bean.getArray().length); - - assertEquals(elements.get(0), bean.getArray()[0]); - assertEquals(elements.get(1), bean.getArray()[1]); - } - - @Test - public void testRetainAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.retainAll(elements.subList(0, 2)); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Arrays - .asList(new Object[] { "0", "1", "2", "3" }), Arrays - .asList(new Object[] { "0", "1" })); - } - - @Test - public void testRetainAllPropertyChangeEvent() throws Exception { - list.addAll(Arrays.asList(new String[] { "0", "1" })); - - assertPropertyChangeEvent(bean, () -> list.retainAll(Arrays.asList(new String[] { "0" }))); - } - - @Test - public void testSet() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - assertEquals(oldElement, bean.getArray()[0]); - - list.set(0, newElement); - assertEquals(newElement, bean.getArray()[0]); - } - - @Test - public void testMove() throws Exception { - String element0 = "element0"; - String element1 = "element1"; - list.add(element0); - list.add(element1); - - assertEquals(2, bean.getArray().length); - assertEquals(element0, bean.getArray()[0]); - assertEquals(element1, bean.getArray()[1]); - - list.move(0, 1); - - assertEquals(2, bean.getArray().length); - assertEquals(element1, bean.getArray()[0]); - assertEquals(element0, bean.getArray()[1]); - } - - @Test - public void testSetListChangeEvent() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - assertEquals(0, listener.count); - - list.set(0, newElement); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.singletonList(oldElement), - Collections.singletonList(newElement)); - } - - @Test - public void testSetPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, () -> list.set(0, "1")); - } - - @Test - public void testListChangeEventFiresWhenNewListIsSet() throws Exception { - Bean[] elements = new Bean[] { new Bean(), new Bean() }; - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setArray(elements); - assertEquals(1, listener.count); - } - - @Test - public void testSetBeanProperty_CorrectForNullOldAndNewValues() { - // The java bean spec allows the old and new values in a - // PropertyChangeEvent to be null, which indicates that an unknown - // change occured. - - // This test ensures that JavaBeanObservableValue fires the correct - // value diff even if the bean implementor is lazy :-P - - Bean bean = new AnnoyingBean(); - bean.setArray(new Object[] { "old" }); - IObservableList observable = BeansObservables.observeList( - new CurrentRealm(true), bean, "array"); - ListChangeEventTracker tracker = ListChangeEventTracker - .observe(observable); - bean.setArray(new Object[] { "new" }); - assertEquals(1, tracker.count); - - List list = new ArrayList(); - list.add("old"); - tracker.event.diff.applyTo(list); - assertEquals(Collections.singletonList("new"), list); - } - - @Test - public void testModifyObservableList_FiresListChange() { - Bean bean = new Bean(new Object[] { "old" }); - IObservableList observable = BeansObservables - .observeList(bean, "array"); - ListChangeEventTracker tracker = ListChangeEventTracker - .observe(observable); - - observable.set(0, "new"); - - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.singletonList("old"), - Collections.singletonList("new")); - } - - @Test - public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() { - Bean bean = new Bean(new Object[0]); - CurrentRealm realm = new CurrentRealm(true); - IObservableList observable = BeansObservables.observeList(realm, bean, - "array"); - ListChangeEventTracker tracker = ListChangeEventTracker - .observe(observable); - - realm.setCurrent(false); - bean.setArray(new Object[] { "element" }); - assertEquals(0, tracker.count); - - realm.setCurrent(true); - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_LIST, Collections - .singletonList("element")); - } - - private static void assertDiff(ListDiff diff, List oldList, List newList) { - oldList = new ArrayList(oldList); // defensive copy in case arg is - // unmodifiable - diff.applyTo(oldList); - assertEquals("applying diff to list did not produce expected result", - newList, oldList); - } - - private static void assertPropertyChangeEvent(Bean bean, Runnable runnable) { - PropertyChangeTracker listener = new PropertyChangeTracker(); - bean.addPropertyChangeListener(listener); - - Object[] old = bean.getArray(); - assertEquals(0, listener.count); - - runnable.run(); - - PropertyChangeEvent event = listener.evt; - assertEquals("event did not fire", 1, listener.count); - assertEquals("array", event.getPropertyName()); - assertTrue("old value", Arrays.equals(old, (Object[]) event - .getOldValue())); - assertTrue("new value", Arrays.equals(bean.getArray(), (Object[]) event - .getNewValue())); - assertFalse("lists are equal", Arrays.equals(bean.getArray(), old)); - } - - private static class PropertyChangeTracker implements - PropertyChangeListener { - int count; - - PropertyChangeEvent evt; - - @Override - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.evt = evt; - } - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(MutableObservableListContractTest.class, new Delegate()); - suite.addTest(ObservableListContractTest.class, new Delegate()); - - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - @Override - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - String propertyName = "array"; - Object bean = new Bean(new Object[0]); - - IObservableList list = BeansObservables.observeList(realm, bean, - propertyName, String.class); - for (int i = 0; i < elementCount; i++) - list.add(createElement(list)); - return list; - } - - @Override - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - @Override - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - @Override - public void change(IObservable observable) { - IObservableList list = (IObservableList) observable; - list.add(createElement(list)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java deleted file mode 100644 index 6ebb71a1f27..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java +++ /dev/null @@ -1,430 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2018 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 221351) - * Brad Reynolds - through JavaBeanObservableArrayBasedListTest.java - * Matthew Hall - bug 213145, 244098, 246103, 194734, 268688, 301774 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.beans.IBeanProperty; -import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.SetChangeEvent; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 1.1 - */ -public class JavaBeanObservableArrayBasedSetTest extends - AbstractDefaultRealmTestCase { - private IObservableSet set; - private IBeanObservable beanObservable; - - private PropertyDescriptor propertyDescriptor; - - private Bean bean; - - private String propertyName; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - propertyName = "array"; - propertyDescriptor = ((IBeanProperty) BeanProperties.set(Bean.class, - propertyName)).getPropertyDescriptor(); - bean = new Bean(new HashSet()); - - set = BeansObservables.observeSet(DisplayRealm.getRealm(Display - .getDefault()), bean, propertyName); - beanObservable = (IBeanObservable) set; - } - - @Test - public void testGetObserved() throws Exception { - assertEquals(bean, beanObservable.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); - } - - @Test - public void testRegistersListenerAfterFirstListenerIsAdded() - throws Exception { - assertFalse(bean.changeSupport.hasListeners(propertyName)); - SetChangeEventTracker.observe(set); - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testRemovesListenerAfterLastListenerIsRemoved() - throws Exception { - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - - assertTrue(bean.changeSupport.hasListeners(propertyName)); - set.removeSetChangeListener(listener); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testSetBeanProperty_FiresSetChangeEvents() throws Exception { - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - - assertEquals(0, listener.count); - bean.setArray(new String[] { "element" }); - assertEquals(1, listener.count); - } - - @Test - public void testAdd_AddsElement() throws Exception { - assertEquals(0, set.size()); - - String element = "1"; - set.add(element); - - assertEquals(1, set.size()); - assertEquals(element, bean.getArray()[0]); - } - - @Test - public void testAdd_SetChangeEvent() throws Exception { - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - String element = "1"; - set.add(element); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - - assertSame(set, event.getObservableSet()); - assertEquals(Collections.singleton(element), event.diff.getAdditions()); - assertEquals(Collections.EMPTY_SET, event.diff.getRemovals()); - } - - @Test - public void testAdd_FiresPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> set.add("0")); - } - - @Test - public void testRemove() throws Exception { - String element = "1"; - set.add(element); - - assertEquals(1, bean.getArray().length); - set.remove(element); - assertEquals(0, bean.getArray().length); - } - - @Test - public void testRemove_SetChangeEvent() throws Exception { - String element = "1"; - set.add(element); - assertEquals(1, set.size()); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - set.remove(element); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - assertEquals(Collections.singleton(element), event.diff.getRemovals()); - assertEquals(Collections.EMPTY_SET, event.diff.getAdditions()); - } - - @Test - public void testRemovePropertyChangeEvent() throws Exception { - set.add("0"); - - assertPropertyChangeEvent(bean, () -> set.remove("0")); - } - - @Test - public void testAddAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, set.size()); - - set.addAll(elements); - - assertEquals(2, bean.getArray().length); - } - - @Test - public void testAddAll_SetChangeEvent() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, set.size()); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - set.addAll(elements); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - - assertEquals(new HashSet(elements), event.diff.getAdditions()); - assertEquals(Collections.EMPTY_SET, event.diff.getRemovals()); - } - - @Test - public void testAddAllPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> set.addAll(Arrays.asList(new String[] { "0", "1" }))); - } - - @Test - public void testRemoveAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - set.addAll(elements); - - assertEquals(2, bean.getArray().length); - set.removeAll(elements); - - assertEquals(0, bean.getArray().length); - } - - @Test - public void testRemoveAll_SetChangeEvent() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - set.addAll(elements); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - assertEquals(0, listener.count); - - set.removeAll(elements); - - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - assertEquals(Collections.EMPTY_SET, event.diff.getAdditions()); - assertEquals(new HashSet(elements), event.diff.getRemovals()); - } - - @Test - public void testRemoveAllPropertyChangeEvent() throws Exception { - set.add("0"); - assertPropertyChangeEvent(bean, () -> set.removeAll(Arrays.asList(new String[] { "0" }))); - } - - @Test - public void testRetainAll() throws Exception { - set.addAll(Arrays.asList(new String[] { "0", "1", "2", "3" })); - - assertEquals(4, bean.getArray().length); - - set.retainAll(Arrays.asList(new String[] { "0", "1" })); - assertEquals(2, bean.getArray().length); - - assertTrue(set.containsAll(Arrays.asList(new String[] { "1", "0" }))); - } - - @Test - public void testRetainAll_SetChangeEvent() throws Exception { - set.addAll(Arrays.asList(new String[] { "0", "1", "2", "3" })); - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - - assertEquals(0, listener.count); - set.retainAll(Arrays.asList(new String[] { "0", "1" })); - - assertEquals(1, listener.count); - SetChangeEvent event = listener.event; - assertEquals(set, event.getObservableSet()); - assertEquals(Collections.EMPTY_SET, event.diff.getAdditions()); - assertEquals(new HashSet(Arrays.asList(new String[] { "2", "3" })), - event.diff.getRemovals()); - } - - @Test - public void testRetainAllPropertyChangeEvent() throws Exception { - set.addAll(Arrays.asList(new String[] { "0", "1" })); - - assertPropertyChangeEvent(bean, () -> set.retainAll(Arrays.asList(new String[] { "0" }))); - } - - @Test - public void testSetChangeEventFiresWhenNewSetIsSet() throws Exception { - Bean[] elements = new Bean[] { new Bean(), new Bean() }; - - SetChangeEventTracker listener = SetChangeEventTracker.observe(set); - - assertEquals(0, listener.count); - bean.setArray(elements); - assertEquals(1, listener.count); - } - - @Test - public void testSetBeanProperty_CorrectForNullOldAndNewValues() { - // The java bean spec allows the old and new values in a - // PropertyChangeEvent to be null, which indicates that an unknown - // change occured. - - // This test ensures that JavaBeanObservableValue fires the correct - // value diff even if the bean implementor is lazy :-P - - Bean bean = new AnnoyingBean(); - bean.setArray(new Object[] { "old" }); - IObservableSet observable = BeansObservables.observeSet( - new CurrentRealm(true), bean, "array"); - SetChangeEventTracker tracker = SetChangeEventTracker - .observe(observable); - bean.setArray(new Object[] { "new" }); - assertEquals(1, tracker.count); - assertEquals(Collections.singleton("old"), tracker.event.diff - .getRemovals()); - assertEquals(Collections.singleton("new"), tracker.event.diff - .getAdditions()); - } - - @Test - public void testModifyObservableSet_FiresSetChange() { - Bean bean = new Bean(new Object[] {}); - IObservableSet observable = BeansObservables.observeSet(bean, "array"); - SetChangeEventTracker tracker = SetChangeEventTracker - .observe(observable); - - observable.add("new"); - - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections - .singleton("new")); - } - - @Test - public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() { - Bean bean = new Bean(new Object[0]); - CurrentRealm realm = new CurrentRealm(true); - IObservableSet observable = BeansObservables.observeSet(realm, bean, - "array"); - SetChangeEventTracker tracker = SetChangeEventTracker - .observe(observable); - - realm.setCurrent(false); - bean.setArray(new Object[] { "element" }); - assertEquals(0, tracker.count); - - realm.setCurrent(true); - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections - .singleton("element")); - } - - private static void assertDiff(SetDiff diff, Set oldSet, Set newSet) { - oldSet = new HashSet(oldSet); // defensive copy in case arg is - // unmodifiable - diff.applyTo(oldSet); - assertEquals("applying diff to list did not produce expected result", - newSet, oldSet); - } - - private static void assertPropertyChangeEvent(Bean bean, Runnable runnable) { - PropertyChangeTracker listener = new PropertyChangeTracker(); - bean.addPropertyChangeListener(listener); - - Object[] old = bean.getArray(); - assertEquals(0, listener.count); - - runnable.run(); - - PropertyChangeEvent event = listener.evt; - assertEquals("event did not fire", 1, listener.count); - assertEquals("array", event.getPropertyName()); - assertTrue("old value", Arrays.equals(old, (Object[]) event - .getOldValue())); - assertTrue("new value", Arrays.equals(bean.getArray(), (Object[]) event - .getNewValue())); - assertFalse("sets are equal", Arrays.equals(bean.getArray(), old)); - } - - private static class PropertyChangeTracker implements - PropertyChangeListener { - int count; - - PropertyChangeEvent evt; - - @Override - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.evt = evt; - } - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(MutableObservableSetContractTest.class, new Delegate()); - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - @Override - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - String propertyName = "array"; - Object bean = new Bean(new Object[0]); - - IObservableSet set = BeansObservables.observeSet(realm, bean, - propertyName, String.class); - for (int i = 0; i < elementCount; i++) - set.add(createElement(set)); - return set; - } - - @Override - public Object createElement(IObservableCollection collection) { - return new Object().toString(); - } - - @Override - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - @Override - public void change(IObservable observable) { - IObservableSet set = (IObservableSet) observable; - set.add(createElement(set)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java deleted file mode 100644 index 61f3b786030..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java +++ /dev/null @@ -1,670 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2018 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145, 244098, 246103, 194734, 268688 - * Ovidio Mallo - bug 301774 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.beans.IBeanProperty; -import org.eclipse.core.databinding.beans.PojoObservables; -import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListChangeEvent; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 1.1 - */ -public class JavaBeanObservableListTest extends AbstractDefaultRealmTestCase { - private IObservableList list; - private IBeanObservable beanObservable; - - private PropertyDescriptor propertyDescriptor; - - private Bean bean; - - private String propertyName; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - propertyName = "list"; - propertyDescriptor = ((IBeanProperty) BeanProperties.list(Bean.class, - propertyName)).getPropertyDescriptor(); - bean = new Bean(new ArrayList()); - - list = BeansObservables.observeList(DisplayRealm.getRealm(Display - .getDefault()), bean, propertyName); - beanObservable = (IBeanObservable) list; - } - - @Test - public void testGetObserved() throws Exception { - assertEquals(bean, beanObservable.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); - } - - @Test - public void testRegistersListenerAfterFirstListenerIsAdded() - throws Exception { - assertFalse(bean.changeSupport.hasListeners(propertyName)); - list.addListChangeListener(new ListChangeEventTracker()); - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testRemovesListenerAfterLastListenerIsRemoved() - throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertTrue(bean.changeSupport.hasListeners(propertyName)); - list.removeListChangeListener(listener); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testFiresListChangeEvents() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setList(Arrays.asList("value")); - assertEquals(1, listener.count); - } - - @Test - public void testAddAddsElement() throws Exception { - int count = list.size(); - String element = "1"; - - assertEquals(0, count); - list.add(element); - assertEquals(count + 1, list.size()); - assertEquals(element, bean.getList().get(count)); - } - - @Test - public void testAddListChangeEvent() throws Exception { - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - String element = "1"; - - list.add(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - - assertSame(list, event.getObservableList()); - assertDiff(event.diff, Collections.EMPTY_LIST, Collections - .singletonList("1")); - } - - @Test - public void testAddFiresPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.add("0")); - } - - @Test - public void testAddAtIndex() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - list.add(0, element); - assertEquals(element, bean.getList().get(0)); - } - - @Test - public void testAddAtIndexListChangeEvent() throws Exception { - String element = "1"; - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.add(0, element); - - ListChangeEvent event = listener.event; - assertDiff(event.diff, Collections.EMPTY_LIST, Collections - .singletonList("1")); - } - - @Test - public void testAddAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.add(0, "0")); - } - - @Test - public void testClear() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, bean.getList().size()); - assertPropertyChangeEvent(bean, () -> list.clear()); - assertEquals(0, bean.getList().size()); - } - - @Test - public void testRemove() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, bean.getList().size()); - list.remove(element); - assertEquals(0, bean.getList().size()); - } - - @Test - public void testRemoveListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(element); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.singletonList("1"), - Collections.EMPTY_LIST); - } - - @Test - public void testRemovePropertyChangeEvent() throws Exception { - list.add("0"); - - assertPropertyChangeEvent(bean, () -> list.remove("0")); - } - - @Test - public void testRemoveAtIndex() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(element, bean.getList().get(0)); - - list.remove(0); - assertEquals(0, bean.getList().size()); - } - - @Test - public void testRemoveAtIndexListChangeEvent() throws Exception { - String element = "1"; - list.add(element); - - assertEquals(1, list.size()); - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - list.remove(0); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.singletonList(element), - Collections.EMPTY_LIST); - } - - @Test - public void testRemoveAtIndexPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, () -> list.remove(0)); - } - - @Test - public void testAddAll() throws Exception { - Collection elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - list.addAll(elements); - - assertEquals(2, bean.getList().size()); - } - - @Test - public void testAddAllListChangEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - assertEquals(0, list.size()); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - assertEquals(0, listener.count); - - list.addAll(elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.EMPTY_LIST, Arrays - .asList(new String[] { "1", "2" })); - } - - @Test - public void testAddAllPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.addAll(Arrays.asList(new String[] { "0", "1" }))); - } - - @Test - public void testAddAllAtIndex() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - assertEquals(2, list.size()); - - list.addAll(2, elements); - - assertEquals(4, bean.getList().size()); - assertEquals(elements.get(0), bean.getList().get(0)); - assertEquals(elements.get(1), bean.getList().get(1)); - } - - @Test - public void testAddAllAtIndexListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - - list.addAll(2, elements); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Arrays.asList(new Object[] { "1", "2" }), Arrays - .asList(new Object[] { "1", "2", "1", "2" })); - } - - @Test - public void testAddAllAtIndexPropertyChangeEvent() throws Exception { - assertPropertyChangeEvent(bean, () -> list.addAll(0, Arrays.asList(new String[] { "1", "2" }))); - } - - @Test - public void testRemoveAll() throws Exception { - list.addAll(Arrays.asList(new String[] { "1", "2", "3", "4" })); - assertEquals(4, bean.getList().size()); - - list.removeAll(Arrays.asList(new String[] { "2", "4" })); - - assertEquals(2, bean.getList().size()); - assertEquals("1", bean.getList().get(0)); - assertEquals("3", bean.getList().get(1)); - } - - @Test - public void testRemoveAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - list.addAll(elements); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.removeAll(elements); - - ListChangeEvent event = listener.event; - assertEquals(list, event.getObservableList()); - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Arrays - .asList(new Object[] { "1", "2", "1", "2" }), - Collections.EMPTY_LIST); - } - - @Test - public void testRemoveAllPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, () -> list.removeAll(Arrays.asList(new String[] { "0" }))); - } - - @Test - public void testRetailAll() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - assertEquals(4, bean.getList().size()); - - list.retainAll(elements.subList(0, 2)); - assertEquals(2, bean.getList().size()); - - assertEquals(elements.get(0), bean.getList().get(0)); - assertEquals(elements.get(1), bean.getList().get(1)); - } - - @Test - public void testRetainAllListChangeEvent() throws Exception { - List elements = Arrays.asList(new String[] { "0", "1", "2", "3" }); - list.addAll(elements); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - list.retainAll(elements.subList(0, 2)); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Arrays - .asList(new Object[] { "0", "1", "2", "3" }), Arrays - .asList(new Object[] { "0", "1" })); - } - - @Test - public void testRetainAllPropertyChangeEvent() throws Exception { - list.addAll(Arrays.asList(new String[] { "0", "1" })); - - assertPropertyChangeEvent(bean, () -> list.retainAll(Arrays.asList(new String[] { "0" }))); - } - - @Test - public void testSet() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - assertEquals(oldElement, bean.getList().get(0)); - - list.set(0, newElement); - assertEquals(newElement, bean.getList().get(0)); - } - - @Test - public void testMove() throws Exception { - String element0 = "element0"; - String element1 = "element1"; - list.add(element0); - list.add(element1); - - assertEquals(2, bean.getList().size()); - assertEquals(element0, bean.getList().get(0)); - assertEquals(element1, bean.getList().get(1)); - - list.move(0, 1); - - assertEquals(2, bean.getList().size()); - assertEquals(element1, bean.getList().get(0)); - assertEquals(element0, bean.getList().get(1)); - } - - @Test - public void testSetListChangeEvent() throws Exception { - String oldElement = "old"; - String newElement = "new"; - list.add(oldElement); - - ListChangeEventTracker listener = ListChangeEventTracker.observe(list); - assertEquals(0, listener.count); - - list.set(0, newElement); - - assertEquals(1, listener.count); - ListChangeEvent event = listener.event; - assertSame(list, event.getObservableList()); - - assertDiff(event.diff, Collections.singletonList(oldElement), - Collections.singletonList(newElement)); - } - - @Test - public void testSetPropertyChangeEvent() throws Exception { - list.add("0"); - assertPropertyChangeEvent(bean, () -> list.set(0, "1")); - } - - @Test - public void testListChangeEventFiresWhenNewListIsSet() throws Exception { - List elements = Arrays.asList(new String[] { "1", "2" }); - - ListChangeEventTracker listener = new ListChangeEventTracker(); - list.addListChangeListener(listener); - - assertEquals(0, listener.count); - bean.setList(elements); - assertEquals(1, listener.count); - } - - @Test - public void testConstructor_RegistersListener() throws Exception { - Bean bean = new Bean(); - IObservableList observable = BeansObservables.observeList(Realm - .getDefault(), bean, "list"); - - assertFalse(bean.hasListeners("list")); - ChangeEventTracker.observe(observable); - assertTrue(bean.hasListeners("list")); - } - - @Test - public void testConstructor_SkipsRegisterListener() throws Exception { - Bean bean = new Bean(); - IObservableList observable = PojoObservables.observeList(Realm - .getDefault(), bean, "list"); - - assertFalse(bean.hasListeners("list")); - ChangeEventTracker.observe(observable); - assertFalse(bean.hasListeners("list")); - } - - @Test - public void testSetBeanProperty_CorrectForNullOldAndNewValues() { - // The java bean spec allows the old and new values in a - // PropertyChangeEvent to be null, which indicates that an unknown - // change occured. - - // This test ensures that JavaBeanObservableValue fires the correct - // value diff even if the bean implementor is lazy :-P - - Bean bean = new AnnoyingBean(); - bean.setList(Collections.singletonList("old")); - IObservableList observable = BeansObservables.observeList( - new CurrentRealm(true), bean, "list"); - ListChangeEventTracker tracker = ListChangeEventTracker - .observe(observable); - bean.setList(Collections.singletonList("new")); - - assertEquals(1, tracker.count); - - List list = new ArrayList(); - list.add("old"); - tracker.event.diff.applyTo(list); - assertEquals(Collections.singletonList("new"), list); - } - - @Test - public void testModifyObservableList_FiresListChange() { - Bean bean = new Bean(new ArrayList()); - IObservableList observable = BeansObservables.observeList(bean, "list"); - ListChangeEventTracker tracker = ListChangeEventTracker - .observe(observable); - - Object element = new Object(); - observable.add(element); - - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_LIST, Collections - .singletonList(element)); - } - - @Test - public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() { - Bean bean = new Bean(Collections.EMPTY_LIST); - CurrentRealm realm = new CurrentRealm(true); - IObservableList observable = BeansObservables.observeList(realm, bean, - "list"); - ListChangeEventTracker tracker = ListChangeEventTracker - .observe(observable); - - realm.setCurrent(false); - bean.setList(Collections.singletonList("element")); - assertEquals(0, tracker.count); - - realm.setCurrent(true); - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_LIST, Collections - .singletonList("element")); - } - - /** - * Makes sure that the list set on the Bean model after changing the - * observable list is modifiable (see bugs 285307 and 301774). - */ - @Test - public void testUpdatedBeanListIsModifiable() { - Bean bean = new Bean(new ArrayList()); - IObservableList observable = BeansObservables.observeList(bean, "list"); - - observable.add(new Object()); - bean.getList().clear(); - } - - /** - * Makes sure that the list set on the Pojo model after changing the - * observable list is modifiable (see bugs 285307 and 301774). - */ - @Test - public void testUpdatedPojoListIsModifiable() { - Bean bean = new Bean(new ArrayList()); - IObservableList observable = PojoObservables.observeList(bean, "list"); - - observable.add(new Object()); - bean.getList().clear(); - } - - private static void assertDiff(ListDiff diff, List oldList, List newList) { - oldList = new ArrayList(oldList); // defensive copy in case arg is - // unmodifiable - diff.applyTo(oldList); - assertEquals("applying diff to list did not produce expected result", - newList, oldList); - } - - private static void assertPropertyChangeEvent(Bean bean, Runnable runnable) { - PropertyChangeTracker listener = new PropertyChangeTracker(); - bean.addPropertyChangeListener(listener); - - List old = bean.getList(); - assertEquals(0, listener.count); - - runnable.run(); - - PropertyChangeEvent event = listener.evt; - assertEquals("event did not fire", 1, listener.count); - assertEquals("list", event.getPropertyName()); - assertEquals("old value", old, event.getOldValue()); - assertEquals("new value", bean.getList(), event.getNewValue()); - assertFalse("lists are equal", bean.getList().equals(old)); - } - - private static class PropertyChangeTracker implements - PropertyChangeListener { - int count; - - PropertyChangeEvent evt; - - @Override - public void propertyChange(PropertyChangeEvent evt) { - count++; - this.evt = evt; - } - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(MutableObservableListContractTest.class, new Delegate()); - suite.addTest(ObservableListContractTest.class, new Delegate()); - - } - - static class Delegate extends AbstractObservableCollectionContractDelegate { - @Override - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - String propertyName = "list"; - Object bean = new Bean(new ArrayList()); - - IObservableList list = BeansObservables.observeList(realm, bean, - propertyName, String.class); - for (int i = 0; i < elementCount; i++) - list.add(createElement(list)); - return list; - } - - @Override - public Object createElement(IObservableCollection collection) { - return new Object().toString(); - } - - @Override - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - @Override - public void change(IObservable observable) { - IObservableList list = (IObservableList) observable; - list.add(createElement(list)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java deleted file mode 100644 index b53e623a5f0..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java +++ /dev/null @@ -1,277 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matthew Hall - bugs 213145, 241585, 246103, 194734, 268688 - * Ovidio Mallo - bug 247741 - *******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.beans.PropertyDescriptor; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.beans.IBeanProperty; -import org.eclipse.core.databinding.beans.PojoObservables; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.map.MapDiff; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.tests.databinding.observable.ThreadRealm; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 3.2 - * - */ -public class JavaBeanObservableMapTest extends AbstractDefaultRealmTestCase { - private Bean model1; - - private Bean model2; - - private WritableSet set; - - private PropertyDescriptor propertyDescriptor; - - private IObservableMap map; - private IBeanObservable beanObservable; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - ThreadRealm realm = new ThreadRealm(); - realm.init(Thread.currentThread()); - model1 = new Bean("1"); - model2 = new Bean("2"); - - set = new WritableSet(realm, new HashSet(), Bean.class); - set.add(model1); - set.add(model2); - - String propertyName = "value"; - propertyDescriptor = ((IBeanProperty) BeanProperties.value(Bean.class, - propertyName)).getPropertyDescriptor(); - map = BeansObservables.observeMap(set, Bean.class, propertyName); - beanObservable = (IBeanObservable) map; - } - - @Test - public void testGetValue() throws Exception { - assertEquals( - "The 'value' from the map should be the value of the property of the model.", - model1.getValue(), map.get(model1)); - } - - @Test - public void testGetValue_KeyOutOfDomain() { - Bean model3 = new Bean("3"); - assertFalse(map.containsKey(model3)); - assertFalse(model3.getValue().equals(map.get(model3))); - } - - @Test - public void testSetValueNotifications() throws Exception { - String oldValue = model1.getValue(); - String newValue = model1.getValue() + model1.getValue(); - MapChangeEventTracker listener = new MapChangeEventTracker(); - - map.addMapChangeListener(listener); - assertEquals(0, listener.count); - model1.setValue(newValue); - assertEquals(1, listener.count); - assertTrue(listener.event.diff.getChangedKeys().contains(model1)); - assertEquals(newValue, listener.event.diff.getNewValue(model1)); - assertEquals(oldValue, listener.event.diff.getOldValue(model1)); - assertFalse(listener.event.diff.getAddedKeys().contains(model1)); - assertFalse(listener.event.diff.getRemovedKeys().contains(model1)); - } - - @Test - public void testPutValue() throws Exception { - String oldValue = model1.getValue(); - String newValue = model1.getValue() + model1.getValue(); - MapChangeEventTracker listener = new MapChangeEventTracker(); - map.addMapChangeListener(listener); - - assertEquals(0, listener.count); - map.put(model1, newValue); - assertEquals(1, listener.count); - assertEquals(newValue, model1.getValue()); - assertEquals(oldValue, listener.event.diff.getOldValue(model1)); - assertEquals(newValue, listener.event.diff.getNewValue(model1)); - assertFalse(listener.event.diff.getAddedKeys().contains(model1)); - assertTrue(listener.event.diff.getChangedKeys().contains(model1)); - assertFalse(listener.event.diff.getRemovedKeys().contains(model1)); - } - - @Test - public void testAddKey() throws Exception { - MapChangeEventTracker listener = new MapChangeEventTracker(); - map.addMapChangeListener(listener); - - Bean model3 = new Bean("3"); - - assertEquals(0, listener.count); - set.add(model3); - assertEquals(1, listener.count); - assertTrue(listener.event.diff.getAddedKeys().contains(model3)); - assertEquals(model3.getValue(), map.get(model3)); - - String newValue = model3.getValue() + model3.getValue(); - model3.setValue(newValue); - assertEquals(2, listener.count); - assertEquals(3, map.size()); - } - - @Test - public void testRemoveKey() throws Exception { - MapChangeEventTracker listener = new MapChangeEventTracker(); - map.addMapChangeListener(listener); - - assertEquals(0, listener.count); - set.remove(model1); - assertEquals(1, listener.count); - assertFalse(listener.event.diff.getAddedKeys().contains(model1)); - assertFalse(listener.event.diff.getChangedKeys().contains(model1)); - assertTrue(listener.event.diff.getRemovedKeys().contains(model1)); - assertEquals(1, map.size()); - } - - @Test - public void testGetObserved() throws Exception { - assertEquals(set, beanObservable.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); - } - - @Test - public void testConstructor_SkipRegisterListeners() throws Exception { - Realm realm = new CurrentRealm(true); - WritableSet set = new WritableSet(realm); - Bean bean = new Bean(); - set.add(bean); - - IObservableMap observable = PojoObservables.observeMap(set, Bean.class, - "value"); - assertFalse(bean.hasListeners("value")); - ChangeEventTracker.observe(observable); - - assertFalse(bean.hasListeners("value")); - } - - @Test - public void testConstructor_RegistersListeners() throws Exception { - Realm realm = new CurrentRealm(true); - WritableSet set = new WritableSet(realm); - Bean bean = new Bean(); - set.add(bean); - - IObservableMap observable = BeansObservables.observeMap(set, - Bean.class, "value"); - assertFalse(bean.hasListeners("value")); - ChangeEventTracker.observe(observable); - - assertTrue(bean.hasListeners("value")); - } - - @Test - public void testSetBeanProperty_CorrectForNullOldAndNewValues() { - // The java bean spec allows the old and new values in a - // PropertyChangeEvent to be null, which indicates that an unknown - // change occured. - - // This test ensures that JavaBeanObservableValue fires the correct - // value diff even if the bean implementor is lazy :-P - - WritableSet set = new WritableSet(new CurrentRealm(true)); - - Bean bean = new AnnoyingBean(); - bean.setValue("old"); - set.add(bean); - - IObservableMap map = BeansObservables.observeMap(set, Bean.class, - "value"); - MapChangeEventTracker tracker = MapChangeEventTracker.observe(map); - - bean.setValue("new"); - - assertEquals(1, tracker.count); - - assertEquals(Collections.EMPTY_SET, tracker.event.diff.getAddedKeys()); - assertEquals(Collections.singleton(bean), tracker.event.diff - .getChangedKeys()); - assertEquals(Collections.EMPTY_SET, tracker.event.diff.getRemovedKeys()); - - assertEquals("old", tracker.event.diff.getOldValue(bean)); - assertEquals("new", tracker.event.diff.getNewValue(bean)); - } - - @Test - public void testModifyObservableMap_FiresMapChange() { - Bean bean = new Bean(Collections.singletonMap("key", "oldValue")); - IObservableMap observable = BeansObservables.observeMap(bean, "map"); - MapChangeEventTracker tracker = MapChangeEventTracker - .observe(observable); - - observable.put("key", "newValue"); - - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.singletonMap("key", - "oldValue"), Collections.singletonMap("key", "newValue")); - } - - @Test - public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() { - Bean bean = new Bean(Collections.EMPTY_MAP); - CurrentRealm realm = new CurrentRealm(true); - IObservableMap observable = BeansObservables.observeMap(realm, bean, - "map"); - MapChangeEventTracker tracker = MapChangeEventTracker - .observe(observable); - - realm.setCurrent(false); - bean.setMap(Collections.singletonMap("key", "value")); - assertEquals(0, tracker.count); - - realm.setCurrent(true); - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_MAP, Collections - .singletonMap("key", "value")); - } - - private static void assertDiff(MapDiff diff, Map oldMap, Map newMap) { - oldMap = new HashMap(oldMap); // defensive copy in case arg is - // unmodifiable - diff.applyTo(oldMap); - assertEquals("applying diff to list did not produce expected result", - newMap, oldMap); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java deleted file mode 100644 index 139ce766756..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Matthew Hall - bugs 221351, 213145, 244098, 246103, 194734, 268688 - * Ovidio Mallo - bugs 247741, 301774 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.beans.IBeanProperty; -import org.eclipse.core.databinding.beans.PojoObservables; -import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.set.IObservableSet; -import org.eclipse.core.databinding.observable.set.SetDiff; -import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Display; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 3.3 - */ -public class JavaBeanObservableSetTest extends AbstractDefaultRealmTestCase { - private IObservableSet observableSet; - private IBeanObservable beanObservable; - private Bean bean; - private PropertyDescriptor propertyDescriptor; - private String propertyName; - private SetChangeEventTracker listener; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - bean = new Bean(); - propertyName = "set"; - propertyDescriptor = ((IBeanProperty) BeanProperties.set(Bean.class, - propertyName)).getPropertyDescriptor(); - - observableSet = BeansObservables - .observeSet(DisplayRealm.getRealm(Display.getDefault()), - bean, propertyName, Bean.class); - beanObservable = (IBeanObservable) observableSet; - listener = new SetChangeEventTracker(); - } - - @Test - public void testGetObserved() throws Exception { - assertEquals(bean, beanObservable.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); - } - - @Test - public void testGetElementType() throws Exception { - assertEquals(Bean.class, observableSet.getElementType()); - } - - @Test - public void testRegistersListenerAfterFirstListenerIsAdded() - throws Exception { - assertFalse(bean.changeSupport.hasListeners(propertyName)); - observableSet.addSetChangeListener(new SetChangeEventTracker()); - assertTrue(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testRemovesListenerAfterLastListenerIsRemoved() - throws Exception { - observableSet.addSetChangeListener(listener); - - assertTrue(bean.changeSupport.hasListeners(propertyName)); - observableSet.removeSetChangeListener(listener); - assertFalse(bean.changeSupport.hasListeners(propertyName)); - } - - @Test - public void testFiresChangeEvents() throws Exception { - observableSet.addSetChangeListener(listener); - assertEquals(0, listener.count); - bean.setSet(new HashSet(Arrays.asList(new String[] { "1" }))); - assertEquals(1, listener.count); - } - - @Test - public void testConstructor_RegisterListeners() throws Exception { - bean = new Bean(); - observableSet = BeansObservables.observeSet(new CurrentRealm(true), - bean, propertyName); - assertFalse(bean.hasListeners(propertyName)); - ChangeEventTracker.observe(observableSet); - assertTrue(bean.hasListeners(propertyName)); - } - - @Test - public void testConstructor_SkipsRegisterListeners() throws Exception { - bean = new Bean(); - - observableSet = PojoObservables.observeSet(new CurrentRealm(true), - bean, propertyName); - assertFalse(bean.hasListeners(propertyName)); - ChangeEventTracker.observe(observableSet); - assertFalse(bean.hasListeners(propertyName)); - } - - @Test - public void testSetBeanProperty_CorrectForNullOldAndNewValues() { - // The java bean spec allows the old and new values in a - // PropertyChangeEvent to be null, which indicates that an unknown - // change occured. - - // This test ensures that JavaBeanObservableValue fires the correct - // value diff even if the bean implementor is lazy :-P - - Bean bean = new AnnoyingBean(); - bean.setSet(Collections.singleton("old")); - IObservableSet observable = BeansObservables.observeSet( - new CurrentRealm(true), bean, "set"); - SetChangeEventTracker tracker = SetChangeEventTracker - .observe(observable); - bean.setSet(Collections.singleton("new")); - assertEquals(1, tracker.count); - assertEquals(Collections.singleton("old"), tracker.event.diff - .getRemovals()); - assertEquals(Collections.singleton("new"), tracker.event.diff - .getAdditions()); - } - - @Test - public void testModifyObservableSet_FiresSetChange() { - Bean bean = new Bean(new HashSet()); - IObservableSet observable = BeansObservables.observeSet(bean, "set"); - SetChangeEventTracker tracker = SetChangeEventTracker - .observe(observable); - - Object element = new Object(); - observable.add(element); - - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections - .singleton(element)); - } - - @Test - public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() { - Bean bean = new Bean(Collections.EMPTY_SET); - CurrentRealm realm = new CurrentRealm(true); - IObservableSet observable = BeansObservables.observeSet(realm, bean, - "set"); - SetChangeEventTracker tracker = SetChangeEventTracker - .observe(observable); - - realm.setCurrent(false); - bean.setSet(Collections.singleton("element")); - assertEquals(0, tracker.count); - - realm.setCurrent(true); - assertEquals(1, tracker.count); - assertDiff(tracker.event.diff, Collections.EMPTY_SET, Collections - .singleton("element")); - } - - /** - * Makes sure that the set set on the Bean model after changing the - * observable set is modifiable (see bugs 285307 and 301774). - */ - @Test - public void testUpdatedBeanSetIsModifiable() { - Bean bean = new Bean(new ArrayList()); - IObservableSet observable = BeansObservables.observeSet(bean, "set"); - - observable.add(new Object()); - bean.getSet().clear(); - } - - /** - * Makes sure that the set set on the Pojo model after changing the - * observable set is modifiable (see bugs 285307 and 301774). - */ - @Test - public void testUpdatedPojoSetIsModifiable() { - Bean bean = new Bean(new ArrayList()); - IObservableSet observable = PojoObservables.observeSet(bean, "set"); - - observable.add(new Object()); - bean.getSet().clear(); - } - - private static void assertDiff(SetDiff diff, Set oldSet, Set newSet) { - oldSet = new HashSet(oldSet); // defensive copy in case arg is - // unmodifiable - diff.applyTo(oldSet); - assertEquals("applying diff to list did not produce expected result", - newSet, oldSet); - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(MutableObservableSetContractTest.class, new Delegate()); - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - @Override - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - Bean bean = new Bean(); - String propertyName = "set"; - - IObservableSet set = BeansObservables.observeSet(realm, bean, - propertyName, String.class); - for (int i = 0; i < elementCount; i++) - set.add(createElement(set)); - return set; - } - - @Override - public Object createElement(IObservableCollection collection) { - return new Object(); - } - - @Override - public Object getElementType(IObservableCollection collection) { - return String.class; - } - - @Override - public void change(IObservable observable) { - IObservableSet set = (IObservableSet) observable; - set.add(createElement(set)); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java deleted file mode 100644 index 8a5e1fb642d..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2018 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 171616 - * Katarzyna Marszalek - test case for bug 198519 - * Matthew Hall - bug 213145, 246103, 194734, 268688 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.beans.PropertyDescriptor; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.IBeanObservable; -import org.eclipse.core.databinding.beans.IBeanProperty; -import org.eclipse.core.databinding.beans.PojoObservables; -import org.eclipse.core.databinding.beans.typed.BeanProperties; -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.value.ComputedValue; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.examples.databinding.model.SimplePerson; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 3.2 - */ -public class JavaBeanObservableValueTest extends AbstractDefaultRealmTestCase { - private Bean bean; - private IObservableValue observableValue; - private IBeanObservable beanObservable; - private PropertyDescriptor propertyDescriptor; - private String propertyName; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - bean = new Bean(); - propertyName = "value"; - propertyDescriptor = ((IBeanProperty) BeanProperties.value(Bean.class, - propertyName)).getPropertyDescriptor(); - observableValue = BeansObservables.observeValue(bean, propertyName); - beanObservable = (IBeanObservable) observableValue; - } - - @Test - public void testGetObserved() throws Exception { - assertEquals(bean, beanObservable.getObserved()); - } - - @Test - public void testGetPropertyDescriptor() throws Exception { - assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); - } - - @Test - public void testSetValueThrowsExceptionThrownByBean() throws Exception { - ThrowsSetException temp = new ThrowsSetException(); - IObservableValue observable = BeansObservables.observeValue(temp, - "value"); - - try { - observable.setValue(""); - fail("exception should have been thrown"); - } catch (RuntimeException e) { - assertEquals(temp.thrownException, e.getCause()); - } - } - - @Test - public void testGetValueThrowsExceptionThrownByBean() throws Exception { - ThrowsGetException temp = new ThrowsGetException(); - IObservableValue observable = BeansObservables.observeValue(temp, - "value"); - - try { - observable.getValue(); - fail("exception should have been thrown"); - } catch (RuntimeException e) { - assertEquals(temp.thrownException, e.getCause()); - } - } - - @Test - public void testBug198519() { - final SimplePerson person = new SimplePerson(); - final ComputedValue cv = new ComputedValue() { - final IObservableValue name = BeansObservables.observeValue(person, - "name"); //$NON-NLS-1$ - - @Override - protected Object calculate() { - return Boolean.valueOf(name.getValue() != null); - } - }; - cv.addChangeListener(event -> cv.getValue()); - person.setName("foo"); - } - - @Test - public void testConstructor_RegistersListeners() throws Exception { - IObservableValue observable = BeansObservables.observeValue(bean, - propertyName); - ChangeEventTracker.observe(observable); - - assertTrue(bean.hasListeners(propertyName)); - } - - @Test - public void testConstructor_SkipRegisterListeners() throws Exception { - IObservableValue observable = PojoObservables.observeValue(bean, - propertyName); - ChangeEventTracker.observe(observable); - - assertFalse(bean.hasListeners(propertyName)); - } - - @Test - public void testSetBeanProperty_CorrectForNullOldAndNewValues() { - // The java bean spec allows the old and new values in a - // PropertyChangeEvent to - // be null, which indicates that an unknown change occured. - - // This test ensures that JavaBeanObservableValue fires the correct - // value diff - // even if the bean implementor is lazy :-P - - Bean bean = new AnnoyingBean(); - bean.setValue("old"); - IObservableValue observable = BeansObservables.observeValue(bean, - "value"); - ValueChangeEventTracker tracker = ValueChangeEventTracker - .observe(observable); - bean.setValue("new"); - assertEquals(1, tracker.count); - assertEquals("old", tracker.event.diff.getOldValue()); - assertEquals("new", tracker.event.diff.getNewValue()); - } - - @Test - public void testSetBeanPropertyOutsideRealm_FiresEventInsideRealm() { - Bean bean = new Bean("old"); - CurrentRealm realm = new CurrentRealm(true); - IObservableValue observable = BeansObservables.observeValue(realm, - bean, "value"); - ValueChangeEventTracker tracker = ValueChangeEventTracker - .observe(observable); - - realm.setCurrent(false); - bean.setValue("new"); - assertEquals(0, tracker.count); - - realm.setCurrent(true); - assertEquals(1, tracker.count); - assertEquals(Diffs.createValueDiff("old", "new"), tracker.event.diff); - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(MutableObservableValueContractTest.class, new Delegate()); - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private Bean bean; - - @Override - public void setUp() { - super.setUp(); - - bean = new Bean(""); - } - - @Override - public IObservableValue createObservableValue(Realm realm) { - return BeansObservables.observeValue(realm, bean, "value"); - } - - @Override - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - @Override - public Object getValueType(IObservableValue observable) { - return String.class; - } - - @Override - public Object createValue(IObservableValue observable) { - return observable.getValue() + "a"; - } - } - - /** - * Throws an exception when the value is set. - * - * @since 3.2 - */ - static /* package */class ThrowsSetException { - private String value; - - /* package */NullPointerException thrownException; - - public void setValue(String value) { - throw thrownException = new NullPointerException(); - } - - public String getValue() { - return value; - } - } - - /* package */static class ThrowsGetException { - public String value; - - /* package */NullPointerException thrownException; - - public String getValue() { - throw thrownException = new NullPointerException(); - } - - public void setValue(String value) { - this.value = value; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java deleted file mode 100644 index 8a61708565c..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanPropertyObservableMapTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2010 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 246103) - * Ovidio Mallo - bug 301774 - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.beans; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.Collections; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.beans.PojoObservables; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.jface.databinding.conformance.util.CurrentRealm; -import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.junit.Test; - -/** - * @since 3.2 - * - */ -public class JavaBeanPropertyObservableMapTest extends - AbstractDefaultRealmTestCase { - @Test - public void testSetBeanProperty_CorrectForNullOldAndNewValues() { - // The java bean spec allows the old and new values in a - // PropertyChangeEvent to be null, which indicates that an unknown - // change occured. - - // This test ensures that JavaBeanObservableValue fires the correct - // value diff even if the bean implementor is lazy :-P - - Bean bean = new AnnoyingBean(); - bean.setMap(Collections.singletonMap("key", "old")); - - IObservableMap map = BeansObservables.observeMap( - new CurrentRealm(true), bean, "map"); - MapChangeEventTracker tracker = MapChangeEventTracker.observe(map); - - bean.setMap(Collections.singletonMap("key", "new")); - - assertEquals(1, tracker.count); - - assertEquals(Collections.EMPTY_SET, tracker.event.diff.getAddedKeys()); - assertEquals(Collections.singleton("key"), tracker.event.diff - .getChangedKeys()); - assertEquals(Collections.EMPTY_SET, tracker.event.diff.getRemovedKeys()); - - assertEquals("old", tracker.event.diff.getOldValue("key")); - assertEquals("new", tracker.event.diff.getNewValue("key")); - } - - /** - * Makes sure that the map set on the Bean model after changing the - * observable map is modifiable (see bugs 285307 and 301774). - */ - @Test - public void testUpdatedBeanMapIsModifiable() { - Bean bean = new Bean(new ArrayList()); - IObservableMap observable = BeansObservables.observeMap(bean, "map"); - - observable.put(new Object(), new Object()); - bean.getMap().clear(); - } - - /** - * Makes sure that the map set on the Pojo model after changing the - * observable map is modifiable (see bugs 285307 and 301774). - */ - @Test - public void testUpdatedPojoMapIsModifiable() { - Bean bean = new Bean(new ArrayList()); - IObservableMap observable = PojoObservables.observeMap(bean, "map"); - - observable.put(new Object(), new Object()); - bean.getMap().clear(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/ListDetailValueObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/ListDetailValueObservableListTest.java deleted file mode 100644 index 95f91315e25..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/ListDetailValueObservableListTest.java +++ /dev/null @@ -1,410 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2022 Ovidio Mallo and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Ovidio Mallo - initial API and implementation (bug 305367) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable.masterdetail; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.IObservableCollection; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.core.databinding.observable.list.ListDiffEntry; -import org.eclipse.core.databinding.observable.list.WritableList; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.ListDetailValueObservableList; -import org.eclipse.jface.databinding.conformance.ObservableListContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.examples.databinding.model.SimplePerson; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.junit.Test; - -/** - * @since 1.3 - */ -public class ListDetailValueObservableListTest extends - AbstractDefaultRealmTestCase { - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(ObservableListContractTest.class, new Delegate()); - } - - @Test - public void testUnmodifiability() { - WritableList masterObservableList = new WritableList(); - masterObservableList.add(new SimplePerson()); - masterObservableList.add(new SimplePerson()); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterObservableList, BeansObservables.valueFactory("name"), - null); - - try { - ldol.add("name"); - fail("ListDetailValueObservableList must not be modifiable."); - } catch (UnsupportedOperationException e) { - // expected exception - } - - try { - ldol.remove(masterObservableList.get(0)); - fail("ListDetailValueObservableList must not be modifiable."); - } catch (UnsupportedOperationException e) { - // expected exception - } - - try { - ldol.removeAll(Collections.singleton(masterObservableList.get(0))); - fail("ListDetailValueObservableList must not be modifiable."); - } catch (UnsupportedOperationException e) { - // expected exception - } - - try { - ldol.retainAll(Collections.EMPTY_LIST); - fail("ListDetailValueObservableList must not be modifiable."); - } catch (UnsupportedOperationException e) { - // expected exception - } - - try { - ldol.move(0, 1); - fail("ListDetailValueObservableList must not be modifiable."); - } catch (UnsupportedOperationException e) { - // expected exception - } - } - - @Test - public void testGetElementType() { - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - new WritableList(), BeansObservables.valueFactory("name"), - String.class); - - assertSame(String.class, ldol.getElementType()); - } - - @Test - public void testGetObserved() { - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - // The observed object is the master list. - assertSame(masterList, ldol.getObserved()); - } - - @Test - public void testMasterListInitiallyNotEmpty() { - WritableList masterList = new WritableList(); - SimplePerson person = new SimplePerson(); - person.setName("name"); - masterList.add(person); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - // Make sure that a non-empty master list is initialized correctly. - assertEquals(masterList.size(), ldol.size()); - assertEquals(person.getName(), ldol.get(0)); - } - - @Test - public void testAddRemove() { - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - // Initially, the detail list is empty. - assertTrue(ldol.isEmpty()); - - // Add a first person and check that its name is in the detail list. - SimplePerson p1 = new SimplePerson(); - p1.setName("name1"); - masterList.add(p1); - assertEquals(masterList.size(), ldol.size()); - assertEquals(p1.getName(), ldol.get(0)); - - // Add a second person and check that it's name is in the detail list. - SimplePerson p2 = new SimplePerson(); - p2.setName("name2"); - masterList.add(p2); - assertEquals(masterList.size(), ldol.size()); - assertEquals(p2.getName(), ldol.get(1)); - - // Remove the first person from the master list and check that we still - // have the name of the second person in the detail list. - masterList.remove(0); - assertEquals(masterList.size(), ldol.size()); - assertEquals(p2.getName(), ldol.get(0)); - - // Remove the second person as well. - masterList.remove(0); - assertTrue(ldol.isEmpty()); - } - - @Test - public void testChangeDetail() { - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - // Change the detail attribute explicitly. - SimplePerson p1 = new SimplePerson(); - p1.setName("name1"); - masterList.add(p1); - assertEquals(p1.getName(), ldol.get(0)); - p1.setName("name2"); - assertEquals(p1.getName(), ldol.get(0)); - - // Change the detail attribute by changing the master. - SimplePerson p2 = new SimplePerson(); - p2.setName("name3"); - masterList.set(0, p2); - assertEquals(p2.getName(), ldol.get(0)); - } - - @Test - public void testSet() { - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - // Change the detail attribute explicitly. - SimplePerson person = new SimplePerson(); - person.setName("name1"); - masterList.add(person); - assertEquals(person.getName(), ldol.get(0)); - - // Set a new name on the detail list. - ldol.set(0, "name2"); - // Check that the name has been propagated to the master. - assertEquals("name2", person.getName()); - assertEquals(person.getName(), ldol.get(0)); - } - - @Test - public void testDuplicateMasterElements() { - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - SimplePerson master = new SimplePerson(); - master.setName("name1"); - - // Add the same master twice. - masterList.add(master); - masterList.add(master); - - // Attach the change listener to the detail list. - ListChangeEventTracker changeTracker = ListChangeEventTracker - .observe(ldol); - - // Setting the name on master should trigger an event on both - // occurrences of in the master list. - master.setName("name2"); - - // We should have 2 replace diffs, i.e. 4 diff entries. - assertEquals(1, changeTracker.count); - assertEquals(4, changeTracker.event.diff.getDifferences().length); - assertReplaceDiffAt(changeTracker.event.diff, 0, 0, "name1", "name2"); - assertReplaceDiffAt(changeTracker.event.diff, 2, 0, "name1", "name2"); - - // Remove one instance of the master (one will remain). - masterList.remove(master); - - // It should still be possible to work on the remaining master instance. - ldol.set(0, "name3"); - assertEquals("name3", master.getName()); - } - - @Test - public void testDetailObservableChangeEvent() { - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - ListChangeEventTracker changeTracker = ListChangeEventTracker - .observe(ldol); - - SimplePerson person = new SimplePerson(); - person.setName("old name"); - - // Initially, we should not have received any event. - assertEquals(0, changeTracker.count); - - // Add the person and check that we receive an addition event on the - // correct index and with the correct value. - masterList.add(person); - assertEquals(1, changeTracker.count); - assertEquals(1, changeTracker.event.diff.getDifferences().length); - assertTrue(changeTracker.event.diff.getDifferences()[0].isAddition()); - assertEquals(0, - changeTracker.event.diff.getDifferences()[0].getPosition()); - assertEquals(person.getName(), - changeTracker.event.diff.getDifferences()[0].getElement()); - - // Change the detail property and check that we receive a replace event. - person.setName("new name"); - assertEquals(2, changeTracker.count); - assertIsSingleReplaceDiff(changeTracker.event.diff, 0, "old name", - "new name"); - } - - private void assertIsSingleReplaceDiff(ListDiff diff, int index, - Object oldElement, Object newElement) { - // We should have 2 diff entries. - assertEquals(2, diff.getDifferences().length); - - // Check that it indeed is a replace diff. - assertReplaceDiffAt(diff, 0, index, oldElement, newElement); - } - - private void assertReplaceDiffAt(ListDiff diff, int diffOffset, int index, - Object oldElement, Object newElement) { - ListDiffEntry entry1 = diff.getDifferences()[0]; - ListDiffEntry entry2 = diff.getDifferences()[1]; - - // One diff entry must be an addition, the other a removal. - assertNotEquals(entry1.isAddition(), entry2.isAddition()); - - // Check for the index on the diff entries. - assertEquals(index, entry1.getPosition()); - assertEquals(index, entry2.getPosition()); - - // Check for the old/new element values on both diff entries. - if (entry1.isAddition()) { - assertEquals(oldElement, entry2.getElement()); - assertEquals(newElement, entry1.getElement()); - } else { - assertEquals(oldElement, entry1.getElement()); - assertEquals(newElement, entry2.getElement()); - } - } - - @Test - public void testMasterNull() { - WritableList masterObservableList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterObservableList, BeansObservables.valueFactory("name"), - String.class); - - // Make sure null values are handled gracefully. - masterObservableList.add(null); - assertEquals(1, ldol.size()); - assertNull(ldol.get(0)); - } - - @Test - public void testDetailObservableValuesAreDisposed() { - final List detailObservables = new ArrayList(); - IObservableFactory detailValueFactory = target -> { - WritableValue detailObservable = new WritableValue(); - // Remember the created observables. - detailObservables.add(detailObservable); - return detailObservable; - }; - - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, detailValueFactory, null); - - masterList.add(new Object()); - masterList.add(new Object()); - - assertEquals(ldol.size(), detailObservables.size()); - - // No detail observables should be disposed yet. - assertFalse(((WritableValue) detailObservables.get(0)).isDisposed()); - assertFalse(((WritableValue) detailObservables.get(1)).isDisposed()); - - // Only the detail observable for the removed master should be disposed. - masterList.remove(1); - assertFalse(((WritableValue) detailObservables.get(0)).isDisposed()); - assertTrue(((WritableValue) detailObservables.get(1)).isDisposed()); - - // After disposing the detail list, all detail observables should be - // disposed. - ldol.dispose(); - assertTrue(((WritableValue) detailObservables.get(0)).isDisposed()); - assertTrue(((WritableValue) detailObservables.get(1)).isDisposed()); - } - - @Test - public void testDisposeOnMasterDisposed() { - WritableList masterList = new WritableList(); - ListDetailValueObservableList ldol = new ListDetailValueObservableList( - masterList, BeansObservables.valueFactory("name"), String.class); - - // Initially, nothing should be disposed. - assertFalse(masterList.isDisposed()); - assertFalse(ldol.isDisposed()); - - // Upon disposing the master list, the detail list should be disposed as - // well. - masterList.dispose(); - assertTrue(masterList.isDisposed()); - assertTrue(ldol.isDisposed()); - } - - private static class Delegate extends - AbstractObservableCollectionContractDelegate { - @Override - public IObservableCollection createObservableCollection(Realm realm, - int elementCount) { - WritableList masterList = new WritableList(realm); - for (int i = 0; i < elementCount; i++) { - masterList.add(new SimplePerson()); - } - - return new TestListDetailValueObservableList(masterList, - BeansObservables.valueFactory(realm, "name"), String.class); - } - - @Override - public void change(IObservable observable) { - TestListDetailValueObservableList ldol = (TestListDetailValueObservableList) observable; - ldol.masterList.add(new SimplePerson()); - } - - @Override - public Object getElementType(IObservableCollection collection) { - return String.class; - } - } - - private static class TestListDetailValueObservableList extends - ListDetailValueObservableList { - final IObservableList masterList; - - public TestListDetailValueObservableList(IObservableList masterList, - IObservableFactory detailValueFactory, Object detailType) { - super(masterList, detailValueFactory, detailType); - this.masterList = masterList; - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/MapDetailValueObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/MapDetailValueObservableMapTest.java deleted file mode 100644 index 69cf41b5799..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/MapDetailValueObservableMapTest.java +++ /dev/null @@ -1,319 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2018 Ovidio Mallo and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Ovidio Mallo - initial API and implementation (bug 305367) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable.masterdetail; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.map.WritableMap; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.MapDetailValueObservableMap; -import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker; -import org.eclipse.jface.examples.databinding.model.SimplePerson; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.junit.Test; - -/** - * @since 1.3 - */ -public class MapDetailValueObservableMapTest extends - AbstractDefaultRealmTestCase { - - @Test - public void testGetKeyType() { - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - new WritableMap(SimplePerson.class, SimplePerson.class), - BeansObservables.valueFactory("name"), String.class); - - assertSame(SimplePerson.class, mdom.getKeyType()); - } - - @Test - public void testGetValueType() { - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - new WritableMap(), BeansObservables.valueFactory("name"), - String.class); - - assertSame(String.class, mdom.getValueType()); - } - - @Test - public void testGetObserved() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // The observed object is the master key set. - assertSame(masterMap, mdom.getObserved()); - } - - @Test - public void testMasterSetInitiallyNotEmpty() { - WritableMap masterMap = new WritableMap(); - SimplePerson person = new SimplePerson(); - person.setName("name"); - masterMap.put(person, person); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Make sure that a non-empty master key set is initialized correctly. - assertEquals(masterMap.size(), mdom.size()); - assertEquals(person.getName(), mdom.get(person)); - } - - @Test - public void testAddRemove() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Initially, the detail map is empty. - assertTrue(mdom.isEmpty()); - - // Add a first person and check that its name is in the detail map. - SimplePerson p1 = new SimplePerson(); - p1.setName("name1"); - masterMap.put(p1, p1); - assertEquals(masterMap.size(), mdom.size()); - assertEquals(p1.getName(), mdom.get(p1)); - - // Add a second person and check that it's name is in the detail map. - SimplePerson p2 = new SimplePerson(); - p2.setName("name2"); - masterMap.put(p2, p2); - assertEquals(masterMap.size(), mdom.size()); - assertEquals(p2.getName(), mdom.get(p2)); - - // Remove the first person from the master map and check that we still - // have the name of the second person in the detail map. - masterMap.remove(p1); - assertEquals(masterMap.size(), mdom.size()); - assertEquals(p2.getName(), mdom.get(p2)); - - // Remove the second person as well. - masterMap.remove(p2); - assertTrue(mdom.isEmpty()); - } - - @Test - public void testChangeDetail() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Change the detail attribute explicitly. - SimplePerson p1 = new SimplePerson(); - p1.setName("name1"); - masterMap.put(p1, p1); - assertEquals(p1.getName(), mdom.get(p1)); - p1.setName("name2"); - assertEquals(p1.getName(), mdom.get(p1)); - - // Change the detail attribute by changing the master. - SimplePerson p2 = new SimplePerson(); - p2.setName("name3"); - masterMap.put(p1, p2); - assertEquals(p2.getName(), mdom.get(p1)); - } - - @Test - public void testPut() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Change the detail attribute explicitly. - SimplePerson person = new SimplePerson(); - person.setName("name1"); - masterMap.put(person, person); - assertEquals(person.getName(), mdom.get(person)); - - // Set a new name on the detail map. - mdom.put(person, "name2"); - // Check that the name has been propagated to the master. - assertEquals("name2", person.getName()); - assertEquals(person.getName(), mdom.get(person)); - } - - @Test - public void testContainsValue() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Add a person with a given name. - SimplePerson person = new SimplePerson(); - person.setName("name"); - masterMap.put(person, person); - - // Make sure the name of the person is contained. - assertTrue(mdom.containsValue(person.getName())); - - // Remove the person and make sure that it's name cannot be found - // anymore. - masterMap.remove(person); - assertFalse(mdom.containsValue(person.getName())); - } - - @Test - public void testRemove() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Add two person objects to the map. - SimplePerson p1 = new SimplePerson(); - SimplePerson p2 = new SimplePerson(); - masterMap.put(p1, p1); - masterMap.put(p2, p2); - - // Initially, both person objects should be contained in the detail map. - assertTrue(mdom.containsKey(p1)); - assertTrue(mdom.containsKey(p2)); - - // Remove one person and check that it is not contained anymore. - mdom.remove(p1); - assertFalse(mdom.containsKey(p1)); - assertTrue(mdom.containsKey(p2)); - - // Trying to remove a non-existent is allowed but has no effect. - mdom.remove(p1); - assertFalse(mdom.containsKey(p1)); - assertTrue(mdom.containsKey(p2)); - } - - @Test - public void testDetailObservableChangeEvent() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - MapChangeEventTracker changeTracker = MapChangeEventTracker - .observe(mdom); - - SimplePerson person = new SimplePerson(); - person.setName("old name"); - - // Initially, we should not have received any event. - assertEquals(0, changeTracker.count); - - // Add the person and check that we receive an addition event on the - // correct index and with the correct value. - masterMap.put(person, person); - assertEquals(1, changeTracker.count); - assertEquals(1, changeTracker.event.diff.getAddedKeys().size()); - assertEquals(0, changeTracker.event.diff.getRemovedKeys().size()); - assertEquals(0, changeTracker.event.diff.getChangedKeys().size()); - assertSame(person, changeTracker.event.diff.getAddedKeys().iterator() - .next()); - assertNull(changeTracker.event.diff.getOldValue(person)); - assertEquals("old name", changeTracker.event.diff.getNewValue(person)); - - // Change the detail property and check that we receive a replace - person.setName("new name"); - assertEquals(2, changeTracker.count); - assertEquals(0, changeTracker.event.diff.getAddedKeys().size()); - assertEquals(0, changeTracker.event.diff.getRemovedKeys().size()); - assertEquals(1, changeTracker.event.diff.getChangedKeys().size()); - assertSame(person, changeTracker.event.diff.getChangedKeys().iterator() - .next()); - assertEquals("old name", changeTracker.event.diff.getOldValue(person)); - assertEquals("new name", changeTracker.event.diff.getNewValue(person)); - } - - @Test - public void testMasterNull() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Make sure null values are handled gracefully. - masterMap.put(null, null); - assertEquals(1, mdom.size()); - assertNull(mdom.get(null)); - } - - @Test - public void testDetailObservableValuesAreDisposed() { - final Map detailObservables = new HashMap(); - IObservableFactory detailValueFactory = target -> { - WritableValue detailObservable = new WritableValue(); - // Remember the created observables. - detailObservables.put(target, detailObservable); - return detailObservable; - }; - - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, detailValueFactory, null); - - Object master1 = new Object(); - Object master2 = new Object(); - masterMap.put(master1, master1); - masterMap.put(master2, master2); - - // Attach a listener in order to ensure that all detail observables are - // actually created. - MapChangeEventTracker.observe(mdom); - - assertEquals(mdom.size(), detailObservables.size()); - - // No detail observables should be disposed yet. - assertFalse(((WritableValue) detailObservables.get(master1)) - .isDisposed()); - assertFalse(((WritableValue) detailObservables.get(master2)) - .isDisposed()); - - // Only the detail observable for the removed master should be disposed. - masterMap.remove(master2); - assertFalse(((WritableValue) detailObservables.get(master1)) - .isDisposed()); - assertTrue(((WritableValue) detailObservables.get(master2)) - .isDisposed()); - - // After disposing the detail map, all detail observables should be - // disposed. - mdom.dispose(); - assertTrue(((WritableValue) detailObservables.get(master1)) - .isDisposed()); - assertTrue(((WritableValue) detailObservables.get(master2)) - .isDisposed()); - } - - @Test - public void testDisposeOnMasterDisposed() { - WritableMap masterMap = new WritableMap(); - MapDetailValueObservableMap mdom = new MapDetailValueObservableMap( - masterMap, BeansObservables.valueFactory("name"), String.class); - - // Initially, nothing should be disposed. - assertFalse(masterMap.isDisposed()); - assertFalse(mdom.isDisposed()); - - // Upon disposing the master map, the detail map should be disposed as - // well. - masterMap.dispose(); - assertTrue(masterMap.isDisposed()); - assertTrue(mdom.isDisposed()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/SetDetailValueObservableMapTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/SetDetailValueObservableMapTest.java deleted file mode 100644 index 7c8656207aa..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/observable/masterdetail/SetDetailValueObservableMapTest.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2018 Ovidio Mallo and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Ovidio Mallo - initial API and implementation (bug 305367) - ******************************************************************************/ - -package org.eclipse.core.tests.internal.databinding.observable.masterdetail; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; -import org.eclipse.core.databinding.observable.set.WritableSet; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap; -import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker; -import org.eclipse.jface.examples.databinding.model.SimplePerson; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.junit.Test; - -/** - * @since 1.3 - */ -public class SetDetailValueObservableMapTest extends - AbstractDefaultRealmTestCase { - - @Test - public void testGetValueType() { - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - new WritableSet(), BeansObservables.valueFactory("name"), - String.class); - - assertSame(String.class, sdom.getValueType()); - } - - @Test - public void testGetObserved() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // The observed object is the master key set. - assertSame(masterKeySet, sdom.getObserved()); - } - - @Test - public void testMasterSetInitiallyNotEmpty() { - WritableSet masterKeySet = new WritableSet(); - SimplePerson person = new SimplePerson(); - person.setName("name"); - masterKeySet.add(person); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Make sure that a non-empty master key set is initialized correctly. - assertEquals(masterKeySet.size(), sdom.size()); - assertEquals(person.getName(), sdom.get(person)); - } - - @Test - public void testAddRemove() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Initially, the detail map is empty. - assertTrue(sdom.isEmpty()); - - // Add a first person and check that its name is in the detail list. - SimplePerson p1 = new SimplePerson(); - p1.setName("name1"); - masterKeySet.add(p1); - assertEquals(masterKeySet.size(), sdom.size()); - assertEquals(p1.getName(), sdom.get(p1)); - - // Add a second person and check that it's name is in the detail list. - SimplePerson p2 = new SimplePerson(); - p2.setName("name2"); - masterKeySet.add(p2); - assertEquals(masterKeySet.size(), sdom.size()); - assertEquals(p2.getName(), sdom.get(p2)); - - // Remove the first person from the master list and check that we still - // have the name of the second person in the detail list. - masterKeySet.remove(p1); - assertEquals(masterKeySet.size(), sdom.size()); - assertEquals(p2.getName(), sdom.get(p2)); - - // Remove the second person as well. - masterKeySet.remove(p2); - assertTrue(sdom.isEmpty()); - } - - @Test - public void testChangeDetail() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Change the detail attribute explicitly. - SimplePerson p1 = new SimplePerson(); - p1.setName("name1"); - masterKeySet.add(p1); - assertEquals(p1.getName(), sdom.get(p1)); - p1.setName("name2"); - assertEquals(p1.getName(), sdom.get(p1)); - - // Change the detail attribute by changing the master. - SimplePerson p2 = new SimplePerson(); - p2.setName("name3"); - masterKeySet.add(p2); - assertEquals(p2.getName(), sdom.get(p2)); - } - - @Test - public void testPut() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Change the detail attribute explicitly. - SimplePerson person = new SimplePerson(); - person.setName("name1"); - masterKeySet.add(person); - assertEquals(person.getName(), sdom.get(person)); - - // Set a new name on the detail map. - sdom.put(person, "name2"); - // Check that the name has been propagated to the master. - assertEquals("name2", person.getName()); - assertEquals(person.getName(), sdom.get(person)); - } - - @Test - public void testContainsValue() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Add a person with a given name. - SimplePerson person = new SimplePerson(); - person.setName("name"); - masterKeySet.add(person); - - // Make sure the name of the person is contained. - assertTrue(sdom.containsValue(person.getName())); - - // Remove the person and make sure that it's name cannot be found - // anymore. - masterKeySet.remove(person); - assertFalse(sdom.containsValue(person.getName())); - } - - @Test - public void testRemove() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Add two person objects to the map. - SimplePerson p1 = new SimplePerson(); - SimplePerson p2 = new SimplePerson(); - masterKeySet.add(p1); - masterKeySet.add(p2); - - // Initially, both person objects should be contained in the detail map. - assertTrue(sdom.containsKey(p1)); - assertTrue(sdom.containsKey(p2)); - - // Remove one person and check that it is not contained anymore. - sdom.remove(p1); - assertFalse(sdom.containsKey(p1)); - assertTrue(sdom.containsKey(p2)); - - // Trying to remove a non-existent is allowed but has no effect. - sdom.remove(p1); - assertFalse(sdom.containsKey(p1)); - assertTrue(sdom.containsKey(p2)); - } - - @Test - public void testDetailObservableChangeEvent() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - MapChangeEventTracker changeTracker = MapChangeEventTracker - .observe(sdom); - - SimplePerson person = new SimplePerson(); - person.setName("old name"); - - // Initially, we should not have received any event. - assertEquals(0, changeTracker.count); - - // Add the person and check that we receive an addition event on the - // correct index and with the correct value. - masterKeySet.add(person); - assertEquals(1, changeTracker.count); - assertEquals(1, changeTracker.event.diff.getAddedKeys().size()); - assertEquals(0, changeTracker.event.diff.getRemovedKeys().size()); - assertEquals(0, changeTracker.event.diff.getChangedKeys().size()); - assertSame(person, changeTracker.event.diff.getAddedKeys().iterator() - .next()); - assertNull(changeTracker.event.diff.getOldValue(person)); - assertEquals("old name", changeTracker.event.diff.getNewValue(person)); - - // Change the detail property and check that we receive a replace - person.setName("new name"); - assertEquals(2, changeTracker.count); - assertEquals(0, changeTracker.event.diff.getAddedKeys().size()); - assertEquals(0, changeTracker.event.diff.getRemovedKeys().size()); - assertEquals(1, changeTracker.event.diff.getChangedKeys().size()); - assertSame(person, changeTracker.event.diff.getChangedKeys().iterator() - .next()); - assertEquals("old name", changeTracker.event.diff.getOldValue(person)); - assertEquals("new name", changeTracker.event.diff.getNewValue(person)); - } - - @Test - public void testMasterNull() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Make sure null values are handled gracefully. - masterKeySet.add(null); - assertEquals(1, sdom.size()); - assertNull(sdom.get(null)); - } - - @Test - public void testDetailObservableValuesAreDisposed() { - final Map detailObservables = new HashMap(); - IObservableFactory detailValueFactory = target -> { - WritableValue detailObservable = new WritableValue(); - // Remember the created observables. - detailObservables.put(target, detailObservable); - return detailObservable; - }; - - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, detailValueFactory, null); - - Object master1 = new Object(); - Object master2 = new Object(); - masterKeySet.add(master1); - masterKeySet.add(master2); - - // Attach a listener in order to ensure that all detail observables are - // actually created. - MapChangeEventTracker.observe(sdom); - - assertEquals(sdom.size(), detailObservables.size()); - - // No detail observables should be disposed yet. - assertFalse(((WritableValue) detailObservables.get(master1)) - .isDisposed()); - assertFalse(((WritableValue) detailObservables.get(master2)) - .isDisposed()); - - // Only the detail observable for the removed master should be disposed. - masterKeySet.remove(master2); - assertFalse(((WritableValue) detailObservables.get(master1)) - .isDisposed()); - assertTrue(((WritableValue) detailObservables.get(master2)) - .isDisposed()); - - // After disposing the detail map, all detail observables should be - // disposed. - sdom.dispose(); - assertTrue(((WritableValue) detailObservables.get(master1)) - .isDisposed()); - assertTrue(((WritableValue) detailObservables.get(master2)) - .isDisposed()); - } - - @Test - public void testDisposeOnMasterDisposed() { - WritableSet masterKeySet = new WritableSet(); - SetDetailValueObservableMap sdom = new SetDetailValueObservableMap( - masterKeySet, BeansObservables.valueFactory("name"), - String.class); - - // Initially, nothing should be disposed. - assertFalse(masterKeySet.isDisposed()); - assertFalse(sdom.isDisposed()); - - // Upon disposing the master list, the detail list should be disposed as - // well. - masterKeySet.dispose(); - assertTrue(masterKeySet.isDisposed()); - assertTrue(sdom.isDisposed()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java index 9d31b5b3831..2663aca4fba 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java @@ -41,7 +41,6 @@ import org.eclipse.core.tests.databinding.beans.AnonymousPojoValuePropertyTest; import org.eclipse.core.tests.databinding.beans.BeanPropertiesTest; import org.eclipse.core.tests.databinding.beans.BeansObservablesTest; -import org.eclipse.core.tests.databinding.beans.PojoObservablesTest; import org.eclipse.core.tests.databinding.beans.PojoPropertiesTest; import org.eclipse.core.tests.databinding.beans.SetOnlyJavaBeanTest; import org.eclipse.core.tests.databinding.conversion.NumberToStringConverterTest; @@ -86,20 +85,10 @@ import org.eclipse.core.tests.internal.databinding.IdentityMapTest; import org.eclipse.core.tests.internal.databinding.IdentitySetTest; import org.eclipse.core.tests.internal.databinding.QueueTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableListDecoratorTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableSetDecoratorTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableValueDecoratorTest; import org.eclipse.core.tests.internal.databinding.beans.BeanPropertyHelperTest; import org.eclipse.core.tests.internal.databinding.beans.BeanPropertyListenerSupportTest; import org.eclipse.core.tests.internal.databinding.beans.BeanPropertyListenerTest; import org.eclipse.core.tests.internal.databinding.beans.BeanValuePropertyTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedListTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedSetTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableListTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableMapTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableSetTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableValueTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanPropertyObservableMapTest; import org.eclipse.core.tests.internal.databinding.conversion.DateConversionSupportTest; import org.eclipse.core.tests.internal.databinding.conversion.IdentityConverterTest; import org.eclipse.core.tests.internal.databinding.conversion.IntegerToStringConverterTest; @@ -135,9 +124,6 @@ import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableMapTest; import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableSetTest; import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableValueTest; -import org.eclipse.core.tests.internal.databinding.observable.masterdetail.ListDetailValueObservableListTest; -import org.eclipse.core.tests.internal.databinding.observable.masterdetail.MapDetailValueObservableMapTest; -import org.eclipse.core.tests.internal.databinding.observable.masterdetail.SetDetailValueObservableMapTest; import org.eclipse.core.tests.internal.databinding.property.value.ListSimpleValueObservableListTest; import org.eclipse.core.tests.internal.databinding.property.value.MapSimpleValueObservableMapTest; import org.eclipse.core.tests.internal.databinding.property.value.SetSimpleValueObservableMapTest; @@ -158,7 +144,6 @@ import org.eclipse.core.tests.internal.databinding.validation.StringToShortValidatorTest; import org.eclipse.jface.tests.databinding.preference.PreferencePageSupportTest; import org.eclipse.jface.tests.databinding.scenarios.BindingScenariosTestSuite; -import org.eclipse.jface.tests.databinding.swt.SWTObservablesTest; import org.eclipse.jface.tests.databinding.swt.WidgetObservableThreadTest; import org.eclipse.jface.tests.databinding.swt.WidgetPropertiesTest; import org.eclipse.jface.tests.databinding.viewers.ObservableListContentProviderTest; @@ -174,14 +159,10 @@ import org.eclipse.jface.tests.examples.databinding.mask.internal.EditMaskParserTest; import org.eclipse.jface.tests.internal.databinding.swt.ButtonObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueTextTest; -import org.eclipse.jface.tests.internal.databinding.swt.CComboSingleSelectionObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.CLabelObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueTextTest; -import org.eclipse.jface.tests.internal.databinding.swt.ComboSingleSelectionObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.ControlObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.DateTimeCalendarObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.DateTimeDateObservableValueTest; @@ -189,20 +170,14 @@ import org.eclipse.jface.tests.internal.databinding.swt.DateTimeTimeObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.GroupObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.LabelObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.ListSingleSelectionObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.LocalDateSelectionPropertyTest; -import org.eclipse.jface.tests.internal.databinding.swt.SWTDelayedObservableValueDecoratorTest; import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueMaxTest; import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueMinTest; import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.ShellObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueMaxTest; import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueMinTest; import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.StyledTextObservableValueFocusOutTest; -import org.eclipse.jface.tests.internal.databinding.swt.StyledTextObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.TableObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.TableSingleSelectionObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.TextEditableObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.TextObservableValueFocusOutTest; @@ -210,12 +185,9 @@ import org.eclipse.jface.tests.internal.databinding.viewers.CheckableCheckedElementsObservableSetTest; import org.eclipse.jface.tests.internal.databinding.viewers.ObservableCollectionContentProviderTest; import org.eclipse.jface.tests.internal.databinding.viewers.ObservableCollectionTreeContentProviderTest; -import org.eclipse.jface.tests.internal.databinding.viewers.SelectionProviderMultiSelectionObservableListTest; -import org.eclipse.jface.tests.internal.databinding.viewers.SelectionProviderSingleSelectionObservableValueTest; import org.eclipse.jface.tests.internal.databinding.viewers.ViewerElementMapTest; import org.eclipse.jface.tests.internal.databinding.viewers.ViewerElementSetTest; import org.eclipse.jface.tests.internal.databinding.viewers.ViewerElementWrapperTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ViewerInputObservableValueTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @@ -224,17 +196,16 @@ @SuiteClasses({ AbstractObservableListTest.class, AbstractObservableMapTest.class, AbstractObservableTest.class, AbstractObservableValueTest.class, AbstractStringToNumberValidatorTest.class, AbstractVetoableValueTest.class, AggregateValidationStatusTest.class, AnonymousBeanValuePropertyTest.class, AnonymousPojoValuePropertyTest.class, - BeanObservableListDecoratorTest.class, BeanObservableListDecoratorTest.class, - BeanObservableSetDecoratorTest.class, BeanObservableValueDecoratorTest.class, BeanPropertiesTest.class, + BeanPropertiesTest.class, BeanPropertyHelperTest.class, BeanPropertyListenerSupportTest.class, BeanPropertyListenerTest.class, BeansObservablesTest.class, BeanValuePropertyTest.class, BidiObservableMapTest.class, BindingMessagesTest.class, BindingScenariosTestSuite.class, BindingStatusTest.class, BindingTest.class, ConformanceTestSuite.class, - ButtonObservableValueTest.class, CComboObservableValueSelectionTest.class, CComboObservableValueTest.class, - CComboObservableValueTextTest.class, CComboSingleSelectionObservableValueTest.class, - CComboSingleSelectionObservableValueTest.class, ChangeSupportTest.class, + ButtonObservableValueTest.class, CComboObservableValueSelectionTest.class, + CComboObservableValueTextTest.class, + ChangeSupportTest.class, CheckableCheckedElementsObservableSetTest.class, CLabelObservableValueTest.class, - ComboObservableValueSelectionTest.class, ComboObservableValueTest.class, ComboObservableValueTextTest.class, - ComboSingleSelectionObservableValueTest.class, CompositeMapTest.class, ComputedListTest.class, + ComboObservableValueSelectionTest.class, ComboObservableValueTextTest.class, + CompositeMapTest.class, ComputedListTest.class, ComputedObservableMapTest.class, ComputedSetTest.class, ComputedValueTest.class, ConstantObservableValueTest.class, ControlObservableValueTest.class, ConverterValuePropertyTest.class, DatabindingContextTest.class, DateAndTimeObservableValueTest.class, DateConversionSupportTest.class, @@ -245,12 +216,9 @@ DetailObservableSetTest.class, DetailObservableValueTest.class, DifferentRealmsBindingTest.class, Diffs_ListDiffTests.class, DiffsTest.class, DuplexingObservableValueTest.class, EditMaskLexerAndTokenTest.class, EditMaskParserTest.class, GroupObservableValueTest.class, IdentityConverterTest.class, IdentityMapTest.class, - IdentitySetTest.class, IntegerToStringConverterTest.class, JavaBeanObservableArrayBasedListTest.class, - JavaBeanObservableArrayBasedSetTest.class, JavaBeanObservableListTest.class, JavaBeanObservableMapTest.class, - JavaBeanObservableSetTest.class, JavaBeanObservableValueTest.class, JavaBeanPropertyObservableMapTest.class, - LabelObservableValueTest.class, ListBindingTest.class, ListDetailValueObservableListTest.class, + IdentitySetTest.class, IntegerToStringConverterTest.class, LabelObservableValueTest.class, + ListBindingTest.class, ListDiffTest.class, ListDiffVisitorTest.class, ListSimpleValueObservableListTest.class, - ListSingleSelectionObservableValueTest.class, MapDetailValueObservableMapTest.class, MapEntryObservableValueTest.class, MapSimpleValueObservableMapTest.class, MultiListTest.class, MultiValidatorTest.class, NumberToBigDecimalTest.class, NumberToBigIntegerConverterTest.class, NumberToByteConverterTest.class, NumberToByteValidatorTest.class, NumberToDoubleConverterTest.class, @@ -263,14 +231,12 @@ ObservableListTest.class, ObservableListTreeContentProviderTest.class, ObservableMapLabelProviderTest.class, ObservableMapTest.class, ObservableSetContentProviderTest.class, ObservableSetTreeContentProviderTest.class, ObservablesManagerTest.class, ObservablesTest.class, ObservableTrackerTest.class, - ObservableValueEditingSupportTest.class, PojoObservablesTest.class, PojoPropertiesTest.class, PolicyTest.class, + ObservableValueEditingSupportTest.class, PojoPropertiesTest.class, PolicyTest.class, PreferencePageSupportTest.class, QueueTest.class, RealmTest.class, ScaleObservableValueMaxTest.class, ScaleObservableValueMinTest.class, ScaleObservableValueSelectionTest.class, - SelectionProviderMultiSelectionObservableListTest.class, - SelectionProviderSingleSelectionObservableValueTest.class, SetDetailValueObservableMapTest.class, - SetOnlyJavaBeanTest.class, SetSimpleValueObservableMapTest.class, ShellObservableValueTest.class, + SetOnlyJavaBeanTest.class, SetSimpleValueObservableMapTest.class, SideEffectTest.class, SpinnerObservableValueMaxTest.class, SpinnerObservableValueMinTest.class, - SpinnerObservableValueSelectionTest.class, SpinnerObservableValueTest.class, StatusToStringConverterTest.class, + SpinnerObservableValueSelectionTest.class, StatusToStringConverterTest.class, StringToBooleanConverterTest.class, StringToByteConverterTest.class, StringToByteValidatorTest.class, StringToCharacterConverterTest.class, StringToCharacterValidatorTest.class, StringToDoubleValidatorTest.class, StringToFloatValidatorTest.class, StringToIntegerValidatorTest.class, StringToLongValidatorTest.class, @@ -278,14 +244,13 @@ StringToNumberParserFloatTest.class, StringToNumberParserIntegerTest.class, StringToNumberParserLongTest.class, StringToNumberParserShortTest.class, StringToNumberParserTest.class, StringToShortConverterTest.class, StringToShortValidatorTest.class, StyledTextObservableValueFocusOutTest.class, - StyledTextObservableValueTest.class, SWTDelayedObservableValueDecoratorTest.class, SWTObservablesTest.class, - TableObservableValueTest.class, TableSingleSelectionObservableValueTest.class, + TableSingleSelectionObservableValueTest.class, TextEditableObservableValueTest.class, TextObservableValueFocusOutTest.class, TextObservableValueTest.class, UnmodifiableObservableListTest.class, UnmodifiableObservableSetTest.class, UnmodifiableObservableValueTest.class, UpdateListStrategyTest.class, UpdateSetStrategyTest.class, UpdateStrategyTest.class, UpdateValueStrategyTest.class, ValidatedObservableValueTest.class, ValidationStatusTest.class, ValueBindingTest.class, ViewerElementMapTest.class, ViewerElementSetTest.class, - ViewerElementWrapperTest.class, ViewerInputObservableValueTest.class, ViewersObservablesTest.class, + ViewerElementWrapperTest.class, ViewersObservablesTest.class, ViewerSupportTest.class, WidgetObservableThreadTest.class, WidgetPropertiesTest.class, WizardPageSupportTest.class, WritableListTest.class, WritableMapTest.class, WritableSetTest.class, WritableValueTest.class }) diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/ConformanceTestSuite.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/ConformanceTestSuite.java index 71b41d636c8..ecf89674d2f 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/ConformanceTestSuite.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/ConformanceTestSuite.java @@ -45,12 +45,6 @@ import org.eclipse.core.tests.databinding.observable.value.DecoratingObservableValueTest; import org.eclipse.core.tests.databinding.observable.value.SelectObservableValueTest; import org.eclipse.core.tests.databinding.observable.value.WritableValueTest; -import org.eclipse.core.tests.internal.databinding.beans.BeanObservableListDecoratorTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedListTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedSetTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableListTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableSetTest; -import org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableValueTest; import org.eclipse.core.tests.internal.databinding.observable.ConstantObservableValueTest; import org.eclipse.core.tests.internal.databinding.observable.DelayedObservableValueTest; import org.eclipse.core.tests.internal.databinding.observable.EmptyObservableListTest; @@ -67,22 +61,18 @@ import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableListTest; import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableSetTest; import org.eclipse.core.tests.internal.databinding.observable.masterdetail.DetailObservableValueTest; -import org.eclipse.core.tests.internal.databinding.observable.masterdetail.ListDetailValueObservableListTest; import org.eclipse.jface.databinding.conformance.util.TestCollection; import org.eclipse.jface.tests.internal.databinding.swt.ButtonObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueSelectionTest; import org.eclipse.jface.tests.internal.databinding.swt.CComboObservableValueTextTest; -import org.eclipse.jface.tests.internal.databinding.swt.CComboSingleSelectionObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.CLabelObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueSelectionTest; import org.eclipse.jface.tests.internal.databinding.swt.ComboObservableValueTextTest; import org.eclipse.jface.tests.internal.databinding.swt.GroupObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.LabelObservableValueTest; -import org.eclipse.jface.tests.internal.databinding.swt.SWTDelayedObservableValueDecoratorTest; import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueMaxTest; import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueMinTest; import org.eclipse.jface.tests.internal.databinding.swt.ScaleObservableValueSelectionTest; -import org.eclipse.jface.tests.internal.databinding.swt.ShellObservableValueTest; import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueMaxTest; import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueMinTest; import org.eclipse.jface.tests.internal.databinding.swt.SpinnerObservableValueSelectionTest; @@ -95,7 +85,6 @@ import org.eclipse.jface.tests.internal.databinding.swt.TextObservableValueFocusOutTest; import org.eclipse.jface.tests.internal.databinding.swt.TextObservableValueModifyTest; import org.eclipse.jface.tests.internal.databinding.viewers.ObservableViewerElementSetTest; -import org.eclipse.jface.tests.internal.databinding.viewers.ViewerInputObservableValueTest; import org.junit.runner.RunWith; import org.junit.runner.Runner; import org.junit.runners.Parameterized; @@ -119,11 +108,9 @@ public static Iterable data() { AbstractObservableListTest.addConformanceTest(suite); AbstractObservableSetTest.addConformanceTest(suite); AbstractObservableTest.addConformanceTest(suite); - BeanObservableListDecoratorTest.addConformanceTest(suite); ButtonObservableValueTest.addConformanceTest(suite); CComboObservableValueSelectionTest.addConformanceTest(suite); CComboObservableValueTextTest.addConformanceTest(suite); - CComboSingleSelectionObservableValueTest.addConformanceTest(suite); CLabelObservableValueTest.addConformanceTest(suite); ComboObservableValueSelectionTest.addConformanceTest(suite); ComboObservableValueTextTest.addConformanceTest(suite); @@ -141,13 +128,7 @@ public static Iterable data() { EmptyObservableSetTest.addConformanceTest(suite); GroupObservableValueTest.addConformanceTest(suite); IdentityObservableSetTest.addConformanceTest(suite); - JavaBeanObservableArrayBasedListTest.addConformanceTest(suite); - JavaBeanObservableArrayBasedSetTest.addConformanceTest(suite); - JavaBeanObservableListTest.addConformanceTest(suite); - JavaBeanObservableSetTest.addConformanceTest(suite); - JavaBeanObservableValueTest.addConformanceTest(suite); LabelObservableValueTest.addConformanceTest(suite); - ListDetailValueObservableListTest.addConformanceTest(suite); MapEntryObservableValueTest.addConformanceTest(suite); MultiListTest.addConformanceTest(suite); ObservableListTest.addConformanceTest(suite); @@ -157,7 +138,6 @@ public static Iterable data() { ScaleObservableValueMinTest.addConformanceTest(suite); ScaleObservableValueSelectionTest.addConformanceTest(suite); SelectObservableValueTest.addConformanceTest(suite); - ShellObservableValueTest.addConformanceTest(suite); SpinnerObservableValueMaxTest.addConformanceTest(suite); SpinnerObservableValueMinTest.addConformanceTest(suite); SpinnerObservableValueSelectionTest.addConformanceTest(suite); @@ -165,7 +145,6 @@ public static Iterable data() { StyledTextObservableValueDefaultSelectionTest.addConformanceTest(suite); StyledTextObservableValueFocusOutTest.addConformanceTest(suite); StyledTextObservableValueModifyTest.addConformanceTest(suite); - SWTDelayedObservableValueDecoratorTest.addConformanceTest(suite); TableSingleSelectionObservableValueTest.addConformanceTest(suite); TextEditableObservableValueTest.addConformanceTest(suite); TextObservableValueDefaultSelectionTest.addConformanceTest(suite); @@ -178,7 +157,6 @@ public static Iterable data() { ValidatedObservableListTest.addConformanceTest(suite); ValidatedObservableSetTest.addConformanceTest(suite); ValidatedObservableValueTest.addConformanceTest(suite); - ViewerInputObservableValueTest.addConformanceTest(suite); WritableListTest.addConformanceTest(suite); WritableSetTest.addConformanceTest(suite); WritableValueTest.addConformanceTest(suite); diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ButtonControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ButtonControlScenario.java index c06671ccb4d..f2ecedc9be0 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ButtonControlScenario.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ButtonControlScenario.java @@ -17,8 +17,8 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.SampleData; import org.eclipse.swt.SWT; @@ -60,8 +60,9 @@ public void tearDown() throws Exception { @Test public void testScenario01() { // Bind the button's selection to the adventure "isPetsAllowed" - getDbc().bindValue(SWTObservables.observeSelection(button), - BeansObservables.observeValue(adventure, "petsAllowed")); + + getDbc().bindValue(WidgetProperties.buttonSelection().observe(button), + BeanProperties.value("petsAllowed").observe(adventure)); // Check the model and GUI are in the same state assertEquals(button.getSelection(), adventure.isPetsAllowed()); @@ -90,8 +91,8 @@ public void testScenario02() { button.dispose(); button = new Button(getComposite(), SWT.TOGGLE); // Bind the button's selection to the adventure "isPetsAllowed" - getDbc().bindValue(SWTObservables.observeSelection(button), - BeansObservables.observeValue(adventure, "petsAllowed")); + getDbc().bindValue(WidgetProperties.buttonSelection().observe(button), + BeanProperties.value("petsAllowed").observe(adventure)); // Check the model and GUI are in the same state assertEquals(button.getSelection(), adventure.isPetsAllowed()); @@ -115,9 +116,8 @@ public void testScenario03() { button = new Button(getComposite(), SWT.RADIO); // Bind the button's selection to the adventure "isPetsAllowed" - getDbc().bindValue(SWTObservables.observeSelection(button), - BeansObservables.observeValue(adventure, "petsAllowed")); - + getDbc().bindValue(WidgetProperties.buttonSelection().observe(button), + BeanProperties.value("petsAllowed").observe(adventure)); // Check the model and GUI are in the same state assertEquals(button.getSelection(), adventure.isPetsAllowed()); // Change the model and check the GUI is updated diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomConverterScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomConverterScenarios.java index 30a8ab6c762..3ea7d497ff9 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomConverterScenarios.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomConverterScenarios.java @@ -18,8 +18,8 @@ import static org.junit.Assert.assertEquals; import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.PriceModelObject; import org.eclipse.jface.examples.databinding.model.SampleData; @@ -68,15 +68,15 @@ public void testScenario01() { // an intermediate object is used PriceModelObject priceModel = new PriceModelObject(); - dbc.bindValue(BeansObservables.observeValue(priceModel, "price"), BeansObservables.observeValue(skiTrip, - "price")); - dbc.bindValue(SWTObservables.observeSelection(spinner_dollars), - BeansObservables.observeValue(priceModel, "dollars")); + dbc.bindValue(BeanProperties.value("price").observe(priceModel), + BeanProperties.value("price").observe(skiTrip)); - dbc.bindValue(SWTObservables.observeSelection(spinner_cents), - BeansObservables.observeValue(priceModel, "cents")); + dbc.bindValue(WidgetProperties.spinnerSelection().observe(spinner_dollars), + BeanProperties.value("dollars").observe(priceModel)); + dbc.bindValue(WidgetProperties.spinnerSelection().observe(spinner_cents), + BeanProperties.value("cents").observe(priceModel)); // spinEventLoop(1); // Make sure that the selection on the spinner_dollars matches the // dollars of the price diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomScenarios.java index cb70cf73512..e38510397af 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomScenarios.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/CustomScenarios.java @@ -17,9 +17,9 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.AggregateObservableValue; import org.eclipse.jface.examples.databinding.model.SampleData; @@ -61,12 +61,12 @@ public void testScenario01() { Adventure adventure = SampleData.WINTER_HOLIDAY; Text text = new Text(getComposite(), SWT.BORDER); - IObservableValue descriptionObservable = BeansObservables.observeValue(adventure, "description"); - IObservableValue nameObservable = BeansObservables.observeValue(adventure, "name"); + IObservableValue descriptionObservable = BeanProperties.value("description").observe(adventure); + + IObservableValue nameObservable = BeanProperties.value("name").observe(adventure); AggregateObservableValue customObservable_comma = new AggregateObservableValue(new IObservableValue[] { descriptionObservable, nameObservable }, ","); - - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), customObservable_comma); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), customObservable_comma); // spinEventLoop(1); // Make sure that the description on the model match the widget assertEquals(adventure.getDescription() + "," + adventure.getName(), text.getText()); diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/LabelControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/LabelControlScenario.java index b04c5fd4bdb..db68e3e0a08 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/LabelControlScenario.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/LabelControlScenario.java @@ -17,8 +17,8 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.SampleData; import org.eclipse.swt.SWT; @@ -63,7 +63,10 @@ public void testScenario01() { // Bind the adventure "name" property to a label control // Change the UI and verify the model and UI are the same value // Change the model and verify the UI changes - getDbc().bindValue(SWTObservables.observeText(label), BeansObservables.observeValue(adventure, "name")); + + getDbc().bindValue(WidgetProperties.text().observe(label), + BeanProperties.value("name").observe(adventure)); + assertEquals(adventure.getName(), label.getText()); adventure.setName("France"); diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ListViewerScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ListViewerScenario.java index 158b2778d84..8ec098b0569 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ListViewerScenario.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/ListViewerScenario.java @@ -18,12 +18,10 @@ import static org.junit.Assert.assertEquals; import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.databinding.observable.list.IObservableList; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.jface.databinding.viewers.ViewerSupport; -import org.eclipse.jface.databinding.viewers.ViewersObservables; +import org.eclipse.jface.databinding.viewers.typed.ViewerProperties; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.Catalog; import org.eclipse.jface.examples.databinding.model.Lodging; @@ -72,8 +70,8 @@ public void tearDown() throws Exception { @Test public void testScenario01() { // Bind the catalog's lodgings to the combo - IObservableList lodgings = BeansObservables.observeList(Realm - .getDefault(), catalog, "lodgings"); + + IObservableList lodgings = BeanProperties.list("lodgings").observe(catalog); ViewerSupport.bind(listViewer, lodgings, BeanProperties.value( Lodging.class, "name")); @@ -96,10 +94,8 @@ public void testScenario01() { // of an adventure final Adventure adventure = SampleData.WINTER_HOLIDAY; - IObservableValue selection = ViewersObservables - .observeSingleSelection(listViewer); - getDbc().bindValue(selection, - BeansObservables.observeValue(adventure, "defaultLodging")); + IObservableValue selection = ViewerProperties.singleSelection().observe(listViewer); + getDbc().bindValue(selection, BeanProperties.value("defaultLodging").observe(adventure)); // Verify that the list selection is the default lodging assertEquals(listViewer.getStructuredSelection().getFirstElement(), adventure.getDefaultLodging()); diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java index 508ce33837d..9fa0a5f5050 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/MasterDetailScenarios.java @@ -26,16 +26,14 @@ import java.util.List; import org.eclipse.core.databinding.beans.typed.BeanProperties; -import org.eclipse.core.databinding.beans.BeansObservables; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; import org.eclipse.core.databinding.observable.value.ComputedValue; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.databinding.viewers.ViewerSupport; -import org.eclipse.jface.databinding.viewers.ViewersObservables; +import org.eclipse.jface.databinding.viewers.typed.ViewerProperties; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.Catalog; import org.eclipse.jface.examples.databinding.model.Category; @@ -65,18 +63,17 @@ public class MasterDetailScenarios extends ScenariosTestCase { protected Object getViewerSelection(ContentViewer contentViewer) { - return ((IStructuredSelection) contentViewer.getSelection()) - .getFirstElement(); + return ((IStructuredSelection) contentViewer.getSelection()).getFirstElement(); } /** * @return the ComboViewer's domain object list */ - protected List getViewerContent(ContentViewer contentViewer) { - Object[] elements = ((IStructuredContentProvider) contentViewer - .getContentProvider()).getElements(null); - if (elements != null) + protected List getViewerContent(ContentViewer contentViewer) { + Object[] elements = ((IStructuredContentProvider) contentViewer.getContentProvider()).getElements(null); + if (elements != null) { return Arrays.asList(elements); + } return null; } @@ -87,38 +84,29 @@ public void testScenario01() { // be edited in a text widget. There is always a selected Lodging // object. ListViewer listViewer = new ListViewer(getComposite(), SWT.BORDER); - Realm realm = DisplayRealm.getRealm(listViewer.getControl() - .getDisplay()); - listViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); + Realm realm = DisplayRealm.getRealm(listViewer.getControl().getDisplay()); + listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); Catalog catalog = SampleData.CATALOG_2005; - IObservableList lodgings = BeansObservables.observeList(realm, catalog, - "lodgings"); - ViewerSupport.bind(listViewer, lodgings, BeanProperties.value( - Lodging.class, "name")); + IObservableList lodgings = BeanProperties.list("lodgings", Lodging.class).observe(realm, catalog); + ViewerSupport.bind(listViewer, lodgings, BeanProperties.value(Lodging.class, "name")); - assertArrayEquals(catalog.getLodgings(), getViewerContent(listViewer) - .toArray()); + assertArrayEquals(catalog.getLodgings(), getViewerContent(listViewer).toArray()); - IObservableValue selectedLodging = ViewersObservables - .observeSingleSelection(listViewer); + IObservableValue selectedLodging = ViewerProperties.singleSelection(Lodging.class).observe(listViewer); selectedLodging.setValue(SampleData.CAMP_GROUND); assertEquals(SampleData.CAMP_GROUND, getViewerSelection(listViewer)); Text txtName = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue( - SWTObservables.observeText(txtName, SWT.Modify), - BeansObservables.observeDetailValue(selectedLodging, "name", - String.class)); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(txtName), + BeanProperties.value(Lodging.class, "name", String.class).observeDetail(selectedLodging)); assertEquals(txtName.getText(), SampleData.CAMP_GROUND.getName()); enterText(txtName, "foobar"); assertEquals("foobar", SampleData.CAMP_GROUND.getName()); - listViewer.setSelection(new StructuredSelection( - SampleData.FIVE_STAR_HOTEL)); + listViewer.setSelection(new StructuredSelection(SampleData.FIVE_STAR_HOTEL)); assertEquals(SampleData.FIVE_STAR_HOTEL, selectedLodging.getValue()); assertEquals(SampleData.FIVE_STAR_HOTEL.getName(), txtName.getText()); SampleData.FIVE_STAR_HOTEL.setName("barfoo"); @@ -152,57 +140,40 @@ public void testScenario02() { // There are two buttons "Add" and "Remove"; clicking on "Add" creates a // new lodging and selects it so it can be edited, clicking on "Remove" // removes the currently selected lodging from the list. - final ListViewer listViewer = new ListViewer(getComposite(), SWT.BORDER); - listViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); - final Catalog catalog = SampleData.CATALOG_2005; + ListViewer listViewer = new ListViewer(getComposite(), SWT.BORDER); + listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + Catalog catalog = SampleData.CATALOG_2005; - IObservableList lodgings = BeansObservables.observeList(realm, catalog, - "lodgings"); - ViewerSupport.bind(listViewer, lodgings, BeanProperties.value( - Lodging.class, "name")); + IObservableList lodgings = BeanProperties.list("lodgings", Lodging.class).observe(realm, catalog); + ViewerSupport.bind(listViewer, lodgings, BeanProperties.value(Lodging.class, "name")); - assertArrayEquals(catalog.getLodgings(), getViewerContent(listViewer) - .toArray()); + assertArrayEquals(catalog.getLodgings(), getViewerContent(listViewer).toArray()); - final IObservableValue selectedLodgingObservable = ViewersObservables - .observeSingleSelection(listViewer); + IObservableValue selectedLodgingObservable = ViewerProperties.singleSelection(Lodging.class) + .observe(listViewer); selectedLodgingObservable.setValue(null); assertTrue(listViewer.getStructuredSelection().isEmpty()); - ComputedValue selectionExistsObservable = new ComputedValue( - boolean.class) { - @Override - protected Object calculate() { - return Boolean.valueOf(selectedLodgingObservable.getValue() != null); - } - }; + IObservableValue selectionExistsObservable = ComputedValue + .create(() -> selectedLodgingObservable.getValue() != null); - assertFalse(((Boolean) selectionExistsObservable.getValue()) - .booleanValue()); + assertFalse(selectionExistsObservable.getValue()); - final Text txtName = new Text(getComposite(), SWT.BORDER); + Text txtName = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeEnabled(txtName), - selectionExistsObservable); - getDbc().bindValue( - SWTObservables.observeText(txtName, SWT.Modify), - BeansObservables.observeDetailValue(selectedLodgingObservable, - "name", String.class)); + getDbc().bindValue(WidgetProperties.enabled().observe(txtName), selectionExistsObservable); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(txtName), + BeanProperties.value(Lodging.class, "name").observeDetail(selectedLodgingObservable)); assertEquals(txtName.getText(), ""); assertFalse(txtName.getEnabled()); - final Text txtDescription = new Text(getComposite(), SWT.BORDER); + Text txtDescription = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeEnabled(txtDescription), - selectionExistsObservable); - getDbc().bindValue( - SWTObservables.observeText(txtDescription, SWT.Modify), - MasterDetailObservables.detailValue(selectedLodgingObservable, - BeansObservables.valueFactory(realm, "description"), - String.class)); + getDbc().bindValue(WidgetProperties.enabled().observe(txtDescription), selectionExistsObservable); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(txtDescription), + BeanProperties.value("description", String.class).observeDetail(selectedLodgingObservable)); assertEquals(txtDescription.getText(), ""); assertFalse(txtDescription.getEnabled()); @@ -211,19 +182,16 @@ protected Object calculate() { addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - Lodging selectedLodging = (Lodging) selectedLodgingObservable - .getValue(); + Lodging selectedLodging = selectedLodgingObservable.getValue(); int insertionIndex = 0; if (selectedLodging != null) { - insertionIndex = Arrays.asList(catalog.getLodgings()) - .indexOf(selectedLodging); + insertionIndex = Arrays.asList(catalog.getLodgings()).indexOf(selectedLodging); assertTrue(insertionIndex >= 0); } Lodging newLodging = SampleData.FACTORY.createLodging(); int itemCount = listViewer.getList().getItemCount(); newLodging.setName("new lodging name " + itemCount); - newLodging.setDescription("new lodging description " - + itemCount); + newLodging.setDescription("new lodging description " + itemCount); catalog.addLodging(newLodging); assertEquals(itemCount + 1, listViewer.getList().getItemCount()); listViewer.setSelection(new StructuredSelection(newLodging)); @@ -231,8 +199,7 @@ public void widgetSelected(SelectionEvent e) { assertTrue(txtName.getEnabled()); assertTrue(txtDescription.getEnabled()); assertEquals(newLodging.getName(), txtName.getText()); - assertEquals(newLodging.getDescription(), txtDescription - .getText()); + assertEquals(newLodging.getDescription(), txtDescription.getText()); } }); @@ -241,11 +208,9 @@ public void widgetSelected(SelectionEvent e) { removeButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { - Lodging selectedLodging = (Lodging) selectedLodgingObservable - .getValue(); + Lodging selectedLodging = selectedLodgingObservable.getValue(); assertNotNull(selectedLodging); - int deletionIndex = Arrays.asList(catalog.getLodgings()) - .indexOf(selectedLodging); + int deletionIndex = Arrays.asList(catalog.getLodgings()).indexOf(selectedLodging); assertTrue(deletionIndex >= 0); int itemCount = listViewer.getList().getItemCount(); catalog.removeLodging(selectedLodging); @@ -269,96 +234,67 @@ public void widgetDefaultSelected(SelectionEvent e) { @Test public void testScenario03() { // List adventures and for the selected adventure allow its default - // lodging�s name and description to be changed in text controls. If + // lodging's name and description to be changed in text controls. If // there is no selected adventure or the default lodging is null the // text controls are disabled. This is a nested property. The default // lodging can be changed elsewhere, and the list - final Catalog catalog = SampleData.CATALOG_2005; + Catalog catalog = SampleData.CATALOG_2005; - final ListViewer categoryListViewer = new ListViewer(getComposite(), - SWT.BORDER); - categoryListViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); + ListViewer categoryListViewer = new ListViewer(getComposite(), SWT.BORDER); + categoryListViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - IObservableList categories = BeansObservables.observeList(realm, - catalog, "categories"); - ViewerSupport.bind(categoryListViewer, categories, BeanProperties - .value(Category.class, "name")); + IObservableList categories = BeanProperties.list("categories", Category.class).observe(realm, + catalog); + ViewerSupport.bind(categoryListViewer, categories, BeanProperties.value(Category.class, "name")); - assertArrayEquals(catalog.getCategories(), getViewerContent( - categoryListViewer).toArray()); + assertArrayEquals(catalog.getCategories(), getViewerContent(categoryListViewer).toArray()); - final IObservableValue selectedCategoryObservable = ViewersObservables - .observeSingleSelection(categoryListViewer); + IObservableValue selectedCategoryObservable = ViewerProperties.singleSelection(Category.class) + .observe(categoryListViewer); - final ListViewer adventureListViewer = new ListViewer(getComposite(), - SWT.BORDER); - adventureListViewer.getList().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, false, false)); + ListViewer adventureListViewer = new ListViewer(getComposite(), SWT.BORDER); + adventureListViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); - IObservableList adventures = BeansObservables.observeDetailList( - selectedCategoryObservable, "adventures", Adventure.class); - ViewerSupport.bind(adventureListViewer, adventures, BeanProperties - .value(Adventure.class, "name")); + IObservableList adventures = BeanProperties.list("adventures", Adventure.class) + .observeDetail(selectedCategoryObservable); + ViewerSupport.bind(adventureListViewer, adventures, BeanProperties.value(Adventure.class, "name")); - ComputedValue categorySelectionExistsObservable = new ComputedValue() { - @Override - protected Object calculate() { - return Boolean.valueOf( - selectedCategoryObservable.getValue() != null); - } - }; + IObservableValue categorySelectionExistsObservable = ComputedValue + .create(() -> selectedCategoryObservable.getValue() != null); - getDbc().bindValue( - SWTObservables.observeEnabled(adventureListViewer.getList()), + getDbc().bindValue(WidgetProperties.enabled().observe(adventureListViewer.getList()), categorySelectionExistsObservable); - final IObservableValue selectedAdventureObservable = ViewersObservables - .observeSingleSelection(adventureListViewer); + IObservableValue selectedAdventureObservable = ViewerProperties.singleSelection(Adventure.class) + .observe(adventureListViewer); - ComputedValue adventureSelectionExistsObservable = new ComputedValue() { - @Override - protected Object calculate() { - return Boolean.valueOf( - selectedAdventureObservable.getValue() != null); - } - }; + IObservableValue adventureSelectionExistsObservable = ComputedValue + .create(() -> selectedAdventureObservable.getValue() != null); - final Text txtName = new Text(getComposite(), SWT.BORDER); + Text txtName = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeEnabled(txtName), - adventureSelectionExistsObservable); - getDbc().bindValue( - SWTObservables.observeText(txtName, SWT.Modify), - BeansObservables.observeDetailValue( - selectedAdventureObservable, "name", String.class)); + getDbc().bindValue(WidgetProperties.enabled().observe(txtName), adventureSelectionExistsObservable); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(txtName), + BeanProperties.value("name", String.class).observeDetail(selectedAdventureObservable)); assertEquals(txtName.getText(), ""); assertFalse(txtName.getEnabled()); - final Text txtDescription = new Text(getComposite(), SWT.BORDER); + Text txtDescription = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeEnabled(txtDescription), - adventureSelectionExistsObservable); - getDbc().bindValue( - SWTObservables.observeText(txtDescription, SWT.Modify), - BeansObservables.observeDetailValue( - selectedAdventureObservable, "description", - String.class)); + getDbc().bindValue(WidgetProperties.enabled().observe(txtDescription), adventureSelectionExistsObservable); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(txtDescription), + BeanProperties.value("description", String.class).observeDetail(selectedAdventureObservable)); assertFalse(adventureListViewer.getList().isEnabled()); - categoryListViewer.setSelection(new StructuredSelection( - SampleData.SUMMER_CATEGORY)); + categoryListViewer.setSelection(new StructuredSelection(SampleData.SUMMER_CATEGORY)); assertTrue(adventureListViewer.getList().isEnabled()); assertFalse(txtName.getEnabled()); - adventureListViewer.setSelection(new StructuredSelection( - SampleData.RAFTING_HOLIDAY)); - assertEquals(Boolean.TRUE, adventureSelectionExistsObservable - .getValue()); + adventureListViewer.setSelection(new StructuredSelection(SampleData.RAFTING_HOLIDAY)); + assertTrue(adventureSelectionExistsObservable.getValue()); assertTrue(txtName.getEnabled()); assertEquals(SampleData.RAFTING_HOLIDAY.getName(), txtName.getText()); - categoryListViewer.setSelection(new StructuredSelection( - SampleData.WINTER_CATEGORY)); + categoryListViewer.setSelection(new StructuredSelection(SampleData.WINTER_CATEGORY)); assertTrue(adventureListViewer.getList().isEnabled()); assertFalse(txtName.getEnabled()); } diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NPETestScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NPETestScenario.java index ab1339a352b..2114f36b209 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NPETestScenario.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/NPETestScenario.java @@ -21,8 +21,8 @@ import java.beans.PropertyChangeListener; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Text; import org.junit.Before; @@ -57,8 +57,10 @@ public void test_InitialNullValue() { System.out .println("Expecting message about not being able to attach a listener"); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(person, "name")); + + + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("name").observe(person)); text.setText("Brad"); text.notifyListeners(SWT.FocusOut, null); diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java index 253b275ddd2..101bb094a5f 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/PropertyScenarios.java @@ -27,7 +27,7 @@ import org.eclipse.core.databinding.AggregateValidationStatus; import org.eclipse.core.databinding.Binding; import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; import org.eclipse.core.databinding.conversion.Converter; import org.eclipse.core.databinding.conversion.IConverter; import org.eclipse.core.databinding.conversion.text.NumberToStringConverter; @@ -37,7 +37,7 @@ import org.eclipse.core.databinding.validation.ValidationStatus; import org.eclipse.core.internal.databinding.conversion.IdentityConverter; import org.eclipse.core.runtime.Status; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.examples.databinding.model.Account; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.Cart; @@ -103,8 +103,9 @@ public void focusLost(FocusEvent e) { @Test public void testScenario01() { Text text = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name")); + + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("name").observe(adventure)); // getDbc().bind(text, new Property(adventure, "name"), null); // uncomment the following line to see what's happening @@ -127,8 +128,9 @@ public void testScenario02() { // is set to false.by the developer (can not change the name) Text text = new Text(getComposite(), SWT.READ_ONLY); - getDbc().bindValue(SWTObservables.observeText(text, SWT.None), - BeansObservables.observeValue(adventure, "name")); + getDbc().bindValue(WidgetProperties.text(SWT.None).observe(text), + BeanProperties.value("name").observe(adventure)); + assertEquals(adventure.getName(), text.getText()); } @@ -144,8 +146,10 @@ public void testScenario03() { Text text = new Text(getComposite(), SWT.BORDER); System.out.println("Expecting message about not being able to attach a listener"); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(cart, "lodgingDays")); + + + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("lodgingDays").observe(cart)); assertEquals(Integer.valueOf(cart.getLodgingDays()).toString(), text.getText()); } @@ -163,11 +167,11 @@ public void testScenario04() { // scenario to the master/detail section? I'm assuming the latter for // now. - IObservableValue defaultLodging = BeansObservables.observeDetailValue( - BeansObservables.observeValue(adventure, "defaultLodging"), - "description", String.class); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), defaultLodging); + IObservableValue defaultLodging = BeanProperties.value("defaultLodging.description", String.class) + .observe(adventure); + + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), defaultLodging); // test changing the description assertEquals(adventure.getDefaultLodging().getDescription(), text.getText()); @@ -241,8 +245,9 @@ public Object convert(Object fromObject) { } }; - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name"), + + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("name").observe(adventure), UpdateValueStrategy.create(converter2), UpdateValueStrategy.create(converter1)); // spinEventLoop(1); @@ -280,8 +285,8 @@ public void testScenario06() { // .addTargetValidator(BindingEvent.PIPELINE_VALUE_CHANGING, validator); Binding binding = getDbc().bindValue( - SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name"), + WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("name").observe(adventure), new UpdateValueStrategy().setConverter(new IdentityConverter( String.class)).setAfterGetValidator(validator), new UpdateValueStrategy().setConverter(new IdentityConverter( @@ -334,8 +339,7 @@ public void testScenario07() { numberFormat, true); getDbc().bindValue( - SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "price"), + WidgetProperties.text(SWT.Modify).observe(text), BeanProperties.value("price").observe(adventure), new UpdateValueStrategy().setAfterGetValidator(validator) .setConverter(targetToModelConverter), new UpdateValueStrategy().setConverter(modelToTargetConverter)); @@ -411,8 +415,9 @@ public Object convert(Object fromObject) { } }; - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "price"), + + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("price").observe(adventure), new UpdateValueStrategy().setConverter(toDouble).setAfterGetValidator(validator),new UpdateValueStrategy().setConverter(toCurrency)); String expected = currencyFormat.format(5); @@ -450,8 +455,9 @@ public void testScenario09() { // checkbox.setLayoutData(new GridData(SWT.LEFT,SWT.TOP, false,false)); adventure.setPetsAllowed(true); - getDbc().bindValue(SWTObservables.observeSelection(checkbox), - BeansObservables.observeValue(adventure, "petsAllowed")); + + getDbc().bindValue(WidgetProperties.buttonSelection().observe(checkbox), + BeanProperties.value("petsAllowed").observe(adventure)); assertEquals(true, checkbox.getSelection()); setButtonSelectionWithEvents(checkbox, false); @@ -479,7 +485,8 @@ public void testScenario11() { Spinner spinner2 = new Spinner(getComposite(), SWT.NONE); spinner2.setMaximum(1); - getDbc().bindValue(SWTObservables.observeSelection(spinner1), SWTObservables.observeMax(spinner2)); + getDbc().bindValue(WidgetProperties.spinnerSelection().observe(spinner1), + WidgetProperties.maximum().observe(spinner2)); assertEquals(1, spinner1.getSelection()); spinner1.setSelection(10); @@ -499,8 +506,8 @@ public void testScenario12() { Text text1 = new Text(getComposite(), SWT.NONE); Text text2 = new Text(getComposite(), SWT.NONE); - IObservableValue checkbox1Selected = SWTObservables.observeSelection(checkbox1); - IObservableValue checkbox2Selected = SWTObservables.observeSelection(checkbox2); + IObservableValue checkbox1Selected = WidgetProperties.buttonSelection().observe(checkbox1); + IObservableValue checkbox2Selected = WidgetProperties.buttonSelection().observe(checkbox2); // bind the two checkboxes so that if one is checked, the other is not // and vice versa. @@ -521,9 +528,8 @@ checkbox2Selected,new UpdateValueStrategy().setConverter(negatingConverter), // bind the enabled state of the two text widgets to one of the // checkboxes each. - - getDbc().bindValue(SWTObservables.observeEnabled(text1), checkbox1Selected); - getDbc().bindValue(SWTObservables.observeEnabled(text2), checkbox2Selected); + getDbc().bindValue(WidgetProperties.enabled().observe(text1), checkbox1Selected); + getDbc().bindValue(WidgetProperties.enabled().observe(text2), checkbox2Selected); assertEquals(true, text1.getEnabled()); assertEquals(false, text2.getEnabled()); @@ -541,8 +547,7 @@ checkbox2Selected,new UpdateValueStrategy().setConverter(negatingConverter), @Test public void testScenario13() { Text text = new Text(getComposite(), SWT.BORDER); - - getDbc().bindValue(SWTObservables.observeText(text, SWT.FocusOut), BeansObservables.observeValue(adventure, "name")); + getDbc().bindValue(WidgetProperties.text(SWT.FocusOut).observe(text), BeanProperties.value("name").observe(adventure)); // uncomment the following line to see what's happening // happening @@ -564,12 +569,14 @@ public void testScenario14() { Text t1 = new Text(getComposite(), SWT.BORDER); Text t2 = new Text(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeText(t1, SWT.Modify), BeansObservables.observeValue(adventure, "name")); - getDbc().bindValue(SWTObservables.observeText(t2, SWT.Modify), BeansObservables.observeValue(adventure, "name")); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(t1), + BeanProperties.value("name").observe(adventure)); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(t2), + BeanProperties.value("name").observe(adventure)); final int[] counter = { 0 }; - IObservableValue uv = BeansObservables.observeValue(adventure, "name"); + IObservableValue uv = BeanProperties.value("name").observe(adventure); uv.addChangeListener(event -> counter[0]++); @@ -592,10 +599,11 @@ public void testScenario15() { Account account = new Account(); account.setExpiryDate(new Date()); - Binding b = getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), BeansObservables.observeValue(account, "expiryDate")); + Binding b = getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("expiryDate").observe(account)); Text errorText = new Text(getComposite(), SWT.NONE); - getDbc().bindValue(SWTObservables.observeText(errorText, SWT.Modify), b.getValidationStatus(), + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(errorText), b.getValidationStatus(), UpdateValueStrategy.never(), null); assertTrue(b.getValidationStatus().getValue().isOK()); enterText(text, "foo"); diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/SpinnerControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/SpinnerControlScenario.java index 306ce8d8984..afdde1ac9ca 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/SpinnerControlScenario.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/SpinnerControlScenario.java @@ -17,8 +17,8 @@ import static org.junit.Assert.assertEquals; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.SampleData; import org.eclipse.swt.SWT; @@ -59,8 +59,9 @@ public void testScenario01() { // Change the UI and verify the model changes // Change the model and verify the UI changes Spinner spinner = new Spinner(getComposite(), SWT.BORDER); - getDbc().bindValue(SWTObservables.observeSelection(spinner), - BeansObservables.observeValue(adventure, "maxNumberOfPeople")); + + getDbc().bindValue(WidgetProperties.spinnerSelection().observe(spinner), + BeanProperties.value("maxNumberOfPeople").observe(adventure)); assertEquals(adventure.getMaxNumberOfPeople(), spinner.getSelection()); // Verify the model is updated when the GUI is changed diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TextControlScenario.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TextControlScenario.java index acf35a33bd8..f97abd02b14 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TextControlScenario.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/scenarios/TextControlScenario.java @@ -18,9 +18,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.text.NumberFormat; + import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.examples.databinding.model.Account; import org.eclipse.jface.examples.databinding.model.Adventure; import org.eclipse.jface.examples.databinding.model.SampleData; @@ -33,8 +35,6 @@ import org.junit.Ignore; import org.junit.Test; -import java.text.NumberFormat; - /** * To run the tests in this class, right-click and select "Run As JUnit Plug-in * Test". This will also start an Eclipse instance. To clean up the launch @@ -76,8 +76,9 @@ public void testScenario01() { // Bind the adventure "name" property to a text field // Change the UI and verify the model changes // Change the model and verify the UI changes - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "name")); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("name").observe(adventure)); + assertEquals(adventure.getName(), text.getText()); text.setText("England"); @@ -98,8 +99,8 @@ public void testScenario02() { // occurs // Change the UI and verify the model changes // Change the model and verify the UI changes - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(transportation, "price")); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("price").observe(transportation)); NumberFormat numberFormat = NumberFormat.getInstance(); @@ -119,7 +120,7 @@ public void testScenario02() { // // the updatePolicy for this test is TIME_LATE so it occurs when focus // // is lost from the Text control // getDbc().bindValue(SWTObservables.observeText(text, SWT.FocusOut), -// BeansObservables.observeValue(adventure, "name"), +// BeanProperties.value("name").observe(adventure), // null, null); // // String currentText = text.getText(); @@ -156,8 +157,8 @@ public void testScenario02() { // // the value will revert // // the updatePolicy for this test is TIME_EARLY so it occurs when each // // keystroke occurs -// getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), -// BeansObservables.observeValue(adventure, "name"), +// getDbc().bindValue( WidgetProperties.text(SWT.Modify).observe(text), +// BeanProperties.value("name").observe(adventure), // null, null); // // String originalName = adventure.getName(); @@ -277,8 +278,8 @@ public void testScenario08() { DataBindingContext dbc = getDbc(); - dbc.bindValue(SWTObservables.observeText(text, SWT.Modify), - BeansObservables.observeValue(adventure, "maxNumberOfPeople"), + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(text), + BeanProperties.value("maxNumberOfPeople").observe(adventure), new CustomBeanUpdateValueStrategy(), null); // make sure we can set a value inside the validator's range @@ -295,7 +296,8 @@ public void testScenario09() { // Verify direct binding between a Text and Label following bugzilla // 118696 Label label = new Label(getComposite(), SWT.NONE); - getDbc().bindValue(SWTObservables.observeText(text, SWT.FocusOut), SWTObservables.observeText(label)); + getDbc().bindValue(WidgetProperties.text(SWT.FocusOut).observe(text), + WidgetProperties.text().observe(label)); // Change the text text.setText("Frog"); @@ -312,7 +314,7 @@ public void testScenario10() { // Verify direct binding between a Text and Label following bugzilla // 118696 with TIME_EARLY Label label = new Label(getComposite(), SWT.NONE); - getDbc().bindValue(SWTObservables.observeText(text, SWT.Modify), SWTObservables.observeText(label)); + getDbc().bindValue(WidgetProperties.text(SWT.Modify).observe(text), WidgetProperties.text().observe(label)); // Change the text String newTextValue = "Frog"; diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java deleted file mode 100644 index 4cf3761fe3b..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java +++ /dev/null @@ -1,721 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009, 2011 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Chris Aniszczyk - bug 131435 - * Matthew Hall - bugs 248621, 213893, 262320, 169876, 306203 - ******************************************************************************/ - -package org.eclipse.jface.tests.databinding.swt; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.eclipse.core.databinding.observable.IDecoratingObservable; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.property.IPropertyObservable; -import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; -import org.eclipse.jface.databinding.conformance.util.RealmTester; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.databinding.swt.ISWTObservable; -import org.eclipse.jface.databinding.swt.ISWTObservableList; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.swt.typed.WidgetProperties; -import org.eclipse.jface.internal.databinding.swt.ButtonImageProperty; -import org.eclipse.jface.internal.databinding.swt.ButtonSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.ButtonTextProperty; -import org.eclipse.jface.internal.databinding.swt.CComboEditableProperty; -import org.eclipse.jface.internal.databinding.swt.CComboItemsProperty; -import org.eclipse.jface.internal.databinding.swt.CComboSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.CComboTextProperty; -import org.eclipse.jface.internal.databinding.swt.CLabelImageProperty; -import org.eclipse.jface.internal.databinding.swt.CLabelTextProperty; -import org.eclipse.jface.internal.databinding.swt.CTabItemTooltipTextProperty; -import org.eclipse.jface.internal.databinding.swt.ComboItemsProperty; -import org.eclipse.jface.internal.databinding.swt.ComboSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.ComboTextProperty; -import org.eclipse.jface.internal.databinding.swt.ControlBackgroundProperty; -import org.eclipse.jface.internal.databinding.swt.ControlForegroundProperty; -import org.eclipse.jface.internal.databinding.swt.ControlTooltipTextProperty; -import org.eclipse.jface.internal.databinding.swt.DateTimeSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.ItemImageProperty; -import org.eclipse.jface.internal.databinding.swt.ItemTextProperty; -import org.eclipse.jface.internal.databinding.swt.LabelImageProperty; -import org.eclipse.jface.internal.databinding.swt.LabelTextProperty; -import org.eclipse.jface.internal.databinding.swt.ListItemsProperty; -import org.eclipse.jface.internal.databinding.swt.ListSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.MenuEnabledProperty; -import org.eclipse.jface.internal.databinding.swt.MenuItemEnabledProperty; -import org.eclipse.jface.internal.databinding.swt.MenuItemSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.ScaleMaximumProperty; -import org.eclipse.jface.internal.databinding.swt.ScaleMinimumProperty; -import org.eclipse.jface.internal.databinding.swt.ScaleSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.ScrollBarEnabledProperty; -import org.eclipse.jface.internal.databinding.swt.SpinnerMaximumProperty; -import org.eclipse.jface.internal.databinding.swt.SpinnerMinimumProperty; -import org.eclipse.jface.internal.databinding.swt.SpinnerSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.StyledTextEditableProperty; -import org.eclipse.jface.internal.databinding.swt.StyledTextTextProperty; -import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionIndexProperty; -import org.eclipse.jface.internal.databinding.swt.TextEditableProperty; -import org.eclipse.jface.internal.databinding.swt.TextTextProperty; -import org.eclipse.jface.internal.databinding.swt.ToolItemEnabledProperty; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.custom.CTabFolder; -import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.DateTime; -import org.eclipse.swt.widgets.Item; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Scale; -import org.eclipse.swt.widgets.ScrollBar; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.swt.widgets.ToolTip; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.Widget; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * @since 1.1 - */ -public class SWTObservablesTest extends AbstractSWTTestCase { - private Shell shell; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - shell = getShell(); - RealmTester.setDefault(DisplayRealm.getRealm(shell.getDisplay())); - } - - @Override - @After - public void tearDown() throws Exception { - super.tearDown(); - - RealmTester.setDefault(null); - } - - @Override - protected Shell createShell() { - return new Shell(SWT.V_SCROLL); - } - - @Test - public void testObserveForeground() throws Exception { - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeForeground(shell); - assertWidgetObservable(value, shell, ControlForegroundProperty.class); - assertEquals(Color.class, value.getValueType()); - } - - @Test - public void testObserveBackground() throws Exception { - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeBackground(shell); - assertWidgetObservable(value, shell, ControlBackgroundProperty.class); - assertEquals(Color.class, value.getValueType()); - } - - @Test - public void testObserveFont() throws Exception { - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeFont(shell); - assertNotNull(value); - assertEquals(Font.class, value.getValueType()); - } - - @Test - public void testObserveSelectionOfSpinner() throws Exception { - Spinner spinner = new Spinner(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(spinner); - assertWidgetObservable(value, spinner, SpinnerSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfButton() throws Exception { - Button button = new Button(shell, SWT.PUSH); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(button); - assertWidgetObservable(value, button, ButtonSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfCombo() throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(combo); - assertWidgetObservable(value, combo, ComboSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfCCombo() throws Exception { - CCombo combo = new CCombo(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(combo); - assertWidgetObservable(value, combo, CComboSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfDateTime_Date() throws Exception { - DateTime dateTime = new DateTime(shell, SWT.DATE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(dateTime); - assertWidgetObservable(value, dateTime, DateTimeSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfDateTime_Calendar() throws Exception { - DateTime dateTime = new DateTime(shell, SWT.CALENDAR); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(dateTime); - assertWidgetObservable(value, dateTime, DateTimeSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfDateTime_Time() throws Exception { - DateTime dateTime = new DateTime(shell, SWT.TIME); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(dateTime); - assertWidgetObservable(value, dateTime, DateTimeSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfList() throws Exception { - List list = new List(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(list); - assertWidgetObservable(value, list, ListSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfScale() throws Exception { - Scale scale = new Scale(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(scale); - assertWidgetObservable(value, scale, ScaleSelectionProperty.class); - } - - @Test - public void testObserveSelectionOfUnsupportedControl() throws Exception { - try { - Text text = new Text(shell, SWT.NONE); - SWTObservables.observeSelection(text); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testObserveTextWithEventOfText() throws Exception { - Text text = new Text(shell, SWT.NONE); - assertFalse(text.isListening(SWT.FocusOut)); - - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(text, - SWT.FocusOut); - assertWidgetObservable(value, text, TextTextProperty.class); - - assertFalse(text.isListening(SWT.FocusOut)); - ChangeEventTracker.observe(value); - assertTrue(text.isListening(SWT.FocusOut)); - } - - @Test - public void testObserveTextOfStyledText() throws Exception { - StyledText text = new StyledText(shell, SWT.NONE); - assertFalse(text.isListening(SWT.FocusOut)); - - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(text, - SWT.FocusOut); - assertWidgetObservable(value, text, StyledTextTextProperty.class); - - assertFalse(text.isListening(SWT.FocusOut)); - ChangeEventTracker.observe(value); - assertTrue(text.isListening(SWT.FocusOut)); - } - - @Test - public void testObserveTextWithEventOfUnsupportedControl() throws Exception { - Label label = new Label(shell, SWT.NONE); - try { - SWTObservables.observeText(label, SWT.FocusOut); - fail("Exception should have been thrown"); - } catch (Exception e) { - } - } - - @Test - public void testObserveTextOfButton() throws Exception { - Button button = new Button(shell, SWT.PUSH); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(button); - assertWidgetObservable(value, button, ButtonTextProperty.class); - } - - @Test - public void testObserveTextOfLabel() throws Exception { - Label label = new Label(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(label); - assertWidgetObservable(value, label, LabelTextProperty.class); - } - - @Test - public void testObserveTextOfCLabel() throws Exception { - CLabel label = new CLabel(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(label); - assertWidgetObservable(value, label, CLabelTextProperty.class); - } - - @Test - public void testObserveTextOfCombo() throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(combo); - assertWidgetObservable(value, combo, ComboTextProperty.class); - } - - /** - * @param observable - * @return - */ - private IPropertyObservable getPropertyObservable(ISWTObservable observable) { - IDecoratingObservable decoratingObservable = (IDecoratingObservable) observable; - return (IPropertyObservable) decoratingObservable - .getDecorated(); - } - - @Test - public void testObserveTextOfCCombo() throws Exception { - CCombo combo = new CCombo(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(combo); - assertWidgetObservable(value, combo, CComboTextProperty.class); - } - - @Test - public void testObserveTextOfText() throws Exception { - Text text = new Text(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(text); - - assertWidgetObservable(value, text, TextTextProperty.class); - - assertFalse(text.isListening(SWT.Modify)); - assertFalse(text.isListening(SWT.FocusOut)); - } - - @Test - public void testObserveTextOfItem() throws Exception { - CTabFolder ctf = new CTabFolder(shell, SWT.NONE); - Item item = new CTabItem(ctf, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeText(item); - assertWidgetObservable(value, item, ItemTextProperty.class); - } - - @Test - public void testObserveTextOfUnsupportedControl() throws Exception { - Table table = new Table(shell, SWT.NONE); - try { - SWTObservables.observeText(table); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testObserveImageOfButton() throws Exception { - Button button = new Button(shell, SWT.PUSH); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeImage(button); - assertWidgetObservable(value, button, ButtonImageProperty.class); - } - - @Test - public void testObserveImageOfCLabel() throws Exception { - CLabel cLabel = new CLabel(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeImage(cLabel); - assertWidgetObservable(value, cLabel, CLabelImageProperty.class); - } - - @Test - public void testObserveImageOfItem() throws Exception { - CTabFolder ctf = new CTabFolder(shell, SWT.NONE); - Item item = new CTabItem(ctf, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeImage(item); - assertWidgetObservable(value, item, ItemImageProperty.class); - } - - @Test - public void testObserveImageOfLabel() throws Exception { - Label label = new Label(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeImage(label); - assertWidgetObservable(value, label, LabelImageProperty.class); - } - - @Test - public void testObserveTooltipOfItem() throws Exception { - CTabFolder ctf = new CTabFolder(shell, SWT.NONE); - Item item = new CTabItem(ctf, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeTooltipText(item); - assertWidgetObservable(value, item, CTabItemTooltipTextProperty.class); - } - - @Test - public void testObserveTooltipOfUnsupportedControl() throws Exception { - ToolTip ttip = new ToolTip(shell, SWT.NONE); - try { - SWTObservables.observeTooltipText(ttip); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testObserveTooltipOfControl() throws Exception { - Label label = new Label(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeTooltipText(label); - assertWidgetObservable(value, label, ControlTooltipTextProperty.class); - } - - @Test - public void testObserveItemsOfCombo() throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableList list = (ISWTObservableList) SWTObservables - .observeItems(combo); - assertWidgetObservable(list, combo, ComboItemsProperty.class); - } - - @Test - public void testObserveItemsOfCCombo() throws Exception { - CCombo ccombo = new CCombo(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableList list = (ISWTObservableList) SWTObservables - .observeItems(ccombo); - assertWidgetObservable(list, ccombo, CComboItemsProperty.class); - } - - @Test - public void testObserveItemsOfList() throws Exception { - List list = new List(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableList observableList = (ISWTObservableList) SWTObservables - .observeItems(list); - assertWidgetObservable(observableList, list, ListItemsProperty.class); - } - - @Test - public void testObserveItemsOfUnsupportedControl() throws Exception { - Table table = new Table(shell, SWT.NONE); - try { - SWTObservables.observeItems(table); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testObserveSingleSelectionIndexOfTable() throws Exception { - Table table = new Table(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSingleSelectionIndex(table); - assertWidgetObservable(value, table, - TableSingleSelectionIndexProperty.class); - } - - @Test - public void testObserveSingleSelectionIndexOfCCombo_DeselectAll() - throws Exception { - CCombo cCombo = new CCombo(shell, SWT.NONE); - cCombo.add("item"); - cCombo.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(cCombo); - assertEquals(0, cCombo.getSelectionIndex()); - value.setValue(-1); - assertEquals(-1, cCombo.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfCCombo_SetValueNull() - throws Exception { - CCombo cCombo = new CCombo(shell, SWT.NONE); - cCombo.add("item"); - cCombo.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(cCombo); - assertEquals(0, cCombo.getSelectionIndex()); - value.setValue(null); - assertEquals(-1, cCombo.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfCombo_DeselectAll() - throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - combo.add("item"); - combo.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(combo); - assertEquals(0, combo.getSelectionIndex()); - value.setValue(-1); - assertEquals(-1, combo.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfCombo_SetValueNull() - throws Exception { - Combo combo = new Combo(shell, SWT.NONE); - combo.add("item"); - combo.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(combo); - assertEquals(0, combo.getSelectionIndex()); - value.setValue(null); - assertEquals(-1, combo.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfList_DeselectAll() - throws Exception { - List list = new List(shell, SWT.NONE); - list.add("item"); - list.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(list); - assertEquals(0, list.getSelectionIndex()); - value.setValue(Integer.valueOf(-1)); - assertEquals(-1, list.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfList_SetValueNull() - throws Exception { - List list = new List(shell, SWT.NONE); - list.add("item"); - list.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(list); - assertEquals(0, list.getSelectionIndex()); - value.setValue(null); - assertEquals(-1, list.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfTable_DeselectAll() - throws Exception { - Table table = new Table(shell, SWT.NONE); - new TableItem(table, SWT.NONE); - table.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(table); - assertEquals(0, table.getSelectionIndex()); - value.setValue(Integer.valueOf(-1)); - assertEquals(-1, table.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfTable_SetValueNull() - throws Exception { - Table table = new Table(shell, SWT.NONE); - new TableItem(table, SWT.NONE); - table.select(0); - - IObservableValue value = WidgetProperties.singleSelectionIndex().observe(table); - assertEquals(0, table.getSelectionIndex()); - value.setValue(null); - assertEquals(-1, table.getSelectionIndex()); - } - - @Test - public void testObserveSingleSelectionIndexOfUnsupportedControl() - throws Exception { - Tree tree = new Tree(shell, SWT.NONE); - try { - SWTObservables.observeSingleSelectionIndex(tree); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - - } - } - - @Test - public void testObserveMinOfSpinner() throws Exception { - Spinner spinner = new Spinner(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeMin(spinner); - assertWidgetObservable(value, spinner, SpinnerMinimumProperty.class); - } - - @Test - public void testObserveMinOfScale() throws Exception { - Scale scale = new Scale(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeMin(scale); - assertWidgetObservable(value, scale, ScaleMinimumProperty.class); - } - - @Test - public void testObserveMinOfUnsupportedControl() throws Exception { - Text text = new Text(shell, SWT.NONE); - try { - SWTObservables.observeMin(text); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testObserveMaxOfSpinner() throws Exception { - Spinner spinner = new Spinner(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeMax(spinner); - assertWidgetObservable(value, spinner, SpinnerMaximumProperty.class); - } - - @Test - public void testObserveMaxOfScale() throws Exception { - Scale scale = new Scale(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeMax(scale); - assertWidgetObservable(value, scale, ScaleMaximumProperty.class); - } - - @Test - public void testObserveMaxOfUnsupportedControl() throws Exception { - Text text = new Text(shell, SWT.NONE); - try { - SWTObservables.observeMax(text); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testObserveEditableOfText() throws Exception { - Text text = new Text(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeEditable(text); - assertWidgetObservable(value, text, TextEditableProperty.class); - } - - @Test - public void testObserveEditableOfCCombo() throws Exception { - CCombo combo = new CCombo(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeEditable(combo); - assertWidgetObservable(value, combo, CComboEditableProperty.class); - } - - @Test - public void testObserveEditableOfStyledText() throws Exception { - StyledText styledText = new StyledText(shell, SWT.NONE); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeEditable(styledText); - assertWidgetObservable(value, styledText, - StyledTextEditableProperty.class); - } - - @Test - public void testObserveEnabledOfMenu() throws Exception { - Menu menu = new Menu(shell, SWT.BAR); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeEnabled(menu); - assertWidgetObservable(value, menu, MenuEnabledProperty.class); - } - - @Test - public void testObserveEnabledOfMenuItem() throws Exception { - Menu menu = new Menu(shell, SWT.DROP_DOWN); - MenuItem item = new MenuItem(menu, SWT.PUSH); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeEnabled(item); - assertWidgetObservable(value, item, MenuItemEnabledProperty.class); - } - - @Test - public void testObserveSelectionOfMenuItem() throws Exception { - Menu menu = new Menu(shell, SWT.DROP_DOWN); - MenuItem item = new MenuItem(menu, SWT.PUSH); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeSelection(item); - assertWidgetObservable(value, item, MenuItemSelectionProperty.class); - } - - @Test - public void testObserveEnabledOfScrollBar() throws Exception { - ScrollBar scrollBar = shell.getVerticalBar(); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeEnabled(scrollBar); - assertWidgetObservable(value, scrollBar, ScrollBarEnabledProperty.class); - } - - @Test - public void testObserveEnabledOfToolItem() throws Exception { - ToolBar bar = new ToolBar(shell, SWT.HORIZONTAL); - ToolItem item = new ToolItem(bar, SWT.PUSH); - @SuppressWarnings("rawtypes") - ISWTObservableValue value = SWTObservables.observeEnabled(item); - assertWidgetObservable(value, item, ToolItemEnabledProperty.class); - } - - private void assertWidgetObservable(ISWTObservable observable, Widget widget, Class propertyClass) { - assertNotNull(observable); - assertTrue(observable.getWidget() == widget); - IPropertyObservable propertyObservable = getPropertyObservable(observable); - assertTrue(propertyClass.isInstance(propertyObservable.getProperty())); - } - - @Test - public void testObserveEditableOfUnsupportedControl() throws Exception { - Label label = new Label(shell, SWT.NONE); - try { - SWTObservables.observeEditable(label); - fail("Exception should have been thrown"); - } catch (IllegalArgumentException e) { - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java deleted file mode 100644 index 57bf9a44f04..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - * Eric Rizzo - bug 134884 - * Matthew Hall - bug 194734, 195222 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.property.value.IValueProperty; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.swt.typed.WidgetProperties; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.junit.Test; - -/** - * @since 3.2 - */ -public class CComboObservableValueTest extends AbstractSWTTestCase { - @Test - public void testDispose() throws Exception { - CCombo combo = new CCombo(getShell(), SWT.NONE); - ISWTObservableValue observableValue = SWTObservables.observeText(combo); - - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - assertEquals("", combo.getText()); - assertEquals("", observableValue.getValue()); - - String expected1 = "Test123"; - combo.setText(expected1); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected1, combo.getText()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - String expected2 = "NewValue123"; - combo.setText(expected2); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected2, combo.getText()); - } - - @Test - public void testSetValueWithNull() { - testSetValueWithNull(WidgetProperties.text()); - testSetValueWithNull(WidgetProperties.widgetSelection()); - } - - protected void testSetValueWithNull(IValueProperty property) { - CCombo combo = new CCombo(getShell(), SWT.NONE); - combo.setItems(new String[] { "one", "two", "three" }); - IObservableValue observable = property.observe(Realm.getDefault(), - combo); - - observable.setValue("two"); - assertEquals("two", combo.getText()); - assertEquals(1, combo.getSelectionIndex()); - - observable.setValue(null); - assertEquals("", combo.getText()); - assertEquals(-1, combo.getSelectionIndex()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java deleted file mode 100644 index 13d83085c3c..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198903 - * Matthew Hall - bug 213145, 194734, 195222 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.swt.typed.WidgetProperties; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.widgets.Shell; -import org.junit.Test; - -/** - * @since 3.2 - */ -public class CComboSingleSelectionObservableValueTest extends - AbstractSWTTestCase { - @Test - public void testSetValue() throws Exception { - CCombo combo = new CCombo(getShell(), SWT.NONE); - IObservableValue observableValue = SWTObservables - .observeSingleSelectionIndex(combo); - combo.add("Item1"); - combo.add("Item2"); - - assertEquals(-1, combo.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - Integer value = Integer.valueOf(1); - observableValue.setValue(value); - assertEquals("combo selection index", value.intValue(), combo - .getSelectionIndex()); - assertEquals("observable value", value, observableValue.getValue()); - - assertEquals("Item2", combo.getText()); - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(SWTMutableObservableValueContractTest.class, new Delegate()); - suite.addTest(SWTObservableValueContractTest.class, new Delegate()); - } - - /* package */static class Delegate extends - AbstractObservableValueContractDelegate { - private CCombo combo; - private Shell shell; - - @Override - public void setUp() { - shell = new Shell(); - combo = new CCombo(shell, SWT.NONE); - combo.add("0"); - combo.add("1"); - } - - @Override - public void tearDown() { - shell.dispose(); - } - - @Override - public IObservableValue createObservableValue(Realm realm) { - return WidgetProperties.singleSelectionIndex() - .observe(realm, combo); - } - - @Override - public void change(IObservable observable) { - IObservableValue value = (IObservableValue) observable; - value.setValue(createValue(value)); - } - - @Override - public Object getValueType(IObservableValue observable) { - return Integer.TYPE; - } - - @Override - public Object createValue(IObservableValue observable) { - return Integer.valueOf(_createValue(observable)); - } - - private int _createValue(IObservableValue observable) { - int value = Math.max(0, combo.getSelectionIndex()); - - // returns either 0 or 1 depending upon current value - return Math.abs(value - 1); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java deleted file mode 100644 index bc62a9b2e87..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - * Matthew Hall - bug 194734, 195222 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.property.value.IValueProperty; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.swt.typed.WidgetProperties; -import org.eclipse.jface.internal.databinding.swt.ComboSelectionProperty; -import org.eclipse.jface.internal.databinding.swt.ComboTextProperty; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; -import org.junit.Test; - -/** - * @since 3.2 - * @no - */ -public class ComboObservableValueTest extends AbstractSWTTestCase { - @Test - public void testDispose() throws Exception { - Combo combo = new Combo(getShell(), SWT.NONE); - IObservableValue observableValue = SWTObservables.observeText(combo); - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - assertEquals("", combo.getText()); - assertEquals("", observableValue.getValue()); - - String expected1 = "Test123"; - combo.setText(expected1); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected1, combo.getText()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - String expected2 = "NewValue123"; - combo.setText(expected2); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected2, combo.getText()); - } - - @Test - public void testSetValueWithNull() { - testSetValueWithNull(WidgetProperties.text()); - testSetValueWithNull(WidgetProperties.widgetSelection()); - } - - protected void testSetValueWithNull(IValueProperty property) { - Combo combo = new Combo(getShell(), SWT.NONE); - combo.setItems(new String[] { "one", "two", "three" }); - IObservableValue observable = property.observe(Realm.getDefault(), - combo); - - observable.setValue("two"); - assertEquals("two", combo.getText()); - if (property instanceof ComboSelectionProperty) { - assertEquals("expect selection at index 1 in selection mode", 1, - combo.getSelectionIndex()); - } - - if (property instanceof ComboTextProperty) { - observable.setValue(null); - assertEquals("expect empty text in text mode", "", combo.getText()); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java deleted file mode 100644 index d355eb2b347..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Ashley Cambrell and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Ashley Cambrell - initial API and implementation (bug 198903) - * Matthew Hall - bug 194734 - ******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Combo; -import org.junit.Test; - -/** - * @since 3.2 - * - */ -public class ComboSingleSelectionObservableValueTest extends - AbstractSWTTestCase { - @Test - public void testSetValue() throws Exception { - Combo combo = new Combo(getShell(), SWT.NONE); - IObservableValue observableValue = SWTObservables - .observeSingleSelectionIndex(combo); - combo.add("Item1"); - combo.add("Item2"); - - assertEquals(-1, combo.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - Integer value = Integer.valueOf(1); - observableValue.setValue(value); - assertEquals("combo selection index", value.intValue(), combo - .getSelectionIndex()); - assertEquals("observable value", value, observableValue.getValue()); - - assertEquals("Item2", combo.getText()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java deleted file mode 100644 index 4bf5c36f6eb..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Ashley Cambrell and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Ashley Cambrell - initial API and implementation - * Matthew Hall - bug 194734 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.List; -import org.junit.Test; - -/** - * @since 3.2 - * - */ -public class ListSingleSelectionObservableValueTest extends AbstractSWTTestCase { - @Test - public void testSetValue() throws Exception { - List list = new List(getShell(), SWT.NONE); - IObservableValue observableValue = SWTObservables - .observeSingleSelectionIndex(list); - list.add("Item1"); - - assertEquals(-1, list.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - Integer value = Integer.valueOf(0); - observableValue.setValue(value); - assertEquals("list selection index", value.intValue(), list - .getSelectionIndex()); - assertEquals("observable value", value, observableValue.getValue()); - } - - @Test - public void testDispose() throws Exception { - List list = new List(getShell(), SWT.NONE); - IObservableValue observableValue = SWTObservables - .observeSingleSelectionIndex(list); - list.add("Item1"); - list.add("Item2"); - - assertEquals(-1, list.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - list.select(0); - list.notifyListeners(SWT.Selection, null); - assertEquals(0, list.getSelectionIndex()); - assertEquals(Integer.valueOf(0), observableValue.getValue()); - - observableValue.dispose(); - - list.select(1); - list.notifyListeners(SWT.Selection, null); - assertEquals(1, list.getSelectionIndex()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SWTDelayedObservableValueDecoratorTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SWTDelayedObservableValueDecoratorTest.java deleted file mode 100644 index ee4a8cd25b7..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SWTDelayedObservableValueDecoratorTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2018 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 212223) - * Matthew Hall - bug 213145, 245647, 194734 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.WritableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.SWTObservableValueDecorator; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Shell; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests for DelayedObservableValue - * - * @since 1.2 - */ -public class SWTDelayedObservableValueDecoratorTest extends - AbstractDefaultRealmTestCase { - private Display display; - private Shell shell; - private Object oldValue; - private Object newValue; - private ISWTObservableValue target; - private ISWTObservableValue delayed; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - display = Display.getCurrent(); - shell = new Shell(display); - target = new SWTObservableValueDecorator(new WritableValue( - DisplayRealm.getRealm(display)), shell); - oldValue = new Object(); - newValue = new Object(); - target.setValue(oldValue); - delayed = SWTObservables.observeDelayedValue(1, target); - } - - @Override - @After - public void tearDown() throws Exception { - delayed.dispose(); - target.dispose(); - target = null; - shell.dispose(); - shell = null; - display = null; - super.tearDown(); - } - - @Test - public void testFocusOut_FiresPendingValueChange() { - assertFiresPendingValueChange(() -> shell.notifyListeners(SWT.FocusOut, new Event())); - } - - private void assertFiresPendingValueChange(Runnable runnable) { - ValueChangeEventTracker tracker = ValueChangeEventTracker - .observe(delayed); - - target.setValue(newValue); - assertTrue(delayed.isStale()); - assertEquals(0, tracker.count); - - runnable.run(); - - assertFalse(delayed.isStale()); - assertEquals(1, tracker.count); - assertEquals(oldValue, tracker.event.diff.getOldValue()); - assertEquals(newValue, tracker.event.diff.getNewValue()); - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(SWTMutableObservableValueContractTest.class, new Delegate()); - suite.addTest(SWTObservableValueContractTest.class, new Delegate()); - } - - static class Delegate extends AbstractObservableValueContractDelegate { - Shell shell; - - @Override - public void setUp() { - super.setUp(); - shell = new Shell(); - } - - @Override - public void tearDown() { - shell.dispose(); - shell = null; - super.tearDown(); - } - - @Override - public IObservableValue createObservableValue(Realm realm) { - return SWTObservables.observeDelayedValue(0, - new SWTObservableValueDecorator(new WritableValue(realm, - null, Object.class), shell)); - } - - @Override - public Object getValueType(IObservableValue observable) { - return Object.class; - } - - @Override - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - @Override - public Object createValue(IObservableValue observable) { - return new Object(); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java deleted file mode 100644 index 5d2811a0d49..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 212235) - * Matthew Hall - bug 213145, 194734, 195222 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.databinding.swt.typed.WidgetProperties; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.widgets.Shell; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests for ShellObservableValue - * - * @since 1.2 - */ -public class ShellObservableValueTest extends AbstractDefaultRealmTestCase { - String oldValue; - String newValue; - Shell shell; - IObservableValue observable; - ValueChangeEventTracker tracker; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - shell = new Shell(); - observable = SWTObservables.observeText(shell); - oldValue = "old"; - newValue = "new"; - shell.setText(oldValue); - tracker = ValueChangeEventTracker.observe(observable); - } - - @Override - @After - public void tearDown() throws Exception { - observable.dispose(); - observable = null; - shell.dispose(); - shell = null; - super.tearDown(); - } - - @Test - public void testGetValueType() { - assertEquals(String.class, observable.getValueType()); - } - - @Test - public void testSetValue_FiresValueChangeEvent() { - observable.setValue(newValue); - - assertEquals(1, tracker.count); - assertEquals(oldValue, tracker.event.diff.getOldValue()); - assertEquals(newValue, tracker.event.diff.getNewValue()); - } - - @Test - public void testSetValue_NullConvertedToEmptyString() { - observable.setValue(null); - - assertEquals("", observable.getValue()); - assertEquals("", shell.getText()); - } - - @Test - public void testShellSetText_GetValueReturnsSame() { - assertEquals(oldValue, observable.getValue()); - - shell.setText(newValue); - - assertEquals(newValue, observable.getValue()); - } - - @Test - public void testShellSetText_NoValueChangeEvent() { - shell.setText(newValue); - assertEquals(0, tracker.count); - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(SWTMutableObservableValueContractTest.class, new Delegate()); - suite.addTest(SWTObservableValueContractTest.class, new Delegate()); - } - - static class Delegate extends AbstractObservableValueContractDelegate { - Shell shell; - - @Override - public void setUp() { - super.setUp(); - shell = new Shell(); - } - - @Override - public void tearDown() { - shell.dispose(); - shell = null; - super.tearDown(); - } - - @Override - public IObservableValue createObservableValue(Realm realm) { - return WidgetProperties.text().observe(realm, shell); - } - - @Override - public Object getValueType(IObservableValue observable) { - return String.class; - } - - @Override - public void change(IObservable observable) { - IObservableValue observableValue = (IObservableValue) observable; - observableValue.setValue(createValue(observableValue)); - } - - int counter; - - @Override - public Object createValue(IObservableValue observable) { - return Integer.toString(counter++); - } - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java deleted file mode 100644 index 7f68d855657..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - * Matthew Hall - bug 194734 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Spinner; -import org.junit.Test; - -/** - * @since 3.2 - * - */ -public class SpinnerObservableValueTest extends AbstractSWTTestCase { - @Test - public void testDispose() throws Exception { - Spinner spinner = new Spinner(getShell(), SWT.NONE); - ISWTObservableValue observableValue = SWTObservables.observeSelection(spinner); - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - assertEquals(0, spinner.getSelection()); - assertEquals(0, ((Integer) observableValue.getValue()).intValue()); - - Integer expected1 = Integer.valueOf(1); - spinner.setSelection(expected1.intValue()); - -// assertEquals(1, testCounterValueChangeListener.counter); - assertEquals(expected1.intValue(), spinner.getSelection()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - Integer expected2 = Integer.valueOf(2); - spinner.setSelection(expected2.intValue()); - -// assertEquals(1, testCounterValueChangeListener.counter); - assertEquals(expected2.intValue(), spinner.getSelection()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java deleted file mode 100644 index 75b76c8b168..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Code 9 Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Code 9 Corporation - initial API and implementation - * Chris Aniszczyk - bug 131435 - * Matthew Hall - bugs 194734, 256543 - *******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.internal.databinding.swt.StyledTextTextProperty; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.widgets.Shell; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests to assert the inputs of the StyledTextObservableValue constructor. - */ -public class StyledTextObservableValueTest extends AbstractDefaultRealmTestCase { - private StyledText text; - private ValueChangeEventTracker listener; - - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - - Shell shell = new Shell(); - text = new StyledText(shell, SWT.NONE); - - listener = new ValueChangeEventTracker(); - } - - /** - * Asserts that only valid SWT event types are accepted on construction of - * StyledTextObservableValue. - */ - @Test - public void testConstructorUpdateEventTypes() { - try { - new StyledTextTextProperty(new int[] { SWT.None }); - new StyledTextTextProperty(new int[] { SWT.FocusOut }); - new StyledTextTextProperty(new int[] { SWT.Modify }); - new StyledTextTextProperty(new int[] { SWT.DefaultSelection }); - assertTrue(true); - } catch (IllegalArgumentException e) { - fail(); - } - - try { - new StyledTextTextProperty(new int[] { SWT.Verify }); - fail(); - } catch (IllegalArgumentException e) { - assertTrue(true); - } - } - - /** - * s - * - * @throws Exception - */ - @Test - public void testGetValueBeforeFocusOutChangeEventsFire() throws Exception { - IObservableValue observableValue = SWTObservables.observeText(text, - SWT.FocusOut); - observableValue.addValueChangeListener(listener); - - String a = "a"; - String b = "b"; - - text.setText(a); - - // fetching the value updates the buffered value - assertEquals(a, observableValue.getValue()); - assertEquals(1, listener.count); - - text.setText(b); - - text.notifyListeners(SWT.FocusOut, null); - - assertEquals(2, listener.count); - assertEquals(a, listener.event.diff.getOldValue()); - assertEquals(b, listener.event.diff.getNewValue()); - } - - @Test - public void testDispose() throws Exception { - IObservableValue observableValue = SWTObservables.observeText(text, - SWT.Modify); - ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); - observableValue.addValueChangeListener(testCounterValueChangeListener); - - String expected1 = "Test123"; - text.setText(expected1); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected1, text.getText()); - assertEquals(expected1, observableValue.getValue()); - - observableValue.dispose(); - - String expected2 = "NewValue123"; - text.setText(expected2); - - assertEquals(1, testCounterValueChangeListener.count); - assertEquals(expected2, text.getText()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java deleted file mode 100644 index d432667bc32..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 Brad Reynolds and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Ashley Cambrell - bug 198904 - * Matthew Hall - bug 194734 - ******************************************************************************/ - -package org.eclipse.jface.tests.internal.databinding.swt; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; -import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableItem; -import org.junit.Test; - -/** - * @since 3.2 - */ -public class TableObservableValueTest extends AbstractSWTTestCase { - @Test - public void testDispose() throws Exception { - Table table = new Table(getShell(), SWT.NONE); - IObservableValue observableValue = SWTObservables - .observeSingleSelectionIndex(table); - - TableItem item1 = new TableItem(table, SWT.NONE); - item1.setText("Item1"); - TableItem item2 = new TableItem(table, SWT.NONE); - item2.setText("Item2"); - - assertEquals(-1, table.getSelectionIndex()); - assertEquals(-1, ((Integer) observableValue.getValue()).intValue()); - - table.select(0); - table.notifyListeners(SWT.Selection, null); - - assertEquals(0, table.getSelectionIndex()); - assertEquals(Integer.valueOf(0), observableValue.getValue()); - - observableValue.dispose(); - - table.select(1); - table.notifyListeners(SWT.Selection, null); - assertEquals(1, table.getSelectionIndex()); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java deleted file mode 100644 index f4f6597f0fb..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 Brad Reynolds. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 116920 - * Matthew Hall - bug 194734 - * Ovidio Mallo - bug 270494 - *******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.viewers; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.databinding.observable.list.ListDiff; -import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; -import org.eclipse.jface.databinding.viewers.typed.ViewerProperties; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests for SelectionProviderMultiSelectionObservableList. - * - * @since 1.2 - */ -public class SelectionProviderMultiSelectionObservableListTest { - private IPostSelectionProvider selectionProvider; - - private TableViewer viewer; - - private static String[] model = new String[] { "element0", "element1", - "element2", "element3" }; - - @Before - public void setUp() throws Exception { - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.MULTI); - viewer.setContentProvider(ArrayContentProvider.getInstance()); - viewer.setInput(model); - selectionProvider = viewer; - } - - @After - public void tearDown() throws Exception { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - } - - @Test - public void testConstructorIllegalArgumentException() { - try { - ViewersObservables.observeMultiSelection(null); - fail(); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testAddRemove_NormalSelection() { - doTestAddRemove(false); - } - - @Test - public void testAddRemove_PostSelection() { - doTestAddRemove(true); - } - - /** - * Asserts that when a selection is set on the viewer: - *
    - *
  • the selection is available in the observable
  • - *
  • Value change events are fired with appropriate diff values
  • - *
- * - * @param postSelection - * true for observing the post selection, - * false for observing the normal selection. - */ - private void doTestAddRemove(boolean postSelection) { - IObservableList observable; - if (postSelection) { - observable = ViewerProperties.multiplePostSelection(String.class).observe(selectionProvider); - } else { - observable = ViewerProperties.multipleSelection(String.class).observe(selectionProvider); - } - - ListChangeEventTracker listener = ListChangeEventTracker - .observe(observable); - assertEquals(0, observable.size()); - - selectionProvider.setSelection(new StructuredSelection(model[0])); - assertEquals(1, listener.count); - assertDiff(listener.event.diff, Collections.emptyList(), Collections.singletonList(model[0])); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(1, observable.size()); - assertEquals(model[0], observable.get(0)); - - selectionProvider.setSelection(new StructuredSelection(model[1])); - assertEquals(2, listener.count); - assertEquals(2, listener.event.diff.getDifferences().length); - assertDiff(listener.event.diff, Collections.singletonList(model[0]), - Collections.singletonList(model[1])); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(1, observable.size()); - assertEquals(model[1], observable.get(0)); - - selectionProvider.setSelection(new StructuredSelection(new Object[] { - model[2], model[3] })); - assertEquals(3, listener.count); - assertEquals(3, listener.event.diff.getDifferences().length); - assertDiff(listener.event.diff, Collections.singletonList(model[1]), - Arrays.asList(new Object[] { model[2], model[3] })); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(2, observable.size()); - assertEquals(model[2], observable.get(0)); - assertEquals(model[3], observable.get(1)); - - selectionProvider.setSelection(StructuredSelection.EMPTY); - assertEquals(4, listener.count); - assertEquals(2, listener.event.diff.getDifferences().length); - assertDiff(listener.event.diff, Arrays.asList(model[2], model[3]), Collections.emptyList()); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(0, observable.size()); - - observable.add(model[1]); - assertEquals(5, listener.count); - assertEquals(1, listener.event.diff.getDifferences().length); - assertDiff(listener.event.diff, Collections.emptyList(), Collections - .singletonList(model[1])); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(1, viewer.getStructuredSelection().size()); - - observable.add(0, model[2]); - assertEquals(6, listener.count); - assertEquals(1, listener.event.diff.getDifferences().length); - // This is a bit surprising (we added at index 0 but the event says - // index 1). It is to the fact that the observable list tracks the - // underlying selection provider's notion of which element is at which - // index. - assertDiff(listener.event.diff, Collections.singletonList(model[1]), - Arrays.asList(model[1], model[2])); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(2, viewer.getStructuredSelection().size()); - - observable.clear(); - assertEquals(7, listener.count); - assertEquals(2, listener.event.diff.getDifferences().length); - assertDiff(listener.event.diff, Arrays.asList(model[1], model[2]), Collections.emptyList()); - assertEquals(observable, listener.event.getObservableList()); - assertEquals(0, viewer.getStructuredSelection().size()); - } - - private void assertDiff(ListDiff diff, List oldList, List newList) { - // defensive copy in case arg is unmodifiable - oldList = new ArrayList<>(oldList); - diff.applyTo(oldList); - assertEquals("applying diff to list did not produce expected result", - newList, oldList); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java deleted file mode 100644 index 280467f0f6b..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 Brad Reynolds. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Brad Reynolds - initial API and implementation - * Brad Reynolds - bug 116920 - * Ashley Cambrell - bug 198906 - * Matthew Hall - bug 194734 - * Ovidio Mallo - bug 270494 - *******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.viewers; - -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.viewers.typed.ViewerProperties; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import junit.framework.TestCase; - -/** - * Tests for SelectionProviderSingleSelectionObservableValue. - * - * @since 1.1 - */ -public class SelectionProviderSingleSelectionObservableValueTest extends - TestCase { - private IPostSelectionProvider selectionProvider; - - private TableViewer viewer; - - private static String[] model = new String[] { "0", "1" }; - - @Override - @Before - public void setUp() throws Exception { - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - viewer.setContentProvider(ArrayContentProvider.getInstance()); - viewer.setInput(model); - selectionProvider = viewer; - } - - @Override - @After - public void tearDown() throws Exception { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - } - - @Test - public void testConstructorIllegalArgumentException() { - try { - ViewersObservables.observeSingleSelection(null); - fail(); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void testSetValue() { - IObservableValue observable = ViewerProperties.singleSelection(String.class).observe(selectionProvider); - - ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); - assertNull(observable.getValue()); - assertEquals(0, listener.count); - - observable.setValue(model[0]); - assertEquals(model[0], getSelectedElement(selectionProvider)); - assertEquals(model[0], observable.getValue()); - assertEquals(1, listener.count); - - observable.setValue(model[1]); - assertEquals(model[1], getSelectedElement(selectionProvider)); - assertEquals(model[1], observable.getValue()); - assertEquals(2, listener.count); - - observable.setValue(null); - assertTrue(selectionProvider.getSelection().isEmpty()); - assertEquals(3, listener.count); - } - - @Test - public void testSelectionChangesTracked() { - doTestSelectionChangesTracked(false); - } - - @Test - public void testPostSelectionChangesTracked() { - doTestSelectionChangesTracked(true); - } - - /** - * Asserts that when a selection is set on the viewer: - *
    - *
  • the selection is available in the observable
  • - *
  • Value change events are fired with appropriate diff values
  • - *
- * - * @param postSelection - * true for observing the post selection, - * false for observing the normal selection. - */ - private void doTestSelectionChangesTracked(boolean postSelection) { - IObservableValue observable; - if (postSelection) { - observable = ViewersObservables - .observeSinglePostSelection(selectionProvider); - } else { - observable = ViewersObservables - .observeSingleSelection(selectionProvider); - } - - ValueChangeEventTracker listener = ValueChangeEventTracker - .observe(observable); - assertNull(observable.getValue()); - - selectionProvider.setSelection(new StructuredSelection(model[0])); - assertEquals(1, listener.count); - assertNull(listener.event.diff.getOldValue()); - assertEquals(model[0], listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(model[0], observable.getValue()); - - selectionProvider.setSelection(new StructuredSelection(model[1])); - assertEquals(2, listener.count); - assertEquals(model[0], listener.event.diff.getOldValue()); - assertEquals(model[1], listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(model[1], observable.getValue()); - - selectionProvider.setSelection(StructuredSelection.EMPTY); - assertEquals(3, listener.count); - assertEquals(model[1], listener.event.diff.getOldValue()); - assertNull(listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(null, observable.getValue()); - } - - @Test - public void testDispose() throws Exception { - IObservableValue observable = ViewersObservables - .observeSingleSelection(selectionProvider); - ValueChangeEventTracker listener = ValueChangeEventTracker - .observe(observable); - - selectionProvider.setSelection(new StructuredSelection(model[0])); - assertEquals(1, listener.count); - assertNull(listener.event.diff.getOldValue()); - assertEquals(model[0], listener.event.diff.getNewValue()); - assertEquals(observable, listener.event.getObservableValue()); - assertEquals(model[0], observable.getValue()); - - observable.dispose(); - selectionProvider.setSelection(new StructuredSelection(model[1])); - assertEquals(1, listener.count); - } - - private static Object getSelectedElement( - ISelectionProvider selectionProvider) { - return ((IStructuredSelection) selectionProvider.getSelection()) - .getFirstElement(); - } -} diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java deleted file mode 100644 index 4865f6e7041..00000000000 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 206839) - * Matthew Hall - bug 213145, 194734, 195222 - *******************************************************************************/ -package org.eclipse.jface.tests.internal.databinding.viewers; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; - -import org.eclipse.core.databinding.observable.IObservable; -import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.observable.value.ValueChangeEvent; -import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; -import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; -import org.eclipse.jface.databinding.conformance.util.TestCollection; -import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; -import org.eclipse.jface.databinding.viewers.ViewersObservables; -import org.eclipse.jface.databinding.viewers.typed.ViewerProperties; -import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Shell; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * Tests for ViewerInputObservableValue. - * - * @since 1.2 - */ -public class ViewerInputObservableValueTest extends AbstractDefaultRealmTestCase { - private TableViewer viewer; - private static String[] model = new String[] { "0", "1" }; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - viewer.setContentProvider(new ContentProvider()); - } - - @Override - @After - public void tearDown() throws Exception { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - super.tearDown(); - } - - @Test - public void testConstructor_IllegalArgumentException() { - try { - ViewersObservables.observeInput(null); - fail("Expected IllegalArgumentException for null argument"); - } catch (IllegalArgumentException expected) { - } - } - - @Test - public void testSetInputOnViewer_FiresChangeEventOnGetValue() { - IObservableValue observable = ViewersObservables.observeInput(viewer); - ValueChangeEventTracker listener = ValueChangeEventTracker - .observe(observable); - - assertNull(viewer.getInput()); - assertEquals(0, listener.count); - - viewer.setInput(model); - - assertEquals(model, viewer.getInput()); - assertEquals(0, listener.count); - - // Call to getValue() causes observable to discover change - assertEquals(model, observable.getValue()); - assertEquals(1, listener.count); - - viewer.setInput(null); - assertEquals(null, viewer.getInput()); - - assertEquals(null, observable.getValue()); - assertEquals(2, listener.count); - } - - @Test - public void testGetSetValue_FiresChangeEvents() { - IObservableValue observable = ViewersObservables.observeInput(viewer); - ValueChangeEventTracker listener = new ValueChangeEventTracker(); - observable.addValueChangeListener(listener); - - assertNull(observable.getValue()); - assertEquals(0, listener.count); - - observable.setValue(model); - - assertEquals(model, observable.getValue()); - assertEquals(1, listener.count); - assertValueChangeEventEquals(observable, null, model, listener.event); - - observable.setValue(null); - - assertNull(observable.getValue()); - assertEquals(2, listener.count); - assertValueChangeEventEquals(observable, model, null, listener.event); - } - - @Test - public void testGetValueType_AlwaysNull() throws Exception { - IObservableValue observable = ViewersObservables.observeInput(viewer); - assertEquals(null, observable.getValueType()); - } - - @Test - public void testDispose() throws Exception { - IObservableValue observable = ViewersObservables.observeInput(viewer); - observable.dispose(); - try { - observable.setValue(model); - fail("Expected NullPointerException"); - } catch (NullPointerException expected) { - } - } - - private void assertValueChangeEventEquals( - IObservableValue expectedObservable, Object expectedOldValue, - Object expectedNewValue, ValueChangeEvent event) { - assertSame(expectedObservable, event.getObservableValue()); - assertEquals(expectedOldValue, event.diff.getOldValue()); - assertEquals(expectedNewValue, event.diff.getNewValue()); - } - - static class ContentProvider implements IStructuredContentProvider { - @Override - public Object[] getElements(Object inputElement) { - return (String[]) inputElement; - } - } - - public static void addConformanceTest(TestCollection suite) { - suite.addTest(MutableObservableValueContractTest.class, new Delegate()); - } - - static class Delegate extends AbstractObservableValueContractDelegate { - TableViewer viewer; - - @Override - public void setUp() { - super.setUp(); - Shell shell = new Shell(); - viewer = new TableViewer(shell, SWT.NONE); - viewer.setContentProvider(new ContentProvider()); - } - - @Override - public void tearDown() { - Shell shell = viewer.getTable().getShell(); - if (!shell.isDisposed()) - shell.dispose(); - super.tearDown(); - } - - @Override - public IObservableValue createObservableValue(Realm realm) { - return ViewerProperties.input().observe(realm, viewer); - } - - @Override - public void change(IObservable observable) { - IObservableValue value = (IObservableValue) observable; - value.setValue(createValue(value)); - } - - @Override - public Object createValue(IObservableValue observable) { - return new String[] { "one", "two" }; - } - - @Override - public Object getValueType(IObservableValue observable) { - return null; - } - } -} diff --git a/tests/org.eclipse.ui.tests.navigator/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests.navigator/META-INF/MANIFEST.MF index 6acecbbfc48..501f1bf5fec 100644 --- a/tests/org.eclipse.ui.tests.navigator/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.tests.navigator/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %bundlename Bundle-SymbolicName: org.eclipse.ui.tests.navigator;singleton:=true -Bundle-Version: 3.6.300.qualifier +Bundle-Version: 3.6.400.qualifier Bundle-Localization: plugin Require-Bundle: org.eclipse.core.resources, org.eclipse.core.runtime, diff --git a/tests/org.eclipse.ui.tests.performance/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests.performance/META-INF/MANIFEST.MF index 94d3d07ad82..096d50d6d07 100644 --- a/tests/org.eclipse.ui.tests.performance/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.tests.performance/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Performance Plug-in Bundle-SymbolicName: org.eclipse.ui.tests.performance;singleton:=true -Bundle-Version: 1.4.300.qualifier +Bundle-Version: 1.4.400.qualifier Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.core.tests.harness, diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/TestBackgroundSaveEditor.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/TestBackgroundSaveEditor.java index fb31c17b5b1..85ab38b8415 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/TestBackgroundSaveEditor.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/TestBackgroundSaveEditor.java @@ -18,7 +18,7 @@ import java.beans.PropertyChangeSupport; import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.beans.typed.BeanProperties; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.runtime.Assert; @@ -28,7 +28,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jface.databinding.swt.DisplayRealm; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -196,10 +196,9 @@ public void createPartControl(Composite parent) { final DataBindingContext dbc = new DataBindingContext(realm); parent.addDisposeListener(e -> dbc.dispose()); - final IObservableValue inputObservable = BeansObservables.observeValue( - realm, data, "input"); - final IObservableValue outputObservable = BeansObservables - .observeValue(realm, data, "output"); + final IObservableValue inputObservable = BeanProperties.value("input").observe(data); + final IObservableValue outputObservable = BeanProperties.value("output").observe(data); + createInputGroup(parent, dbc, inputObservable); createOptionsGroup(parent, realm, dbc); @@ -217,7 +216,8 @@ private void createOutputGroup(Composite parent, Text outputText = new Text(outputGroup, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI); GridDataFactory.fillDefaults().grab(true, true).applyTo(outputText); - dbc.bindValue(SWTObservables.observeText(outputText, SWT.NONE), + + dbc.bindValue(WidgetProperties.text().observe(outputText), outputObservable, null, null); GridLayoutFactory.swtDefaults().generateLayout(outputGroup); } @@ -229,9 +229,10 @@ private void createOptionsGroup(Composite parent, Realm realm, Button dirtyButton = new Button(optionsGroup, SWT.CHECK); new Label(optionsGroup, SWT.NONE).setText("Editor is dirty"); - IObservableValue dirtyObservable = BeansObservables.observeValue(realm, - mySaveable, "dirty"); - dbc.bindValue(SWTObservables.observeSelection(dirtyButton), + + IObservableValue dirtyObservable = BeanProperties.value("dirty").observe(mySaveable); + + dbc.bindValue(WidgetProperties.buttonSelection().observe(dirtyButton), dirtyObservable, null, null); // IObservableValue inputAndOutputDiffer = new ComputedValue(realm) { // protected Object calculate() { @@ -244,35 +245,35 @@ private void createOptionsGroup(Composite parent, Realm realm, Button saveInBackgroundButton = new Button(optionsGroup, SWT.CHECK); new Label(optionsGroup, SWT.NONE) .setText("Do part of the save in the background"); - dbc.bindValue(SWTObservables.observeSelection(saveInBackgroundButton), - BeansObservables.observeValue(realm, data, "saveInBackground"), + + dbc.bindValue(WidgetProperties.buttonSelection().observe(saveInBackgroundButton), + BeanProperties.value("saveInBackground").observe(data), null, null); Button foregroundExceptionButton = new Button(optionsGroup, SWT.CHECK); new Label(optionsGroup, SWT.NONE) .setText("Throw exception while saving in the foreground"); - dbc.bindValue(SWTObservables - .observeSelection(foregroundExceptionButton), BeansObservables - .observeValue(realm, data, "throwExceptionInForeground"), null, null); + dbc.bindValue(WidgetProperties.buttonSelection().observe(foregroundExceptionButton), + + BeanProperties.value("throwExceptionInForeground").observe(data), null, null); Button backgroundExceptionButton = new Button(optionsGroup, SWT.CHECK); new Label(optionsGroup, SWT.NONE) .setText("Throw exception while saving in the background"); - dbc.bindValue(SWTObservables - .observeSelection(backgroundExceptionButton), BeansObservables - .observeValue(realm, data, "throwExceptionInBackground"), null, null); + dbc.bindValue( + WidgetProperties.buttonSelection().observe(backgroundExceptionButton), + BeanProperties.value("throwExceptionInBackground").observe(data), null, null); + ; new Label(optionsGroup, SWT.NONE).setText("Foreground save time:"); Text optionsForegroundTime = new Text(optionsGroup, SWT.BORDER); - dbc.bindValue(SWTObservables.observeText(optionsForegroundTime, - SWT.Modify), BeansObservables.observeValue(realm, data, - "foregroundSaveTime"), null, null); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(optionsForegroundTime), + BeanProperties.value("foregroundSaveTime").observe(data), null, null); new Label(optionsGroup, SWT.NONE).setText("Background save time:"); Text optionsBackgroundTime = new Text(optionsGroup, SWT.BORDER); - dbc.bindValue(SWTObservables.observeText(optionsBackgroundTime, - SWT.Modify), BeansObservables.observeValue(realm, data, - "backgroundSaveTime"), null, null); + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(optionsBackgroundTime), + BeanProperties.value("backgroundSaveTime").observe(data), null, null); GridLayoutFactory.swtDefaults().numColumns(2).generateLayout( optionsGroup); @@ -284,7 +285,7 @@ private void createInputGroup(Composite parent, inputGroup.setText("Input"); inputText = new Text(inputGroup, SWT.BORDER | SWT.MULTI); - dbc.bindValue(SWTObservables.observeText(inputText, SWT.Modify), + dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(inputText), inputObservable, null, null); GridLayoutFactory.swtDefaults().generateLayout(inputGroup); diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/ViewWithSaveables.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/ViewWithSaveables.java index 67abd766eb8..88511ddb382 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/ViewWithSaveables.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/manual/ViewWithSaveables.java @@ -30,7 +30,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider; -import org.eclipse.jface.databinding.viewers.ViewersObservables; +import org.eclipse.jface.databinding.viewers.typed.ViewerProperties; import org.eclipse.jface.internal.databinding.provisional.swt.ControlUpdater; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -104,7 +104,9 @@ public void widgetSelected(SelectionEvent e) { } }); } - selection = ViewersObservables.observeSingleSelection(viewer); + + + selection = ViewerProperties.singleSelection().observe(viewer); { final Button button = new Button(parent, SWT.PUSH); button.setText("Remove"); diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java index 5cfe57fd9b2..c12c158fa19 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2017 IBM Corporation and others. + * Copyright (c) 2011, 2022 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -24,6 +24,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.ui.internal.progress.JobInfo; +import org.eclipse.ui.internal.progress.JobSnapshot; import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.Before; import org.junit.Rule; @@ -91,10 +92,10 @@ public void setUp() throws Exception { @Test public void testCompareToContractCompliance() { for(int xi = 0; xi0) && (compare(y, z)>0)) implies compare(x, z)>0. diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java index a3c8d057833..7bfe9a85f84 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/progress/JobInfoTestOrdering.java @@ -24,6 +24,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.ui.internal.progress.JobInfo; +import org.eclipse.ui.internal.progress.JobSnapshot; import org.eclipse.ui.tests.harness.util.TestRunLogUtil; import org.junit.Rule; import org.junit.Test; @@ -39,7 +40,7 @@ public class JobInfoTestOrdering { */ @Test public void testJobStateOrdering() { - List jobinfos = new ArrayList<>(); + List jobinfos = new ArrayList<>(); int counter = 0; TestJob job; JobInfo ji; @@ -50,7 +51,7 @@ public void testJobStateOrdering() { job.setPriority(Job.INTERACTIVE); job.setInternalJobState(Job.NONE); // JOB STATE ji = new ExtendedJobInfo(job); - jobinfos.add(ji); + jobinfos.add(new JobSnapshot(ji)); job = new TestJob("Job" + (counter++)); job.setUser(true); @@ -58,7 +59,7 @@ public void testJobStateOrdering() { job.setPriority(Job.INTERACTIVE); job.setInternalJobState(Job.SLEEPING); // JOB STATE ji = new ExtendedJobInfo(job); - jobinfos.add(ji); + jobinfos.add(new JobSnapshot(ji)); job = new TestJob("Job" + (counter++)); job.setUser(true); @@ -66,7 +67,7 @@ public void testJobStateOrdering() { job.setPriority(Job.INTERACTIVE); job.setInternalJobState(Job.WAITING); // JOB STATE ji = new ExtendedJobInfo(job); - jobinfos.add(ji); + jobinfos.add(new JobSnapshot(ji)); job = new TestJob("Job" + (counter++)); job.setUser(true); @@ -74,13 +75,13 @@ public void testJobStateOrdering() { job.setPriority(Job.INTERACTIVE); job.setInternalJobState(Job.RUNNING); // JOB STATE ji = new ExtendedJobInfo(job); - jobinfos.add(ji); + jobinfos.add(new JobSnapshot(ji)); jobinfos.sort(null); - assertEquals(Job.RUNNING, jobinfos.get(0).getJob().getState()); - assertEquals(Job.WAITING, jobinfos.get(1).getJob().getState()); - assertEquals(Job.SLEEPING, jobinfos.get(2).getJob().getState()); - assertEquals(Job.NONE, jobinfos.get(3).getJob().getState()); + assertEquals(Job.RUNNING, jobinfos.get(0).getState()); + assertEquals(Job.WAITING, jobinfos.get(1).getState()); + assertEquals(Job.SLEEPING, jobinfos.get(2).getState()); + assertEquals(Job.NONE, jobinfos.get(3).getState()); } /** @@ -89,35 +90,35 @@ public void testJobStateOrdering() { */ @Test public void testJobPriorityOrdering() { - List jobInfos = new ArrayList<>(); + List jobInfos = new ArrayList<>(); Job job; job = new TestJob("TestJob"); job.setPriority(Job.DECORATE); - jobInfos.add(new ExtendedJobInfo(job)); + jobInfos.add(new JobSnapshot(new ExtendedJobInfo(job))); job = new TestJob("TestJob"); job.setPriority(Job.BUILD); - jobInfos.add(new ExtendedJobInfo(job)); + jobInfos.add(new JobSnapshot(new ExtendedJobInfo(job))); job = new TestJob("TestJob"); job.setPriority(Job.LONG); - jobInfos.add(new ExtendedJobInfo(job)); + jobInfos.add(new JobSnapshot(new ExtendedJobInfo(job))); job = new TestJob("TestJob"); job.setPriority(Job.SHORT); - jobInfos.add(new ExtendedJobInfo(job)); + jobInfos.add(new JobSnapshot(new ExtendedJobInfo(job))); job = new TestJob("TestJob"); job.setPriority(Job.INTERACTIVE); - jobInfos.add(new ExtendedJobInfo(job)); + jobInfos.add(new JobSnapshot(new ExtendedJobInfo(job))); Collections.shuffle(jobInfos); jobInfos.sort(null); - assertEquals(Job.INTERACTIVE, jobInfos.get(0).getJob().getPriority()); - assertEquals(Job.SHORT, jobInfos.get(1).getJob().getPriority()); - assertEquals(Job.LONG, jobInfos.get(2).getJob().getPriority()); - assertEquals(Job.BUILD, jobInfos.get(3).getJob().getPriority()); - assertEquals(Job.DECORATE, jobInfos.get(4).getJob().getPriority()); + assertEquals(Job.INTERACTIVE, jobInfos.get(0).getPriority()); + assertEquals(Job.SHORT, jobInfos.get(1).getPriority()); + assertEquals(Job.LONG, jobInfos.get(2).getPriority()); + assertEquals(Job.BUILD, jobInfos.get(3).getPriority()); + assertEquals(Job.DECORATE, jobInfos.get(4).getPriority()); } } diff --git a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF index 7d0ad4f43c1..7a3db4f0fd7 100644 --- a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Eclipse UI Tests Bundle-SymbolicName: org.eclipse.ui.tests; singleton:=true -Bundle-Version: 3.15.800.qualifier +Bundle-Version: 3.15.900.qualifier Eclipse-BundleShape: dir Bundle-Activator: org.eclipse.ui.tests.TestPlugin Bundle-Vendor: Eclipse.org