Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 120651 Details for
Bug 194734
[Databinding] Property-based observables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
clipboard.txt (text/plain), 488.94 KB, created by
Matthew Hall
on 2008-12-16 20:05:15 EST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Matthew Hall
Created:
2008-12-16 20:05:15 EST
Size:
488.94 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.databinding.beans >Index: src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableMap.java >diff -N src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableMap.java >--- src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableMap.java 11 Nov 2008 16:05:38 -0000 1.6 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,193 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2006, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 171616 >- * Matthew hall - bugs 223164, 241585, 226289, 246103 >- *******************************************************************************/ >- >-package org.eclipse.core.internal.databinding.beans; >- >-import java.beans.PropertyChangeListener; >-import java.beans.PropertyDescriptor; >-import java.lang.reflect.Method; >-import java.util.HashMap; >-import java.util.Map; >- >-import org.eclipse.core.databinding.beans.IBeanObservable; >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.map.ComputedObservableMap; >-import org.eclipse.core.databinding.observable.set.IObservableSet; >-import org.eclipse.core.databinding.util.Policy; >-import org.eclipse.core.internal.databinding.Util; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; >- >-/** >- * @since 1.0 >- * >- */ >-public class JavaBeanObservableMap extends ComputedObservableMap implements >- IBeanObservable { >- >- private PropertyDescriptor propertyDescriptor; >- >- private PropertyChangeListener elementListener = new PropertyChangeListener() { >- public void propertyChange(final java.beans.PropertyChangeEvent event) { >- if (!updating) { >- getRealm().exec(new Runnable() { >- public void run() { >- Object source = event.getSource(); >- Object oldValue = event.getOldValue(); >- Object newValue = event.getNewValue(); >- if (oldValue == null && newValue == null) { >- oldValue = cachedValues.get(new IdentityWrapper( >- source)); >- newValue = doGet(source); >- } >- cachedValues.put(new IdentityWrapper(source), newValue); >- if (!Util.equals(oldValue, newValue)) { >- fireMapChange(Diffs.createMapDiffSingleChange( >- source, oldValue, newValue)); >- } >- } >- }); >- } >- } >- }; >- >- private ListenerSupport listenerSupport; >- >- private boolean updating = false; >- >- private boolean attachListeners; >- >- // Applicable only while hasListeners() == true >- private Map cachedValues; >- >- /** >- * @param domain >- * @param propertyDescriptor >- */ >- public JavaBeanObservableMap(IObservableSet domain, >- PropertyDescriptor propertyDescriptor) { >- this(domain, propertyDescriptor, true); >- } >- >- /** >- * @param domain >- * @param propertyDescriptor >- * @param attachListeners >- */ >- public JavaBeanObservableMap(IObservableSet domain, >- PropertyDescriptor propertyDescriptor, boolean attachListeners) { >- super(domain, propertyDescriptor.getPropertyType()); >- >- this.propertyDescriptor = propertyDescriptor; >- this.attachListeners = attachListeners; >- if (attachListeners) { >- this.listenerSupport = new ListenerSupport(elementListener, >- propertyDescriptor.getName()); >- } >- } >- >- protected void firstListenerAdded() { >- if (attachListeners) { >- cachedValues = new HashMap(); >- } >- super.firstListenerAdded(); >- } >- >- protected void lastListenerRemoved() { >- super.lastListenerRemoved(); >- if (attachListeners) { >- cachedValues = null; >- } >- } >- >- protected void hookListener(Object domainElement) { >- if (attachListeners && domainElement != null) { >- listenerSupport.hookListener(domainElement); >- cachedValues.put(new IdentityWrapper(domainElement), >- doGet(domainElement)); >- } >- } >- >- protected void unhookListener(Object domainElement) { >- if (attachListeners && domainElement != null) { >- cachedValues.remove(new IdentityWrapper(domainElement)); >- listenerSupport.unhookListener(domainElement); >- } >- } >- >- protected Object doGet(Object key) { >- if (key == null) { >- return null; >- } >- try { >- Method readMethod = propertyDescriptor.getReadMethod(); >- if (!readMethod.isAccessible()) { >- readMethod.setAccessible(true); >- } >- return readMethod.invoke(key, new Object[0]); >- } catch (Exception e) { >- Policy.getLog().log( >- new Status(IStatus.ERROR, Policy.JFACE_DATABINDING, >- IStatus.ERROR, "cannot get value", e)); //$NON-NLS-1$ >- throw new RuntimeException(e); >- } >- } >- >- protected Object doPut(Object key, Object value) { >- try { >- Object oldValue = get(key); >- if (!Util.equals(oldValue, value)) { >- Method writeMethod = propertyDescriptor.getWriteMethod(); >- if (!writeMethod.isAccessible()) { >- writeMethod.setAccessible(true); >- } >- writeMethod.invoke(key, new Object[] { value }); >- } >- >- if (hasListeners()) { >- // oldValue contains the live value which may be different from >- // the cached value if the bean does not have listener API or >- // does not fire events properly. For consistency we want to >- // provide the cached value as the old value, rather than the >- // live value so that consumers that hook/unhook listeners can >- // do so without maintaining caches of their own. >- Object newValue = doGet(key); >- oldValue = cachedValues.put(new IdentityWrapper(key), newValue); >- >- if (!Util.equals(oldValue, newValue)) { >- fireSingleChange(key, oldValue, newValue); >- } >- } >- return oldValue; >- } catch (Exception e) { >- Policy.getLog().log( >- new Status(IStatus.ERROR, Policy.JFACE_DATABINDING, >- IStatus.ERROR, "cannot set value", e)); //$NON-NLS-1$ >- throw new RuntimeException(e); >- } >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.core.databinding.beans.IBeanObservable#getObserved() >- */ >- public Object getObserved() { >- return keySet(); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.core.databinding.beans.IBeanObservable#getPropertyDescriptor() >- */ >- public PropertyDescriptor getPropertyDescriptor() { >- return propertyDescriptor; >- } >-} >Index: src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableList.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableList.java >diff -N src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableList.java >--- src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableList.java 26 Oct 2008 13:06:52 -0000 1.4 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,399 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2006-2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 171616 >- * Matthew Hall - bugs 208858, 221351, 213145, 223164, 244098 >- * Mike Evans - bug 217558 >- *******************************************************************************/ >- >-package org.eclipse.core.internal.databinding.beans; >- >-import java.beans.PropertyChangeListener; >-import java.beans.PropertyDescriptor; >-import java.lang.reflect.Array; >-import java.lang.reflect.InvocationTargetException; >-import java.lang.reflect.Method; >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.Collection; >-import java.util.Iterator; >-import java.util.List; >- >-import org.eclipse.core.databinding.BindingException; >-import org.eclipse.core.databinding.beans.IBeanObservable; >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.list.ListDiffEntry; >-import org.eclipse.core.databinding.observable.list.ObservableList; >- >-/** >- * @since 1.0 >- * >- */ >-public class JavaBeanObservableList extends ObservableList implements >- IBeanObservable { >- >- private final Object object; >- >- private boolean updating = false; >- >- private PropertyDescriptor descriptor; >- >- private ListenerSupport listenerSupport; >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- * @param elementType >- */ >- public JavaBeanObservableList(Realm realm, Object object, >- PropertyDescriptor descriptor, Class elementType) { >- this(realm, object, descriptor, elementType, true); >- } >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- * @param elementType >- * @param attachListeners >- */ >- public JavaBeanObservableList(Realm realm, Object object, >- PropertyDescriptor descriptor, Class elementType, >- boolean attachListeners) { >- >- super(realm, new ArrayList(), elementType); >- this.object = object; >- this.descriptor = descriptor; >- >- if (attachListeners) { >- PropertyChangeListener listener = new PropertyChangeListener() { >- public void propertyChange(java.beans.PropertyChangeEvent event) { >- if (!updating) { >- getRealm().exec(new Runnable() { >- public void run() { >- updateWrappedList(new ArrayList(Arrays >- .asList(getValues()))); >- } >- }); >- } >- } >- }; >- this.listenerSupport = new ListenerSupport(listener, >- descriptor.getName()); >- listenerSupport.hookListener(this.object); >- } >- >- // initialize list without firing events >- wrappedList.addAll(Arrays.asList(getValues())); >- } >- >- public void dispose() { >- if (listenerSupport != null) { >- listenerSupport.dispose(); >- listenerSupport = null; >- } >- super.dispose(); >- } >- >- private Object primGetValues() { >- Exception ex = null; >- try { >- Method readMethod = descriptor.getReadMethod(); >- if (!readMethod.isAccessible()) { >- readMethod.setAccessible(true); >- } >- return readMethod.invoke(object, new Object[0]); >- } catch (IllegalArgumentException e) { >- ex = e; >- } catch (IllegalAccessException e) { >- ex = e; >- } catch (InvocationTargetException e) { >- ex = e; >- } >- throw new BindingException("Could not read collection values", ex); //$NON-NLS-1$ >- } >- >- private Object[] getValues() { >- Object[] values = null; >- >- Object result = primGetValues(); >- if (descriptor.getPropertyType().isArray()) >- values = (Object[]) result; >- else { >- // TODO add jUnit for POJO (var. SettableValue) collections >- Collection list = (Collection) result; >- if (list != null) { >- values = list.toArray(); >- } >- } >- if (values == null) >- values = new Object[0]; >- return values; >- } >- >- public Object getObserved() { >- return object; >- } >- >- public PropertyDescriptor getPropertyDescriptor() { >- return descriptor; >- } >- >- private void setValues() { >- if (descriptor.getPropertyType().isArray()) { >- Class componentType = descriptor.getPropertyType() >- .getComponentType(); >- Object[] newArray = (Object[]) Array.newInstance(componentType, >- wrappedList.size()); >- wrappedList.toArray(newArray); >- primSetValues(newArray); >- } else { >- // assume that it is a java.util.List >- primSetValues(new ArrayList(wrappedList)); >- } >- } >- >- private void primSetValues(Object newValue) { >- Exception ex = null; >- try { >- Method writeMethod = descriptor.getWriteMethod(); >- if (!writeMethod.isAccessible()) { >- writeMethod.setAccessible(true); >- } >- writeMethod.invoke(object, new Object[] { newValue }); >- return; >- } catch (IllegalArgumentException e) { >- ex = e; >- } catch (IllegalAccessException e) { >- ex = e; >- } catch (InvocationTargetException e) { >- ex = e; >- } >- throw new BindingException("Could not write collection values", ex); //$NON-NLS-1$ >- } >- >- public Object set(int index, Object element) { >- getterCalled(); >- updating = true; >- try { >- Object oldElement = wrappedList.set(index, element); >- setValues(); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >- index, false, oldElement), Diffs.createListDiffEntry(index, >- true, element))); >- return oldElement; >- } finally { >- updating = false; >- } >- } >- >- public Object move(int oldIndex, int newIndex) { >- getterCalled(); >- updating = true; >- try { >- int size = wrappedList.size(); >- if (oldIndex < 0 || oldIndex >= size) >- throw new IndexOutOfBoundsException( >- "oldIndex: " + oldIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ >- if (newIndex < 0 || newIndex >= size) >- throw new IndexOutOfBoundsException( >- "newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$ >- if (oldIndex == newIndex) >- return wrappedList.get(oldIndex); >- Object element = wrappedList.remove(oldIndex); >- wrappedList.add(newIndex, element); >- setValues(); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >- oldIndex, false, element), Diffs.createListDiffEntry( >- newIndex, true, element))); >- return element; >- } finally { >- updating = false; >- } >- } >- >- public Object remove(int index) { >- getterCalled(); >- updating = true; >- try { >- Object oldElement = wrappedList.remove(index); >- setValues(); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >- index, false, oldElement))); >- return oldElement; >- } finally { >- updating = false; >- } >- } >- >- public boolean add(Object element) { >- updating = true; >- try { >- int index = wrappedList.size(); >- boolean result = wrappedList.add(element); >- setValues(); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >- index, true, element))); >- return result; >- } finally { >- updating = false; >- } >- } >- >- public void add(int index, Object element) { >- updating = true; >- try { >- wrappedList.add(index, element); >- setValues(); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >- index, true, element))); >- } finally { >- updating = false; >- } >- } >- >- public boolean addAll(Collection c) { >- if (c.isEmpty()) { >- return false; >- } >- updating = true; >- try { >- int index = wrappedList.size(); >- boolean result = wrappedList.addAll(c); >- setValues(); >- ListDiffEntry[] entries = new ListDiffEntry[c.size()]; >- int i = 0; >- for (Iterator it = c.iterator(); it.hasNext();) { >- Object o = it.next(); >- entries[i++] = Diffs.createListDiffEntry(index++, true, o); >- } >- fireListChange(Diffs.createListDiff(entries)); >- return result; >- } finally { >- updating = false; >- } >- } >- >- public boolean addAll(int index, Collection c) { >- if (c.isEmpty()) { >- return false; >- } >- updating = true; >- try { >- boolean result = wrappedList.addAll(index, c); >- setValues(); >- ListDiffEntry[] entries = new ListDiffEntry[c.size()]; >- int i = 0; >- for (Iterator it = c.iterator(); it.hasNext();) { >- Object o = it.next(); >- entries[i++] = Diffs.createListDiffEntry(index++, true, o); >- } >- fireListChange(Diffs.createListDiff(entries)); >- return result; >- } finally { >- updating = false; >- } >- } >- >- public boolean remove(Object o) { >- getterCalled(); >- int index = wrappedList.indexOf(o); >- if (index == -1) { >- return false; >- } >- updating = true; >- try { >- Object oldElement = wrappedList.remove(index); >- setValues(); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >- index, false, oldElement))); >- return true; >- } finally { >- updating = false; >- } >- } >- >- public boolean removeAll(Collection c) { >- getterCalled(); >- boolean changed = false; >- updating = true; >- try { >- List diffEntries = new ArrayList(); >- for (Iterator it = c.iterator(); it.hasNext();) { >- Object o = it.next(); >- int index = wrappedList.indexOf(o); >- if (index != -1) { >- changed = true; >- Object oldElement = wrappedList.remove(index); >- diffEntries.add(Diffs.createListDiffEntry(index, false, >- oldElement)); >- } >- } >- if (changed) { >- setValues(); >- fireListChange(Diffs >- .createListDiff((ListDiffEntry[]) diffEntries >- .toArray(new ListDiffEntry[diffEntries.size()]))); >- } >- return changed; >- } finally { >- updating = false; >- } >- } >- >- public boolean retainAll(Collection c) { >- getterCalled(); >- boolean changed = false; >- updating = true; >- try { >- List diffEntries = new ArrayList(); >- int index = 0; >- for (Iterator it = wrappedList.iterator(); it.hasNext();) { >- Object o = it.next(); >- boolean retain = c.contains(o); >- if (retain) { >- index++; >- } else { >- changed = true; >- it.remove(); >- diffEntries.add(Diffs.createListDiffEntry(index, false, o)); >- } >- } >- if (changed) { >- setValues(); >- fireListChange(Diffs >- .createListDiff((ListDiffEntry[]) diffEntries >- .toArray(new ListDiffEntry[diffEntries.size()]))); >- } >- return changed; >- } finally { >- updating = false; >- } >- } >- >- public void clear() { >- updating = true; >- try { >- List diffEntries = new ArrayList(); >- for (Iterator it = wrappedList.iterator(); it.hasNext();) { >- Object o = it.next(); >- diffEntries.add(Diffs.createListDiffEntry(0, false, o)); >- } >- wrappedList.clear(); >- setValues(); >- fireListChange(Diffs.createListDiff((ListDiffEntry[]) diffEntries >- .toArray(new ListDiffEntry[diffEntries.size()]))); >- } finally { >- updating = false; >- } >- } >- >-} >Index: src/org/eclipse/core/internal/databinding/beans/JavaBeanPropertyObservableMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/JavaBeanPropertyObservableMap.java >diff -N src/org/eclipse/core/internal/databinding/beans/JavaBeanPropertyObservableMap.java >--- src/org/eclipse/core/internal/databinding/beans/JavaBeanPropertyObservableMap.java 11 Nov 2008 16:05:38 -0000 1.4 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,263 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Matthew Hall and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Matthew Hall - initial API and implementation (bug 221704) >- * Matthew Hall - bug 223164, 226289, 244098, 246103 >- *******************************************************************************/ >- >-package org.eclipse.core.internal.databinding.beans; >- >-import java.beans.PropertyChangeEvent; >-import java.beans.PropertyChangeListener; >-import java.beans.PropertyDescriptor; >-import java.lang.reflect.InvocationTargetException; >-import java.lang.reflect.Method; >-import java.util.Collections; >-import java.util.HashMap; >-import java.util.HashSet; >-import java.util.Iterator; >-import java.util.Map; >-import java.util.Set; >- >-import org.eclipse.core.databinding.BindingException; >-import org.eclipse.core.databinding.beans.IBeanObservable; >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.map.ObservableMap; >-import org.eclipse.core.internal.databinding.Util; >-import org.eclipse.core.runtime.Assert; >- >-/** >- * @since 1.0 >- * >- */ >-public class JavaBeanPropertyObservableMap extends ObservableMap implements >- IBeanObservable { >- >- private final Object object; >- >- private Object keyType; >- private Object valueType; >- >- private boolean updating = false; >- >- private PropertyDescriptor descriptor; >- >- private ListenerSupport listenerSupport; >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- * @param keyType >- * @param valueType >- */ >- public JavaBeanPropertyObservableMap(Realm realm, Object object, >- PropertyDescriptor descriptor, Object keyType, Object valueType) { >- this(realm, object, descriptor, keyType, valueType, true); >- } >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- * @param keyType >- * @param valueType >- * @param attachListeners >- */ >- public JavaBeanPropertyObservableMap(Realm realm, Object object, >- PropertyDescriptor descriptor, Object keyType, Object valueType, >- boolean attachListeners) { >- super(realm, new HashMap()); >- this.object = object; >- this.descriptor = descriptor; >- this.keyType = keyType; >- this.valueType = valueType; >- if (attachListeners) { >- PropertyChangeListener listener = new PropertyChangeListener() { >- public void propertyChange(final PropertyChangeEvent event) { >- if (!updating) { >- getRealm().exec(new Runnable() { >- public void run() { >- Map oldMap = (Map) event.getOldValue(); >- Map newMap = (Map) event.getNewValue(); >- if (oldMap == null && newMap == null) { >- oldMap = wrappedMap; >- newMap = getMap(); >- } >- >- if (!Util.equals(oldMap, newMap)) { >- wrappedMap = new HashMap(newMap); >- fireMapChange(Diffs.computeMapDiff(oldMap, >- newMap)); >- } >- } >- }); >- } >- } >- }; >- >- listenerSupport = new ListenerSupport(listener, >- descriptor.getName()); >- listenerSupport.hookListener(this.object); >- } >- >- wrappedMap.putAll(getMap()); >- } >- >- public Object getKeyType() { >- return keyType; >- } >- >- public Object getValueType() { >- return valueType; >- } >- >- private Object primGetMap() { >- try { >- Method readMethod = descriptor.getReadMethod(); >- if (!readMethod.isAccessible()) { >- readMethod.setAccessible(true); >- } >- return readMethod.invoke(object, new Object[0]); >- } catch (IllegalArgumentException e) { >- } catch (IllegalAccessException e) { >- } catch (InvocationTargetException e) { >- } >- Assert.isTrue(false, "Could not read collection values"); //$NON-NLS-1$ >- return null; >- } >- >- private void primSetMap(Object newValue) { >- Exception ex = null; >- try { >- Method writeMethod = descriptor.getWriteMethod(); >- if (!writeMethod.isAccessible()) { >- writeMethod.setAccessible(true); >- } >- writeMethod.invoke(object, new Object[] { newValue }); >- return; >- } catch (IllegalArgumentException e) { >- ex = e; >- } catch (IllegalAccessException e) { >- ex = e; >- } catch (InvocationTargetException e) { >- ex = e; >- } >- throw new BindingException("Could not write collection values", ex); //$NON-NLS-1$ >- } >- >- private Map getMap() { >- Map result = (Map) primGetMap(); >- >- if (result == null) >- result = new HashMap(); >- return result; >- } >- >- private void setMap() { >- primSetMap(new HashMap(wrappedMap)); >- } >- >- public Object put(Object key, Object value) { >- checkRealm(); >- updating = true; >- try { >- boolean add = !wrappedMap.containsKey(key); >- Object result = wrappedMap.put(key, value); >- if (!Util.equals(result, value)) { >- setMap(); >- if (add) { >- fireMapChange(Diffs.createMapDiffSingleAdd(key, value)); >- } else { >- fireMapChange(Diffs.createMapDiffSingleChange(key, result, >- value)); >- } >- } >- return result; >- } finally { >- updating = false; >- } >- } >- >- public void putAll(Map map) { >- checkRealm(); >- updating = true; >- try { >- Set addedKeys = new HashSet(map.size()); >- Map changes = new HashMap(map.size()); >- for (Iterator it = map.entrySet().iterator(); it.hasNext();) { >- Map.Entry entry = (Entry) it.next(); >- Object key = entry.getKey(); >- Object newValue = entry.getValue(); >- boolean add = !wrappedMap.containsKey(key); >- Object oldValue = wrappedMap.put(key, newValue); >- if (add) { >- addedKeys.add(key); >- } else if (!Util.equals(oldValue, newValue)) { >- changes.put(key, oldValue); >- } >- } >- if (!addedKeys.isEmpty() || !changes.isEmpty()) { >- setMap(); >- fireMapChange(Diffs.createMapDiff(addedKeys, >- Collections.EMPTY_SET, changes.keySet(), changes, >- wrappedMap)); >- } >- } finally { >- updating = false; >- } >- } >- >- public Object remove(Object key) { >- checkRealm(); >- if (!wrappedMap.containsKey(key)) { >- return null; >- } >- updating = true; >- try { >- Object result = wrappedMap.remove(key); >- setMap(); >- fireMapChange(Diffs.createMapDiffSingleRemove(key, result)); >- return result; >- } finally { >- updating = false; >- } >- } >- >- public void clear() { >- checkRealm(); >- if (wrappedMap.isEmpty()) >- return; >- updating = true; >- try { >- Map oldMap = wrappedMap; >- wrappedMap = new HashMap(); >- setMap(); >- fireMapChange(Diffs.computeMapDiff(oldMap, Collections.EMPTY_MAP)); >- } finally { >- updating = false; >- } >- } >- >- public Object getObserved() { >- return object; >- } >- >- public PropertyDescriptor getPropertyDescriptor() { >- return descriptor; >- } >- >- public synchronized void dispose() { >- if (listenerSupport != null) { >- listenerSupport.dispose(); >- listenerSupport = null; >- } >- super.dispose(); >- } >-} >Index: src/org/eclipse/core/internal/databinding/beans/ListenerSupport.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/ListenerSupport.java >diff -N src/org/eclipse/core/internal/databinding/beans/ListenerSupport.java >--- src/org/eclipse/core/internal/databinding/beans/ListenerSupport.java 24 Mar 2008 19:13:25 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,216 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 118516 >- *******************************************************************************/ >-package org.eclipse.core.internal.databinding.beans; >- >-import java.beans.PropertyChangeEvent; >-import java.beans.PropertyChangeListener; >-import java.lang.reflect.InvocationTargetException; >-import java.lang.reflect.Method; >-import java.util.HashSet; >-import java.util.Iterator; >-import java.util.Set; >- >-import org.eclipse.core.databinding.beans.BeansObservables; >-import org.eclipse.core.databinding.util.Policy; >-import org.eclipse.core.runtime.Assert; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Status; >- >-/** >- * This is a helper that will hook up and listen for <code>PropertyChangeEvent</code> events >- * for a set of target JavaBeans >- * >- * @since 1.0 >- */ >-public class ListenerSupport { >- >- private Set elementsListenedTo = new HashSet(); >- >- private PropertyChangeListener listener; >- >- private String propertyName; >- >- /** >- * Constructs a new instance. >- * >- * @param listener is the callback that will be called >- * when a <code>PropertyChangeEvent</code> is fired on any >- * of the target objects. Will only receive change events >- * when the provided <code>propertyName</code> changes. >- * @param propertyName >- */ >- public ListenerSupport(final PropertyChangeListener listener, >- final String propertyName) { >- Assert.isNotNull(listener, "Listener cannot be null"); //$NON-NLS-1$ >- Assert.isNotNull(propertyName, "Property name cannot be null"); //$NON-NLS-1$ >- >- this.propertyName = propertyName; >- this.listener = new PropertyChangeListener() { >- public void propertyChange(PropertyChangeEvent evt) { >- if (propertyName.equals(evt.getPropertyName())) { >- listener.propertyChange(evt); >- } >- } >- }; >- } >- >- /** >- * Start listen to target (if it supports the JavaBean property change listener pattern) >- * >- * @param target >- */ >- public void hookListener(Object target) { >- if (processListener( >- "addPropertyChangeListener", "Could not attach listener to ", target)) { //$NON-NLS-1$ //$NON-NLS-2$ >- elementsListenedTo.add(new IdentityWrapper(target)); >- } >- } >- >- /** >- * Add listeners for new targets (those this instance of<code>ListenerSupport</code> does not >- * already listen to), >- * Stop to listen to those object that this instance listen to and is one of the object in targets >- * >- * @param targets >- */ >- public void setHookTargets(Object[] targets) { >- Set elementsToUnhook = new HashSet(elementsListenedTo); >- if (targets!=null) { >- for (int i = 0; i < targets.length; i++) { >- Object newValue = targets[i]; >- IdentityWrapper identityWrapper = new IdentityWrapper(newValue); >- if(!elementsToUnhook.remove(identityWrapper)) >- hookListener(newValue); >- } >- } >- >- for (Iterator it = elementsToUnhook.iterator(); it.hasNext();) { >- Object o = it.next(); >- if (o.getClass()!=IdentityWrapper.class) >- o = new IdentityWrapper(o); >- elementsListenedTo.remove(o); >- unhookListener(o); >- } >- } >- >- /** >- * Stop listen to target >- * >- * @param target >- */ >- public void unhookListener(Object target) { >- if (target.getClass() == IdentityWrapper.class) >- target = ((IdentityWrapper) target).unwrap(); >- >- if (processListener( >- "removePropertyChangeListener", "Cound not remove listener from ", target)) { //$NON-NLS-1$//$NON-NLS-2$ >- elementsListenedTo.remove(new IdentityWrapper(target)); >- } >- } >- >- >- /** >- * >- */ >- public void dispose() { >- if (elementsListenedTo!=null) { >- Object[] targets = elementsListenedTo.toArray(); >- for (int i = 0; i < targets.length; i++) { >- unhookListener(targets[i]); >- } >- elementsListenedTo=null; >- listener=null; >- } >- } >- >- /** >- * @return elements that were registred to >- */ >- public Object[] getHookedTargets() { >- Object[] targets = null; >- if (elementsListenedTo!=null && elementsListenedTo.size()>0) { >- Object[] identityList = elementsListenedTo.toArray(); >- targets = new Object[identityList.length]; >- for (int i = 0; i < identityList.length; i++) >- targets[i]=((IdentityWrapper)identityList[i]).unwrap(); >- } >- return targets; >- } >- >- /** >- * Invokes the method for the provided <code>methodName</code> attempting >- * to first use the method with the property name and then the unnamed >- * version. >- * >- * @param methodName >- * either addPropertyChangeListener or >- * removePropertyChangeListener >- * @param message >- * string that will be prefixed to the target in an error message >- * @param target >- * object to invoke the method on >- * @return <code>true</code> if the method was invoked successfully >- */ >- private boolean processListener(String methodName, String message, >- Object target) { >- Method method = null; >- Object[] parameters = null; >- >- try { >- try { >- method = target.getClass().getMethod( >- methodName, >- new Class[] { String.class, >- PropertyChangeListener.class }); >- >- parameters = new Object[] { propertyName, listener }; >- } catch (NoSuchMethodException e) { >- method = target.getClass().getMethod(methodName, >- new Class[] { PropertyChangeListener.class }); >- >- parameters = new Object[] { listener }; >- } >- } catch (SecurityException e) { >- // ignore >- } catch (NoSuchMethodException e) { >- log(IStatus.WARNING, message + target, e); >- } >- >- if (method != null) { >- if (!method.isAccessible()) { >- method.setAccessible(true); >- } >- try { >- method.invoke(target, parameters); >- return true; >- } catch (IllegalArgumentException e) { >- log(IStatus.WARNING, message + target, e); >- } catch (IllegalAccessException e) { >- log(IStatus.WARNING, message + target, e); >- } catch (InvocationTargetException e) { >- log(IStatus.WARNING, message + target, e); >- } >- } >- return false; >- } >- >- /** >- * Logs a message to the Data Binding logger. >- */ >- private void log(int severity, String message, Throwable throwable) { >- if (BeansObservables.DEBUG) { >- Policy.getLog().log( >- new Status(severity, Policy.JFACE_DATABINDING, IStatus.OK, >- message, throwable)); >- } >- } >-} >Index: src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableSet.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableSet.java >diff -N src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableSet.java >--- src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableSet.java 26 Oct 2008 13:06:52 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,301 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2006-2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 171616 >- * Matthew Hall - bugs 221351, 223164, 244098 >- *******************************************************************************/ >- >-package org.eclipse.core.internal.databinding.beans; >- >-import java.beans.PropertyChangeListener; >-import java.beans.PropertyDescriptor; >-import java.lang.reflect.Array; >-import java.lang.reflect.InvocationTargetException; >-import java.lang.reflect.Method; >-import java.util.Arrays; >-import java.util.Collection; >-import java.util.Collections; >-import java.util.HashSet; >-import java.util.Iterator; >-import java.util.Set; >- >-import org.eclipse.core.databinding.BindingException; >-import org.eclipse.core.databinding.beans.IBeanObservable; >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.set.ObservableSet; >-import org.eclipse.core.runtime.Assert; >- >-/** >- * @since 1.0 >- * >- */ >-public class JavaBeanObservableSet extends ObservableSet implements IBeanObservable { >- >- private final Object object; >- >- private boolean updating = false; >- >- private PropertyDescriptor descriptor; >- >- private ListenerSupport listenerSupport; >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- * @param elementType >- */ >- public JavaBeanObservableSet(Realm realm, Object object, >- PropertyDescriptor descriptor, Class elementType) { >- this(realm, object, descriptor, elementType, true); >- } >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- * @param elementType >- * @param attachListeners >- */ >- public JavaBeanObservableSet(Realm realm, Object object, >- PropertyDescriptor descriptor, Class elementType, >- boolean attachListeners) { >- super(realm, new HashSet(), elementType); >- this.object = object; >- this.descriptor = descriptor; >- if (attachListeners) { >- PropertyChangeListener listener = new PropertyChangeListener() { >- public void propertyChange(java.beans.PropertyChangeEvent event) { >- if (!updating) { >- getRealm().exec(new Runnable() { >- public void run() { >- Set newElements = new HashSet(Arrays >- .asList(getValues())); >- Set addedElements = new HashSet(newElements); >- Set removedElements = new HashSet(wrappedSet); >- // remove all new elements from old elements to >- // compute >- // the removed elements >- removedElements.removeAll(newElements); >- addedElements.removeAll(wrappedSet); >- wrappedSet = newElements; >- fireSetChange(Diffs.createSetDiff( >- addedElements, removedElements)); >- } >- }); >- } >- } >- }; >- this.listenerSupport = new ListenerSupport(listener, descriptor >- .getName()); >- listenerSupport.hookListener(this.object); >- } >- >- wrappedSet.addAll(Arrays.asList(getValues())); >- } >- >- private Object primGetValues() { >- try { >- Method readMethod = descriptor.getReadMethod(); >- if (!readMethod.isAccessible()) { >- readMethod.setAccessible(true); >- } >- return readMethod.invoke(object, new Object[0]); >- } catch (IllegalArgumentException e) { >- } catch (IllegalAccessException e) { >- } catch (InvocationTargetException e) { >- } >- Assert.isTrue(false, "Could not read collection values"); //$NON-NLS-1$ >- return null; >- } >- >- private Object[] getValues() { >- Object[] values = null; >- >- Object result = primGetValues(); >- if (descriptor.getPropertyType().isArray()) >- values = (Object[]) result; >- else { >- // TODO add jUnit for POJO (var. SettableValue) collections >- Collection list = (Collection) result; >- if (list != null) >- values = list.toArray(); >- } >- if (values == null) >- values = new Object[0]; >- return values; >- } >- >- private void setValues() { >- if (descriptor.getPropertyType().isArray()) { >- Class componentType = descriptor.getPropertyType() >- .getComponentType(); >- Object[] newArray = (Object[]) Array.newInstance(componentType, >- wrappedSet.size()); >- wrappedSet.toArray(newArray); >- primSetValues(newArray); >- } else { >- // assume that it is a java.util.Set >- primSetValues(new HashSet(wrappedSet)); >- } >- } >- >- public boolean add(Object o) { >- getterCalled(); >- updating = true; >- try { >- boolean added = wrappedSet.add(o); >- if (added) { >- setValues(); >- fireSetChange(Diffs.createSetDiff(Collections.singleton(o), >- Collections.EMPTY_SET)); >- } >- return added; >- } finally { >- updating = false; >- } >- } >- >- public boolean remove(Object o) { >- getterCalled(); >- updating = true; >- try { >- boolean removed = wrappedSet.remove(o); >- if (removed) { >- setValues(); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >- Collections.singleton(o))); >- } >- return removed; >- } finally { >- updating = false; >- } >- } >- >- public boolean addAll(Collection c) { >- getterCalled(); >- updating = true; >- try { >- Set additions = new HashSet(); >- for (Iterator iterator = c.iterator(); iterator.hasNext();) { >- Object element = iterator.next(); >- if (wrappedSet.add(element)) >- additions.add(element); >- } >- boolean changed = !additions.isEmpty(); >- if (changed) { >- setValues(); >- fireSetChange(Diffs.createSetDiff(additions, >- Collections.EMPTY_SET)); >- } >- return changed; >- } finally { >- updating = false; >- } >- } >- >- public boolean removeAll(Collection c) { >- getterCalled(); >- updating = true; >- try { >- Set removals = new HashSet(); >- for (Iterator iterator = c.iterator(); iterator.hasNext();) { >- Object element = iterator.next(); >- if (wrappedSet.remove(element)) >- removals.add(element); >- } >- boolean changed = !removals.isEmpty(); >- if (changed) { >- setValues(); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >- removals)); >- } >- return changed; >- } finally { >- updating = false; >- } >- } >- >- public boolean retainAll(Collection c) { >- getterCalled(); >- updating = true; >- try { >- Set removals = new HashSet(); >- for (Iterator iterator = wrappedSet.iterator(); iterator.hasNext();) { >- Object element = iterator.next(); >- if (!c.contains(element)) { >- iterator.remove(); >- removals.add(element); >- } >- } >- boolean changed = !removals.isEmpty(); >- if (changed) { >- setValues(); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >- removals)); >- } >- return changed; >- } finally { >- updating = false; >- } >- } >- >- public void clear() { >- getterCalled(); >- if (wrappedSet.isEmpty()) >- return; >- >- updating = true; >- try { >- Set removals = new HashSet(wrappedSet); >- wrappedSet.clear(); >- setValues(); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); >- } finally { >- updating = false; >- } >- } >- >- private void primSetValues(Object newValue) { >- Exception ex = null; >- try { >- Method writeMethod = descriptor.getWriteMethod(); >- if (!writeMethod.isAccessible()) { >- writeMethod.setAccessible(true); >- } >- writeMethod.invoke(object, new Object[] { newValue }); >- return; >- } catch (IllegalArgumentException e) { >- ex = e; >- } catch (IllegalAccessException e) { >- ex = e; >- } catch (InvocationTargetException e) { >- ex = e; >- } >- throw new BindingException("Could not write collection values", ex); //$NON-NLS-1$ >- } >- >- public Object getObserved() { >- return object; >- } >- >- public PropertyDescriptor getPropertyDescriptor() { >- return descriptor; >- } >- >- public synchronized void dispose() { >- if (listenerSupport != null) { >- listenerSupport.dispose(); >- listenerSupport = null; >- } >- >- super.dispose(); >- } >-} >Index: src/org/eclipse/core/databinding/beans/BeansObservables.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/BeansObservables.java,v >retrieving revision 1.22 >diff -u -r1.22 BeansObservables.java >--- src/org/eclipse/core/databinding/beans/BeansObservables.java 24 Oct 2008 21:29:58 -0000 1.22 >+++ src/org/eclipse/core/databinding/beans/BeansObservables.java 17 Dec 2008 01:04:03 -0000 >@@ -8,17 +8,13 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Brad Reynolds - bugs 164268, 171616, 147515 >- * Matthew Hall - bug 221704, 234686, 246625, 226289, 246782 >+ * Matthew Hall - bug 221704, 234686, 246625, 226289, 246782, 194734 > * Thomas Kratz - bug 213787 > *******************************************************************************/ > package org.eclipse.core.databinding.beans; > >-import java.beans.BeanInfo; >-import java.beans.IntrospectionException; >-import java.beans.Introspector; > import java.beans.PropertyDescriptor; > >-import org.eclipse.core.databinding.BindingException; > import org.eclipse.core.databinding.observable.IObservable; > import org.eclipse.core.databinding.observable.Realm; > import org.eclipse.core.databinding.observable.list.IObservableList; >@@ -27,17 +23,17 @@ > 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.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.databinding.util.Policy; > import org.eclipse.core.internal.databinding.Util; > 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.JavaBeanObservableList; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; >-import org.eclipse.core.internal.databinding.beans.JavaBeanPropertyObservableMap; >+import org.eclipse.core.internal.databinding.beans.BeanPropertyHelper; > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; >@@ -87,9 +83,12 @@ > */ > public static IObservableValue observeValue(Realm realm, Object bean, > String propertyName) { >- PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), >+ IValueProperty property = BeanProperties.valueProperty(bean.getClass(), > propertyName); >- return new JavaBeanObservableValue(realm, bean, descriptor); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableValueDecorator(property.observeValue(realm, >+ bean), propertyDescriptor); > } > > /** >@@ -107,9 +106,12 @@ > */ > public static IObservableMap observeMap(IObservableSet domain, > Class beanClass, String propertyName) { >- PropertyDescriptor descriptor = getPropertyDescriptor(beanClass, >+ IValueProperty property = BeanProperties.valueProperty(beanClass, > propertyName); >- return new JavaBeanObservableMap(domain, descriptor); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableMapDecorator(property >+ .observeDetailValues(domain), propertyDescriptor); > } > > /** >@@ -153,10 +155,12 @@ > */ > public static IObservableMap observeMap(Realm realm, Object bean, > String propertyName, Class keyType, Class valueType) { >- PropertyDescriptor descriptor = getPropertyDescriptor(bean.getClass(), >- propertyName); >- return new JavaBeanPropertyObservableMap(realm, bean, descriptor, >- keyType, valueType); >+ IMapProperty property = BeanProperties.mapProperty(bean.getClass(), >+ propertyName, keyType, valueType); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableMapDecorator(property.observeMap(realm, bean), >+ propertyDescriptor); > } > > /** >@@ -193,29 +197,10 @@ > * given bean object > * @since 1.2 > */ >- public static IObservableMap observeMap(Object bean, String propertyName, Class keyType, Class valueType) { >- return observeMap(Realm.getDefault(), bean, propertyName, keyType, valueType); >- } >- >- /*package*/ static PropertyDescriptor getPropertyDescriptor(Class beanClass, >- String propertyName) { >- BeanInfo beanInfo; >- try { >- beanInfo = Introspector.getBeanInfo(beanClass); >- } catch (IntrospectionException e) { >- // cannot introspect, give up >- return null; >- } >- PropertyDescriptor[] propertyDescriptors = beanInfo >- .getPropertyDescriptors(); >- for (int i = 0; i < propertyDescriptors.length; i++) { >- PropertyDescriptor descriptor = propertyDescriptors[i]; >- if (descriptor.getName().equals(propertyName)) { >- return descriptor; >- } >- } >- throw new BindingException( >- "Could not find property with name " + propertyName + " in class " + beanClass); //$NON-NLS-1$ //$NON-NLS-2$ >+ public static IObservableMap observeMap(Object bean, String propertyName, >+ Class keyType, Class valueType) { >+ return observeMap(Realm.getDefault(), bean, propertyName, keyType, >+ valueType); > } > > /** >@@ -283,9 +268,9 @@ > * 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 <code>PropertyChangeEvents</code>. This is done to >- * provide the same behavior as is expected from arrays as specified in the >- * bean spec in section 7.2. >+ * listeners via <code>PropertyChangeEvents</code>. 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 >@@ -294,8 +279,8 @@ > * @param propertyName > * the name of the property > * @param elementType >- * type of the elements in the list. If <code>null</code> and >- * the property is an array the type will be inferred. If >+ * type of the elements in the list. If <code>null</code> and the >+ * property is an array the type will be inferred. If > * <code>null</code> and the property type cannot be inferred > * element type will be <code>null</code>. > * @return an observable list tracking the collection-typed named property >@@ -303,12 +288,12 @@ > */ > public static IObservableList observeList(Realm realm, Object bean, > String propertyName, Class elementType) { >- PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean >- .getClass(), propertyName); >- elementType = getCollectionElementType(elementType, propertyDescriptor); >- >- return new JavaBeanObservableList(realm, bean, propertyDescriptor, >- elementType); >+ IListProperty property = BeanProperties.listProperty(bean.getClass(), >+ propertyName, elementType); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableListDecorator(property.observeList( >+ realm, bean), propertyDescriptor); > } > > /** >@@ -495,10 +480,8 @@ > > IObservableValue value = MasterDetailObservables.detailValue(master, > valueFactory(realm, propertyName), propertyType); >- BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( >- value, getValueTypePropertyDescriptor(master, propertyName)); >- >- return decorator; >+ return new BeanObservableValueDecorator(value, BeanPropertyHelper >+ .getValueTypePropertyDescriptor(master, propertyName)); > } > > /* package */static void warnIfDifferentRealms(Realm detailRealm, >@@ -538,10 +521,9 @@ > /** > * Helper method for > * <code>MasterDetailObservables.detailValue(master, valueFactory(realm, >- * propertyName), propertyType)</code>. >- * This method returns an {@link IBeanObservable} with a >- * {@link PropertyDescriptor} based on the given master type and property >- * name. >+ * propertyName), propertyType)</code>. This method returns an >+ * {@link IBeanObservable} with a {@link PropertyDescriptor} based on the >+ * given master type and property name. > * > * @param realm > * the realm >@@ -564,15 +546,14 @@ > * instead. > */ > public static IObservableValue observeDetailValue(Realm realm, >- IObservableValue master, Class masterType, String propertyName, Class propertyType) { >+ 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, > valueFactory(realm, propertyName), propertyType); >- BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( >- value, getPropertyDescriptor(masterType, propertyName)); >- >- return decorator; >+ return new BeanObservableValueDecorator(value, BeanPropertyHelper >+ .getPropertyDescriptor(masterType, propertyName)); > } > > /** >@@ -627,11 +608,9 @@ > IObservableList observableList = MasterDetailObservables.detailList( > master, listFactory(realm, propertyName, propertyType), > propertyType); >- BeanObservableListDecorator decorator = new BeanObservableListDecorator( >- observableList, getValueTypePropertyDescriptor(master, >+ return new BeanObservableListDecorator(observableList, >+ BeanPropertyHelper.getValueTypePropertyDescriptor(master, > propertyName)); >- >- return decorator; > } > > /** >@@ -679,11 +658,8 @@ > IObservableSet observableSet = MasterDetailObservables.detailSet( > master, setFactory(realm, propertyName, propertyType), > propertyType); >- BeanObservableSetDecorator decorator = new BeanObservableSetDecorator( >- observableSet, getValueTypePropertyDescriptor(master, >- propertyName)); >- >- return decorator; >+ return new BeanObservableSetDecorator(observableSet, BeanPropertyHelper >+ .getValueTypePropertyDescriptor(master, propertyName)); > } > > /** >@@ -725,10 +701,8 @@ > warnIfDifferentRealms(realm, master.getRealm()); > IObservableMap observableMap = MasterDetailObservables.detailMap( > master, mapPropertyFactory(realm, propertyName)); >- BeanObservableMapDecorator decorator = new BeanObservableMapDecorator( >- observableMap, getValueTypePropertyDescriptor(master, >- propertyName)); >- return decorator; >+ return new BeanObservableMapDecorator(observableMap, BeanPropertyHelper >+ .getValueTypePropertyDescriptor(master, propertyName)); > } > > /** >@@ -771,12 +745,12 @@ > */ > public static IObservableSet observeSet(Realm realm, Object bean, > String propertyName, Class elementType) { >- PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean >- .getClass(), propertyName); >- elementType = getCollectionElementType(elementType, propertyDescriptor); >- >- return new JavaBeanObservableSet(realm, bean, propertyDescriptor, >- elementType); >+ ISetProperty property = BeanProperties.setProperty(bean.getClass(), >+ propertyName, elementType); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableSetDecorator(property.observeSet( >+ realm, bean), propertyDescriptor); > } > > /** >@@ -863,17 +837,19 @@ > * @param propertyName > * the name of the property > * @return a factory for creating {@link IObservableMap} objects >- * >+ * > * @since 1.1 > */ >- public static IObservableFactory setToMapFactory(final Class beanClass, final String propertyName) { >+ public static IObservableFactory setToMapFactory(final Class beanClass, >+ final String propertyName) { > return new IObservableFactory() { > public IObservable createObservable(Object target) { >- return observeMap((IObservableSet) target, beanClass, propertyName); >+ return 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 >@@ -911,32 +887,4 @@ > public static IObservableFactory mapPropertyFactory(String propertyName) { > return mapPropertyFactory(Realm.getDefault(), propertyName); > } >- >- /** >- * @param elementType >- * can be <code>null</code> >- * @param propertyDescriptor >- * @return type of the items in a collection/array property >- */ >- /*package*/ static Class getCollectionElementType(Class elementType, >- PropertyDescriptor propertyDescriptor) { >- if (elementType == null) { >- Class propertyType = propertyDescriptor.getPropertyType(); >- elementType = propertyType.isArray() ? propertyType >- .getComponentType() : Object.class; >- } >- >- return elementType; >- } >- >- /** >- * @param observable >- * @param propertyName >- * @return property descriptor or <code>null</code> >- */ >- /* package*/ static PropertyDescriptor getValueTypePropertyDescriptor( >- IObservableValue observable, String propertyName) { >- return (observable.getValueType() != null) ? getPropertyDescriptor( >- (Class) observable.getValueType(), propertyName) : null; >- } > } >Index: src/org/eclipse/core/internal/databinding/beans/BeanMapProperty.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/BeanMapProperty.java >diff -N src/org/eclipse/core/internal/databinding/beans/BeanMapProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/beans/BeanMapProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,135 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.beans; >+ >+import java.beans.PropertyChangeEvent; >+import java.beans.PropertyChangeListener; >+import java.beans.PropertyDescriptor; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.core.databinding.beans.IBeanProperty; >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.map.MapDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.map.IMapPropertyChangeListener; >+import org.eclipse.core.databinding.property.map.MapPropertyChangeEvent; >+import org.eclipse.core.databinding.property.map.SimpleMapProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanMapProperty extends SimpleMapProperty implements IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private Object keyType; >+ private Object valueType; >+ >+ /** >+ * @param propertyDescriptor >+ * @param keyType >+ * @param valueType >+ */ >+ public BeanMapProperty(PropertyDescriptor propertyDescriptor, >+ Object keyType, Object valueType) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.keyType = keyType; >+ this.valueType = valueType; >+ } >+ >+ protected Map doGetMap(Object source) { >+ if (source == null) >+ return Collections.EMPTY_MAP; >+ Object propertyValue = BeanPropertyHelper.readProperty(source, >+ propertyDescriptor); >+ return asMap(propertyValue); >+ } >+ >+ private Map asMap(Object propertyValue) { >+ if (propertyValue == null) >+ return new HashMap(); >+ return (Map) propertyValue; >+ } >+ >+ protected void setMap(Object source, Map map, MapDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.writeProperty(source, propertyDescriptor, map); >+ } >+ } >+ >+ public PropertyDescriptor getPropertyDescriptor() { >+ return propertyDescriptor; >+ } >+ >+ public Object getKeyType() { >+ return keyType; >+ } >+ >+ public Object getValueType() { >+ return valueType; >+ } >+ >+ public INativePropertyListener adaptListener( >+ final IMapPropertyChangeListener listener) { >+ return new Listener(listener); >+ } >+ >+ private class Listener implements INativePropertyListener, >+ PropertyChangeListener { >+ private final IMapPropertyChangeListener listener; >+ >+ private Listener(IMapPropertyChangeListener listener) { >+ this.listener = listener; >+ } >+ >+ public void propertyChange(PropertyChangeEvent evt) { >+ if (propertyDescriptor.getName().equals(evt.getPropertyName())) { >+ Object oldValue = evt.getOldValue(); >+ Object newValue = evt.getNewValue(); >+ >+ MapDiff diff; >+ if (oldValue == null && newValue == null) { >+ diff = null; // unknown change >+ } else { >+ diff = Diffs.computeMapDiff(asMap(oldValue), >+ asMap(newValue)); >+ } >+ >+ listener.handleMapPropertyChange(new MapPropertyChangeEvent(evt >+ .getSource(), BeanMapProperty.this, diff)); >+ } >+ } >+ } >+ >+ public void addListener(Object source, INativePropertyListener listener) { >+ BeanPropertyListenerSupport.hookListener(source, propertyDescriptor >+ .getName(), (PropertyChangeListener) listener); >+ } >+ >+ public void removeListener(Object source, INativePropertyListener listener) { >+ BeanPropertyListenerSupport.unhookListener(source, propertyDescriptor >+ .getName(), (PropertyChangeListener) listener); >+ } >+ >+ public String toString() { >+ Class beanClass = propertyDescriptor.getReadMethod() >+ .getDeclaringClass(); >+ String propertyName = propertyDescriptor.getName(); >+ String s = beanClass.getName() + "." + propertyName + "{:}"; //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ if (keyType != null || valueType != null) { >+ s += " <" + keyType + ", " + valueType + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ } >+ return s; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/beans/PojoMapProperty.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/PojoMapProperty.java >diff -N src/org/eclipse/core/internal/databinding/beans/PojoMapProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/beans/PojoMapProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,100 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.beans; >+ >+import java.beans.PropertyDescriptor; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.core.databinding.beans.IBeanProperty; >+import org.eclipse.core.databinding.observable.map.MapDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.map.IMapPropertyChangeListener; >+import org.eclipse.core.databinding.property.map.SimpleMapProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class PojoMapProperty extends SimpleMapProperty implements IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private Object keyType; >+ private Object valueType; >+ >+ /** >+ * @param propertyDescriptor >+ * @param keyType >+ * @param valueType >+ */ >+ public PojoMapProperty(PropertyDescriptor propertyDescriptor, >+ Object keyType, Object valueType) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.keyType = keyType; >+ this.valueType = valueType; >+ } >+ >+ protected Map doGetMap(Object source) { >+ if (source == null) >+ return Collections.EMPTY_MAP; >+ Object propertyValue = BeanPropertyHelper.readProperty(source, >+ propertyDescriptor); >+ return asMap(propertyValue); >+ } >+ >+ private Map asMap(Object propertyValue) { >+ if (propertyValue == null) >+ return new HashMap(); >+ return (Map) propertyValue; >+ } >+ >+ protected void setMap(Object source, Map map, MapDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.writeProperty(source, propertyDescriptor, map); >+ } >+ } >+ >+ public PropertyDescriptor getPropertyDescriptor() { >+ return propertyDescriptor; >+ } >+ >+ public Object getKeyType() { >+ return keyType; >+ } >+ >+ public Object getValueType() { >+ return valueType; >+ } >+ >+ public INativePropertyListener adaptListener( >+ IMapPropertyChangeListener listener) { >+ return null; >+ } >+ >+ public void addListener(Object source, INativePropertyListener listener) { >+ } >+ >+ public void removeListener(Object source, INativePropertyListener listener) { >+ } >+ >+ public String toString() { >+ Class beanClass = propertyDescriptor.getReadMethod() >+ .getDeclaringClass(); >+ String propertyName = propertyDescriptor.getName(); >+ String s = beanClass.getName() + "." + propertyName + "{:}"; //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ if (keyType != null || valueType != null) { >+ s += " <" + keyType + ", " + valueType + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ } >+ return s; >+ } >+} >Index: src/org/eclipse/core/databinding/beans/PojoProperties.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/beans/PojoProperties.java >diff -N src/org/eclipse/core/databinding/beans/PojoProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/beans/PojoProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,159 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.beans; >+ >+import java.beans.PropertyChangeEvent; >+ >+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.BeanPropertyHelper; >+import org.eclipse.core.internal.databinding.beans.PojoListProperty; >+import org.eclipse.core.internal.databinding.beans.PojoMapProperty; >+import org.eclipse.core.internal.databinding.beans.PojoSetProperty; >+import org.eclipse.core.internal.databinding.beans.PojoValueProperty; >+ >+/** >+ * 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. >+ * >+ * @since 1.2 >+ */ >+public class PojoProperties { >+ /** >+ * Returns a value property for the given property name of the given bean >+ * class. >+ * >+ * @param beanClass >+ * the bean class >+ * @param propertyName >+ * the property name >+ * @return a value property for the given property name of the given bean >+ * class. >+ */ >+ public static IValueProperty valueProperty(Class beanClass, >+ String propertyName) { >+ return valueProperty(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 >+ * @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 IValueProperty valueProperty(Class beanClass, >+ String propertyName, Class valueType) { >+ return new PojoValueProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), valueType); >+ } >+ >+ /** >+ * 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 ISetProperty setProperty(Class beanClass, String propertyName) { >+ return setProperty(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 ISetProperty setProperty(Class beanClass, >+ String propertyName, Class elementType) { >+ return new PojoSetProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, 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 IListProperty listProperty(Class beanClass, >+ String propertyName) { >+ return listProperty(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 IListProperty listProperty(Class beanClass, >+ String propertyName, Class elementType) { >+ return new PojoListProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), elementType); >+ } >+ >+ /** >+ * 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 IMapProperty mapProperty(Class beanClass, >+ String propertyName, Object keyType, Object valueType) { >+ return new PojoMapProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), keyType, valueType); >+ } >+} >Index: src/org/eclipse/core/internal/databinding/beans/BeanListProperty.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/BeanListProperty.java >diff -N src/org/eclipse/core/internal/databinding/beans/BeanListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/beans/BeanListProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,148 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.beans; >+ >+import java.beans.PropertyChangeEvent; >+import java.beans.PropertyChangeListener; >+import java.beans.PropertyDescriptor; >+import java.lang.reflect.Array; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.core.databinding.beans.IBeanProperty; >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.list.IListPropertyChangeListener; >+import org.eclipse.core.databinding.property.list.ListPropertyChangeEvent; >+import org.eclipse.core.databinding.property.list.SimpleListProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanListProperty extends SimpleListProperty implements >+ IBeanProperty { >+ private final PropertyDescriptor propertyDescriptor; >+ private final Class elementType; >+ >+ /** >+ * @param propertyDescriptor >+ * @param elementType >+ */ >+ public BeanListProperty(PropertyDescriptor propertyDescriptor, >+ Class elementType) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.elementType = elementType == null ? BeanPropertyHelper >+ .getCollectionPropertyElementType(propertyDescriptor) >+ : elementType; >+ } >+ >+ public Object getElementType() { >+ return elementType; >+ } >+ >+ protected List doGetList(Object source) { >+ if (source == null) >+ return Collections.EMPTY_LIST; >+ Object propertyValue = BeanPropertyHelper.readProperty(source, >+ propertyDescriptor); >+ return asList(propertyValue); >+ } >+ >+ private List asList(Object propertyValue) { >+ if (propertyValue == null) >+ return new ArrayList(); >+ if (propertyDescriptor.getPropertyType().isArray()) >+ return new ArrayList(Arrays.asList((Object[]) propertyValue)); >+ return (List) propertyValue; >+ } >+ >+ protected void setList(Object source, List list, ListDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.writeProperty(source, propertyDescriptor, >+ convertListToBeanPropertyType(list)); >+ } >+ } >+ >+ private Object convertListToBeanPropertyType(List list) { >+ Object propertyValue = list; >+ if (propertyDescriptor.getPropertyType().isArray()) { >+ Class componentType = propertyDescriptor.getPropertyType() >+ .getComponentType(); >+ Object[] array = (Object[]) Array.newInstance(componentType, list >+ .size()); >+ list.toArray(array); >+ propertyValue = array; >+ } >+ return propertyValue; >+ } >+ >+ public PropertyDescriptor getPropertyDescriptor() { >+ return propertyDescriptor; >+ } >+ >+ public INativePropertyListener adaptListener( >+ final IListPropertyChangeListener listener) { >+ return new Listener(listener); >+ } >+ >+ private class Listener implements INativePropertyListener, >+ PropertyChangeListener { >+ private final IListPropertyChangeListener listener; >+ >+ private Listener(IListPropertyChangeListener listener) { >+ this.listener = listener; >+ } >+ >+ public void propertyChange(PropertyChangeEvent evt) { >+ if (propertyDescriptor.getName().equals(evt.getPropertyName())) { >+ Object oldValue = evt.getOldValue(); >+ Object newValue = evt.getNewValue(); >+ >+ ListDiff diff; >+ if (oldValue == null && newValue == null) { >+ diff = null; // unknown change >+ } else { >+ diff = Diffs.computeListDiff(asList(oldValue), >+ asList(newValue)); >+ } >+ >+ listener.handleListPropertyChange(new ListPropertyChangeEvent( >+ evt.getSource(), BeanListProperty.this, diff)); >+ } >+ } >+ } >+ >+ public void addListener(Object source, INativePropertyListener listener) { >+ BeanPropertyListenerSupport.hookListener(source, propertyDescriptor >+ .getName(), (PropertyChangeListener) listener); >+ } >+ >+ public void removeListener(Object source, INativePropertyListener listener) { >+ BeanPropertyListenerSupport.unhookListener(source, propertyDescriptor >+ .getName(), (PropertyChangeListener) listener); >+ } >+ >+ public String toString() { >+ Class beanClass = propertyDescriptor.getReadMethod() >+ .getDeclaringClass(); >+ String propertyName = propertyDescriptor.getName(); >+ String s = beanClass.getName() + "." + propertyName + "[]"; //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ if (elementType != null) >+ s += " <" + elementType.getName() + ">"; //$NON-NLS-1$//$NON-NLS-2$ >+ return s; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/beans/BeanSetProperty.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/BeanSetProperty.java >diff -N src/org/eclipse/core/internal/databinding/beans/BeanSetProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/beans/BeanSetProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,146 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.beans; >+ >+import java.beans.PropertyChangeEvent; >+import java.beans.PropertyChangeListener; >+import java.beans.PropertyDescriptor; >+import java.lang.reflect.Array; >+import java.util.Arrays; >+import java.util.Collections; >+import java.util.HashSet; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.beans.IBeanProperty; >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.set.ISetPropertyChangeListener; >+import org.eclipse.core.databinding.property.set.SetPropertyChangeEvent; >+import org.eclipse.core.databinding.property.set.SimpleSetProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanSetProperty extends SimpleSetProperty implements IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private Class elementType; >+ >+ /** >+ * @param propertyDescriptor >+ * @param elementType >+ */ >+ public BeanSetProperty(PropertyDescriptor propertyDescriptor, >+ Class elementType) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.elementType = elementType == null ? BeanPropertyHelper >+ .getCollectionPropertyElementType(propertyDescriptor) >+ : elementType; >+ } >+ >+ public Object getElementType() { >+ return elementType; >+ } >+ >+ protected Set doGetSet(Object source) { >+ if (source == null) >+ return Collections.EMPTY_SET; >+ Object propertyValue = BeanPropertyHelper.readProperty(source, >+ propertyDescriptor); >+ return asSet(propertyValue); >+ } >+ >+ private Set asSet(Object propertyValue) { >+ if (propertyValue == null) >+ return Collections.EMPTY_SET; >+ if (propertyDescriptor.getPropertyType().isArray()) >+ return new HashSet(Arrays.asList((Object[]) propertyValue)); >+ return (Set) propertyValue; >+ } >+ >+ protected void setSet(Object source, Set set, SetDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.writeProperty(source, propertyDescriptor, >+ convertSetToBeanPropertyType(set)); >+ } >+ } >+ >+ private Object convertSetToBeanPropertyType(Set set) { >+ Object propertyValue = set; >+ if (propertyDescriptor.getPropertyType().isArray()) { >+ Class componentType = propertyDescriptor.getPropertyType() >+ .getComponentType(); >+ Object[] array = (Object[]) Array.newInstance(componentType, set >+ .size()); >+ propertyValue = set.toArray(array); >+ } >+ return propertyValue; >+ } >+ >+ public PropertyDescriptor getPropertyDescriptor() { >+ return propertyDescriptor; >+ } >+ >+ public INativePropertyListener adaptListener( >+ final ISetPropertyChangeListener listener) { >+ return new Listener(listener); >+ } >+ >+ private class Listener implements INativePropertyListener, >+ PropertyChangeListener { >+ private final ISetPropertyChangeListener listener; >+ >+ private Listener(ISetPropertyChangeListener listener) { >+ this.listener = listener; >+ } >+ >+ public void propertyChange(PropertyChangeEvent evt) { >+ if (propertyDescriptor.getName().equals(evt.getPropertyName())) { >+ Object oldValue = evt.getOldValue(); >+ Object newValue = evt.getNewValue(); >+ >+ SetDiff diff; >+ if (oldValue == null && newValue == null) { >+ diff = null; // unknown change >+ } else { >+ diff = Diffs.computeSetDiff(asSet(oldValue), >+ asSet(newValue)); >+ } >+ >+ listener.handleSetPropertyChange(new SetPropertyChangeEvent(evt >+ .getSource(), BeanSetProperty.this, diff)); >+ } >+ } >+ } >+ >+ public void addListener(Object source, INativePropertyListener listener) { >+ BeanPropertyListenerSupport.hookListener(source, propertyDescriptor >+ .getName(), (PropertyChangeListener) listener); >+ } >+ >+ public void removeListener(Object source, INativePropertyListener listener) { >+ BeanPropertyListenerSupport.unhookListener(source, propertyDescriptor >+ .getName(), (PropertyChangeListener) listener); >+ } >+ >+ public String toString() { >+ Class beanClass = propertyDescriptor.getReadMethod() >+ .getDeclaringClass(); >+ String propertyName = propertyDescriptor.getName(); >+ String s = beanClass.getName() + "." + propertyName + "{}"; //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ if (elementType != null) >+ s += " <" + elementType.getName() + ">"; //$NON-NLS-1$//$NON-NLS-2$ >+ return s; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/beans/PojoListProperty.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/PojoListProperty.java >diff -N src/org/eclipse/core/internal/databinding/beans/PojoListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/beans/PojoListProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,113 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.beans; >+ >+import java.beans.PropertyDescriptor; >+import java.lang.reflect.Array; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.core.databinding.beans.IBeanProperty; >+import org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.list.IListPropertyChangeListener; >+import org.eclipse.core.databinding.property.list.SimpleListProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class PojoListProperty extends SimpleListProperty implements >+ IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private Class elementType; >+ >+ /** >+ * @param propertyDescriptor >+ * @param elementType >+ */ >+ public PojoListProperty(PropertyDescriptor propertyDescriptor, >+ Class elementType) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.elementType = elementType == null ? BeanPropertyHelper >+ .getCollectionPropertyElementType(propertyDescriptor) >+ : elementType; >+ } >+ >+ public Object getElementType() { >+ return elementType; >+ } >+ >+ protected List doGetList(Object source) { >+ if (source == null) >+ return Collections.EMPTY_LIST; >+ Object propertyValue = BeanPropertyHelper.readProperty(source, >+ propertyDescriptor); >+ return asList(propertyValue); >+ } >+ >+ private List asList(Object propertyValue) { >+ if (propertyValue == null) >+ return new ArrayList(); >+ if (propertyDescriptor.getPropertyType().isArray()) >+ return new ArrayList(Arrays.asList((Object[]) propertyValue)); >+ return (List) propertyValue; >+ } >+ >+ protected void setList(Object source, List list, ListDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.writeProperty(source, propertyDescriptor, >+ convertListToBeanPropertyType(list)); >+ } >+ } >+ >+ private Object convertListToBeanPropertyType(List list) { >+ Object propertyValue = list; >+ if (propertyDescriptor.getPropertyType().isArray()) { >+ Class componentType = propertyDescriptor.getPropertyType() >+ .getComponentType(); >+ Object[] array = (Object[]) Array.newInstance(componentType, list >+ .size()); >+ list.toArray(array); >+ propertyValue = array; >+ } >+ return propertyValue; >+ } >+ >+ public PropertyDescriptor getPropertyDescriptor() { >+ return propertyDescriptor; >+ } >+ >+ public INativePropertyListener adaptListener( >+ IListPropertyChangeListener listener) { >+ return null; >+ } >+ >+ public void addListener(Object source, INativePropertyListener listener) { >+ } >+ >+ public void removeListener(Object source, INativePropertyListener listener) { >+ } >+ >+ public String toString() { >+ Class beanClass = propertyDescriptor.getReadMethod() >+ .getDeclaringClass(); >+ String propertyName = propertyDescriptor.getName(); >+ String s = beanClass.getName() + "." + propertyName + "[]"; //$NON-NLS-1$ //$NON-NLS-2$ >+ >+ if (elementType != null) >+ s += " <" + elementType.getName() + ">"; //$NON-NLS-1$//$NON-NLS-2$ >+ return s; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/beans/BeanPropertyHelper.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/BeanPropertyHelper.java >diff -N src/org/eclipse/core/internal/databinding/beans/BeanPropertyHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/beans/BeanPropertyHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,169 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.beans; >+ >+import java.beans.BeanInfo; >+import java.beans.IntrospectionException; >+import java.beans.Introspector; >+import java.beans.PropertyDescriptor; >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+ >+import org.eclipse.core.databinding.BindingException; >+import org.eclipse.core.databinding.beans.BeansObservables; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.util.Policy; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class BeanPropertyHelper { >+ /** >+ * Sets the contents of the given property on the given source object to the >+ * given value. >+ * >+ * @param source >+ * the source object which has the property being updated >+ * @param propertyDescriptor >+ * the property being changed >+ * @param value >+ * the new value of the property >+ */ >+ public static void writeProperty(Object source, >+ PropertyDescriptor propertyDescriptor, Object value) { >+ try { >+ Method writeMethod = propertyDescriptor.getWriteMethod(); >+ if (!writeMethod.isAccessible()) { >+ writeMethod.setAccessible(true); >+ } >+ writeMethod.invoke(source, new Object[] { value }); >+ } catch (InvocationTargetException e) { >+ /* >+ * InvocationTargetException wraps any exception thrown by the >+ * invoked method. >+ */ >+ throw new RuntimeException(e.getCause()); >+ } catch (Exception e) { >+ if (BeansObservables.DEBUG) { >+ Policy >+ .getLog() >+ .log( >+ new Status( >+ IStatus.WARNING, >+ Policy.JFACE_DATABINDING, >+ IStatus.OK, >+ "Could not change value of " + source + "." + propertyDescriptor.getName(), e)); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } >+ } >+ >+ /** >+ * Returns the contents of the given property for the given bean. >+ * >+ * @param source >+ * the source bean >+ * @param propertyDescriptor >+ * the property to retrieve >+ * @return the contents of the given property for the given bean. >+ */ >+ public static Object readProperty(Object source, >+ PropertyDescriptor propertyDescriptor) { >+ try { >+ Method readMethod = propertyDescriptor.getReadMethod(); >+ if (readMethod == null) { >+ throw new BindingException(propertyDescriptor.getName() >+ + " property does not have a read method."); //$NON-NLS-1$ >+ } >+ if (!readMethod.isAccessible()) { >+ readMethod.setAccessible(true); >+ } >+ return readMethod.invoke(source, null); >+ } catch (InvocationTargetException e) { >+ /* >+ * InvocationTargetException wraps any exception thrown by the >+ * invoked method. >+ */ >+ throw new RuntimeException(e.getCause()); >+ } catch (Exception e) { >+ if (BeansObservables.DEBUG) { >+ Policy >+ .getLog() >+ .log( >+ new Status( >+ IStatus.WARNING, >+ Policy.JFACE_DATABINDING, >+ IStatus.OK, >+ "Could not read value of " + source + "." + propertyDescriptor.getName(), e)); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ return null; >+ } >+ } >+ >+ /** >+ * Returns the element type of the given collection-typed property for the >+ * given bean. >+ * >+ * @param descriptor >+ * the property being inspected >+ * @return the element type of the given collection-typed property if it is >+ * an array property, or Object.class otherwise. >+ */ >+ public static Class getCollectionPropertyElementType( >+ PropertyDescriptor descriptor) { >+ Class propertyType = descriptor.getPropertyType(); >+ return propertyType.isArray() ? propertyType.getComponentType() >+ : Object.class; >+ } >+ >+ /** >+ * @param beanClass >+ * @param propertyName >+ * @return the PropertyDescriptor for the named property on the given bean >+ * class >+ */ >+ public static PropertyDescriptor getPropertyDescriptor(Class beanClass, >+ String propertyName) { >+ BeanInfo beanInfo; >+ try { >+ beanInfo = Introspector.getBeanInfo(beanClass); >+ } catch (IntrospectionException e) { >+ // cannot introspect, give up >+ return null; >+ } >+ PropertyDescriptor[] propertyDescriptors = beanInfo >+ .getPropertyDescriptors(); >+ for (int i = 0; i < propertyDescriptors.length; i++) { >+ PropertyDescriptor descriptor = propertyDescriptors[i]; >+ if (descriptor.getName().equals(propertyName)) { >+ return descriptor; >+ } >+ } >+ throw new BindingException( >+ "Could not find property with name " + propertyName + " in class " + beanClass); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ >+ /** >+ * @param observable >+ * @param propertyName >+ * @return property descriptor or <code>null</code> >+ */ >+ /* package */public static PropertyDescriptor getValueTypePropertyDescriptor( >+ IObservableValue observable, String propertyName) { >+ if (observable.getValueType() != null) >+ return getPropertyDescriptor((Class) observable.getValueType(), >+ propertyName); >+ return null; >+ } >+} >#P org.eclipse.jface.databinding >Index: src/org/eclipse/jface/internal/databinding/viewers/ViewerSingleSelectionObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/ViewerSingleSelectionObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/ViewerSingleSelectionObservableValue.java >--- src/org/eclipse/jface/internal/databinding/viewers/ViewerSingleSelectionObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,45 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 137877 >- * Brad Reynolds - bug 164653 >- * Brad Reynolds - bug 147515 >- * Ashley Cambrell - bug 198906 >- *******************************************************************************/ >- >-package org.eclipse.jface.internal.databinding.viewers; >- >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.databinding.viewers.IViewerObservableValue; >-import org.eclipse.jface.viewers.Viewer; >- >-/** >- * Observes single selection of a <code>Viewer</code>. >- * >- * @since 1.2 >- */ >-public class ViewerSingleSelectionObservableValue extends >- SelectionProviderSingleSelectionObservableValue implements >- IViewerObservableValue { >- >- private Viewer viewer; >- >- /** >- * @param realm >- * @param viewer >- */ >- public ViewerSingleSelectionObservableValue(Realm realm, Viewer viewer) { >- super(realm, viewer); >- this.viewer = viewer; >- } >- >- public Viewer getViewer() { >- return viewer; >- } >-} >Index: src/org/eclipse/jface/internal/databinding/viewers/ViewerMultipleSelectionObservableList.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/ViewerMultipleSelectionObservableList.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/ViewerMultipleSelectionObservableList.java >--- src/org/eclipse/jface/internal/databinding/viewers/ViewerMultipleSelectionObservableList.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,47 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 137877 >- * Brad Reynolds - bug 164653 >- * Brad Reynolds - bug 147515 >- * Ashley Cambrell - bug 198906 >- *******************************************************************************/ >- >-package org.eclipse.jface.internal.databinding.viewers; >- >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.databinding.viewers.IViewerObservableList; >-import org.eclipse.jface.viewers.Viewer; >- >-/** >- * Observes single selection of a <code>Viewer</code>. >- * >- * @since 1.2 >- */ >-public class ViewerMultipleSelectionObservableList extends >- SelectionProviderMultipleSelectionObservableList implements >- IViewerObservableList { >- >- private Viewer viewer; >- >- /** >- * @param realm >- * @param viewer >- * @param elementType >- */ >- public ViewerMultipleSelectionObservableList(Realm realm, Viewer viewer, >- Object elementType) { >- super(realm, viewer, elementType); >- this.viewer = viewer; >- } >- >- public Viewer getViewer() { >- return viewer; >- } >-} >Index: src/org/eclipse/jface/internal/databinding/viewers/CheckboxViewerCheckedElementsObservableSet.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/CheckboxViewerCheckedElementsObservableSet.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/CheckboxViewerCheckedElementsObservableSet.java >--- src/org/eclipse/jface/internal/databinding/viewers/CheckboxViewerCheckedElementsObservableSet.java 19 Mar 2008 23:27:05 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,90 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Matthew Hall and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Matthew Hall - initial API and implementation (bug 124684) >- ******************************************************************************/ >- >-package org.eclipse.jface.internal.databinding.viewers; >- >-import java.util.Arrays; >-import java.util.Set; >- >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.databinding.viewers.IViewerObservableSet; >-import org.eclipse.jface.viewers.CheckboxTableViewer; >-import org.eclipse.jface.viewers.CheckboxTreeViewer; >-import org.eclipse.jface.viewers.StructuredViewer; >-import org.eclipse.jface.viewers.Viewer; >- >-/** >- * An observable set that tracks the checked elements in a CheckboxTableViewer >- * or CheckboxTreeViewer >- * >- * @since 1.2 >- */ >-public class CheckboxViewerCheckedElementsObservableSet extends >- CheckableCheckedElementsObservableSet implements IViewerObservableSet { >- private StructuredViewer viewer; >- >- /** >- * Constructs a new instance on the given realm and checkable. >- * >- * @param realm >- * the observable's realm >- * @param viewer >- * the CheckboxTableViewer viewer to track. >- * @param elementType >- * type of elements in the set >- */ >- public CheckboxViewerCheckedElementsObservableSet(Realm realm, >- CheckboxTableViewer viewer, Object elementType) { >- super(realm, viewer, elementType, createElementSet(viewer)); >- this.viewer = viewer; >- } >- >- /** >- * Constructs a new instance on the given realm and checkable. >- * >- * @param realm >- * the observable's realm >- * @param viewer >- * the CheckboxTreeViewer viewer to track. >- * @param elementType >- * type of elements in the set >- */ >- public CheckboxViewerCheckedElementsObservableSet(Realm realm, >- CheckboxTreeViewer viewer, Object elementType) { >- super(realm, viewer, elementType, createElementSet(viewer)); >- this.viewer = viewer; >- } >- >- Set createDiffSet() { >- return ViewerElementSet.withComparer(viewer.getComparer()); >- } >- >- private static Set createElementSet(CheckboxTableViewer viewer) { >- Set set = ViewerElementSet.withComparer(viewer.getComparer()); >- set.addAll(Arrays.asList(viewer.getCheckedElements())); >- return set; >- } >- >- private static Set createElementSet(CheckboxTreeViewer viewer) { >- Set set = ViewerElementSet.withComparer(viewer.getComparer()); >- set.addAll(Arrays.asList(viewer.getCheckedElements())); >- return set; >- } >- >- public Viewer getViewer() { >- return viewer; >- } >- >- public synchronized void dispose() { >- viewer = null; >- super.dispose(); >- } >-} >Index: src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValue.java >--- src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,147 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 137877 >- * Brad Reynolds - bug 164653 >- * Brad Reynolds - bug 147515 >- * Ashley Cambrell - bug 198906 >- *******************************************************************************/ >- >-package org.eclipse.jface.internal.databinding.viewers; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.value.AbstractObservableValue; >-import org.eclipse.jface.util.Util; >-import org.eclipse.jface.viewers.ISelection; >-import org.eclipse.jface.viewers.ISelectionChangedListener; >-import org.eclipse.jface.viewers.ISelectionProvider; >-import org.eclipse.jface.viewers.IStructuredSelection; >-import org.eclipse.jface.viewers.SelectionChangedEvent; >-import org.eclipse.jface.viewers.StructuredSelection; >- >-/** >- * Observes single selection of an <code>ISelectionProvider</code>. >- * >- * @since 1.1 >- */ >-public class SelectionProviderSingleSelectionObservableValue extends >- AbstractObservableValue { >- >- private final ISelectionProvider selectionProvider; >- >- private boolean updating = false; >- >- private Object currentSelection; >- >- private ISelectionChangedListener selectionChangedListener; >- >- /** >- * Constructs a new instance associated with the provided >- * <code>selectionProvider</code>. In order to initialize itself properly >- * the constructor invokes {@link #doGetValue()}. This could be dangerous >- * for subclasses, see {@link #doGetValue()} for an explanation. >- * >- * @param realm >- * >- * @param selectionProvider >- * @see #doGetValue() >- */ >- public SelectionProviderSingleSelectionObservableValue(Realm realm, >- ISelectionProvider selectionProvider) { >- super(realm); >- if (selectionProvider == null) { >- throw new IllegalArgumentException( >- "The 'selectionProvider' parameter is null."); //$NON-NLS-1$ >- } >- >- this.selectionProvider = selectionProvider; >- this.currentSelection = doGetValue(); >- >- selectionChangedListener = new ISelectionChangedListener() { >- public void selectionChanged(SelectionChangedEvent event) { >- if (!updating) { >- Object oldSelection = currentSelection; >- currentSelection = doGetValue(); >- fireValueChange(Diffs.createValueDiff(oldSelection, >- currentSelection)); >- } >- } >- }; >- selectionProvider.addSelectionChangedListener(selectionChangedListener); >- } >- >- /** >- * Sets the selection to the provided <code>value</code>. Value change >- * events are fired after selection is set in the selection provider. >- * >- * @param value >- * object to set as selected, <code>null</code> if wanting to >- * remove selection >- */ >- public void doSetValue(final Object value) { >- try { >- updating = true; >- >- Object oldSelection = currentSelection; >- selectionProvider >- .setSelection(value == null ? StructuredSelection.EMPTY >- : new StructuredSelection(value)); >- currentSelection = doGetValue(); >- if (!Util.equals(oldSelection, currentSelection)) { >- fireValueChange(Diffs.createValueDiff(oldSelection, >- currentSelection)); >- } >- } finally { >- updating = false; >- } >- } >- >- /** >- * Retrieves the current selection. >- * <p> >- * If a subclass overrides this method it must not depend upon the subclass >- * to have been fully initialized before this method is invoked. >- * <code>doGetValue()</code> is invoked by the >- * {@link #SelectionProviderSingleSelectionObservableValue(Realm, ISelectionProvider) constructor} >- * which means the subclass's constructor will not have fully executed >- * before this method is invoked. >- * </p> >- * >- * @return selection will be an instance of >- * <code>IStructuredSelection</code> if a selection exists, >- * <code>null</code> if no selection >- * @see #SelectionProviderSingleSelectionObservableValue(Realm, >- * ISelectionProvider) >- */ >- protected Object doGetValue() { >- ISelection selection = selectionProvider.getSelection(); >- if (selection instanceof IStructuredSelection) { >- IStructuredSelection sel = (IStructuredSelection) selection; >- return sel.getFirstElement(); >- } >- >- return null; >- } >- >- public Object getValueType() { >- return null; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- selectionProvider >- .removeSelectionChangedListener(selectionChangedListener); >- super.dispose(); >- } >-} >Index: src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsObservableSet.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsObservableSet.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsObservableSet.java >--- src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsObservableSet.java 19 Mar 2008 23:03:24 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,219 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Matthew Hall and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Matthew Hall - initial API and implementation (bug 124684) >- ******************************************************************************/ >- >-package org.eclipse.jface.internal.databinding.viewers; >- >-import java.util.Collection; >-import java.util.Collections; >-import java.util.HashSet; >-import java.util.Iterator; >-import java.util.Set; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.set.AbstractObservableSet; >-import org.eclipse.core.runtime.Assert; >-import org.eclipse.jface.viewers.CheckStateChangedEvent; >-import org.eclipse.jface.viewers.ICheckStateListener; >-import org.eclipse.jface.viewers.ICheckable; >- >-/** >- * >- * @since 1.2 >- */ >-public class CheckableCheckedElementsObservableSet extends >- AbstractObservableSet { >- private ICheckable checkable; >- private Set wrappedSet; >- private Object elementType; >- private ICheckStateListener listener; >- >- /** >- * Constructs a new instance on the given realm and checkable. >- * >- * @param realm >- * the observable's realm >- * @param checkable >- * the ICheckable to track >- * @param elementType >- * type of elements in the set >- */ >- public CheckableCheckedElementsObservableSet(Realm realm, >- ICheckable checkable, Object elementType) { >- this(realm, checkable, elementType, new HashSet()); >- } >- >- /** >- * Constructs a new instance of the given realm, and checkable, >- * >- * @param realm >- * the observable's realm >- * @param checkable >- * the ICheckable to track >- * @param elementType >- * type of elements in the set >- * @param wrappedSet >- * the set being wrapped >- */ >- public CheckableCheckedElementsObservableSet(Realm realm, >- ICheckable checkable, Object elementType, final Set wrappedSet) { >- super(realm); >- Assert.isNotNull(checkable, "Checkable cannot be null"); //$NON-NLS-1$ >- Assert.isNotNull(wrappedSet, "Wrapped set cannot be null"); //$NON-NLS-1$ >- this.checkable = checkable; >- this.wrappedSet = wrappedSet; >- this.elementType = elementType; >- >- listener = new ICheckStateListener() { >- public void checkStateChanged(CheckStateChangedEvent event) { >- Object element = event.getElement(); >- if (event.getChecked()) { >- if (wrappedSet.add(element)) >- fireSetChange(Diffs.createSetDiff(Collections >- .singleton(element), Collections.EMPTY_SET)); >- } else { >- if (wrappedSet.remove(element)) >- fireSetChange(Diffs.createSetDiff( >- Collections.EMPTY_SET, Collections >- .singleton(element))); >- } >- } >- }; >- checkable.addCheckStateListener(listener); >- } >- >- protected Set getWrappedSet() { >- return wrappedSet; >- } >- >- Set createDiffSet() { >- return new HashSet(); >- } >- >- public Object getElementType() { >- return elementType; >- } >- >- public boolean add(Object o) { >- getterCalled(); >- boolean added = wrappedSet.add(o); >- if (added) { >- checkable.setChecked(o, true); >- fireSetChange(Diffs.createSetDiff(Collections.singleton(o), >- Collections.EMPTY_SET)); >- } >- return added; >- } >- >- public boolean remove(Object o) { >- getterCalled(); >- boolean removed = wrappedSet.remove(o); >- if (removed) { >- checkable.setChecked(o, false); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >- Collections.singleton(o))); >- } >- return removed; >- } >- >- public boolean addAll(Collection c) { >- getterCalled(); >- Set additions = createDiffSet(); >- for (Iterator iterator = c.iterator(); iterator.hasNext();) { >- Object element = iterator.next(); >- if (wrappedSet.add(element)) { >- checkable.setChecked(element, true); >- additions.add(element); >- } >- } >- boolean changed = !additions.isEmpty(); >- if (changed) >- fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET)); >- return changed; >- } >- >- public boolean removeAll(Collection c) { >- getterCalled(); >- Set removals = createDiffSet(); >- for (Iterator iterator = c.iterator(); iterator.hasNext();) { >- Object element = iterator.next(); >- if (wrappedSet.remove(element)) { >- checkable.setChecked(element, false); >- removals.add(element); >- } >- } >- boolean changed = !removals.isEmpty(); >- if (changed) >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); >- return changed; >- } >- >- public boolean retainAll(Collection c) { >- getterCalled(); >- >- // To ensure that elements are compared correctly, e.g. ViewerElementSet >- Set toRetain = createDiffSet(); >- toRetain.addAll(c); >- >- Set removals = createDiffSet(); >- for (Iterator iterator = wrappedSet.iterator(); iterator.hasNext();) { >- Object element = iterator.next(); >- if (!toRetain.contains(element)) { >- iterator.remove(); >- checkable.setChecked(element, false); >- removals.add(element); >- } >- } >- boolean changed = !removals.isEmpty(); >- if (changed) >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); >- return changed; >- } >- >- public void clear() { >- removeAll(wrappedSet); >- } >- >- public Iterator iterator() { >- getterCalled(); >- final Iterator wrappedIterator = wrappedSet.iterator(); >- return new Iterator() { >- private Object last = null; >- >- public boolean hasNext() { >- getterCalled(); >- return wrappedIterator.hasNext(); >- } >- >- public Object next() { >- getterCalled(); >- return last = wrappedIterator.next(); >- } >- >- public void remove() { >- getterCalled(); >- wrappedIterator.remove(); >- checkable.setChecked(last, false); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >- Collections.singleton(last))); >- } >- }; >- } >- >- public synchronized void dispose() { >- if (checkable != null) { >- checkable.removeCheckStateListener(listener); >- checkable = null; >- listener = null; >- } >- super.dispose(); >- } >-} >Index: src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java >--- src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTObservableValue.java 11 Apr 2008 20:46:33 -0000 1.8 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,69 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2006 The Pampered Chef, Inc. and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * The Pampered Chef, Inc. - initial API and implementation >- ******************************************************************************/ >- >-package org.eclipse.jface.internal.databinding.provisional.swt; >- >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.value.AbstractObservableValue; >-import org.eclipse.jface.databinding.swt.ISWTObservableValue; >-import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.swt.events.DisposeEvent; >-import org.eclipse.swt.events.DisposeListener; >-import org.eclipse.swt.widgets.Widget; >- >-/** >- * NON-API - An abstract superclass for observable values that gurantees that the >- * observable will be disposed when the control to which it is attached is >- * disposed. >- * >- * @since 1.1 >- */ >-public abstract class AbstractSWTObservableValue extends AbstractObservableValue implements ISWTObservableValue { >- >- private final Widget widget; >- >- /** >- * Standard constructor for an SWT ObservableValue. Makes sure that >- * the observable gets disposed when the SWT widget is disposed. >- * >- * @param widget >- */ >- protected AbstractSWTObservableValue(Widget widget) { >- this(SWTObservables.getRealm(widget.getDisplay()), widget); >- } >- >- /** >- * Constructor that allows for the setting of the realm. Makes sure that the >- * observable gets disposed when the SWT widget is disposed. >- * >- * @param realm >- * @param widget >- * @since 1.2 >- */ >- protected AbstractSWTObservableValue(Realm realm, Widget widget) { >- super(realm); >- this.widget = widget; >- widget.addDisposeListener(disposeListener); >- } >- >- private DisposeListener disposeListener = new DisposeListener() { >- public void widgetDisposed(DisposeEvent e) { >- AbstractSWTObservableValue.this.dispose(); >- } >- }; >- >- /** >- * @return Returns the widget. >- */ >- public Widget getWidget() { >- return widget; >- } >-} >Index: src/org/eclipse/jface/databinding/swt/SWTObservables.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/SWTObservables.java,v >retrieving revision 1.24 >diff -u -r1.24 SWTObservables.java >--- src/org/eclipse/jface/databinding/swt/SWTObservables.java 26 Oct 2008 18:51:28 -0000 1.24 >+++ src/org/eclipse/jface/databinding/swt/SWTObservables.java 17 Dec 2008 01:04:05 -0000 >@@ -9,9 +9,10 @@ > * IBM Corporation - initial API and implementation > * Matt Carter - bug 170668 > * Brad Reynolds - bug 170848 >- * Matthew Hall - bugs 180746, 207844, 245647, 248621, 232917 >+ * Matthew Hall - bugs 180746, 207844, 245647, 248621, 232917, 194734 > * Michael Krauter - bug 180223 > * Boris Bokowski - bug 245647 >+ * Tom Schindl - bug 246462 > *******************************************************************************/ > package org.eclipse.jface.databinding.swt; > >@@ -24,34 +25,17 @@ > 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.internal.databinding.internal.swt.LinkObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue; >-import org.eclipse.jface.internal.databinding.swt.CComboObservableList; >-import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.CComboSingleSelectionObservableValue; >-import org.eclipse.jface.internal.databinding.swt.CLabelObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ComboObservableList; >-import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ComboSingleSelectionObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ControlObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ItemObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ItemTooltipObservableValue; >-import org.eclipse.jface.internal.databinding.swt.LabelObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ListObservableList; >-import org.eclipse.jface.internal.databinding.swt.ListObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ListSingleSelectionObservableValue; >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; > import org.eclipse.jface.internal.databinding.swt.SWTDelayedObservableValueDecorator; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >-import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ShellObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >-import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; >-import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; >-import org.eclipse.jface.internal.databinding.swt.TextObservableValue; >+import org.eclipse.jface.internal.databinding.swt.SWTObservableListDecorator; >+import org.eclipse.jface.internal.databinding.swt.SWTObservableValueDecorator; >+import org.eclipse.jface.internal.databinding.swt.SWTVetoableValueDecorator; > 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; >@@ -139,26 +123,41 @@ > .observeDelayedValue(delay, observable), observable.getWidget()); > } > >+ private static ISWTObservableValue observeWidgetProperty(Widget widget, >+ IValueProperty property) { >+ return new SWTObservableValueDecorator(property.observeValue( >+ getRealm(widget.getDisplay()), widget), 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 > */ > public static ISWTObservableValue observeEnabled(Control control) { >- return new ControlObservableValue(control, SWTProperties.ENABLED); >+ return observeWidgetProperty(control, ControlProperties.enabled()); > } > > /** >+ * 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 > */ > public static ISWTObservableValue observeVisible(Control control) { >- return new ControlObservableValue(control, SWTProperties.VISIBLE); >+ return observeWidgetProperty(control, ControlProperties.visible()); > } > > /** >- * Returns an observable tracking the tooltip text of the given item. The supported types are: >+ * Returns an observable tracking the tooltip text of the given item. The >+ * supported types are: > * <ul> > * <li>org.eclipse.swt.widgets.Control</li> > * <li>org.eclipse.swt.custom.CTabItem</li> >@@ -168,35 +167,49 @@ > * <li>org.eclipse.swt.widgets.TrayItem</li> > * <li>org.eclipse.swt.widgets.TreeColumn</li> > * </ul> >+ * > * @param widget >- * @return an observable value tracking the tooltip text of the given >- * item >+ * @return an observable value tracking the tooltip text of the given item > * > * @since 1.3 > */ > public static ISWTObservableValue observeTooltipText(Widget widget) { > if (widget instanceof Control) { >- return new ControlObservableValue((Control)widget, SWTProperties.TOOLTIP_TEXT); >- } else if (widget instanceof CTabItem >- || widget instanceof TabItem >- || widget instanceof TableColumn >- || widget instanceof ToolItem >- || widget instanceof TrayItem >- || widget instanceof TreeColumn) { >- return new ItemTooltipObservableValue((Item) widget); >+ return observeTooltipText((Control) widget); > } >- >- throw new IllegalArgumentException( >- "Item [" + widget.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ >+ IValueProperty property; >+ if (widget instanceof CTabItem) { >+ property = CTabItemProperties.tooltipText(); >+ } else if (widget instanceof TabItem) { >+ property = TabItemProperties.tooltipText(); >+ } else if (widget instanceof TableColumn) { >+ property = TableColumnProperties.tooltipText(); >+ } else if (widget instanceof ToolItem) { >+ property = ToolItemProperties.tooltipText(); >+ } else if (widget instanceof TrayItem) { >+ property = TrayItemProperties.tooltipText(); >+ } else if (widget instanceof TreeColumn) { >+ property = TreeColumnProperties.tooltipText(); >+ } else { >+ throw new IllegalArgumentException( >+ "Item [" + widget.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ >+ return observeWidgetProperty(widget, property); > } > > /** >+ * 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 > */ > public static ISWTObservableValue observeTooltipText(Control control) { >- return observeTooltipText((Widget) control); >+ return observeWidgetProperty(control, ControlProperties.toolTipText()); > } > > /** >@@ -217,26 +230,25 @@ > * if <code>control</code> type is unsupported > */ > public static ISWTObservableValue observeSelection(Control control) { >+ IValueProperty property; > if (control instanceof Spinner) { >- return new SpinnerObservableValue((Spinner) control, >- SWTProperties.SELECTION); >+ property = SpinnerProperties.selection(); > } else if (control instanceof Button) { >- return new ButtonObservableValue((Button) control); >+ property = ButtonProperties.selection(); > } else if (control instanceof Combo) { >- return new ComboObservableValue((Combo) control, >- SWTProperties.SELECTION); >+ property = ComboProperties.selection(); > } else if (control instanceof CCombo) { >- return new CComboObservableValue((CCombo) control, >- SWTProperties.SELECTION); >+ property = CComboProperties.selection(); > } else if (control instanceof List) { >- return new ListObservableValue((List) control); >+ property = ListProperties.selection(); > } else if (control instanceof Scale) { >- return new ScaleObservableValue((Scale) control, >- SWTProperties.SELECTION); >+ property = ScaleProperties.selection(); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ > } > >- throw new IllegalArgumentException( >- "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ return observeWidgetProperty(control, property); > } > > /** >@@ -253,15 +265,17 @@ > * if <code>control</code> type is unsupported > */ > public static ISWTObservableValue observeMin(Control control) { >+ IValueProperty property; > if (control instanceof Spinner) { >- return new SpinnerObservableValue((Spinner) control, >- SWTProperties.MIN); >+ property = SpinnerProperties.minimum(); > } else if (control instanceof Scale) { >- return new ScaleObservableValue((Scale) control, SWTProperties.MIN); >+ property = ScaleProperties.minimum(); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ > } > >- throw new IllegalArgumentException( >- "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ return observeWidgetProperty(control, property); > } > > /** >@@ -278,15 +292,17 @@ > * if <code>control</code> type is unsupported > */ > public static ISWTObservableValue observeMax(Control control) { >+ IValueProperty property; > if (control instanceof Spinner) { >- return new SpinnerObservableValue((Spinner) control, >- SWTProperties.MAX); >+ property = SpinnerProperties.maximum(); > } else if (control instanceof Scale) { >- return new ScaleObservableValue((Scale) control, SWTProperties.MAX); >+ property = ScaleProperties.maximum(); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ > } > >- throw new IllegalArgumentException( >- "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ return observeWidgetProperty(control, property); > } > > /** >@@ -294,21 +310,29 @@ > * <code>control</code>. The supported types are: > * <ul> > * <li>org.eclipse.swt.widgets.Text</li> >+ * <li>org.eclipse.swt.custom.StyledText (as of 1.3)</li> > * </ul> > * > * @param control >- * @param event event type to register for change events >+ * @param event >+ * event type to register for change events > * @return observable value > * @throws IllegalArgumentException > * if <code>control</code> type is unsupported > */ > public static ISWTObservableValue observeText(Control control, int event) { >+ IValueProperty property; > if (control instanceof Text) { >- return new TextObservableValue((Text) control, event); >+ property = TextProperties.text(event); >+ } else if (control instanceof StyledText) { >+ property = StyledTextProperties.text(event); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ > } > >- throw new IllegalArgumentException( >- "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ return new SWTVetoableValueDecorator(property.observeValue( >+ getRealm(control.getDisplay()), control), control); > } > > /** >@@ -329,27 +353,14 @@ > * @return observable value > * @throws IllegalArgumentException > * if the type of <code>widget</code> is unsupported >- * >+ * > * @since 1.3 > */ > public static ISWTObservableValue observeText(Widget widget) { >- if (widget instanceof Label) { >- return new LabelObservableValue((Label) widget); >- } else if (widget instanceof Link) { >- return new LinkObservableValue((Link) widget); >- } else if (widget instanceof CLabel) { >- return new CLabelObservableValue((CLabel) widget); >- } else if (widget instanceof Combo) { >- return new ComboObservableValue((Combo) widget, SWTProperties.TEXT); >- } else if (widget instanceof CCombo) { >- return new CComboObservableValue((CCombo) widget, >- SWTProperties.TEXT); >- } else if (widget instanceof Shell) { >- return new ShellObservableValue((Shell) widget); >- } else if (widget instanceof Text) { >- return new TextObservableValue((Text) widget, SWT.None); >+ if (widget instanceof Control) { >+ return observeText((Control) widget); > } else if (widget instanceof Item) { >- return new ItemObservableValue((Item)widget); >+ return observeWidgetProperty(widget, ItemProperties.text()); > } > > throw new IllegalArgumentException( >@@ -367,6 +378,7 @@ > * <li>org.eclipse.swt.custom.CCombo</li> > * <li>org.eclipse.swt.widgets.Shell</li> > * <li>org.eclipse.swt.widgets.Text (as of 1.3)</li> >+ * <li>org.eclipse.swt.custom.StyledText (as of 1.3)</li> > * </ul> > * > * @param control >@@ -375,7 +387,29 @@ > * if <code>control</code> type is unsupported > */ > public static ISWTObservableValue observeText(Control control) { >- return observeText((Widget) control); >+ if (control instanceof Text || control instanceof StyledText) { >+ return observeText(control, SWT.None); >+ } >+ >+ IValueProperty property; >+ if (control instanceof Label) { >+ property = LabelProperties.text(); >+ } else if (control instanceof Link) { >+ property = LinkProperties.text(); >+ } else if (control instanceof CLabel) { >+ property = CLabelProperties.text(); >+ } else if (control instanceof Combo) { >+ property = ComboProperties.text(); >+ } else if (control instanceof CCombo) { >+ property = CComboProperties.text(); >+ } else if (control instanceof Shell) { >+ property = ShellProperties.text(); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ } >+ >+ return observeWidgetProperty(control, property); > } > > /** >@@ -393,16 +427,20 @@ > * if <code>control</code> type is unsupported > */ > public static IObservableList observeItems(Control control) { >+ IListProperty property; > if (control instanceof Combo) { >- return new ComboObservableList((Combo) control); >+ property = ComboProperties.items(); > } else if (control instanceof CCombo) { >- return new CComboObservableList((CCombo) control); >+ property = CComboProperties.items(); > } else if (control instanceof List) { >- return new ListObservableList((List) control); >+ property = ListProperties.items(); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ > } > >- throw new IllegalArgumentException( >- "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ return new SWTObservableListDecorator(property.observeList( >+ getRealm(control.getDisplay()), control), control); > } > > /** >@@ -422,85 +460,111 @@ > */ > public static ISWTObservableValue observeSingleSelectionIndex( > Control control) { >+ IValueProperty property; > if (control instanceof Table) { >- return new TableSingleSelectionObservableValue((Table) control); >+ property = TableProperties.singleSelectionIndex(); > } else if (control instanceof Combo) { >- return new ComboSingleSelectionObservableValue((Combo) control); >+ property = ComboProperties.singleSelectionIndex(); > } else if (control instanceof CCombo) { >- return new CComboSingleSelectionObservableValue((CCombo) control); >+ property = CComboProperties.singleSelectionIndex(); > } else if (control instanceof List) { >- return new ListSingleSelectionObservableValue((List) control); >+ property = ListProperties.singleSelectionIndex(); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ > } > >- throw new IllegalArgumentException( >- "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ return observeWidgetProperty(control, property); > } > > /** >+ * 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 > */ > public static ISWTObservableValue observeForeground(Control control) { >- return new ControlObservableValue(control, SWTProperties.FOREGROUND); >+ return observeWidgetProperty(control, ControlProperties.foreground()); > } > > /** >+ * 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 > */ > public static ISWTObservableValue observeBackground(Control control) { >- return new ControlObservableValue(control, SWTProperties.BACKGROUND); >+ return observeWidgetProperty(control, ControlProperties.background()); > } > > /** >+ * 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 > */ > public static ISWTObservableValue observeFont(Control control) { >- return new ControlObservableValue(control, SWTProperties.FONT); >+ return observeWidgetProperty(control, ControlProperties.font()); > } >- >+ > /** >+ * 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 > */ > public static ISWTObservableValue observeSize(Control control) { >- return new ControlObservableValue(control,SWTProperties.SIZE); >+ return observeWidgetProperty(control, ControlProperties.size()); > } >- >+ > /** >+ * 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 new ControlObservableValue(control,SWTProperties.LOCATION); >+ return observeWidgetProperty(control, ControlProperties.location()); > } >- >+ > /** >+ * 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 > */ > public static ISWTObservableValue observeFocus(Control control) { >- return new ControlObservableValue(control,SWTProperties.FOCUS); >+ return observeWidgetProperty(control, ControlProperties.focused()); > } >- >+ > /** >+ * 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 > */ > public static ISWTObservableValue observeBounds(Control control) { >- return new ControlObservableValue(control,SWTProperties.BOUNDS); >+ return observeWidgetProperty(control, ControlProperties.bounds()); > } >- >+ > /** >- * Returns an observable observing the editable attribute of >- * the provided <code>control</code>. The supported types are: >+ * Returns an observable observing the editable attribute of the provided >+ * <code>control</code>. The supported types are: > * <ul> > * <li>org.eclipse.swt.widgets.Text</li> > * </ul> >@@ -511,12 +575,15 @@ > * if <code>control</code> type is unsupported > */ > public static ISWTObservableValue observeEditable(Control control) { >+ IValueProperty property; > if (control instanceof Text) { >- return new TextEditableObservableValue((Text) control); >+ property = TextProperties.editable(); >+ } else { >+ throw new IllegalArgumentException( >+ "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ > } >- >- throw new IllegalArgumentException( >- "Widget [" + control.getClass().getName() + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >+ >+ return observeWidgetProperty(control, property); > } > > private static class DisplayRealm extends Realm { >Index: src/org/eclipse/jface/internal/databinding/swt/ScaleObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ScaleObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ScaleObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ScaleObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,150 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Peter Centgraf - bug 175763 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.runtime.Assert; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.events.SelectionAdapter; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.widgets.Scale; >- >-/** >- * @since 1.0 >- * >- */ >-public class ScaleObservableValue extends AbstractSWTObservableValue { >- >- private final Scale scale; >- >- private final String attribute; >- >- private boolean updating = false; >- >- private int currentSelection; >- >- private SelectionListener listener; >- >- /** >- * @param scale >- * @param attribute >- */ >- public ScaleObservableValue(Scale scale, String attribute) { >- super(scale); >- this.scale = scale; >- this.attribute = attribute; >- init(); >- } >- >- /** >- * @param realm >- * @param scale >- * @param attribute >- */ >- public ScaleObservableValue(Realm realm, Scale scale, String attribute) { >- super(realm, scale); >- this.scale = scale; >- this.attribute = attribute; >- init(); >- } >- >- private void init() { >- if (attribute.equals(SWTProperties.SELECTION)) { >- currentSelection = scale.getSelection(); >- scale.addSelectionListener(listener = new SelectionAdapter() { >- public void widgetSelected(SelectionEvent e) { >- if (!updating) { >- int newSelection = ScaleObservableValue.this.scale >- .getSelection(); >- notifyIfChanged(currentSelection, newSelection); >- currentSelection = newSelection; >- } >- } >- }); >- } else if (!attribute.equals(SWTProperties.MIN) >- && !attribute.equals(SWTProperties.MAX)) { >- throw new IllegalArgumentException( >- "Attribute name not valid: " + attribute); //$NON-NLS-1$ >- } >- } >- >- public void doSetValue(final Object value) { >- int oldValue; >- int newValue; >- try { >- updating = true; >- newValue = ((Integer) value).intValue(); >- if (attribute.equals(SWTProperties.SELECTION)) { >- oldValue = scale.getSelection(); >- scale.setSelection(newValue); >- currentSelection = newValue; >- } else if (attribute.equals(SWTProperties.MIN)) { >- oldValue = scale.getMinimum(); >- scale.setMinimum(newValue); >- } else if (attribute.equals(SWTProperties.MAX)) { >- oldValue = scale.getMaximum(); >- scale.setMaximum(newValue); >- } else { >- Assert.isTrue(false, "invalid attribute name:" + attribute); //$NON-NLS-1$ >- return; >- } >- >- notifyIfChanged(oldValue, newValue); >- } finally { >- updating = false; >- } >- } >- >- public Object doGetValue() { >- int value = 0; >- if (attribute.equals(SWTProperties.SELECTION)) { >- value = scale.getSelection(); >- } else if (attribute.equals(SWTProperties.MIN)) { >- value = scale.getMinimum(); >- } else if (attribute.equals(SWTProperties.MAX)) { >- value = scale.getMaximum(); >- } >- return new Integer(value); >- } >- >- public Object getValueType() { >- return Integer.TYPE; >- } >- >- /** >- * @return attribute being observed >- */ >- public String getAttribute() { >- return attribute; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- >- if (listener != null && !scale.isDisposed()) { >- scale.removeSelectionListener(listener); >- } >- listener = null; >- } >- >- private void notifyIfChanged(int oldValue, int newValue) { >- if (oldValue != newValue) { >- fireValueChange(Diffs.createValueDiff(new Integer(oldValue), >- new Integer(newValue))); >- } >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/CComboObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CComboObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CComboObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/CComboObservableValue.java 14 Apr 2008 17:56:26 -0000 1.4 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,166 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 164653 >- * Ashley Cambrell - bug 198904 >- * Matthew Hall - bug 118516 >- * Eric Rizzo - bug 134884 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.runtime.Assert; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.custom.CCombo; >-import org.eclipse.swt.events.ModifyEvent; >-import org.eclipse.swt.events.ModifyListener; >- >-/** >- * @since 3.2 >- * >- */ >-public class CComboObservableValue extends AbstractSWTObservableValue { >- >- /** >- * >- */ >- >- private final CCombo ccombo; >- >- private final String attribute; >- >- private boolean updating = false; >- >- private String currentValue; >- >- private ModifyListener modifyListener; >- >- /** >- * @param ccombo >- * @param attribute >- */ >- public CComboObservableValue(CCombo ccombo, String attribute) { >- super(ccombo); >- this.ccombo = ccombo; >- this.attribute = attribute; >- init(); >- } >- >- /** >- * @param realm >- * @param ccombo >- * @param attribute >- */ >- public CComboObservableValue(Realm realm, CCombo ccombo, String attribute) { >- super(realm, ccombo); >- this.ccombo = ccombo; >- this.attribute = attribute; >- init(); >- } >- >- private void init() { >- if (attribute.equals(SWTProperties.SELECTION) >- || attribute.equals(SWTProperties.TEXT)) { >- this.currentValue = ccombo.getText(); >- modifyListener = new ModifyListener() { >- >- public void modifyText(ModifyEvent e) { >- if (!updating) { >- String oldValue = currentValue; >- currentValue = CComboObservableValue.this.ccombo >- .getText(); >- >- notifyIfChanged(oldValue, currentValue); >- } >- } >- }; >- ccombo.addModifyListener(modifyListener); >- } else >- throw new IllegalArgumentException(); >- } >- >- public void doSetValue(final Object value) { >- String oldValue = ccombo.getText(); >- try { >- updating = true; >- if (attribute.equals(SWTProperties.TEXT)) { >- String stringValue = value != null ? value.toString() : ""; //$NON-NLS-1$ >- ccombo.setText(stringValue); >- } else if (attribute.equals(SWTProperties.SELECTION)) { >- String items[] = ccombo.getItems(); >- int index = -1; >- if (value == null) { >- ccombo.select(-1); >- } else if (items != null) { >- for (int i = 0; i < items.length; i++) { >- if (value.equals(items[i])) { >- index = i; >- break; >- } >- } >- if (index == -1) { >- ccombo.setText((String) value); >- } else { >- ccombo.select(index); // -1 will not "unselect" >- } >- } >- } >- } finally { >- updating = false; >- currentValue = ccombo.getText(); >- } >- >- notifyIfChanged(oldValue, currentValue); >- } >- >- public Object doGetValue() { >- if (attribute.equals(SWTProperties.TEXT)) >- return ccombo.getText(); >- >- Assert.isTrue(attribute.equals(SWTProperties.SELECTION), >- "unexpected attribute: " + attribute); //$NON-NLS-1$ >- // The problem with a ccombo, is that it changes the text and >- // fires before it update its selection index >- return ccombo.getText(); >- } >- >- public Object getValueType() { >- Assert.isTrue(attribute.equals(SWTProperties.TEXT) >- || attribute.equals(SWTProperties.SELECTION), >- "unexpected attribute: " + attribute); //$NON-NLS-1$ >- return String.class; >- } >- >- /** >- * @return attribute being observed >- */ >- public String getAttribute() { >- return attribute; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- >- if (modifyListener != null && !ccombo.isDisposed()) { >- ccombo.removeModifyListener(modifyListener); >- } >- } >- >- private void notifyIfChanged(String oldValue, String newValue) { >- if (!oldValue.equals(newValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, ccombo.getText())); >- } >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/CLabelObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CLabelObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CLabelObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/CLabelObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,62 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 164653 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.custom.CLabel; >- >-/** >- * @since 1.0 >- * >- */ >-public class CLabelObservableValue extends AbstractSWTObservableValue { >- >- private final CLabel label; >- >- /** >- * @param label >- */ >- public CLabelObservableValue(CLabel label) { >- super(label); >- this.label = label; >- } >- >- /** >- * @param realm >- * @param label >- */ >- public CLabelObservableValue(Realm realm, CLabel label) { >- super(realm, label); >- this.label = label; >- } >- >- public void doSetValue(final Object value) { >- String oldValue = label.getText(); >- String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ >- label.setText(newValue); >- >- if (!newValue.equals(oldValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >- >- public Object doGetValue() { >- return label.getText(); >- } >- >- public Object getValueType() { >- return String.class; >- } >- >-} >Index: src/org/eclipse/jface/internal/databinding/swt/ComboObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ComboObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ComboObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ComboObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,155 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 164653 >- * Ashley Cambrell - bug 198904 >- * Matthew Hall - bug 118516 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.runtime.Assert; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.events.ModifyEvent; >-import org.eclipse.swt.events.ModifyListener; >-import org.eclipse.swt.widgets.Combo; >- >-/** >- * @since 3.2 >- * >- */ >-public class ComboObservableValue extends AbstractSWTObservableValue { >- >- private final Combo combo; >- private final String attribute; >- private boolean updating = false; >- private String currentValue; >- private ModifyListener modifyListener; >- >- /** >- * @param combo >- * @param attribute >- */ >- public ComboObservableValue(Combo combo, String attribute) { >- super(combo); >- this.combo = combo; >- this.attribute = attribute; >- init(); >- } >- >- /** >- * @param realm >- * @param combo >- * @param attribute >- */ >- public ComboObservableValue(Realm realm, Combo combo, String attribute) { >- super(realm, combo); >- this.combo = combo; >- this.attribute = attribute; >- init(); >- } >- >- private void init() { >- if (attribute.equals(SWTProperties.SELECTION) >- || attribute.equals(SWTProperties.TEXT)) { >- this.currentValue = combo.getText(); >- modifyListener = new ModifyListener() { >- >- public void modifyText(ModifyEvent e) { >- if (!updating) { >- String oldValue = currentValue; >- currentValue = ComboObservableValue.this.combo >- .getText(); >- >- notifyIfChanged(oldValue, currentValue); >- } >- } >- }; >- combo.addModifyListener(modifyListener); >- } else >- throw new IllegalArgumentException(); >- } >- >- public void doSetValue(final Object value) { >- String oldValue = combo.getText(); >- try { >- updating = true; >- if (attribute.equals(SWTProperties.TEXT)) { >- String stringValue = value != null ? value.toString() : ""; //$NON-NLS-1$ >- combo.setText(stringValue); >- } else if (attribute.equals(SWTProperties.SELECTION)) { >- String items[] = combo.getItems(); >- int index = -1; >- if (items != null && value != null) { >- for (int i = 0; i < items.length; i++) { >- if (value.equals(items[i])) { >- index = i; >- break; >- } >- } >- if (index == -1) { >- combo.setText((String) value); >- } else { >- combo.select(index); // -1 will not "unselect" >- } >- } >- } >- } finally { >- updating = false; >- currentValue = combo.getText(); >- } >- >- notifyIfChanged(oldValue, currentValue); >- } >- >- public Object doGetValue() { >- if (attribute.equals(SWTProperties.TEXT)) >- return combo.getText(); >- >- Assert.isTrue(attribute.equals(SWTProperties.SELECTION), >- "unexpected attribute: " + attribute); //$NON-NLS-1$ >- // The problem with a ccombo, is that it changes the text and >- // fires before it update its selection index >- return combo.getText(); >- } >- >- public Object getValueType() { >- Assert.isTrue(attribute.equals(SWTProperties.TEXT) >- || attribute.equals(SWTProperties.SELECTION), >- "unexpected attribute: " + attribute); //$NON-NLS-1$ >- return String.class; >- } >- >- /** >- * @return attribute being observed >- */ >- public String getAttribute() { >- return attribute; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- >- if (modifyListener != null && !combo.isDisposed()) { >- combo.removeModifyListener(modifyListener); >- } >- } >- >- private void notifyIfChanged(String oldValue, String newValue) { >- if (!oldValue.equals(newValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/LabelObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/LabelObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/LabelObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/LabelObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,62 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 164653 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.widgets.Label; >- >-/** >- * @since 3.3 >- * >- */ >-public class LabelObservableValue extends AbstractSWTObservableValue { >- >- private final Label label; >- >- /** >- * @param label >- */ >- public LabelObservableValue(Label label) { >- super(label); >- this.label = label; >- } >- >- /** >- * @param realm >- * @param label >- */ >- public LabelObservableValue(Realm realm, Label label) { >- super(realm, label); >- this.label = label; >- } >- >- public void doSetValue(final Object value) { >- String oldValue = label.getText(); >- String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ >- label.setText(newValue); >- >- if (!newValue.equals(oldValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >- >- public Object doGetValue() { >- return label.getText(); >- } >- >- public Object getValueType() { >- return String.class; >- } >- >-} >Index: src/org/eclipse/jface/internal/databinding/swt/ComboObservableList.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ComboObservableList.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ComboObservableList.java >--- src/org/eclipse/jface/internal/databinding/swt/ComboObservableList.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,51 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.swt.widgets.Combo; >- >-/** >- * @since 3.2 >- * >- */ >-public class ComboObservableList extends SWTObservableList { >- >- private final Combo combo; >- >- /** >- * @param combo >- */ >- public ComboObservableList(Combo combo) { >- super(SWTObservables.getRealm(combo.getDisplay())); >- this.combo = combo; >- } >- >- protected int getItemCount() { >- return combo.getItemCount(); >- } >- >- protected void setItems(String[] newItems) { >- combo.setItems(newItems); >- } >- >- protected String[] getItems() { >- return combo.getItems(); >- } >- >- protected String getItem(int index) { >- return combo.getItem(index); >- } >- >- protected void setItem(int index, String string) { >- combo.setItem(index, string); >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,71 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - bug 164653 >- * Ashley Cambrell - bugs 198903, 198904 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.widgets.Combo; >- >-/** >- * @since 1.0 >- * >- */ >-public class ComboSingleSelectionObservableValue extends >- SingleSelectionObservableValue { >- >- private SelectionListener selectionListener; >- >- /** >- * @param combo >- */ >- public ComboSingleSelectionObservableValue(Combo combo) { >- super(combo); >- } >- >- private Combo getCombo() { >- return (Combo) getWidget(); >- } >- >- protected void doAddSelectionListener(final Runnable runnable) { >- selectionListener = new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- runnable.run(); >- } >- >- public void widgetSelected(SelectionEvent e) { >- runnable.run(); >- } >- }; >- getCombo().addSelectionListener(selectionListener); >- } >- >- protected int doGetSelectionIndex() { >- return getCombo().getSelectionIndex(); >- } >- >- protected void doSetSelectionIndex(int index) { >- getCombo().select(index); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- if (selectionListener != null && !getCombo().isDisposed()) { >- getCombo().removeSelectionListener(selectionListener); >- } >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/ItemObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ItemObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ItemObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ItemObservableValue.java 1 Oct 2008 16:52:49 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,61 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.widgets.Item; >- >-/** >- * @since 3.5 >- * >- */ >-public class ItemObservableValue extends AbstractSWTObservableValue { >- >- private final Item item; >- >- /** >- * @param item >- */ >- public ItemObservableValue(Item item) { >- super(item); >- this.item = item; >- } >- >- /** >- * @param realm >- * @param item >- */ >- public ItemObservableValue(Realm realm, Item item) { >- super(realm, item); >- this.item = item; >- } >- >- public void doSetValue(final Object value) { >- String oldValue = item.getText(); >- String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ >- item.setText(newValue); >- >- if (!newValue.equals(oldValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >- >- public Object doGetValue() { >- return item.getText(); >- } >- >- public Object getValueType() { >- return String.class; >- } >- >-} >\ No newline at end of file >Index: src/org/eclipse/jface/internal/databinding/swt/ListObservableList.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ListObservableList.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ListObservableList.java >--- src/org/eclipse/jface/internal/databinding/swt/ListObservableList.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,51 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2008 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.swt.widgets.List; >- >-/** >- * @since 3.2 >- * >- */ >-public class ListObservableList extends SWTObservableList { >- >- private final List list; >- >- /** >- * @param list >- */ >- public ListObservableList(List list) { >- super(SWTObservables.getRealm(list.getDisplay())); >- this.list = list; >- } >- >- protected int getItemCount() { >- return list.getItemCount(); >- } >- >- protected void setItems(String[] newItems) { >- list.setItems(newItems); >- } >- >- protected String[] getItems() { >- return list.getItems(); >- } >- >- protected String getItem(int index) { >- return list.getItem(index); >- } >- >- protected void setItem(int index, String string) { >- list.setItem(index, string); >- } >-} >Index: src/org/eclipse/jface/databinding/swt/ButtonProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ButtonProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ButtonProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ButtonProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.ButtonSelectionProperty; >+ >+/** >+ * A factory for creating properties of SWT Buttons. >+ * >+ * @since 1.3 >+ */ >+public class ButtonProperties { >+ /** >+ * Returns a value property for the selection state of a SWT Button. >+ * >+ * @return a value property for the selection state of a SWT Button. >+ */ >+ public static IValueProperty selection() { >+ return new ButtonSelectionProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/viewers/CheckboxTableViewerProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/viewers/CheckboxTableViewerProperties.java >diff -N src/org/eclipse/jface/databinding/viewers/CheckboxTableViewerProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/viewers/CheckboxTableViewerProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.viewers; >+ >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.jface.internal.databinding.viewers.CheckboxTableViewerCheckedElementsProperty; >+ >+/** >+ * A factory for creating properties of JFace CheckboxTableViewer >+ * >+ * @since 1.3 >+ */ >+public class CheckboxTableViewerProperties { >+ /** >+ * Returns a set property for the checked elements of a JFace >+ * CheckboxTableViewer. >+ * >+ * @param elementType >+ * the element type of the returned property >+ * >+ * @return a set property for the checked elements of a JFace >+ * CheckboxTableViewer. >+ */ >+ public static ISetProperty checkedElements(Object elementType) { >+ return new CheckboxTableViewerCheckedElementsProperty(elementType); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlEnabledProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlEnabledProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlEnabledProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlEnabledProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlEnabledProperty extends WidgetBooleanValueProperty { >+ public boolean doGetBooleanValue(Object source) { >+ return ((Control) source).getEnabled(); >+ } >+ >+ void doSetBooleanValue(Object source, boolean value) { >+ ((Control) source).setEnabled(value); >+ } >+ >+ public String toString() { >+ return "Control.enabled <boolean>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/ScaleProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ScaleProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ScaleProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ScaleProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,51 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.ScaleMaximumProperty; >+import org.eclipse.jface.internal.databinding.swt.ScaleMinimumProperty; >+import org.eclipse.jface.internal.databinding.swt.ScaleSelectionProperty; >+ >+/** >+ * A factory for creating properties of SWT Scales. >+ * >+ * @since 1.3 >+ */ >+public class ScaleProperties { >+ /** >+ * Returns a value property for the selected value of a SWT Scale. >+ * >+ * @return a value property for the selected value of a SWT Scale. >+ */ >+ public static IValueProperty selection() { >+ return new ScaleSelectionProperty(); >+ } >+ >+ /** >+ * Returns a value property for the minimum value of a SWT Scale. >+ * >+ * @return a value property for the minimum value of a SWT Scale. >+ */ >+ public static IValueProperty minimum() { >+ return new ScaleMinimumProperty(); >+ } >+ >+ /** >+ * Returns a value property for the maximum value of a SWT Scale. >+ * >+ * @return a value property for the maximum value of a SWT Scale. >+ */ >+ public static IValueProperty maximum() { >+ return new ScaleMaximumProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ButtonSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ButtonSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ButtonSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ButtonSelectionProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Button; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ButtonSelectionProperty extends WidgetBooleanValueProperty { >+ /** >+ * >+ */ >+ public ButtonSelectionProperty() { >+ super(SWT.Selection); >+ } >+ >+ boolean doGetBooleanValue(Object source) { >+ return ((Button) source).getSelection(); >+ } >+ >+ void doSetBooleanValue(Object source, boolean value) { >+ ((Button) source).setSelection(value); >+ } >+ >+ public String toString() { >+ return "Button.selection <Boolean>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ScaleMaximumProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ScaleMaximumProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ScaleMaximumProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ScaleMaximumProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Scale; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ScaleMaximumProperty extends WidgetIntValueProperty { >+ int doGetIntValue(Object source) { >+ return ((Scale) source).getMaximum(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Scale) source).setMaximum(value); >+ } >+ >+ public String toString() { >+ return "Scale.maximum <int>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ListSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ListSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ListSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ListSelectionProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.List; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ListSelectionProperty extends WidgetStringValueProperty { >+ /** >+ * >+ */ >+ public ListSelectionProperty() { >+ super(SWT.Selection); >+ } >+ >+ String doGetStringValue(Object source) { >+ List list = (List) source; >+ int index = list.getSelectionIndex(); >+ if (index >= 0) >+ return list.getItem(index); >+ return null; >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ List list = (List) source; >+ String items[] = list.getItems(); >+ int index = -1; >+ if (items != null && value != null) { >+ for (int i = 0; i < items.length; i++) { >+ if (value.equals(items[i])) { >+ index = i; >+ break; >+ } >+ } >+ list.select(index); >+ } >+ } >+ >+ public String toString() { >+ return "List.selection <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ItemTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ItemTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ItemTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ItemTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Item; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ItemTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((Item) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((Item) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "Item.text <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/LinkTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/LinkTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/LinkTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/LinkTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Link; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class LinkTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((Link) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((Link) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "Link.text <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/ControlProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ControlProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ControlProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ControlProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,121 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.ControlBackgroundProperty; >+import org.eclipse.jface.internal.databinding.swt.ControlBoundsProperty; >+import org.eclipse.jface.internal.databinding.swt.ControlEnabledProperty; >+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.ControlTooltipTextProperty; >+import org.eclipse.jface.internal.databinding.swt.ControlVisibleProperty; >+ >+/** >+ * A factory for creating properties of SWT controls. >+ * >+ * @since 1.3 >+ */ >+public class ControlProperties { >+ /** >+ * Returns a value property for the enablement state of a SWT Control. >+ * >+ * @return a value property for the enablement state of a SWT Control. >+ */ >+ public static IValueProperty enabled() { >+ return new ControlEnabledProperty(); >+ } >+ >+ /** >+ * Returns a value property for the visibility state of a SWT Control. >+ * >+ * @return a value property for the visibility state of a SWT Control. >+ */ >+ public static IValueProperty visible() { >+ return new ControlVisibleProperty(); >+ } >+ >+ /** >+ * Returns a value property for the tooltip text of a SWT Control. >+ * >+ * @return a value property for the tooltip text of a SWT Control. >+ */ >+ public static IValueProperty toolTipText() { >+ return new ControlTooltipTextProperty(); >+ } >+ >+ /** >+ * Returns a value property for the foreground color of a SWT Control. >+ * >+ * @return a value property for the foreground color of a SWT Control. >+ */ >+ public static IValueProperty foreground() { >+ return new ControlForegroundProperty(); >+ } >+ >+ /** >+ * Returns a value property for the background color of a SWT Control. >+ * >+ * @return a value property for the background color of a SWT Control. >+ */ >+ public static IValueProperty background() { >+ return new ControlBackgroundProperty(); >+ } >+ >+ /** >+ * Returns a value property for the font of a SWT Control. >+ * >+ * @return a value property for the font of a SWT Control. >+ */ >+ public static IValueProperty font() { >+ return new ControlFontProperty(); >+ } >+ >+ /** >+ * Returns a value property for the size of a SWT Control. >+ * >+ * @return a value property for the size of a SWT Control. >+ */ >+ public static IValueProperty size() { >+ return new ControlSizeProperty(); >+ } >+ >+ /** >+ * Returns a value property for the location of a SWT Control. >+ * >+ * @return a value property for the location of a SWT Control. >+ */ >+ public static IValueProperty location() { >+ return new ControlLocationProperty(); >+ } >+ >+ /** >+ * Returns a value property for the bounds of a SWT Control. >+ * >+ * @return a value property for the bounds of a SWT Control. >+ */ >+ public static IValueProperty bounds() { >+ return new ControlBoundsProperty(); >+ } >+ >+ /** >+ * Returns a value property for the focus state of a SWT Control. >+ * >+ * @return a value property for the focus state of a SWT Control. >+ */ >+ public static IValueProperty focused() { >+ return new ControlFocusedProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/viewers/CheckboxTreeViewerProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/viewers/CheckboxTreeViewerProperties.java >diff -N src/org/eclipse/jface/databinding/viewers/CheckboxTreeViewerProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/viewers/CheckboxTreeViewerProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.viewers; >+ >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.jface.internal.databinding.viewers.CheckboxTreeViewerCheckedElementsProperty; >+ >+/** >+ * A factory for creating properties of JFace CheckboxTreeViewer >+ * >+ * @since 1.3 >+ */ >+public class CheckboxTreeViewerProperties { >+ /** >+ * Returns a set property for the checked elements of a JFace >+ * CheckboxTreeViewer. >+ * >+ * @param elementType >+ * the element type of the returned property >+ * >+ * @return a set property for the checked elements of a JFace >+ * CheckboxTreeViewer. >+ */ >+ public static ISetProperty checkedElements(Object elementType) { >+ return new CheckboxTreeViewerCheckedElementsProperty(elementType); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/TableColumnTooltipTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TableColumnTooltipTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TableColumnTooltipTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/TableColumnTooltipTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.TableColumn; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TableColumnTooltipTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((TableColumn) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((TableColumn) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "TableColumn.tooltipText <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ComboSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ComboSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ComboSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ComboSelectionProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Combo; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ComboSelectionProperty extends WidgetStringValueProperty { >+ /** >+ * >+ */ >+ public ComboSelectionProperty() { >+ super(SWT.Modify); >+ } >+ >+ String doGetStringValue(Object source) { >+ return ((Combo) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ Combo combo = (Combo) source; >+ String items[] = combo.getItems(); >+ int index = -1; >+ if (items != null && value != null) { >+ for (int i = 0; i < items.length; i++) { >+ if (value.equals(items[i])) { >+ index = i; >+ break; >+ } >+ } >+ if (index == -1) { >+ combo.setText(value); >+ } else { >+ combo.select(index); // -1 will not "unselect" >+ } >+ } >+ } >+ >+ public String toString() { >+ return "Combo.selection <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/CheckboxTreeViewerCheckedElementsProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/CheckboxTreeViewerCheckedElementsProperty.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/CheckboxTreeViewerCheckedElementsProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/CheckboxTreeViewerCheckedElementsProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,57 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.viewers; >+ >+import java.util.Arrays; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.jface.viewers.CheckboxTreeViewer; >+import org.eclipse.jface.viewers.ICheckable; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CheckboxTreeViewerCheckedElementsProperty extends >+ CheckableCheckedElementsProperty { >+ /** >+ * @param elementType >+ */ >+ public CheckboxTreeViewerCheckedElementsProperty(Object elementType) { >+ super(elementType); >+ } >+ >+ protected Set createElementSet(ICheckable checkable) { >+ return ViewerElementSet.withComparer(((CheckboxTreeViewer) checkable) >+ .getComparer()); >+ } >+ >+ protected Set doGetSet(ICheckable checkable) { >+ CheckboxTreeViewer viewer = (CheckboxTreeViewer) checkable; >+ Set set = createElementSet(viewer); >+ set.addAll(Arrays.asList(viewer.getCheckedElements())); >+ return set; >+ } >+ >+ protected void doSetSet(Object source, Set set, SetDiff diff) { >+ CheckboxTreeViewer viewer = (CheckboxTreeViewer) source; >+ viewer.setCheckedElements(set.toArray()); >+ } >+ >+ public String toString() { >+ String s = "CheckboxTreeViewer.checkedElements{}"; //$NON-NLS-1$ >+ if (getElementType() != null) >+ s += " <" + getElementType() + ">"; //$NON-NLS-1$//$NON-NLS-2$ >+ return s; >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/CLabelTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CLabelTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CLabelTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/CLabelTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.custom.CLabel; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CLabelTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((CLabel) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((CLabel) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "CLabel.text <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableSetDecorator.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableSetDecorator.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableSetDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableSetDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.viewers; >+ >+import org.eclipse.core.databinding.observable.set.DecoratingObservableSet; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.jface.databinding.viewers.IViewerObservableSet; >+import org.eclipse.jface.viewers.Viewer; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ViewerObservableSetDecorator extends DecoratingObservableSet >+ implements IViewerObservableSet { >+ private final Viewer viewer; >+ >+ /** >+ * @param decorated >+ * @param viewer >+ */ >+ public ViewerObservableSetDecorator(IObservableSet decorated, Viewer viewer) { >+ super(decorated, true); >+ this.viewer = viewer; >+ } >+ >+ public Viewer getViewer() { >+ return viewer; >+ } >+ >+} >Index: src/org/eclipse/jface/internal/databinding/swt/CComboItemsProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CComboItemsProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CComboItemsProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/CComboItemsProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.custom.CCombo; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CComboItemsProperty extends ControlStringListProperty { >+ protected void doSetStringList(Control control, String[] list) { >+ ((CCombo) control).setItems(list); >+ } >+ >+ public String[] doGetStringList(Control control) { >+ return ((CCombo) control).getItems(); >+ } >+ >+ public String toString() { >+ return "CCombo.items[] <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionIndexProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionIndexProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionIndexProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ComboSingleSelectionIndexProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Combo; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ComboSingleSelectionIndexProperty extends WidgetIntValueProperty { >+ /** >+ * >+ */ >+ public ComboSingleSelectionIndexProperty() { >+ super(new int[] { SWT.Selection, SWT.DefaultSelection }); >+ } >+ >+ int doGetIntValue(Object source) { >+ return ((Combo) source).getSelectionIndex(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Combo) source).select(value); >+ } >+ >+ public String toString() { >+ return "Combo.selectionIndex <int>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ToolItemTooltipTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ToolItemTooltipTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ToolItemTooltipTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ToolItemTooltipTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.ToolItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ToolItemTooltipTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((ToolItem) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((ToolItem) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "ToolItem.tooltipText <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/TextProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/TextProperties.java >diff -N src/org/eclipse/jface/databinding/swt/TextProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/TextProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.TextEditableProperty; >+import org.eclipse.jface.internal.databinding.swt.TextTextProperty; >+import org.eclipse.swt.SWT; >+ >+/** >+ * A factory for creating properties of SWT Texts. >+ * >+ * @since 1.3 >+ */ >+public class TextProperties { >+ /** >+ * Returns a value property for the text of a SWT Text. >+ * >+ * @param event >+ * the SWT event type to register for change events. May be >+ * {@link SWT#None}, {@link SWT#Modify} or {@link SWT#FocusOut}. >+ * >+ * @return a value property for the text of a SWT Text. >+ */ >+ public static IValueProperty text(int event) { >+ return new TextTextProperty(event); >+ } >+ >+ /** >+ * Returns a value property for the editable state of a SWT Text. >+ * @return a value property for the editable state of a SWT Text. >+ */ >+ public static IValueProperty editable() { >+ return new TextEditableProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/SWTVetoableValueDecorator.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SWTVetoableValueDecorator.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SWTVetoableValueDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/SWTVetoableValueDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,141 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.IDecoratingObservable; >+import org.eclipse.core.databinding.observable.IObservable; >+import org.eclipse.core.databinding.observable.IStaleListener; >+import org.eclipse.core.databinding.observable.ObservableTracker; >+import org.eclipse.core.databinding.observable.StaleEvent; >+import org.eclipse.core.databinding.observable.value.AbstractVetoableValue; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.observable.value.IValueChangeListener; >+import org.eclipse.core.databinding.observable.value.ValueChangeEvent; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.jface.databinding.swt.ISWTObservableValue; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Widget; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SWTVetoableValueDecorator extends AbstractVetoableValue implements >+ ISWTObservableValue, IDecoratingObservable { >+ >+ private IObservableValue decorated; >+ private Widget widget; >+ >+ private IValueChangeListener valueListener = new IValueChangeListener() { >+ public void handleValueChange(ValueChangeEvent event) { >+ fireValueChange(event.diff); >+ } >+ }; >+ >+ private IStaleListener staleListener = new IStaleListener() { >+ public void handleStale(StaleEvent staleEvent) { >+ fireStale(); >+ } >+ }; >+ >+ private Listener verifyListener = new Listener() { >+ public void handleEvent(Event event) { >+ String currentText = (String) decorated.getValue(); >+ String newText = currentText.substring(0, event.start) + event.text >+ + currentText.substring(event.end); >+ if (!fireValueChanging(Diffs.createValueDiff(currentText, newText))) { >+ event.doit = false; >+ } >+ } >+ }; >+ >+ private Listener disposeListener = new Listener() { >+ public void handleEvent(Event event) { >+ SWTVetoableValueDecorator.this.dispose(); >+ } >+ }; >+ >+ /** >+ * @param decorated >+ * @param widget >+ */ >+ public SWTVetoableValueDecorator(IObservableValue decorated, Widget widget) { >+ super(decorated.getRealm()); >+ this.decorated = decorated; >+ this.widget = widget; >+ Assert >+ .isTrue(decorated.getValueType().equals(String.class), >+ "SWTVetoableValueDecorator can only decorate observable values of String type"); //$NON-NLS-1$ >+ widget.addListener(SWT.Dispose, disposeListener); >+ } >+ >+ private void getterCalled() { >+ ObservableTracker.getterCalled(this); >+ } >+ >+ protected void firstListenerAdded() { >+ decorated.addValueChangeListener(valueListener); >+ decorated.addStaleListener(staleListener); >+ widget.addListener(SWT.Verify, verifyListener); >+ } >+ >+ protected void lastListenerRemoved() { >+ if (decorated != null) { >+ decorated.removeValueChangeListener(valueListener); >+ decorated.removeStaleListener(staleListener); >+ } >+ if (widget != null && !widget.isDisposed()) >+ widget.removeListener(SWT.Verify, verifyListener); >+ } >+ >+ protected void doSetApprovedValue(Object value) { >+ checkRealm(); >+ decorated.setValue(value); >+ } >+ >+ protected Object doGetValue() { >+ getterCalled(); >+ return decorated.getValue(); >+ } >+ >+ public Object getValueType() { >+ return decorated.getValueType(); >+ } >+ >+ public boolean isStale() { >+ getterCalled(); >+ return decorated.isStale(); >+ } >+ >+ public void dispose() { >+ if (decorated != null) { >+ decorated.dispose(); >+ decorated = null; >+ } >+ if (widget != null && !widget.isDisposed()) { >+ widget.removeListener(SWT.Verify, verifyListener); >+ } >+ this.widget = null; >+ super.dispose(); >+ } >+ >+ public Widget getWidget() { >+ return widget; >+ } >+ >+ public IObservable getDecorated() { >+ return decorated; >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/ShellProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ShellProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ShellProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ShellProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.ShellTextProperty; >+ >+/** >+ * A factory for creating properties of SWT Shells. >+ * >+ * @since 1.3 >+ */ >+public class ShellProperties { >+ /** >+ * Returns a value property for the text of a SWT Shell. >+ * >+ * @return a value property for the text of a SWT Shell. >+ */ >+ public static IValueProperty text() { >+ return new ShellTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/LinkProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/LinkProperties.java >diff -N src/org/eclipse/jface/databinding/swt/LinkProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/LinkProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.LinkTextProperty; >+ >+/** >+ * A factory for creating properties of SWT Links. >+ * >+ * @since 1.3 >+ */ >+public class LinkProperties { >+ /** >+ * Returns a value property for the text of a SWT Link. >+ * >+ * @return a value property for the text of a SWT Link. >+ */ >+ public static IValueProperty text() { >+ return new LinkTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/TabItemProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/TabItemProperties.java >diff -N src/org/eclipse/jface/databinding/swt/TabItemProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/TabItemProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.TabItemTooltipTextProperty; >+ >+/** >+ * A factory for creating properties of SWT TabItems >+ * >+ * @since 1.3 >+ */ >+public class TabItemProperties { >+ /** >+ * Returns a value property for the tooltip text of a SWT TabItem. >+ * >+ * @return a value property for the tooltip text of a SWT TabItem. >+ */ >+ public static IValueProperty tooltipText() { >+ return new TabItemTooltipTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsProperty.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/CheckableCheckedElementsProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,119 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.viewers; >+ >+import java.util.Collections; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.set.ISetPropertyChangeListener; >+import org.eclipse.core.databinding.property.set.SetPropertyChangeEvent; >+import org.eclipse.core.databinding.property.set.SimpleSetProperty; >+import org.eclipse.jface.viewers.CheckStateChangedEvent; >+import org.eclipse.jface.viewers.ICheckStateListener; >+import org.eclipse.jface.viewers.ICheckable; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CheckableCheckedElementsProperty extends SimpleSetProperty { >+ private Object elementType; >+ >+ /** >+ * @param elementType >+ */ >+ public CheckableCheckedElementsProperty(Object elementType) { >+ this.elementType = elementType; >+ } >+ >+ public Object getElementType() { >+ return elementType; >+ } >+ >+ protected Set doGetSet(Object source) { >+ ICheckable checkable = (ICheckable) source; >+ >+ Set set = doGetSet(checkable); >+ if (set == null) { >+ set = createElementSet(checkable); >+ } >+ >+ return set; >+ } >+ >+ protected Set doGetSet(ICheckable checkable) { >+ return null; // overridden by viewer-specific subclasses >+ } >+ >+ protected Set createElementSet(ICheckable checkable) { >+ return new HashSet(); >+ } >+ >+ protected void setSet(Object source, Set set, SetDiff diff) { >+ ICheckable checkable = (ICheckable) source; >+ for (Iterator it = diff.getAdditions().iterator(); it.hasNext();) { >+ checkable.setChecked(it.next(), true); >+ } >+ for (Iterator it = diff.getRemovals().iterator(); it.hasNext();) { >+ checkable.setChecked(it.next(), false); >+ } >+ } >+ >+ public INativePropertyListener adaptListener(ISetPropertyChangeListener listener) { >+ return new CheckStateListener(listener); >+ } >+ >+ public void addListener(Object source, INativePropertyListener listener) { >+ ((ICheckable) source) >+ .addCheckStateListener((ICheckStateListener) listener); >+ } >+ >+ public void removeListener(Object source, INativePropertyListener listener) { >+ ((ICheckable) source) >+ .removeCheckStateListener((ICheckStateListener) listener); >+ } >+ >+ private class CheckStateListener implements INativePropertyListener, >+ ICheckStateListener { >+ private ISetPropertyChangeListener listener; >+ >+ private CheckStateListener(ISetPropertyChangeListener listener) { >+ this.listener = listener; >+ } >+ >+ public void checkStateChanged(CheckStateChangedEvent event) { >+ Object element = event.getElement(); >+ SetDiff diff; >+ if (event.getChecked()) { >+ diff = Diffs.createSetDiff(Collections.singleton(element), >+ Collections.EMPTY_SET); >+ } else { >+ diff = Diffs.createSetDiff(Collections.EMPTY_SET, Collections >+ .singleton(element)); >+ } >+ listener.handleSetPropertyChange(new SetPropertyChangeEvent(event >+ .getSource(), CheckableCheckedElementsProperty.this, diff)); >+ } >+ } >+ >+ public String toString() { >+ String s = "ICheckable.checkedElements{}"; //$NON-NLS-1$ >+ if (getElementType() != null) >+ s += " <" + getElementType() + ">"; //$NON-NLS-1$//$NON-NLS-2$ >+ return s; >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/WidgetBooleanValueProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/WidgetBooleanValueProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/WidgetBooleanValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/WidgetBooleanValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public abstract class WidgetBooleanValueProperty extends WidgetValueProperty { >+ WidgetBooleanValueProperty(int[] events) { >+ super(events, Boolean.TYPE); >+ } >+ >+ WidgetBooleanValueProperty(int event) { >+ super(event, Boolean.TYPE); >+ } >+ >+ WidgetBooleanValueProperty() { >+ super(Boolean.TYPE); >+ } >+ >+ public Object getValue(Object source) { >+ return doGetBooleanValue(source) ? Boolean.TRUE : Boolean.FALSE; >+ } >+ >+ public void setValue(Object source, Object value) { >+ if (value == null) >+ value = Boolean.FALSE; >+ doSetBooleanValue(source, ((Boolean) value).booleanValue()); >+ } >+ >+ abstract boolean doGetBooleanValue(Object source); >+ >+ abstract void doSetBooleanValue(Object source, boolean value); >+} >Index: src/org/eclipse/jface/internal/databinding/swt/WidgetIntValueProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/WidgetIntValueProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/WidgetIntValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/WidgetIntValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public abstract class WidgetIntValueProperty extends WidgetValueProperty { >+ WidgetIntValueProperty() { >+ super(Integer.TYPE); >+ } >+ >+ WidgetIntValueProperty(int event) { >+ super(event, Integer.TYPE); >+ } >+ >+ WidgetIntValueProperty(int[] events) { >+ super(events, Integer.TYPE); >+ } >+ >+ public Object getValue(Object source) { >+ return new Integer(doGetIntValue(source)); >+ } >+ >+ public void setValue(Object source, Object value) { >+ doSetIntValue(source, ((Integer) value).intValue()); >+ } >+ >+ abstract int doGetIntValue(Object source); >+ >+ abstract void doSetIntValue(Object source, int intValue); >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlSizeProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlSizeProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlSizeProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlSizeProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation >+ * Tom Schindl - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlSizeProperty extends WidgetValueProperty { >+ /** >+ * >+ */ >+ public ControlSizeProperty() { >+ super(SWT.Resize, Point.class); >+ } >+ >+ public Object getValue(Object source) { >+ return ((Control) source).getSize(); >+ } >+ >+ public void setValue(Object source, Object value) { >+ ((Control) source).setSize((Point) value); >+ } >+ >+ public String toString() { >+ return "Control.size <Point>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/CheckboxTableViewerCheckedElementsProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/CheckboxTableViewerCheckedElementsProperty.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/CheckboxTableViewerCheckedElementsProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/CheckboxTableViewerCheckedElementsProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,57 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.viewers; >+ >+import java.util.Arrays; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.jface.viewers.CheckboxTableViewer; >+import org.eclipse.jface.viewers.ICheckable; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CheckboxTableViewerCheckedElementsProperty extends >+ CheckableCheckedElementsProperty { >+ /** >+ * @param elementType >+ */ >+ public CheckboxTableViewerCheckedElementsProperty(Object elementType) { >+ super(elementType); >+ } >+ >+ protected Set createElementSet(ICheckable checkable) { >+ return ViewerElementSet.withComparer(((CheckboxTableViewer) checkable) >+ .getComparer()); >+ } >+ >+ protected Set doGetSet(ICheckable checkable) { >+ CheckboxTableViewer viewer = (CheckboxTableViewer) checkable; >+ Set set = createElementSet(viewer); >+ set.addAll(Arrays.asList(viewer.getCheckedElements())); >+ return set; >+ } >+ >+ protected void doSetSet(Object source, Set set, SetDiff diff) { >+ CheckboxTableViewer viewer = (CheckboxTableViewer) source; >+ viewer.setCheckedElements(set.toArray()); >+ } >+ >+ public String toString() { >+ String s = "CheckboxTableViewer.checkedElements{}"; //$NON-NLS-1$ >+ if (getElementType() != null) >+ s += " <" + getElementType() + ">"; //$NON-NLS-1$//$NON-NLS-2$ >+ return s; >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/TreeColumnProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/TreeColumnProperties.java >diff -N src/org/eclipse/jface/databinding/swt/TreeColumnProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/TreeColumnProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.TreeItemTooltipTextProperty; >+ >+/** >+ * A factory for creating properties of SWT TabItems >+ * >+ * @since 1.3 >+ */ >+public class TreeColumnProperties { >+ /** >+ * Returns a value property for the tooltip text of a SWT TreeColumn. >+ * >+ * @return a value property for the tooltip text of a SWT TreeColumn. >+ */ >+ public static IValueProperty tooltipText() { >+ return new TreeItemTooltipTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/viewers/ViewerProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/viewers/ViewerProperties.java >diff -N src/org/eclipse/jface/databinding/viewers/ViewerProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/viewers/ViewerProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.viewers; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.viewers.ViewerInputProperty; >+ >+/** >+ * A factory for creating properties of JFace Viewers >+ * >+ * @since 1.3 >+ */ >+public class ViewerProperties { >+ /** >+ * Returns a value property for the input of a JFace Viewer. >+ * >+ * @return a value property for the input of a JFace Viewer. >+ */ >+ public static IValueProperty input() { >+ return new ViewerInputProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/CTabItemProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/CTabItemProperties.java >diff -N src/org/eclipse/jface/databinding/swt/CTabItemProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/CTabItemProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.CTabItemTooltipTextProperty; >+ >+/** >+ * A factory for creating properties of SWT CTabItems >+ * >+ * @since 1.3 >+ */ >+public class CTabItemProperties { >+ /** >+ * Returns a value property for the tooltip text of a SWT CTabItem. >+ * >+ * @return a value property for the tooltip text of a SWT CTabItem. >+ */ >+ public static IValueProperty tooltipText() { >+ return new CTabItemTooltipTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/CComboSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CComboSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CComboSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/CComboSelectionProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,57 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.CCombo; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CComboSelectionProperty extends WidgetStringValueProperty { >+ /** >+ * >+ */ >+ public CComboSelectionProperty() { >+ super(SWT.Modify); >+ } >+ >+ String doGetStringValue(Object source) { >+ return ((CCombo) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ CCombo ccombo = (CCombo) source; >+ String items[] = ccombo.getItems(); >+ int index = -1; >+ if (value == null) { >+ ccombo.select(-1); >+ } else if (items != null) { >+ for (int i = 0; i < items.length; i++) { >+ if (value.equals(items[i])) { >+ index = i; >+ break; >+ } >+ } >+ if (index == -1) { >+ ccombo.setText(value); >+ } else { >+ ccombo.select(index); // -1 will not "unselect" >+ } >+ } >+ } >+ >+ public String toString() { >+ return "CCombo.selection <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/TableProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/TableProperties.java >diff -N src/org/eclipse/jface/databinding/swt/TableProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/TableProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionIndexProperty; >+ >+/** >+ * A factory for creating properties of SWT Tables. >+ * >+ * @since 1.3 >+ */ >+public class TableProperties { >+ /** >+ * Returns a value property for the single selection index of a SWT Table. >+ * >+ * @return a value property for the single selection index of a SWT Table. >+ */ >+ public static IValueProperty singleSelectionIndex() { >+ return new TableSingleSelectionIndexProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/ComboProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ComboProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ComboProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ComboProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,62 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.ComboItemsProperty; >+import org.eclipse.jface.internal.databinding.swt.ComboSelectionProperty; >+import org.eclipse.jface.internal.databinding.swt.ComboSingleSelectionIndexProperty; >+import org.eclipse.jface.internal.databinding.swt.ComboTextProperty; >+ >+/** >+ * A factory for creating properties of SWT Combos. >+ * >+ * @since 1.3 >+ */ >+public class ComboProperties { >+ /** >+ * Returns a value property for the selection text of a SWT Combo. >+ * >+ * @return a value property for the selection text of a SWT Combo. >+ */ >+ public static IValueProperty selection() { >+ return new ComboSelectionProperty(); >+ } >+ >+ /** >+ * Returns a value property for the text of a SWT Combo. >+ * >+ * @return a value property for the text of a SWT Combo. >+ */ >+ public static IValueProperty text() { >+ return new ComboTextProperty(); >+ } >+ >+ /** >+ * Returns a list property for the items of a SWT Combo. >+ * >+ * @return a list property for the items of a SWT Combo. >+ */ >+ public static IListProperty items() { >+ return new ComboItemsProperty(); >+ } >+ >+ /** >+ * Returns a value property for the single selection index of a SWT Combo. >+ * >+ * @return a value property for the single selection index of a SWT Combo. >+ */ >+ public static IValueProperty singleSelectionIndex() { >+ return new ComboSingleSelectionIndexProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/viewers/CheckableProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/viewers/CheckableProperties.java >diff -N src/org/eclipse/jface/databinding/viewers/CheckableProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/viewers/CheckableProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.viewers; >+ >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.jface.internal.databinding.viewers.CheckableCheckedElementsProperty; >+ >+/** >+ * A factory for creating properties of JFace ICheckables >+ * >+ * @since 1.3 >+ */ >+public class CheckableProperties { >+ /** >+ * Returns a set property for the checked elements of a JFace ICheckable. >+ * >+ * @param elementType >+ * the element type of the returned property >+ * >+ * @return a set property for the checked elements of a JFace ICheckable. >+ */ >+ public static ISetProperty checkedElements(Object elementType) { >+ return new CheckableCheckedElementsProperty(elementType); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ComboTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ComboTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ComboTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ComboTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Combo; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ComboTextProperty extends WidgetStringValueProperty { >+ /** >+ * >+ */ >+ public ComboTextProperty() { >+ super(SWT.Modify); >+ } >+ >+ String doGetStringValue(Object source) { >+ return ((Combo) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((Combo) source).setText(value != null ? value : ""); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "Combo.text <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableListDecorator.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableListDecorator.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableListDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/ViewerObservableListDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,41 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.viewers; >+ >+import org.eclipse.core.databinding.observable.list.DecoratingObservableList; >+import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.jface.databinding.viewers.IViewerObservableList; >+import org.eclipse.jface.viewers.Viewer; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ViewerObservableListDecorator extends DecoratingObservableList >+ implements IViewerObservableList { >+ private final Viewer viewer; >+ >+ /** >+ * @param decorated >+ * @param viewer >+ */ >+ public ViewerObservableListDecorator(IObservableList decorated, >+ Viewer viewer) { >+ super(decorated, true); >+ this.viewer = viewer; >+ } >+ >+ public Viewer getViewer() { >+ return viewer; >+ } >+ >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ComboItemsProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ComboItemsProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ComboItemsProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ComboItemsProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ComboItemsProperty extends ControlStringListProperty { >+ protected void doSetStringList(Control control, String[] list) { >+ ((Combo) control).setItems(list); >+ } >+ >+ public String[] doGetStringList(Control control) { >+ return ((Combo) control).getItems(); >+ } >+ >+ public String toString() { >+ return "Combo.items[] <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/TableColumnProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/TableColumnProperties.java >diff -N src/org/eclipse/jface/databinding/swt/TableColumnProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/TableColumnProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.TableColumnTooltipTextProperty; >+ >+/** >+ * A factory for creating properties of SWT TableColumns >+ * >+ * @since 1.3 >+ */ >+public class TableColumnProperties { >+ /** >+ * Returns a value property for the tooltip text of a SWT TableColumns. >+ * >+ * @return a value property for the tooltip text of a SWT TableColumns. >+ */ >+ public static IValueProperty tooltipText() { >+ return new TableColumnTooltipTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionIndexProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionIndexProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionIndexProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionIndexProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.CCombo; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CComboSingleSelectionIndexProperty extends WidgetIntValueProperty { >+ /** >+ * >+ */ >+ public CComboSingleSelectionIndexProperty() { >+ super(new int[] { SWT.Selection, SWT.DefaultSelection }); >+ } >+ >+ int doGetIntValue(Object source) { >+ return ((CCombo) source).getSelectionIndex(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((CCombo) source).select(value); >+ } >+ >+ public String toString() { >+ return "CCombo.selectionIndex <int>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/WidgetStringValueProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/WidgetStringValueProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/WidgetStringValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/WidgetStringValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,38 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public abstract class WidgetStringValueProperty extends WidgetValueProperty { >+ WidgetStringValueProperty(int event) { >+ super(event, String.class); >+ } >+ >+ WidgetStringValueProperty() { >+ super(String.class); >+ } >+ >+ public Object getValue(Object source) { >+ return doGetStringValue(source); >+ } >+ >+ public void setValue(Object source, Object value) { >+ doSetStringValue(source, (String) value); >+ } >+ >+ abstract String doGetStringValue(Object source); >+ >+ abstract void doSetStringValue(Object source, String value); >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ScaleMinimumProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ScaleMinimumProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ScaleMinimumProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ScaleMinimumProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Scale; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ScaleMinimumProperty extends WidgetIntValueProperty { >+ int doGetIntValue(Object source) { >+ return ((Scale) source).getMinimum(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Scale) source).setMinimum(value); >+ } >+ >+ public String toString() { >+ return "Scale.minimum <int>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/ItemProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ItemProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ItemProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ItemProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.ItemTextProperty; >+ >+/** >+ * A factory for creating properties of SWT controls. >+ * >+ * @since 1.3 >+ */ >+public class ItemProperties { >+ /** >+ * Returns a value property for the text of a SWT Item. >+ * >+ * @return a value property for the text of a SWT Item >+ */ >+ public static IValueProperty text() { >+ return new ItemTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/SpinnerMinimumProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SpinnerMinimumProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SpinnerMinimumProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/SpinnerMinimumProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Spinner; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SpinnerMinimumProperty extends WidgetIntValueProperty { >+ int doGetIntValue(Object source) { >+ return ((Spinner) source).getMinimum(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Spinner) source).setMinimum(value); >+ } >+ >+ public String toString() { >+ return "Spinner.minimum <int>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/TrayItemProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/TrayItemProperties.java >diff -N src/org/eclipse/jface/databinding/swt/TrayItemProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/TrayItemProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.databinding.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.TrayItemTooltipTextProperty; >+ >+/** >+ * A factory for creating properties of SWT TrayItems >+ * >+ * @since 1.3 >+ */ >+public class TrayItemProperties { >+ /** >+ * Returns a value property for the tooltip text of a SWT TrayItems. >+ * >+ * @return a value property for the tooltip text of a SWT TrayItems. >+ */ >+ public static IValueProperty tooltipText() { >+ return new TrayItemTooltipTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/WidgetValueProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/WidgetValueProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/WidgetValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/WidgetValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,84 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.SimpleValueProperty; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Widget; >+ >+abstract class WidgetValueProperty extends SimpleValueProperty { >+ private int[] events; >+ private Object valueType; >+ >+ WidgetValueProperty(Object valueType) { >+ this(null, valueType); >+ } >+ >+ WidgetValueProperty(int event, Object valueType) { >+ this(new int[] { event }, valueType); >+ } >+ >+ WidgetValueProperty(int[] events, Object valueType) { >+ this.events = events; >+ this.valueType = valueType; >+ } >+ >+ public final Object getValueType() { >+ return valueType; >+ } >+ >+ public INativePropertyListener adaptListener(IValuePropertyChangeListener listener) { >+ return new WidgetListener(listener); >+ } >+ >+ public void addListener(Object source, INativePropertyListener listener) { >+ if (events != null) { >+ for (int i = 0; i < events.length; i++) { >+ int event = events[i]; >+ if (event != SWT.None) { >+ ((Widget) source).addListener(event, (Listener) listener); >+ } >+ } >+ } >+ } >+ >+ public void removeListener(Object source, INativePropertyListener listener) { >+ if (events != null) { >+ Widget widget = (Widget) source; >+ if (!widget.isDisposed()) { >+ for (int i = 0; i < events.length; i++) { >+ int event = events[i]; >+ if (event != SWT.None) >+ widget.removeListener(event, (Listener) listener); >+ } >+ } >+ } >+ } >+ >+ private class WidgetListener implements INativePropertyListener, Listener { >+ private final IValuePropertyChangeListener listener; >+ >+ protected WidgetListener(IValuePropertyChangeListener listener) { >+ this.listener = listener; >+ } >+ >+ public void handleEvent(Event event) { >+ listener.handleValuePropertyChange(new ValuePropertyChangeEvent( >+ event.widget, WidgetValueProperty.this, null)); >+ } >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/TextEditableProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TextEditableProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TextEditableProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/TextEditableProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Text; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TextEditableProperty extends WidgetBooleanValueProperty { >+ boolean doGetBooleanValue(Object source) { >+ return ((Text) source).getEditable(); >+ } >+ >+ void doSetBooleanValue(Object source, boolean value) { >+ ((Text) source).setEditable(value); >+ } >+ >+ public String toString() { >+ return "Text.editable <boolean>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ShellTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ShellTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ShellTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ShellTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ShellTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((Shell) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((Shell) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "Shell.text <String>"; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/CComboTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CComboTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CComboTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/CComboTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.CCombo; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CComboTextProperty extends WidgetStringValueProperty { >+ /** >+ * >+ */ >+ public CComboTextProperty() { >+ super(SWT.Modify); >+ } >+ >+ String doGetStringValue(Object source) { >+ return ((CCombo) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((CCombo) source).setText(value != null ? value : ""); //$NON-NLS-1$ >+ } >+ >+ public String toString() { >+ return "CCombo.text <String>"; //$NON-NLS-1$ >+ } >+} >#P org.eclipse.core.databinding >Index: src/org/eclipse/core/databinding/property/set/SetPropertyChangeEvent.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/set/SetPropertyChangeEvent.java >diff -N src/org/eclipse/core/databinding/property/set/SetPropertyChangeEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/set/SetPropertyChangeEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.set; >+ >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+import org.eclipse.core.databinding.property.PropertyChangeEvent; >+ >+/** >+ * Set change event describing an incremental change of a set property on a >+ * particular property source. >+ * >+ * @since 1.2 >+ */ >+public class SetPropertyChangeEvent extends PropertyChangeEvent { >+ private static final long serialVersionUID = 1L; >+ >+ /** >+ * The set property that changed >+ */ >+ public final ISetProperty property; >+ >+ /** >+ * SetDiff enumerating the added and removed elements in the set, or null if >+ * the change is unknown. >+ */ >+ public final SetDiff diff; >+ >+ /** >+ * Constructs a SetPropertyChangeEvent with the given attributes >+ * >+ * @param source >+ * the property source >+ * @param property >+ * the property that changed on the source >+ * @param diff >+ * a SetDiff describing the changes to the set property >+ */ >+ public SetPropertyChangeEvent(Object source, ISetProperty property, >+ SetDiff diff) { >+ super(source); >+ this.property = property; >+ this.diff = diff; >+ } >+ >+ protected void dispatch(IPropertyChangeListener listener) { >+ ((ISetPropertyChangeListener) listener).handleSetPropertyChange(this); >+ } >+} >Index: src/org/eclipse/core/databinding/property/value/IValuePropertyChangeListener.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/IValuePropertyChangeListener.java >diff -N src/org/eclipse/core/databinding/property/value/IValuePropertyChangeListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/IValuePropertyChangeListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.value; >+ >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+ >+/** >+ * Listener for changes to value properties on a property source >+ * >+ * @since 1.2 >+ */ >+public interface IValuePropertyChangeListener extends IPropertyChangeListener { >+ /** >+ * Handle a change to a value property on a specific property source. >+ * >+ * @param event >+ * an event describing the value change that occured. >+ */ >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event); >+} >Index: src/org/eclipse/core/databinding/property/list/ListPropertyObservableList.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/list/ListPropertyObservableList.java >diff -N src/org/eclipse/core/databinding/property/list/ListPropertyObservableList.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/list/ListPropertyObservableList.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,639 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.list; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.Collections; >+import java.util.ConcurrentModificationException; >+import java.util.Iterator; >+import java.util.List; >+import java.util.ListIterator; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.ObservableTracker; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.AbstractObservableList; >+import org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.observable.list.ListDiffEntry; >+import org.eclipse.core.databinding.property.IProperty; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.IPropertyObservable; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class ListPropertyObservableList extends AbstractObservableList >+ implements IPropertyObservable { >+ private Object source; >+ private SimpleListProperty property; >+ >+ private volatile boolean updating = false; >+ >+ private volatile int modCount = 0; >+ >+ private INativePropertyListener listener; >+ >+ private List cachedList; >+ >+ /** >+ * @param realm >+ * @param source >+ * @param property >+ */ >+ public ListPropertyObservableList(Realm realm, Object source, >+ SimpleListProperty property) { >+ super(realm); >+ this.source = source; >+ this.property = property; >+ } >+ >+ protected void firstListenerAdded() { >+ if (!isDisposed()) { >+ cachedList = property.getList(source); >+ >+ if (listener == null) { >+ listener = property >+ .adaptListener(new IListPropertyChangeListener() { >+ public void handleListPropertyChange( >+ final ListPropertyChangeEvent event) { >+ modCount++; >+ if (!isDisposed() && !updating) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ List oldList = cachedList; >+ List newList = cachedList = property >+ .getList(source); >+ ListDiff diff = event.diff; >+ if (diff == null) { >+ diff = Diffs.computeListDiff( >+ oldList, newList); >+ } >+ fireListChange(diff); >+ } >+ }); >+ } >+ } >+ }); >+ } >+ property.addListener(source, listener); >+ } >+ } >+ >+ protected void lastListenerRemoved() { >+ if (listener != null) { >+ property.removeListener(source, listener); >+ } >+ >+ cachedList = null; >+ } >+ >+ private void getterCalled() { >+ ObservableTracker.getterCalled(this); >+ } >+ >+ public Object getElementType() { >+ return property.getElementType(); >+ } >+ >+ // Queries >+ >+ protected int doGetSize() { >+ return property.size(source); >+ } >+ >+ public boolean contains(Object o) { >+ getterCalled(); >+ return property.contains(source, o); >+ } >+ >+ public boolean containsAll(Collection c) { >+ getterCalled(); >+ return property.containsAll(source, c); >+ } >+ >+ public Object get(int index) { >+ getterCalled(); >+ return property.get(source, index); >+ } >+ >+ public int indexOf(Object o) { >+ getterCalled(); >+ return property.indexOf(source, o); >+ } >+ >+ public boolean isEmpty() { >+ getterCalled(); >+ return property.isEmpty(source); >+ } >+ >+ public int lastIndexOf(Object o) { >+ getterCalled(); >+ return property.lastIndexOf(source, o); >+ } >+ >+ public Object[] toArray() { >+ getterCalled(); >+ return property.toArray(source); >+ } >+ >+ public Object[] toArray(Object[] a) { >+ getterCalled(); >+ return property.toArray(source, a); >+ } >+ >+ // Single change operations >+ >+ public boolean add(Object o) { >+ checkRealm(); >+ add(property.size(source), o); >+ return true; >+ } >+ >+ public void add(int index, Object o) { >+ checkRealm(); >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.add(source, index, o); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, >+ true, o))); >+ } >+ >+ public Iterator iterator() { >+ getterCalled(); >+ return new Iterator() { >+ int expectedModCount = modCount; >+ ListIterator delegate = new ArrayList(property.getList(source)) >+ .listIterator(); >+ >+ Object lastElement = null; >+ int lastIndex = -1; >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.hasNext(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ Object next = lastElement = delegate.next(); >+ lastIndex = delegate.previousIndex(); >+ return next; >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ if (lastIndex == -1) >+ throw new IllegalStateException(); >+ >+ delegate.remove(); // stay in sync >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.remove(source, lastIndex); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >+ lastIndex, false, lastElement))); >+ >+ lastElement = null; >+ lastIndex = -1; >+ >+ expectedModCount = modCount; >+ } >+ >+ private void checkForComodification() { >+ if (expectedModCount != modCount) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ >+ public Object move(int oldIndex, int newIndex) { >+ checkRealm(); >+ >+ int size = property.size(source); >+ if (oldIndex < 0 || oldIndex >= size || newIndex < 0 >+ || newIndex >= size) >+ throw new IndexOutOfBoundsException(); >+ if (oldIndex == newIndex) >+ return property.get(source, oldIndex); >+ >+ Object element; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ element = property.move(source, oldIndex, newIndex); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(oldIndex, >+ false, element), Diffs.createListDiffEntry(newIndex, true, >+ element))); >+ >+ return element; >+ } >+ >+ public boolean remove(Object o) { >+ checkRealm(); >+ >+ int index = property.indexOf(source, o); >+ if (index == -1) >+ return false; >+ >+ remove(index); >+ >+ return true; >+ } >+ >+ public ListIterator listIterator() { >+ return listIterator(0); >+ } >+ >+ public ListIterator listIterator(final int index) { >+ getterCalled(); >+ return new ListIterator() { >+ int expectedModCount = modCount; >+ ListIterator delegate = new ArrayList(property.getList(source)) >+ .listIterator(index); >+ >+ Object lastElement = null; >+ int lastIndex = -1; >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.hasNext(); >+ } >+ >+ public int nextIndex() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.nextIndex(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ lastElement = delegate.next(); >+ lastIndex = delegate.previousIndex(); >+ return lastElement; >+ } >+ >+ public boolean hasPrevious() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.hasPrevious(); >+ } >+ >+ public int previousIndex() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.previousIndex(); >+ } >+ >+ public Object previous() { >+ getterCalled(); >+ checkForComodification(); >+ lastElement = delegate.previous(); >+ lastIndex = delegate.nextIndex(); >+ return lastElement; >+ } >+ >+ public void add(Object o) { >+ checkRealm(); >+ checkForComodification(); >+ int index = delegate.nextIndex(); >+ >+ delegate.add(o); // keep in sync >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.add(source, index, o); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >+ index, true, o))); >+ >+ lastElement = null; >+ lastIndex = -1; >+ expectedModCount = modCount; >+ } >+ >+ public void set(Object o) { >+ checkRealm(); >+ checkForComodification(); >+ >+ delegate.set(o); >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.set(source, lastIndex, o); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >+ lastIndex, false, lastElement), Diffs >+ .createListDiffEntry(lastIndex, true, o))); >+ >+ lastElement = o; >+ >+ expectedModCount = modCount; >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ if (lastIndex == -1) >+ throw new IllegalStateException(); >+ >+ delegate.remove(); // keep in sync >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.remove(source, lastIndex); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >+ lastIndex, false, lastElement))); >+ >+ lastElement = null; >+ lastIndex = -1; >+ expectedModCount = modCount; >+ } >+ >+ private void checkForComodification() { >+ if (expectedModCount != modCount) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ >+ public Object remove(int index) { >+ checkRealm(); >+ >+ Object element; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ element = property.remove(source, index); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, >+ false, element))); >+ >+ return element; >+ } >+ >+ public Object set(int index, Object o) { >+ checkRealm(); >+ >+ Object oldElement; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ oldElement = property.set(source, index, o); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, >+ false, oldElement), Diffs.createListDiffEntry(index, true, o))); >+ >+ return oldElement; >+ } >+ >+ public List subList(int fromIndex, int toIndex) { >+ getterCalled(); >+ return Collections.unmodifiableList(property.getList(source).subList( >+ fromIndex, toIndex)); >+ } >+ >+ // Bulk change operations >+ >+ public boolean addAll(Collection c) { >+ checkRealm(); >+ >+ return addAll(property.size(source), c); >+ } >+ >+ public boolean addAll(int index, Collection c) { >+ checkRealm(); >+ >+ if (c.isEmpty()) >+ return false; >+ >+ ListDiffEntry[] entries = new ListDiffEntry[c.size()]; >+ int offsetIndex = 0; >+ for (Iterator it = c.iterator(); it.hasNext();) { >+ Object element = it.next(); >+ entries[offsetIndex] = Diffs.createListDiffEntry(index >+ + offsetIndex, true, element); >+ offsetIndex++; >+ } >+ >+ boolean changed; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ changed = property.addAll(source, index, c); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ if (changed) >+ fireListChange(Diffs.createListDiff(entries)); >+ >+ return changed; >+ } >+ >+ public boolean removeAll(Collection c) { >+ checkRealm(); >+ >+ if (property.isEmpty(source) || c.isEmpty()) >+ return false; >+ >+ boolean changed; >+ >+ List entries = new ArrayList(); >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ List list = new ArrayList(property.getList(source)); >+ for (ListIterator it = list.listIterator(); it.hasNext();) { >+ Object element = it.next(); >+ int index = it.previousIndex(); >+ if (c.contains(element)) { >+ it.remove(); >+ entries.add(Diffs >+ .createListDiffEntry(index, false, element)); >+ } >+ } >+ changed = property.removeAll(source, c); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ >+ if (changed) >+ fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries >+ .toArray(new ListDiffEntry[entries.size()]))); >+ >+ return changed; >+ } >+ >+ public boolean retainAll(Collection c) { >+ checkRealm(); >+ >+ if (property.isEmpty(source)) >+ return false; >+ >+ if (c.isEmpty()) { >+ clear(); >+ return true; >+ } >+ >+ boolean changed; >+ >+ List entries = new ArrayList(); >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ List list = new ArrayList(property.getList(source)); >+ for (ListIterator it = list.listIterator(); it.hasNext();) { >+ Object element = it.next(); >+ int index = it.previousIndex(); >+ if (!c.contains(element)) { >+ it.remove(); >+ entries.add(Diffs >+ .createListDiffEntry(index, false, element)); >+ } >+ } >+ changed = property.retainAll(source, c); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ >+ if (changed) >+ fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries >+ .toArray(new ListDiffEntry[entries.size()]))); >+ >+ return changed; >+ } >+ >+ public void clear() { >+ checkRealm(); >+ >+ if (property.isEmpty(source)) >+ return; >+ >+ List entries = new ArrayList(); >+ for (Iterator it = property.getList(source).iterator(); it.hasNext();) { >+ // always report 0 as the remove index >+ entries.add(Diffs.createListDiffEntry(0, false, it.next())); >+ } >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.clear(source); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedList = property.getList(source); >+ fireListChange(Diffs.createListDiff((ListDiffEntry[]) entries >+ .toArray(new ListDiffEntry[entries.size()]))); >+ } >+ >+ public boolean equals(Object o) { >+ getterCalled(); >+ return property.equals(source, o); >+ } >+ >+ public int hashCode() { >+ getterCalled(); >+ return property.hashCode(source); >+ } >+ >+ public Object getObserved() { >+ return source; >+ } >+ >+ public IProperty getProperty() { >+ return property; >+ } >+ >+ public synchronized void dispose() { >+ if (!isDisposed()) { >+ if (listener != null) >+ property.removeListener(source, listener); >+ property = null; >+ source = null; >+ listener = null; >+ } >+ super.dispose(); >+ } >+} >Index: src/org/eclipse/core/databinding/property/value/ListValuePropertyObservableList.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/ListValuePropertyObservableList.java >diff -N src/org/eclipse/core/databinding/property/value/ListValuePropertyObservableList.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/ListValuePropertyObservableList.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,438 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.value; >+ >+import java.lang.reflect.Array; >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.List; >+import java.util.ListIterator; >+import java.util.Map; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.IObserving; >+import org.eclipse.core.databinding.observable.IStaleListener; >+import org.eclipse.core.databinding.observable.ObservableTracker; >+import org.eclipse.core.databinding.observable.StaleEvent; >+import org.eclipse.core.databinding.observable.list.AbstractObservableList; >+import org.eclipse.core.databinding.observable.list.IListChangeListener; >+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.core.databinding.observable.list.ListDiffEntry; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.set.ISetChangeListener; >+import org.eclipse.core.databinding.observable.set.SetChangeEvent; >+import org.eclipse.core.databinding.observable.set.WritableSet; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.internal.databinding.IdentityWrapper; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 1.2 >+ */ >+public class ListValuePropertyObservableList extends AbstractObservableList >+ implements IObserving { >+ private IObservableList masterList; >+ private SimpleValueProperty detailProperty; >+ >+ private IObservableSet knownMasterElements; >+ private Map cachedValues; >+ >+ private boolean updating; >+ >+ private IListChangeListener masterListener = new IListChangeListener() { >+ public void handleListChange(ListChangeEvent event) { >+ if (!isDisposed()) { >+ updateKnownElements(); >+ fireListChange(convertDiff(event.diff)); >+ } >+ } >+ >+ private void updateKnownElements() { >+ Set identityKnownElements = new HashSet(); >+ for (Iterator it = masterList.iterator(); it.hasNext();) { >+ identityKnownElements.add(new IdentityWrapper(it.next())); >+ } >+ >+ knownMasterElements.retainAll(identityKnownElements); >+ knownMasterElements.addAll(identityKnownElements); >+ } >+ >+ private ListDiff convertDiff(ListDiff diff) { >+ // Convert diff to detail value >+ ListDiffEntry[] masterEntries = diff.getDifferences(); >+ ListDiffEntry[] detailEntries = new ListDiffEntry[masterEntries.length]; >+ for (int i = 0; i < masterEntries.length; i++) { >+ ListDiffEntry masterDifference = masterEntries[i]; >+ int index = masterDifference.getPosition(); >+ boolean addition = masterDifference.isAddition(); >+ Object masterElement = masterDifference.getElement(); >+ Object elementDetailValue = detailProperty >+ .getValue(masterElement); >+ detailEntries[i] = Diffs.createListDiffEntry(index, addition, >+ elementDetailValue); >+ } >+ return Diffs.createListDiff(detailEntries); >+ } >+ }; >+ >+ private IStaleListener staleListener = new IStaleListener() { >+ public void handleStale(StaleEvent staleEvent) { >+ fireStale(); >+ } >+ }; >+ >+ private INativePropertyListener detailListener = detailProperty >+ .adaptListener(new IValuePropertyChangeListener() { >+ public void handleValuePropertyChange( >+ final ValuePropertyChangeEvent event) { >+ if (!isDisposed() && !updating) { >+ Object masterElement = event.getSource(); >+ int[] indices = indicesOf(masterElement); >+ Object oldValue = event.diff.getOldValue(); >+ Object newValue = event.diff.getNewValue(); >+ ListDiffEntry[] entries = new ListDiffEntry[indices.length * 2]; >+ for (int i = 0; i < indices.length; i++) { >+ int index = indices[i]; >+ entries[i * 2] = Diffs.createListDiffEntry(index, >+ false, oldValue); >+ entries[i * 2 + 1] = Diffs.createListDiffEntry( >+ index, true, newValue); >+ } >+ >+ ListDiff diff = Diffs.createListDiff(entries); >+ cachedValues.put(new IdentityWrapper(masterElement), newValue); >+ fireListChange(diff); >+ } >+ } >+ >+ private int[] indicesOf(Object element) { >+ List indices = new ArrayList(); >+ >+ for (ListIterator it = masterList.listIterator(); it >+ .hasNext();) { >+ if (element == it.next()) >+ indices.add(new Integer(it.previousIndex())); >+ } >+ >+ int[] result = new int[indices.size()]; >+ for (int i = 0; i < result.length; i++) { >+ result[i] = ((Integer) indices.get(i)).intValue(); >+ } >+ return result; >+ } >+ }); >+ >+ /** >+ * @param masterList >+ * @param valueProperty >+ */ >+ public ListValuePropertyObservableList(IObservableList masterList, >+ SimpleValueProperty valueProperty) { >+ super(masterList.getRealm()); >+ this.masterList = masterList; >+ this.detailProperty = valueProperty; >+ } >+ >+ protected void firstListenerAdded() { >+ knownMasterElements = new WritableSet(getRealm()); >+ cachedValues = new HashMap(); >+ knownMasterElements.addSetChangeListener(new ISetChangeListener() { >+ public void handleSetChange(SetChangeEvent event) { >+ for (Iterator it = event.diff.getRemovals().iterator(); it >+ .hasNext();) { >+ IdentityWrapper wrapper = (IdentityWrapper) it.next(); >+ Object key = wrapper.unwrap(); >+ detailProperty.removeListener(key, detailListener); >+ cachedValues.remove(wrapper); >+ } >+ for (Iterator it = event.diff.getAdditions().iterator(); it >+ .hasNext();) { >+ IdentityWrapper wrapper = (IdentityWrapper) it.next(); >+ Object key = wrapper.unwrap(); >+ cachedValues.put(wrapper, detailProperty.getValue(key)); >+ detailProperty.addListener(key, detailListener); >+ } >+ } >+ }); >+ for (Iterator it = masterList.iterator(); it.hasNext();) { >+ knownMasterElements.add(new IdentityWrapper(it.next())); >+ } >+ >+ masterList.addListChangeListener(masterListener); >+ masterList.addStaleListener(staleListener); >+ } >+ >+ protected void lastListenerRemoved() { >+ masterList.removeListChangeListener(masterListener); >+ masterList.removeStaleListener(staleListener); >+ if (knownMasterElements != null) { >+ knownMasterElements.clear(); // clears cachedValues >+ knownMasterElements.dispose(); >+ knownMasterElements = null; >+ } >+ cachedValues = null; >+ } >+ >+ protected int doGetSize() { >+ getterCalled(); >+ return masterList.size(); >+ } >+ >+ private void getterCalled() { >+ ObservableTracker.getterCalled(this); >+ } >+ >+ public Object getElementType() { >+ return detailProperty.getValueType(); >+ } >+ >+ public Object get(int index) { >+ getterCalled(); >+ Object masterElement = masterList.get(index); >+ return detailProperty.getValue(masterElement); >+ } >+ >+ public boolean add(Object o) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean addAll(Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean addAll(int index, Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean contains(Object o) { >+ getterCalled(); >+ >+ for (Iterator it = masterList.iterator(); it.hasNext();) { >+ if (Util.equals(detailProperty.getValue(it.next()), o)) >+ return true; >+ } >+ return false; >+ } >+ >+ public boolean isEmpty() { >+ getterCalled(); >+ return masterList.isEmpty(); >+ } >+ >+ public boolean isStale() { >+ getterCalled(); >+ return masterList.isStale(); >+ } >+ >+ public Iterator iterator() { >+ getterCalled(); >+ return new Iterator() { >+ Iterator it = masterList.iterator(); >+ >+ public boolean hasNext() { >+ getterCalled(); >+ return it.hasNext(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ Object masterElement = it.next(); >+ return detailProperty.getValue(masterElement); >+ } >+ >+ public void remove() { >+ throw new UnsupportedOperationException(); >+ } >+ }; >+ } >+ >+ public Object move(int oldIndex, int newIndex) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean remove(Object o) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean removeAll(Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean retainAll(Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object[] toArray() { >+ getterCalled(); >+ Object[] masterElements = masterList.toArray(); >+ Object[] result = new Object[masterElements.length]; >+ for (int i = 0; i < result.length; i++) { >+ result[i] = detailProperty.getValue(masterElements[i]); >+ } >+ return result; >+ } >+ >+ public Object[] toArray(Object[] a) { >+ getterCalled(); >+ Object[] masterElements = masterList.toArray(); >+ if (a.length < masterElements.length) >+ a = (Object[]) Array.newInstance(a.getClass().getComponentType(), >+ masterElements.length); >+ for (int i = 0; i < masterElements.length; i++) { >+ a[i] = detailProperty.getValue(masterElements[i]); >+ } >+ return a; >+ } >+ >+ public void add(int index, Object o) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public void clear() { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public ListIterator listIterator() { >+ return listIterator(0); >+ } >+ >+ public ListIterator listIterator(final int index) { >+ getterCalled(); >+ return new ListIterator() { >+ ListIterator it = masterList.listIterator(index); >+ int lastIndex = -1; >+ Object lastMasterElement; >+ Object lastElement; >+ boolean haveIterated = false; >+ >+ public void add(Object arg0) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean hasNext() { >+ getterCalled(); >+ return it.hasNext(); >+ } >+ >+ public boolean hasPrevious() { >+ getterCalled(); >+ return it.hasPrevious(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ lastMasterElement = it.next(); >+ lastElement = detailProperty.getValue(lastMasterElement); >+ lastIndex = it.previousIndex(); >+ haveIterated = true; >+ return lastElement; >+ } >+ >+ public int nextIndex() { >+ getterCalled(); >+ return it.nextIndex(); >+ } >+ >+ public Object previous() { >+ getterCalled(); >+ lastMasterElement = it.previous(); >+ lastElement = detailProperty.getValue(lastMasterElement); >+ lastIndex = it.nextIndex(); >+ haveIterated = true; >+ return lastElement; >+ } >+ >+ public int previousIndex() { >+ getterCalled(); >+ return it.previousIndex(); >+ } >+ >+ public void remove() { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public void set(Object o) { >+ checkRealm(); >+ if (!haveIterated) >+ throw new IllegalStateException(); >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ detailProperty.setValue(lastElement, o); >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedValues.put(new IdentityWrapper(lastMasterElement), o); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry( >+ lastIndex, false, lastElement), Diffs >+ .createListDiffEntry(lastIndex, true, o))); >+ >+ lastElement = o; >+ } >+ }; >+ } >+ >+ public Object remove(int index) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object set(int index, Object o) { >+ checkRealm(); >+ Object masterElement = masterList.get(index); >+ Object oldValue = detailProperty.getValue(masterElement); >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ detailProperty.setValue(masterElement, o); >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedValues.put(new IdentityWrapper(masterElement), o); >+ fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, >+ false, oldValue), Diffs.createListDiffEntry(index, true, o))); >+ >+ return oldValue; >+ } >+ >+ public Object getObserved() { >+ return masterList; >+ } >+ >+ public synchronized void dispose() { >+ if (masterList != null) { >+ masterList.removeListChangeListener(masterListener); >+ masterList = null; >+ } >+ if (knownMasterElements != null) { >+ knownMasterElements.clear(); // detaches listeners >+ knownMasterElements.dispose(); >+ knownMasterElements = null; >+ } >+ >+ masterListener = null; >+ detailListener = null; >+ detailProperty = null; >+ cachedValues = null; >+ >+ super.dispose(); >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/core/databinding/property/list/ListProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/list/ListProperty.java >diff -N src/org/eclipse/core/databinding/property/list/ListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/list/ListProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,21 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.list; >+ >+/** >+ * Abstract implementation of IListProperty. >+ * >+ * @since 1.2 >+ */ >+public abstract class ListProperty implements IListProperty { >+ public abstract String toString(); >+} >Index: src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java >diff -N src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/set/SimpleSetProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,418 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.set; >+ >+import java.util.Collection; >+import java.util.Collections; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Set; >+ >+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.masterdetail.IObservableFactory; >+import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+ >+/** >+ * Simplified abstract implementation of ISetProperty. This class takes care of >+ * most of the functional requirements for an ISetProperty implementation, >+ * leaving only the property-specific details to subclasses. >+ * <p> >+ * Subclasses must implement these methods: >+ * <ul> >+ * <li>{@link #getElementType()} >+ * <li>{@link #getSet(Object)} >+ * <li>{@link #setSet(Object, Set, SetDiff)} >+ * </ul> >+ * >+ * @since 1.2 >+ */ >+public abstract class SimpleSetProperty implements ISetProperty { >+ /** >+ * Returns whether the source's collection property contains the given >+ * element. >+ * >+ * @param source >+ * the property source >+ * @param o >+ * the element >+ * @return whether the source's collection property contains the given >+ * element. >+ */ >+ protected boolean contains(Object source, Object o) { >+ return getSet(source).contains(o); >+ } >+ >+ /** >+ * Returns whether the source's collection property contains all elements in >+ * the given collection >+ * >+ * @param source >+ * the property source >+ * @param c >+ * the collection of elements to test for >+ * @return whether the source's collection property contains all elements in >+ * the given collection >+ */ >+ protected boolean containsAll(Object source, Collection c) { >+ return getSet(source).containsAll(c); >+ } >+ >+ /** >+ * Returns a Set with the current contents of the source's set property >+ * >+ * @param source >+ * the property source >+ * @return a Set with the current contents of the source's set property >+ */ >+ protected final Set getSet(Object source) { >+ return Collections.unmodifiableSet(doGetSet(source)); >+ } >+ >+ /** >+ * Returns an unmodifiable Set with the current contents of the source's set >+ * property >+ * >+ * @param source >+ * the property source >+ * @return an unmodifiable Set with the current contents of the source's set >+ * property >+ */ >+ protected abstract Set doGetSet(Object source); >+ >+ /** >+ * Returns the type of the elements in the collection or <code>null</code> >+ * if untyped >+ * >+ * @return the type of the elements in the collection or <code>null</code> >+ * if untyped >+ */ >+ protected abstract Object getElementType(); >+ >+ /** >+ * Returns whether the source's collection property is equal to the >+ * argument. >+ * >+ * @param source >+ * the property source >+ * @param o >+ * the object to test for equality to the source's collection >+ * property >+ * @return whether the source's collection property is equal to the argument >+ */ >+ protected boolean equals(Object source, Object o) { >+ return getSet(source).equals(o); >+ } >+ >+ /** >+ * Returns the hash code of the source's collection property. >+ * >+ * @param source >+ * the property source >+ * @return the hash code of the source's collection property >+ */ >+ protected int hashCode(Object source) { >+ return getSet(source).hashCode(); >+ } >+ >+ /** >+ * Returns whether the source's collection property is empty >+ * >+ * @param source >+ * the property source >+ * @return whether the source's collection property is empty >+ */ >+ protected boolean isEmpty(Object source) { >+ return getSet(source).isEmpty(); >+ } >+ >+ /** >+ * Returns the size of the source's collection property >+ * >+ * @param source >+ * the property source >+ * @return the size of the source's collection property >+ */ >+ protected int size(Object source) { >+ return getSet(source).size(); >+ } >+ >+ /** >+ * Returns an array of all elements in the source's collection property >+ * >+ * @param source >+ * the property source >+ * @param array >+ * the array into which the elements will be copied. If the array >+ * is not large enough to hold all elements, the elements will be >+ * returned in a new array of the same runtime type. >+ * @return an array of all elements in the source's collection property >+ */ >+ protected Object[] toArray(Object source, Object[] array) { >+ return getSet(source).toArray(array); >+ } >+ >+ /** >+ * Returns an array of all elements in the source's collection property >+ * >+ * @param source >+ * the property source >+ * @return an array of all elements in the source's collection property >+ */ >+ protected Object[] toArray(Object source) { >+ return getSet(source).toArray(); >+ } >+ >+ /** >+ * Updates the property on the source with the specified change. >+ * >+ * @param source >+ * the property source >+ * @param set >+ * the new set >+ * @param diff >+ * a diff describing the change >+ */ >+ protected abstract void setSet(Object source, Set set, SetDiff diff); >+ >+ /** >+ * Adds the element to the source's collection property >+ * >+ * @param source >+ * the property source >+ * @param o >+ * the element to add >+ * @return whether the element was added to the source's collection property >+ */ >+ protected boolean add(Object source, Object o) { >+ Set set = getSet(source); >+ if (!set.contains(o)) { >+ set = new HashSet(set); >+ boolean added = set.add(o); >+ if (added) { >+ setSet(source, set, Diffs.createSetDiff(Collections >+ .singleton(o), Collections.EMPTY_SET)); >+ } >+ return added; >+ } >+ return false; >+ } >+ >+ /** >+ * Adds all elements in the specified collection to the source's collection >+ * property. >+ * >+ * @param source >+ * the property source >+ * @param c >+ * the collection of elements to add. >+ * @return whether the source's collection property was changed >+ */ >+ protected boolean addAll(Object source, Collection c) { >+ if (c.isEmpty()) >+ return false; >+ >+ Set set = getSet(source); >+ Set additions = new HashSet(); >+ for (Iterator it = c.iterator(); it.hasNext();) { >+ Object o = it.next(); >+ if (!set.contains(o)) { >+ additions.add(o); >+ } >+ } >+ boolean changed = !additions.isEmpty(); >+ if (changed) { >+ set = new HashSet(set); >+ set.addAll(additions); >+ >+ setSet(source, set, Diffs.createSetDiff(additions, >+ Collections.EMPTY_SET)); >+ } >+ return changed; >+ } >+ >+ /** >+ * Removes all elements from the source's collection property. >+ * >+ * @param source >+ * the property source >+ */ >+ protected void clear(Object source) { >+ if (!isEmpty(source)) { >+ setSet(source, new HashSet(), Diffs.createSetDiff( >+ Collections.EMPTY_SET, getSet(source))); >+ } >+ } >+ >+ /** >+ * Removes the element from the source's collection property >+ * >+ * @param source >+ * the property source >+ * @param o >+ * the element to remove >+ * @return whether the element was removed from the source's collection >+ * property >+ */ >+ protected boolean remove(Object source, Object o) { >+ Set set = getSet(source); >+ if (set.contains(o)) { >+ set = new HashSet(set); >+ boolean removed = set.remove(o); >+ if (removed) { >+ setSet(source, set, Diffs.createSetDiff(Collections.EMPTY_SET, >+ Collections.singleton(o))); >+ } >+ return removed; >+ } >+ return false; >+ } >+ >+ /** >+ * Removes all elements from the source's collection property which are >+ * contained in the specified collection. >+ * >+ * @param source >+ * the property source >+ * @param c >+ * the collection of elements to be removed >+ * @return whether the source's collection property was changed >+ */ >+ protected boolean removeAll(Object source, Collection c) { >+ if (c.isEmpty()) >+ return false; >+ >+ Set set = new HashSet(getSet(source)); >+ Set removals = new HashSet(); >+ for (Iterator it = set.iterator(); it.hasNext();) { >+ Object o = it.next(); >+ if (c.contains(o)) { >+ removals.add(o); >+ it.remove(); >+ } >+ } >+ boolean changed = !removals.isEmpty(); >+ if (changed) { >+ setSet(source, set, Diffs.createSetDiff(Collections.EMPTY_SET, >+ removals)); >+ } >+ return changed; >+ } >+ >+ /** >+ * Removes all elements from the source's collection property which are not >+ * contained in the specified collection. >+ * >+ * @param source >+ * the property source >+ * @param c >+ * the collection of elements to retain >+ * @return whether the source's collection property was changed >+ */ >+ protected boolean retainAll(Object source, Collection c) { >+ if (isEmpty(source)) >+ return false; >+ if (c.isEmpty()) { >+ clear(source); >+ return true; >+ } >+ >+ Set set = new HashSet(getSet(source)); >+ Set removals = new HashSet(); >+ for (Iterator it = set.iterator(); it.hasNext();) { >+ Object o = it.next(); >+ if (!c.contains(o)) { >+ removals.add(o); >+ it.remove(); >+ } >+ } >+ boolean changed = !removals.isEmpty(); >+ if (changed) { >+ setSet(source, set, Diffs.createSetDiff(Collections.EMPTY_SET, >+ removals)); >+ } >+ return changed; >+ } >+ >+ /** >+ * Returns a listener which implements the correct listener interface for >+ * the expected source object, and which parlays property change events from >+ * the source object to the given listener. If there is no listener API for >+ * this property, this method returns null. >+ * >+ * @param listener >+ * the property listener to receive events >+ * @return a native listener which parlays property change events to the >+ * specified listener. >+ * @throws ClassCastException >+ * if the provided listener does not implement the correct >+ * listener interface (IValueProperty, IListProperty, >+ * ISetProperty or IMapProperty) depending on the property. >+ * @noreference This method is not intended to be referenced by clients. >+ */ >+ protected abstract INativePropertyListener adaptListener( >+ ISetPropertyChangeListener listener); >+ >+ /** >+ * Adds the specified listener as a listener for this property on the >+ * specified property source. If the source object has no listener API for >+ * this property (i.e. {@link #adaptListener(ISetPropertyChangeListener)} >+ * returns null), this method does nothing. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * a listener obtained from calling >+ * {@link #adaptListener(ISetPropertyChangeListener)}. >+ * @noreference This method is not intended to be referenced by clients. >+ */ >+ protected abstract void addListener(Object source, >+ INativePropertyListener listener); >+ >+ /** >+ * Removes the specified listener as a listener for this property on the >+ * specified property source. If the source object has no listener API for >+ * this property (i.e. {@link #adaptListener(ISetPropertyChangeListener)} >+ * returns null), this method does nothing. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * a listener obtained from calling >+ * {@link #adaptListener(ISetPropertyChangeListener)} . >+ * @noreference This method is not intended to be referenced by clients. >+ */ >+ protected abstract void removeListener(Object source, >+ INativePropertyListener listener); >+ >+ public IObservableSet observeSet(Realm realm, Object source) { >+ return new SetPropertyObservableSet(realm, source, this); >+ } >+ >+ public IObservableSet observeDetailSet(IObservableValue master) { >+ final Realm realm = master.getRealm(); >+ IObservableFactory factory = new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return SimpleSetProperty.this.observeSet(realm, target); >+ } >+ }; >+ return MasterDetailObservables.detailSet(master, factory, >+ getElementType()); >+ } >+ >+ public abstract String toString(); >+} >Index: src/org/eclipse/core/databinding/property/PropertyChangeEvent.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/PropertyChangeEvent.java >diff -N src/org/eclipse/core/databinding/property/PropertyChangeEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/PropertyChangeEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property; >+ >+import java.util.EventObject; >+ >+/** >+ * Base class for change events in the properties API >+ * >+ * @since 1.2 >+ */ >+public abstract class PropertyChangeEvent extends EventObject { >+ private static final long serialVersionUID = 1L; >+ >+ protected PropertyChangeEvent(Object source) { >+ super(source); >+ } >+ >+ protected abstract void dispatch(IPropertyChangeListener listener); >+ >+ public boolean equals(Object obj) { >+ if (obj == this) >+ return true; >+ if (obj == null) >+ return false; >+ if (getClass() != obj.getClass()) >+ return false; >+ >+ return getSource().equals(((PropertyChangeEvent) obj).getSource()); >+ } >+ >+ public int hashCode() { >+ return getSource().hashCode(); >+ } >+} >Index: src/org/eclipse/core/databinding/property/map/IMapPropertyChangeListener.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/map/IMapPropertyChangeListener.java >diff -N src/org/eclipse/core/databinding/property/map/IMapPropertyChangeListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/map/IMapPropertyChangeListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.map; >+ >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+ >+/** >+ * Listener for changes to map properties on a property source >+ * >+ * @since 1.2 >+ */ >+public interface IMapPropertyChangeListener extends IPropertyChangeListener { >+ /** >+ * Handle a change to a map property on a specific property source. >+ * >+ * @param event >+ * an event describing the map change that occured. >+ */ >+ public void handleMapPropertyChange(MapPropertyChangeEvent event); >+} >Index: src/org/eclipse/core/databinding/property/set/SetProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/set/SetProperty.java >diff -N src/org/eclipse/core/databinding/property/set/SetProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/set/SetProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,21 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.set; >+ >+/** >+ * Abstract implementation of ISetProperty >+ * >+ * @since 1.2 >+ */ >+public abstract class SetProperty implements ISetProperty { >+ public abstract String toString(); >+} >Index: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailValue.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailValue.java >diff -N src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailValue.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailValue.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,70 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.property; >+ >+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.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.ValueProperty; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class ValuePropertyDetailValue extends ValueProperty implements >+ IValueProperty { >+ private IValueProperty masterProperty; >+ private IValueProperty detailProperty; >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ValuePropertyDetailValue(IValueProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ public IObservableValue observeValue(Realm realm, Object source) { >+ IObservableValue master = masterProperty.observeValue(realm, source); >+ return detailProperty.observeDetailValue(master); >+ } >+ >+ public IObservableValue observeDetailValue(IObservableValue master) { >+ IObservableValue masterValue = masterProperty >+ .observeDetailValue(master); >+ return detailProperty.observeDetailValue(masterValue); >+ } >+ >+ public IObservableList observeDetailValues(IObservableList master) { >+ master = masterProperty.observeDetailValues(master); >+ return detailProperty.observeDetailValues(master); >+ } >+ >+ public IObservableMap observeDetailValues(IObservableSet master) { >+ IObservableMap masterMap = masterProperty.observeDetailValues(master); >+ return detailProperty.observeDetailValues(masterMap); >+ } >+ >+ public IObservableMap observeDetailValues(IObservableMap master) { >+ master = masterProperty.observeDetailValues(master); >+ return detailProperty.observeDetailValues(master); >+ } >+ >+ public String toString() { >+ return masterProperty + " => " + detailProperty; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/core/internal/databinding/property/SetPropertyDetailValueMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/SetPropertyDetailValueMap.java >diff -N src/org/eclipse/core/internal/databinding/property/SetPropertyDetailValueMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/SetPropertyDetailValueMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,53 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.property; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.map.MapProperty; >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SetPropertyDetailValueMap extends MapProperty { >+ private final ISetProperty masterProperty; >+ private final IValueProperty detailProperty; >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public SetPropertyDetailValueMap(ISetProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ public IObservableMap observeMap(Realm realm, Object source) { >+ IObservableSet master = masterProperty.observeSet(realm, source); >+ return detailProperty.observeDetailValues(master); >+ } >+ >+ public IObservableMap observeDetailMap(IObservableValue master) { >+ IObservableSet masterSet = masterProperty.observeDetailSet(master); >+ return detailProperty.observeDetailValues(masterSet); >+ } >+ >+ public String toString() { >+ return masterProperty + " => " + detailProperty; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/core/databinding/property/map/MapProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/map/MapProperty.java >diff -N src/org/eclipse/core/databinding/property/map/MapProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/map/MapProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,21 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.map; >+ >+/** >+ * Abstract implementation of IMapProperty >+ * >+ * @since 1.2 >+ */ >+public abstract class MapProperty implements IMapProperty { >+ public abstract String toString(); >+} >\ No newline at end of file >Index: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailSet.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailSet.java >diff -N src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailSet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailSet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,53 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.property; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.core.databinding.property.set.SetProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ValuePropertyDetailSet extends SetProperty { >+ private IValueProperty masterProperty; >+ private ISetProperty detailProperty; >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ValuePropertyDetailSet(IValueProperty masterProperty, >+ ISetProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ public IObservableSet observeSet(Realm realm, Object source) { >+ IObservableValue master = masterProperty.observeValue(realm, source); >+ return detailProperty.observeDetailSet(master); >+ } >+ >+ public IObservableSet observeDetailSet(IObservableValue master) { >+ IObservableValue masterValue = masterProperty >+ .observeDetailValue(master); >+ return detailProperty.observeDetailSet(masterValue); >+ } >+ >+ public String toString() { >+ return masterProperty + " => " + detailProperty; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/core/internal/databinding/property/ListPropertyDetailValueList.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/ListPropertyDetailValueList.java >diff -N src/org/eclipse/core/internal/databinding/property/ListPropertyDetailValueList.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/ListPropertyDetailValueList.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.property; >+ >+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.property.list.IListProperty; >+import org.eclipse.core.databinding.property.list.ListProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ListPropertyDetailValueList extends ListProperty { >+ private final IListProperty masterProperty; >+ private final IValueProperty detailProperty; >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ListPropertyDetailValueList(IListProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ public IObservableList observeList(Realm realm, Object source) { >+ IObservableList master = masterProperty.observeList(realm, source); >+ return detailProperty.observeDetailValues(master); >+ } >+ >+ public IObservableList observeDetailList(IObservableValue master) { >+ IObservableList masterList = masterProperty.observeDetailList(master); >+ return detailProperty.observeDetailValues(masterList); >+ } >+ >+ public String toString() { >+ return masterProperty + " => " + detailProperty; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/core/databinding/property/value/ValueProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/ValueProperty.java >diff -N src/org/eclipse/core/databinding/property/value/ValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/ValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,21 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.value; >+ >+/** >+ * Abstract implementation of IValueProperty >+ * >+ * @since 1.2 >+ */ >+public abstract class ValueProperty implements IValueProperty { >+ public abstract String toString(); >+} >Index: src/org/eclipse/core/databinding/property/map/IMapProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/map/IMapProperty.java >diff -N src/org/eclipse/core/databinding/property/map/IMapProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/map/IMapProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,54 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.map; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.IProperty; >+ >+/** >+ * Interface for map-typed properties >+ * >+ * @since 1.2 >+ * @noimplement This interface is not intended to be implemented by clients. >+ * Clients should instead subclass one of the classes that >+ * implement this interface. Note that direct implementers of this >+ * interface outside of the framework will be broken in future >+ * releases when methods are added to this interface. >+ */ >+public interface IMapProperty extends IProperty { >+ /** >+ * Returns an observable map observing this map property on the given >+ * property source >+ * >+ * @param realm >+ * the observable's realm >+ * @param source >+ * the property source >+ * @return an observable map observing this map-typed property on the given >+ * property source >+ */ >+ public IObservableMap observeMap(Realm realm, Object source); >+ >+ /** >+ * Returns an observable map on the master observable's realm which tracks >+ * this property of the values in the entry set of <code>master</code>. >+ * >+ * @param master >+ * the master observable >+ * @return an observable map on the master observable's realm which tracks >+ * this property of the values in the entry set of >+ * <code>master</code>. >+ */ >+ public IObservableMap observeDetailMap(IObservableValue master); >+} >Index: src/org/eclipse/core/internal/databinding/property/MapPropertyDetailValueMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/MapPropertyDetailValueMap.java >diff -N src/org/eclipse/core/internal/databinding/property/MapPropertyDetailValueMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/MapPropertyDetailValueMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.property; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.core.databinding.property.map.MapProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class MapPropertyDetailValueMap extends MapProperty { >+ private final IMapProperty masterProperty; >+ private final IValueProperty detailProperty; >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public MapPropertyDetailValueMap(IMapProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ public IObservableMap observeMap(Realm realm, Object source) { >+ IObservableMap master = masterProperty.observeMap(realm, source); >+ return detailProperty.observeDetailValues(master); >+ } >+ >+ public IObservableMap observeDetailMap(IObservableValue master) { >+ IObservableMap masterMap = masterProperty.observeDetailMap(master); >+ return detailProperty.observeDetailValues(masterMap); >+ } >+ >+ public String toString() { >+ return masterProperty + " => " + detailProperty; //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/core/databinding/property/set/SetPropertyObservableSet.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/set/SetPropertyObservableSet.java >diff -N src/org/eclipse/core/databinding/property/set/SetPropertyObservableSet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/set/SetPropertyObservableSet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,343 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.set; >+ >+import java.util.Collection; >+import java.util.Collections; >+import java.util.ConcurrentModificationException; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.set.AbstractObservableSet; >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.core.databinding.property.IProperty; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.IPropertyObservable; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class SetPropertyObservableSet extends AbstractObservableSet implements >+ IPropertyObservable { >+ private Object source; >+ private SimpleSetProperty property; >+ >+ private volatile boolean updating = false; >+ >+ private volatile int modCount = 0; >+ >+ private INativePropertyListener listener; >+ >+ private Set cachedSet; >+ >+ /** >+ * @param realm >+ * @param source >+ * @param property >+ */ >+ public SetPropertyObservableSet(Realm realm, Object source, >+ SimpleSetProperty property) { >+ super(realm); >+ this.source = source; >+ this.property = property; >+ } >+ >+ protected void firstListenerAdded() { >+ if (!isDisposed()) { >+ cachedSet = property.getSet(source); >+ >+ if (listener == null) { >+ listener = property >+ .adaptListener(new ISetPropertyChangeListener() { >+ public void handleSetPropertyChange( >+ final SetPropertyChangeEvent event) { >+ modCount++; >+ if (!isDisposed() && !updating) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ Set oldSet = cachedSet; >+ Set newSet = cachedSet = property >+ .getSet(source); >+ SetDiff diff = event.diff; >+ if (diff == null) { >+ diff = Diffs.computeSetDiff( >+ oldSet, newSet); >+ } >+ fireSetChange(diff); >+ } >+ }); >+ } >+ } >+ }); >+ } >+ property.addListener(source, listener); >+ } >+ } >+ >+ protected void lastListenerRemoved() { >+ if (listener != null) { >+ property.removeListener(source, listener); >+ } >+ >+ cachedSet = null; >+ } >+ >+ protected Set getWrappedSet() { >+ return property.getSet(source); >+ } >+ >+ public Object getElementType() { >+ return property.getElementType(); >+ } >+ >+ // Queries >+ >+ protected int doGetSize() { >+ return property.size(source); >+ } >+ >+ // Single change operations >+ >+ public boolean add(Object o) { >+ checkRealm(); >+ >+ boolean changed; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ changed = property.add(source, o); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedSet = property.getSet(source); >+ >+ if (changed) >+ fireSetChange(Diffs.createSetDiff(Collections.singleton(o), >+ Collections.EMPTY_SET)); >+ >+ return changed; >+ } >+ >+ public Iterator iterator() { >+ getterCalled(); >+ return new Iterator() { >+ int expectedModCount = modCount; >+ Iterator delegate = new HashSet(property.getSet(source)).iterator(); >+ Object last = null; >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.hasNext(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ last = delegate.next(); >+ return last; >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ >+ delegate.remove(); // stay in sync >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.remove(source, last); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedSet = property.getSet(source); >+ >+ fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >+ Collections.singleton(last))); >+ >+ last = null; >+ expectedModCount = modCount; >+ } >+ >+ private void checkForComodification() { >+ if (expectedModCount != modCount) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ >+ public boolean remove(Object o) { >+ getterCalled(); >+ >+ boolean changed; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ changed = property.remove(source, o); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedSet = property.getSet(source); >+ fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, Collections >+ .singleton(o))); >+ >+ return changed; >+ } >+ >+ // Bulk change operations >+ >+ public boolean addAll(Collection c) { >+ getterCalled(); >+ >+ if (c.isEmpty()) >+ return false; >+ >+ Set additions = new HashSet(c); >+ additions.removeAll(property.getSet(source)); >+ if (additions.isEmpty()) >+ return false; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.addAll(source, c); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedSet = property.getSet(source); >+ fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET)); >+ >+ return true; >+ } >+ >+ public boolean removeAll(Collection c) { >+ getterCalled(); >+ >+ if (property.isEmpty(source) || c.isEmpty()) >+ return false; >+ >+ Set removals = new HashSet(c); >+ removals.retainAll(property.getSet(source)); >+ if (removals.isEmpty()) >+ return false; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.removeAll(source, c); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedSet = property.getSet(source); >+ fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); >+ >+ return true; >+ } >+ >+ public boolean retainAll(Collection c) { >+ getterCalled(); >+ >+ if (property.isEmpty(source)) >+ return false; >+ >+ if (c.isEmpty()) { >+ clear(); >+ return true; >+ } >+ >+ Set removals = new HashSet(property.getSet(source)); >+ removals.removeAll(c); >+ if (removals.isEmpty()) >+ return false; >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.retainAll(source, c); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedSet = property.getSet(source); >+ fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); >+ >+ return true; >+ } >+ >+ public void clear() { >+ getterCalled(); >+ >+ if (property.isEmpty(source)) >+ return; >+ >+ Set removals = new HashSet(property.getSet(source)); >+ >+ boolean wasUpdating = updating; >+ updating = true; >+ try { >+ property.clear(source); >+ modCount++; >+ } finally { >+ updating = wasUpdating; >+ } >+ >+ cachedSet = property.getSet(source); >+ fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removals)); >+ } >+ >+ public boolean equals(Object o) { >+ getterCalled(); >+ return property.equals(source, o); >+ } >+ >+ public int hashCode() { >+ getterCalled(); >+ return property.hashCode(source); >+ } >+ >+ public Object getObserved() { >+ return source; >+ } >+ >+ public IProperty getProperty() { >+ return property; >+ } >+ >+ public synchronized void dispose() { >+ if (!isDisposed()) { >+ if (listener != null) >+ property.removeListener(source, listener); >+ property = null; >+ source = null; >+ listener = null; >+ } >+ super.dispose(); >+ } >+} >Index: src/org/eclipse/core/databinding/property/value/MapValuePropertyObservableMap.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/MapValuePropertyObservableMap.java >diff -N src/org/eclipse/core/databinding/property/value/MapValuePropertyObservableMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/MapValuePropertyObservableMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,362 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.value; >+ >+import java.util.AbstractSet; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Map; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.IObserving; >+import org.eclipse.core.databinding.observable.IStaleListener; >+import org.eclipse.core.databinding.observable.ObservableTracker; >+import org.eclipse.core.databinding.observable.StaleEvent; >+import org.eclipse.core.databinding.observable.map.AbstractObservableMap; >+import org.eclipse.core.databinding.observable.map.IMapChangeListener; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.map.MapChangeEvent; >+import org.eclipse.core.databinding.observable.map.MapDiff; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.set.ISetChangeListener; >+import org.eclipse.core.databinding.observable.set.SetChangeEvent; >+import org.eclipse.core.databinding.observable.set.WritableSet; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.internal.databinding.IdentityWrapper; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class MapValuePropertyObservableMap extends AbstractObservableMap >+ implements IObserving { >+ private IObservableMap masterMap; >+ private SimpleValueProperty detailProperty; >+ >+ private IObservableSet knownMasterValues; >+ private Map cachedValues; >+ >+ private boolean updating = false; >+ >+ private IMapChangeListener masterListener = new IMapChangeListener() { >+ public void handleMapChange(final MapChangeEvent event) { >+ if (!isDisposed()) { >+ updateKnownValues(); >+ if (!updating) >+ fireMapChange(convertDiff(event.diff)); >+ } >+ } >+ >+ private void updateKnownValues() { >+ Set identityKnownValues = new HashSet(); >+ for (Iterator it = masterMap.values().iterator(); it.hasNext();) { >+ identityKnownValues.add(new IdentityWrapper(it.next())); >+ } >+ >+ knownMasterValues.retainAll(identityKnownValues); >+ knownMasterValues.addAll(identityKnownValues); >+ } >+ >+ private MapDiff convertDiff(MapDiff diff) { >+ Map oldValues = new HashMap(); >+ Map newValues = new HashMap(); >+ >+ Set addedKeys = diff.getAddedKeys(); >+ for (Iterator it = addedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ Object newSource = diff.getNewValue(key); >+ Object newValue = detailProperty.getValue(newSource); >+ newValues.put(key, newValue); >+ } >+ >+ Set removedKeys = diff.getRemovedKeys(); >+ for (Iterator it = removedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ Object oldSource = diff.getOldValue(key); >+ Object oldValue = detailProperty.getValue(oldSource); >+ oldValues.put(key, oldValue); >+ } >+ >+ Set changedKeys = new HashSet(diff.getChangedKeys()); >+ for (Iterator it = changedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ >+ Object oldSource = diff.getOldValue(key); >+ Object newSource = diff.getNewValue(key); >+ >+ Object oldValue = detailProperty.getValue(oldSource); >+ Object newValue = detailProperty.getValue(newSource); >+ >+ if (Util.equals(oldValue, newValue)) { >+ it.remove(); >+ } else { >+ oldValues.put(key, oldValue); >+ newValues.put(key, newValue); >+ } >+ } >+ >+ return Diffs.createMapDiff(addedKeys, removedKeys, changedKeys, >+ oldValues, newValues); >+ } >+ }; >+ >+ private IStaleListener staleListener = new IStaleListener() { >+ public void handleStale(StaleEvent staleEvent) { >+ fireStale(); >+ } >+ }; >+ >+ private INativePropertyListener detailListener = detailProperty >+ .adaptListener(new IValuePropertyChangeListener() { >+ public void handleValuePropertyChange( >+ ValuePropertyChangeEvent event) { >+ Object masterValue = event.getSource(); >+ final Set keys = keysFor(masterValue); >+ >+ final Object oldDetailValue = event.diff.getOldValue(); >+ final Object newDetailValue = event.diff.getNewValue(); >+ >+ if (!Util.equals(oldDetailValue, newDetailValue)) { >+ fireMapChange(new MapDiff() { >+ public Set getAddedKeys() { >+ return Collections.EMPTY_SET; >+ } >+ >+ public Set getChangedKeys() { >+ return keys; >+ } >+ >+ public Set getRemovedKeys() { >+ return Collections.EMPTY_SET; >+ } >+ >+ public Object getNewValue(Object key) { >+ return newDetailValue; >+ } >+ >+ public Object getOldValue(Object key) { >+ return oldDetailValue; >+ } >+ }); >+ } >+ } >+ >+ private Set keysFor(Object value) { >+ Set keys = new HashSet(); >+ >+ for (Iterator it = masterMap.entrySet().iterator(); it >+ .hasNext();) { >+ Map.Entry entry = (Entry) it.next(); >+ if (entry.getValue() == value) { >+ keys.add(entry.getKey()); >+ } >+ } >+ >+ return keys; >+ } >+ }); >+ >+ /** >+ * @param map >+ * @param valueProperty >+ */ >+ public MapValuePropertyObservableMap(IObservableMap map, >+ SimpleValueProperty valueProperty) { >+ super(map.getRealm()); >+ this.masterMap = map; >+ this.detailProperty = valueProperty; >+ } >+ >+ protected void firstListenerAdded() { >+ knownMasterValues = new WritableSet(getRealm()); >+ cachedValues = new HashMap(); >+ knownMasterValues.addSetChangeListener(new ISetChangeListener() { >+ public void handleSetChange(SetChangeEvent event) { >+ for (Iterator it = event.diff.getRemovals().iterator(); it >+ .hasNext();) { >+ IdentityWrapper wrapper = (IdentityWrapper) it.next(); >+ Object key = wrapper.unwrap(); >+ detailProperty.removeListener(key, detailListener); >+ cachedValues.remove(wrapper); >+ } >+ for (Iterator it = event.diff.getAdditions().iterator(); it >+ .hasNext();) { >+ IdentityWrapper wrapper = (IdentityWrapper) it.next(); >+ Object key = wrapper.unwrap(); >+ cachedValues.put(wrapper, detailProperty.getValue(key)); >+ detailProperty.addListener(key, detailListener); >+ } >+ } >+ }); >+ for (Iterator it = masterMap.values().iterator(); it.hasNext();) { >+ knownMasterValues.add(new IdentityWrapper(it.next())); >+ } >+ >+ masterMap.addMapChangeListener(masterListener); >+ masterMap.addStaleListener(staleListener); >+ } >+ >+ protected void lastListenerRemoved() { >+ masterMap.removeMapChangeListener(masterListener); >+ masterMap.removeStaleListener(staleListener); >+ if (knownMasterValues != null) { >+ knownMasterValues.clear(); // removes attached listeners >+ knownMasterValues.dispose(); >+ knownMasterValues = null; >+ } >+ cachedValues = null; >+ } >+ >+ protected Object doGet(Object key) { >+ if (!masterMap.containsKey(key)) >+ return null; >+ return detailProperty.getValue(masterMap.get(key)); >+ } >+ >+ protected Object doPut(Object key, Object value) { >+ if (!masterMap.containsKey(key)) >+ return null; >+ Object source = masterMap.get(key); >+ >+ Object oldValue = detailProperty.getValue(source); >+ >+ updating = true; >+ try { >+ detailProperty.setValue(source, value); >+ } finally { >+ updating = false; >+ } >+ >+ Object newValue = detailProperty.getValue(source); >+ >+ if (!Util.equals(oldValue, newValue)) { >+ fireMapChange(Diffs.createMapDiffSingleChange(key, oldValue, >+ newValue)); >+ } >+ >+ return oldValue; >+ } >+ >+ private Set entrySet; >+ >+ public Set entrySet() { >+ getterCalled(); >+ if (entrySet == null) >+ entrySet = new EntrySet(); >+ return entrySet; >+ } >+ >+ class EntrySet extends AbstractSet { >+ public Iterator iterator() { >+ return new Iterator() { >+ Iterator it = masterMap.entrySet().iterator(); >+ >+ public boolean hasNext() { >+ getterCalled(); >+ return it.hasNext(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ Map.Entry next = (Map.Entry) it.next(); >+ return new MapEntry(next.getKey()); >+ } >+ >+ public void remove() { >+ it.remove(); >+ } >+ }; >+ } >+ >+ public int size() { >+ return masterMap.size(); >+ } >+ } >+ >+ class MapEntry implements Map.Entry { >+ private Object key; >+ >+ MapEntry(Object key) { >+ this.key = key; >+ } >+ >+ public Object getKey() { >+ getterCalled(); >+ return key; >+ } >+ >+ public Object getValue() { >+ getterCalled(); >+ return get(key); >+ } >+ >+ public Object setValue(Object value) { >+ return put(key, value); >+ } >+ >+ public boolean equals(Object o) { >+ getterCalled(); >+ if (o == this) >+ return true; >+ if (o == null) >+ return false; >+ if (!(o instanceof Map.Entry)) >+ return false; >+ Map.Entry that = (Map.Entry) o; >+ return Util.equals(this.getKey(), that.getKey()) >+ && Util.equals(this.getValue(), that.getValue()); >+ } >+ >+ public int hashCode() { >+ getterCalled(); >+ Object value = getValue(); >+ return (key == null ? 0 : key.hashCode()) >+ ^ (value == null ? 0 : value.hashCode()); >+ } >+ } >+ >+ public boolean isStale() { >+ getterCalled(); >+ return masterMap.isStale(); >+ } >+ >+ private void getterCalled() { >+ ObservableTracker.getterCalled(this); >+ } >+ >+ public Object getObserved() { >+ return masterMap; >+ } >+ >+ public synchronized void dispose() { >+ if (masterMap != null) { >+ masterMap.removeMapChangeListener(masterListener); >+ masterMap = null; >+ } >+ if (knownMasterValues != null) { >+ knownMasterValues.clear(); // detaches listeners >+ knownMasterValues.dispose(); >+ knownMasterValues = null; >+ } >+ >+ masterListener = null; >+ detailListener = null; >+ detailProperty = null; >+ cachedValues = null; >+ >+ super.dispose(); >+ } >+} >Index: src/org/eclipse/core/databinding/property/map/MapPropertyChangeEvent.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/map/MapPropertyChangeEvent.java >diff -N src/org/eclipse/core/databinding/property/map/MapPropertyChangeEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/map/MapPropertyChangeEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.map; >+ >+import org.eclipse.core.databinding.observable.map.MapDiff; >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+import org.eclipse.core.databinding.property.PropertyChangeEvent; >+ >+/** >+ * Map change event describing an incremental change of a map property on a >+ * particular property source. >+ * >+ * @since 1.2 >+ */ >+public class MapPropertyChangeEvent extends PropertyChangeEvent { >+ private static final long serialVersionUID = 1L; >+ >+ /** >+ * The map property that changed >+ */ >+ public final IMapProperty property; >+ >+ /** >+ * MapDiff enumerating the added, changed, and removed entries in the map, >+ * or null if the change is unknown. >+ */ >+ public final MapDiff diff; >+ >+ /** >+ * Constructs a MapPropertyChangeEvent with the given attributes >+ * >+ * @param source >+ * the property source >+ * @param property >+ * the property that changed on the source >+ * @param diff >+ * a MapDiff describing the changes to the map property >+ */ >+ public MapPropertyChangeEvent(Object source, IMapProperty property, >+ MapDiff diff) { >+ super(source); >+ this.property = property; >+ this.diff = diff; >+ } >+ >+ protected void dispatch(IPropertyChangeListener listener) { >+ ((IMapPropertyChangeListener) listener).handleMapPropertyChange(this); >+ } >+} >Index: src/org/eclipse/core/databinding/property/value/SetValuePropertyObservableMap.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/SetValuePropertyObservableMap.java >diff -N src/org/eclipse/core/databinding/property/value/SetValuePropertyObservableMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/SetValuePropertyObservableMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,128 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation (bug 194734) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property.value; >+ >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.Map; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.IObserving; >+import org.eclipse.core.databinding.observable.map.ComputedObservableMap; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+ >+/** >+ * @since 1.2 >+ */ >+public class SetValuePropertyObservableMap extends ComputedObservableMap >+ implements IObserving { >+ private SimpleValueProperty detailProperty; >+ >+ private INativePropertyListener listener; >+ >+ private Map cachedValues; >+ >+ /** >+ * @param keySet >+ * @param valueProperty >+ */ >+ public SetValuePropertyObservableMap(IObservableSet keySet, >+ SimpleValueProperty valueProperty) { >+ super(keySet); >+ this.detailProperty = valueProperty; >+ } >+ >+ protected void firstListenerAdded() { >+ if (listener == null) { >+ cachedValues = new HashMap(this); >+ >+ listener = detailProperty >+ .adaptListener(new IValuePropertyChangeListener() { >+ public void handleValuePropertyChange( >+ final ValuePropertyChangeEvent event) { >+ if (!isDisposed()) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ Object key = event.getSource(); >+ Object oldValue; >+ Object newValue; >+ >+ ValueDiff diff = event.diff; >+ if (diff == null) { >+ oldValue = cachedValues.get(key); >+ newValue = detailProperty >+ .getValue(key); >+ } else { >+ oldValue = event.diff.getOldValue(); >+ newValue = event.diff.getNewValue(); >+ } >+ >+ cachedValues.put(key, newValue); >+ fireMapChange(Diffs >+ .createMapDiffSingleChange(key, >+ oldValue, newValue)); >+ } >+ }); >+ } >+ } >+ }); >+ } >+ super.firstListenerAdded(); >+ } >+ >+ protected void lastListenerRemoved() { >+ super.lastListenerRemoved(); >+ } >+ >+ protected void hookListener(Object addedKey) { >+ if (listener != null) { >+ detailProperty.addListener(addedKey, listener); >+ } >+ } >+ >+ protected void unhookListener(Object removedKey) { >+ if (listener != null) { >+ detailProperty.removeListener(removedKey, listener); >+ } >+ } >+ >+ protected Object doGet(Object key) { >+ return detailProperty.getValue(key); >+ } >+ >+ protected Object doPut(Object key, Object value) { >+ Object result = detailProperty.getValue(key); >+ detailProperty.setValue(key, value); >+ cachedValues.put(key, value); >+ return result; >+ } >+ >+ public Object getObserved() { >+ return keySet(); >+ } >+ >+ public synchronized void dispose() { >+ if (!isDisposed()) { >+ if (listener != null) { >+ for (Iterator it = values().iterator(); it.hasNext();) { >+ unhookListener(it.next()); >+ } >+ listener = null; >+ } >+ detailProperty = null; >+ } >+ >+ super.dispose(); >+ } >+} >#P org.eclipse.jface.tests.databinding >Index: src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java,v >retrieving revision 1.11 >diff -u -r1.11 SWTObservablesTest.java >--- src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java 1 Oct 2008 19:00:14 -0000 1.11 >+++ src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,39 +7,46 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 > * Matthew Hall - bug 248621 > ******************************************************************************/ > > package org.eclipse.jface.tests.databinding.swt; > >+import org.eclipse.core.databinding.observable.IDecoratingObservable; > import org.eclipse.core.databinding.observable.list.IObservableList; >+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.ISWTObservable; > import org.eclipse.jface.databinding.swt.ISWTObservableValue; > import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.ButtonObservableValue; >-import org.eclipse.jface.internal.databinding.swt.CComboObservableList; >-import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.CLabelObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ComboObservableList; >-import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ControlObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ItemObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ItemTooltipObservableValue; >-import org.eclipse.jface.internal.databinding.swt.LabelObservableValue; >-import org.eclipse.jface.internal.databinding.swt.ListObservableList; >-import org.eclipse.jface.internal.databinding.swt.ListObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >-import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >-import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; >-import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; >-import org.eclipse.jface.internal.databinding.swt.TextObservableValue; >+import org.eclipse.jface.internal.databinding.swt.CComboSelectionProperty; >+import org.eclipse.jface.internal.databinding.swt.CComboTextProperty; >+import org.eclipse.jface.internal.databinding.swt.CLabelTextProperty; >+import org.eclipse.jface.internal.databinding.swt.CTabItemTooltipTextProperty; >+import org.eclipse.jface.internal.databinding.swt.ComboSelectionProperty; >+import org.eclipse.jface.internal.databinding.swt.ComboTextProperty; >+import org.eclipse.jface.internal.databinding.swt.ControlTooltipTextProperty; >+import org.eclipse.jface.internal.databinding.swt.ItemTextProperty; >+import org.eclipse.jface.internal.databinding.swt.LabelTextProperty; >+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.SpinnerMaximumProperty; >+import org.eclipse.jface.internal.databinding.swt.SpinnerMinimumProperty; >+import org.eclipse.jface.internal.databinding.swt.SpinnerSelectionProperty; >+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.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; >@@ -96,54 +103,54 @@ > Spinner spinner = new Spinner(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeSelection(spinner); > assertNotNull(value); >- assertTrue(value instanceof SpinnerObservableValue); >+ assertTrue(value.getWidget() == spinner); > >- SpinnerObservableValue spinnerObservable = (SpinnerObservableValue) value; >- assertEquals(SWTProperties.SELECTION, spinnerObservable.getAttribute()); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof SpinnerSelectionProperty); > } > > public void testObserveSelectionOfButton() throws Exception { > Button button = new Button(shell, SWT.PUSH); > ISWTObservableValue value = SWTObservables.observeSelection(button); > assertNotNull(value); >- assertTrue(value instanceof ButtonObservableValue); >+ assertTrue(value.getWidget() == button); > } > > public void testObserveSelectionOfCombo() throws Exception { > Combo combo = new Combo(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeSelection(combo); > assertNotNull(value); >- assertTrue(value instanceof ComboObservableValue); >+ assertTrue(value.getWidget() == combo); > >- ComboObservableValue comboObservable = (ComboObservableValue) value; >- assertEquals(SWTProperties.SELECTION, comboObservable.getAttribute()); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof ComboSelectionProperty); > } > > public void testObserveSelectionOfCCombo() throws Exception { > CCombo combo = new CCombo(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeSelection(combo); > assertNotNull(value); >- assertTrue(value instanceof CComboObservableValue); >+ assertTrue(value.getWidget() == combo); > >- CComboObservableValue ccomboObservable = (CComboObservableValue) value; >- assertEquals(SWTProperties.SELECTION, ccomboObservable.getAttribute()); >+ IPropertyObservable property = getPropertyObservable(value); >+ assertTrue(property.getProperty() instanceof CComboSelectionProperty); > } > > public void testObserveSelectionOfList() throws Exception { > List list = new List(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeSelection(list); > assertNotNull(value); >- assertTrue(value instanceof ListObservableValue); >+ assertTrue(value.getWidget() == list); > } > > public void testObserveSelectionOfScale() throws Exception { > Scale scale = new Scale(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeSelection(scale); > assertNotNull(value); >- assertTrue(value instanceof ScaleObservableValue); >+ assertTrue(value.getWidget() == scale); > >- ScaleObservableValue scaleObservable = (ScaleObservableValue) value; >- assertEquals(SWTProperties.SELECTION, scaleObservable.getAttribute()); >+ IPropertyObservable property = getPropertyObservable(value); >+ assertTrue(property.getProperty() instanceof ScaleSelectionProperty); > } > > public void testObserveSelectionOfUnsupportedControl() throws Exception { >@@ -162,7 +169,28 @@ > ISWTObservableValue value = SWTObservables.observeText(text, > SWT.FocusOut); > assertNotNull(value); >- assertTrue(value instanceof TextObservableValue); >+ assertTrue(value.getWidget() == text); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof TextTextProperty); >+ >+ assertFalse(text.isListening(SWT.FocusOut)); >+ ChangeEventTracker.observe(value); >+ assertTrue(text.isListening(SWT.FocusOut)); >+ } >+ >+ public void testObserveTextOfStyledText() throws Exception { >+ StyledText text = new StyledText(shell, SWT.NONE); >+ assertFalse(text.isListening(SWT.FocusOut)); >+ >+ ISWTObservableValue value = SWTObservables.observeText(text, >+ SWT.FocusOut); >+ assertNotNull(value); >+ assertTrue(value.getWidget() == text); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof StyledTextTextProperty); >+ >+ assertFalse(text.isListening(SWT.FocusOut)); >+ ChangeEventTracker.observe(value); > assertTrue(text.isListening(SWT.FocusOut)); > } > >@@ -179,41 +207,62 @@ > Label label = new Label(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeText(label); > assertNotNull(label); >- assertTrue(value instanceof LabelObservableValue); >+ assertTrue(value.getWidget() == label); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof LabelTextProperty); > } > > public void testObserveTextOfCLabel() throws Exception { > CLabel label = new CLabel(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeText(label); > assertNotNull(label); >- assertTrue(value instanceof CLabelObservableValue); >+ assertTrue(value.getWidget() == label); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof CLabelTextProperty); > } > > public void testObserveTextOfCombo() throws Exception { > Combo combo = new Combo(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeText(combo); > assertNotNull(value); >- assertTrue(value instanceof ComboObservableValue); >+ assertTrue(value.getWidget() == combo); > >- ComboObservableValue comboObservable = (ComboObservableValue) value; >- assertEquals(SWTProperties.TEXT, comboObservable.getAttribute()); >+ assertTrue(getPropertyObservable(value).getProperty() instanceof ComboTextProperty); >+ } >+ >+ /** >+ * @param observable >+ * @return >+ */ >+ private IPropertyObservable getPropertyObservable( >+ ISWTObservableValue observable) { >+ IDecoratingObservable decoratingObservable = (IDecoratingObservable) observable; >+ IPropertyObservable propertyObservable = (IPropertyObservable) decoratingObservable >+ .getDecorated(); >+ return propertyObservable; > } > > public void testObserveTextOfCCombo() throws Exception { > CCombo combo = new CCombo(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeText(combo); > assertNotNull(value); >- assertTrue(value instanceof CComboObservableValue); >+ assertTrue(value.getWidget() == combo); > >- CComboObservableValue ccomboObservable = (CComboObservableValue) value; >- assertEquals(SWTProperties.TEXT, ccomboObservable.getAttribute()); >+ IDecoratingObservable decorating = (IDecoratingObservable) value; >+ IPropertyObservable property = (IPropertyObservable) decorating >+ .getDecorated(); >+ assertTrue(property.getProperty() instanceof CComboTextProperty); > } > > public void testObserveTextOfText() throws Exception { > Text text = new Text(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeText(text); > assertNotNull(value); >- assertTrue(value instanceof TextObservableValue); >+ >+ assertTrue(value.getWidget() == text); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof TextTextProperty); >+ > assertFalse(text.isListening(SWT.Modify)); > assertFalse(text.isListening(SWT.FocusOut)); > } >@@ -223,7 +272,9 @@ > Item item = new CTabItem(ctf, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeText(item); > assertNotNull(value); >- assertTrue(value instanceof ItemObservableValue); >+ assertTrue(value.getWidget() == item); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof ItemTextProperty); > } > > public void testObserveTextOfUnsupportedControl() throws Exception { >@@ -240,7 +291,9 @@ > Item item = new CTabItem(ctf, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeTooltipText(item); > assertNotNull(value); >- assertTrue(value instanceof ItemTooltipObservableValue); >+ assertTrue(value.getWidget() == item); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof CTabItemTooltipTextProperty); > } > > public void testObserveTooltipOfUnsupportedControl() throws Exception { >@@ -256,28 +309,33 @@ > Label label = new Label(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeTooltipText(label); > assertNotNull(value); >- assertTrue(value instanceof ControlObservableValue); >+ assertTrue(value.getWidget() == label); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof ControlTooltipTextProperty); > } > > public void testObserveItemsOfCombo() throws Exception { > Combo combo = new Combo(shell, SWT.NONE); > IObservableList list = SWTObservables.observeItems(combo); > assertNotNull(list); >- assertTrue(list instanceof ComboObservableList); >+ assertTrue(list instanceof ISWTObservable); >+ assertTrue(((ISWTObservable) list).getWidget() == combo); > } > > public void testObserveItemsOfCCombo() throws Exception { > CCombo ccombo = new CCombo(shell, SWT.NONE); > IObservableList list = SWTObservables.observeItems(ccombo); > assertNotNull(list); >- assertTrue(list instanceof CComboObservableList); >+ ISWTObservable swtObservable = (ISWTObservable) list; >+ assertTrue(swtObservable.getWidget() == ccombo); > } > > public void testObserveItemsOfList() throws Exception { > List list = new List(shell, SWT.NONE); > IObservableList observableList = SWTObservables.observeItems(list); > assertNotNull(observableList); >- assertTrue(observableList instanceof ListObservableList); >+ ISWTObservable swtObservable = (ISWTObservable) observableList; >+ assertTrue(swtObservable.getWidget() == list); > } > > public void testObserveItemsOfUnsupportedControl() throws Exception { >@@ -294,7 +352,9 @@ > ISWTObservableValue value = SWTObservables > .observeSingleSelectionIndex(table); > assertNotNull(value); >- assertTrue(value instanceof TableSingleSelectionObservableValue); >+ assertTrue(value.getWidget() == table); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof TableSingleSelectionIndexProperty); > } > > public void testObserveSingleSelectionIndexOfUnsupportedControl() >@@ -312,20 +372,20 @@ > Spinner spinner = new Spinner(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeMin(spinner); > assertNotNull(value); >- assertTrue(value instanceof SpinnerObservableValue); >+ assertTrue(value.getWidget() == spinner); > >- SpinnerObservableValue spinnerObservable = (SpinnerObservableValue) value; >- assertEquals(SWTProperties.MIN, spinnerObservable.getAttribute()); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof SpinnerMinimumProperty); > } > > public void testObserveMinOfScale() throws Exception { > Scale scale = new Scale(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeMin(scale); > assertNotNull(value); >- assertTrue(value instanceof ScaleObservableValue); >+ assertTrue(value.getWidget() == scale); > >- ScaleObservableValue scaleObservable = (ScaleObservableValue) value; >- assertEquals(SWTProperties.MIN, scaleObservable.getAttribute()); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof ScaleMinimumProperty); > } > > public void testObserveMinOfUnsupportedControl() throws Exception { >@@ -341,20 +401,20 @@ > Spinner spinner = new Spinner(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeMax(spinner); > assertNotNull(value); >- assertTrue(value instanceof SpinnerObservableValue); >+ assertTrue(value.getWidget() == spinner); > >- SpinnerObservableValue spinnerObservable = (SpinnerObservableValue) value; >- assertEquals(SWTProperties.MAX, spinnerObservable.getAttribute()); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof SpinnerMaximumProperty); > } > > public void testObserveMaxOfScale() throws Exception { > Scale scale = new Scale(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeMax(scale); > assertNotNull(value); >- assertTrue(value instanceof ScaleObservableValue); >+ assertTrue(value.getWidget() == scale); > >- ScaleObservableValue scaleObservable = (ScaleObservableValue) value; >- assertEquals(SWTProperties.MAX, scaleObservable.getAttribute()); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof ScaleMaximumProperty); > } > > public void testObserveMaxOfUnsupportedControl() throws Exception { >@@ -370,7 +430,9 @@ > Text text = new Text(shell, SWT.NONE); > ISWTObservableValue value = SWTObservables.observeEditable(text); > assertNotNull(value); >- assertTrue(value instanceof TextEditableObservableValue); >+ assertTrue(value.getWidget() == text); >+ IPropertyObservable propertyObservable = getPropertyObservable(value); >+ assertTrue(propertyObservable.getProperty() instanceof TextEditableProperty); > } > > public void testObserveEditableOfUnsupportedControl() throws Exception { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMinTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMinTest.java,v >retrieving revision 1.2 >diff -u -r1.2 ScaleObservableValueMinTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMinTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMinTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > *******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -22,8 +22,7 @@ > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; > import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; > import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >-import org.eclipse.jface.internal.databinding.swt.ScaleObservableValue; >+import org.eclipse.jface.databinding.swt.ScaleProperties; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Scale; >@@ -42,11 +41,11 @@ > public ScaleObservableValueMinTest() { > this(null); > } >- >+ > public ScaleObservableValueMinTest(String testName) { > super(testName, new Delegate()); > } >- >+ > protected void setUp() throws Exception { > super.setUp(); > >@@ -56,9 +55,10 @@ > } > > protected IObservable doCreateObservable() { >- return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); >+ return getObservableContractDelegate().createObservable( >+ SWTObservables.getRealm(Display.getDefault())); > } >- >+ > public void testGetValue() throws Exception { > int min = 100; > scale.setMinimum(min); >@@ -72,9 +72,11 @@ > } > > public static Test suite() { >- TestSuite suite = new TestSuite(ScaleObservableValueMinTest.class.toString()); >+ TestSuite suite = new TestSuite(ScaleObservableValueMinTest.class >+ .toString()); > suite.addTestSuite(ScaleObservableValueMinTest.class); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); > return suite; > } > >@@ -95,7 +97,7 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ScaleObservableValue(realm, scale, SWTProperties.MIN); >+ return ScaleProperties.minimum().observeValue(realm, scale); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/CLabelObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CLabelObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 CLabelObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/CLabelObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/CLabelObservableValueTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -21,8 +21,8 @@ > 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.swt.CLabelProperties; > import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.CLabelObservableValue; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.CLabel; > import org.eclipse.swt.widgets.Display; >@@ -36,38 +36,41 @@ > private Delegate delegate; > private IObservableValue observable; > private CLabel label; >- >+ > protected void setUp() throws Exception { > super.setUp(); >- >+ > delegate = new Delegate(); > delegate.setUp(); > label = delegate.label; >- observable = delegate.createObservableValue(SWTObservables.getRealm(Display.getDefault())); >+ observable = delegate.createObservableValue(SWTObservables >+ .getRealm(Display.getDefault())); > } >- >+ > protected void tearDown() throws Exception { > super.tearDown(); >- >+ > delegate.tearDown(); > observable.dispose(); > } >- >- public void testSetValue() throws Exception { >- //preconditions >- assertEquals(null, label.getText()); >- assertEquals(null, observable.getValue()); >- >- String value = "value"; >- observable.setValue(value); >- assertEquals("label text", value, label.getText()); >- assertEquals("observable value", value, observable.getValue()); >- } >- >+ >+ public void testSetValue() throws Exception { >+ // preconditions >+ assertEquals(null, label.getText()); >+ assertEquals(null, observable.getValue()); >+ >+ String value = "value"; >+ observable.setValue(value); >+ assertEquals("label text", value, label.getText()); >+ assertEquals("observable value", value, observable.getValue()); >+ } >+ > public static Test suite() { >- TestSuite suite = new TestSuite(CLabelObservableValueTest.class.getName()); >+ TestSuite suite = new TestSuite(CLabelObservableValueTest.class >+ .getName()); > suite.addTestSuite(CLabelObservableValueTest.class); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); > return suite; > } > >@@ -87,18 +90,18 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new CLabelObservableValue(realm, label); >+ return CLabelProperties.text().observeValue(realm, label); > } > > public void change(IObservable observable) { > IObservableValue value = (IObservableValue) observable; > value.setValue(value.getValue() + "a"); > } >- >+ > public Object getValueType(IObservableValue observable) { > return String.class; > } >- >+ > public Object createValue(IObservableValue observable) { > return observable.getValue() + "a"; > } >Index: src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueFocusOutTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueFocusOutTest.java,v >retrieving revision 1.2 >diff -u -r1.2 TextObservableValueFocusOutTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueFocusOutTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueFocusOutTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > *******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -21,7 +21,7 @@ > 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.internal.databinding.swt.TextObservableValue; >+import org.eclipse.jface.databinding.swt.TextProperties; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.Text; >@@ -31,8 +31,10 @@ > */ > public class TextObservableValueFocusOutTest extends TestCase { > public static Test suite() { >- TestSuite suite = new TestSuite(TextObservableValueFocusOutTest.class.toString()); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ TestSuite suite = new TestSuite(TextObservableValueFocusOutTest.class >+ .toString()); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); > return suite; > } > >@@ -41,7 +43,7 @@ > private Shell shell; > > private Text text; >- >+ > public void setUp() { > shell = new Shell(); > text = new Text(shell, SWT.NONE); >@@ -52,7 +54,7 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new TextObservableValue(realm, text, SWT.FocusOut); >+ return TextProperties.text(SWT.FocusOut).observeValue(realm, text); > } > > public Object getValueType(IObservableValue observable) { >@@ -61,10 +63,10 @@ > > public void change(IObservable observable) { > text.setFocus(); >- >+ > IObservableValue observableValue = (IObservableValue) observable; > text.setText((String) createValue(observableValue)); >- >+ > text.notifyListeners(SWT.FocusOut, null); > } > >Index: src/org/eclipse/jface/tests/internal/databinding/swt/TextEditableObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextEditableObservableValueTest.java,v >retrieving revision 1.2 >diff -u -r1.2 TextEditableObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/TextEditableObservableValueTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/TextEditableObservableValueTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > *******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -21,7 +21,7 @@ > import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; > import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; >-import org.eclipse.jface.internal.databinding.swt.TextEditableObservableValue; >+import org.eclipse.jface.databinding.swt.TextProperties; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.Text; >@@ -29,9 +29,8 @@ > /** > * @since 1.1 > */ >-public class TextEditableObservableValueTest extends >- ObservableDelegateTest { >- >+public class TextEditableObservableValueTest extends ObservableDelegateTest { >+ > private Delegate delegate; > private Text text; > private IObservableValue observable; >@@ -39,78 +38,85 @@ > public TextEditableObservableValueTest() { > this(null); > } >- >+ > public TextEditableObservableValueTest(String testName) { > super(testName, new Delegate()); > } > >- /* (non-Javadoc) >- * @see org.eclipse.jface.conformance.databinding.ObservableDelegateTest#setUp() >+ /* >+ * (non-Javadoc) >+ * >+ * @see >+ * org.eclipse.jface.conformance.databinding.ObservableDelegateTest#setUp() > */ > protected void setUp() throws Exception { > super.setUp(); >- >+ > delegate = (Delegate) getObservableContractDelegate(); > observable = (IObservableValue) getObservable(); > text = delegate.text; > } >- >+ > protected IObservable doCreateObservable() { > return super.doCreateObservable(); > } >- >+ > public void testGetValue() throws Exception { > text.setEditable(false); > assertEquals(Boolean.valueOf(text.getEditable()), observable.getValue()); >- >+ > text.setEditable(true); > assertEquals(Boolean.valueOf(text.getEditable()), observable.getValue()); > } >- >+ > public void testSetValue() throws Exception { > text.setEditable(false); > observable.setValue(Boolean.TRUE); > assertEquals(Boolean.TRUE, Boolean.valueOf(text.getEditable())); >- >+ > observable.setValue(Boolean.FALSE); > assertEquals(Boolean.FALSE, Boolean.valueOf(text.getEditable())); > } >- >+ > public static Test suite() { >- TestSuite suite = new TestSuite(TextEditableObservableValueTest.class.toString()); >+ TestSuite suite = new TestSuite(TextEditableObservableValueTest.class >+ .toString()); > suite.addTestSuite(TextEditableObservableValueTest.class); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); > return suite; > } >- >- /*package*/ static class Delegate extends AbstractObservableValueContractDelegate { >+ >+ /* package */static class Delegate extends >+ AbstractObservableValueContractDelegate { > private Shell shell; > Text text; >- >- public void setUp() { >+ >+ public void setUp() { > shell = new Shell(); > text = new Text(shell, SWT.NONE); > } > >- public void tearDown() { >+ public void tearDown() { > shell.dispose(); > } >- >+ > public IObservableValue createObservableValue(Realm realm) { >- return new TextEditableObservableValue(realm, text); >+ return TextProperties.editable().observeValue(realm, text); > } >- >+ > public Object getValueType(IObservableValue observable) { > return Boolean.TYPE; > } >- >+ > public void change(IObservable observable) { > IObservableValue observableValue = (IObservableValue) observable; > observableValue.setValue(createValue(observableValue)); > } >- >+ > public Object createValue(IObservableValue observable) { >- return (Boolean.TRUE.equals(observable.getValue()) ? Boolean.FALSE: Boolean.TRUE); >+ return (Boolean.TRUE.equals(observable.getValue()) ? Boolean.FALSE >+ : Boolean.TRUE); > } > } > } >Index: src/org/eclipse/jface/tests/internal/databinding/swt/LabelObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/LabelObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 LabelObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/LabelObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/LabelObservableValueTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -21,8 +21,8 @@ > import org.eclipse.jface.databinding.conformance.ObservableDelegateTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; > import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; >+import org.eclipse.jface.databinding.swt.LabelProperties; > import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.LabelObservableValue; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Label; >@@ -35,43 +35,46 @@ > private Delegate delegate; > private IObservableValue observable; > private Label label; >- >+ > public LabelObservableValueTest() { > this(null); > } >- >+ > public LabelObservableValueTest(String testName) { > super(testName, new Delegate()); > } >- >+ > protected void setUp() throws Exception { > super.setUp(); >- >+ > delegate = (Delegate) getObservableContractDelegate(); > observable = (IObservableValue) getObservable(); > label = delegate.label; > } >- >+ > protected IObservable doCreateObservable() { >- return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); >+ return getObservableContractDelegate().createObservable( >+ SWTObservables.getRealm(Display.getDefault())); > } >- >- public void testSetValue() throws Exception { >- //preconditions >- assertEquals("", label.getText()); >- assertEquals("", observable.getValue()); >- >- String value = "value"; >- observable.setValue(value); >- assertEquals("label text", value, label.getText()); >- assertEquals("observable value", value, observable.getValue()); >- } >- >- public static Test suite() { >- TestSuite suite = new TestSuite(LabelObservableValueTest.class.toString()); >- suite.addTestSuite(LabelObservableValueTest.class); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >- return suite; >+ >+ public void testSetValue() throws Exception { >+ // preconditions >+ assertEquals("", label.getText()); >+ assertEquals("", observable.getValue()); >+ >+ String value = "value"; >+ observable.setValue(value); >+ assertEquals("label text", value, label.getText()); >+ assertEquals("observable value", value, observable.getValue()); >+ } >+ >+ public static Test suite() { >+ TestSuite suite = new TestSuite(LabelObservableValueTest.class >+ .toString()); >+ suite.addTestSuite(LabelObservableValueTest.class); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); >+ return suite; > } > > /* package */static class Delegate extends >@@ -90,18 +93,18 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new LabelObservableValue(realm, label); >+ return LabelProperties.text().observeValue(realm, label); > } > > public void change(IObservable observable) { > IObservableValue value = (IObservableValue) observable; > value.setValue(value.getValue() + "a"); > } >- >+ > public Object getValueType(IObservableValue observable) { > return String.class; > } >- >+ > public Object createValue(IObservableValue observable) { > return observable.getValue() + "a"; > } >Index: src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueSelectionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueSelectionTest.java,v >retrieving revision 1.2 >diff -u -r1.2 CComboObservableValueSelectionTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueSelectionTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueSelectionTest.java 17 Dec 2008 01:04:07 -0000 >@@ -22,10 +22,10 @@ > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; > import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; > import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; >+import org.eclipse.jface.databinding.swt.CComboProperties; > import org.eclipse.jface.databinding.swt.ISWTObservable; > import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.CComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >+import org.eclipse.jface.internal.databinding.swt.SWTObservableValueDecorator; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.CCombo; > import org.eclipse.swt.widgets.Display; >@@ -57,16 +57,19 @@ > IObservableValue observable = (IObservableValue) delegate > .createObservable(SWTObservables.getRealm(Display.getDefault())); > >- ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); >+ ValueChangeEventTracker listener = ValueChangeEventTracker >+ .observe(observable); > combo.select(0); > > assertEquals("Observable was not notified.", 1, listener.count); > } > > public static Test suite() { >- TestSuite suite = new TestSuite(CComboObservableValueSelectionTest.class.getName()); >+ TestSuite suite = new TestSuite( >+ CComboObservableValueSelectionTest.class.getName()); > suite.addTestSuite(CComboObservableValueSelectionTest.class); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); > return suite; > } > >@@ -88,15 +91,13 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new CComboObservableValue(realm, combo, >- SWTProperties.SELECTION); >+ return new SWTObservableValueDecorator(CComboProperties.selection() >+ .observeValue(realm, combo), combo); > } > > public void change(IObservable observable) { >- int index = combo >- .indexOf((String) createValue((IObservableValue) observable)); >- >- combo.select(index); >+ IObservableValue ov = (IObservableValue) observable; >+ ov.setValue(createValue(ov)); > } > > public Object getValueType(IObservableValue observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 CComboSingleSelectionObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/CComboSingleSelectionObservableValueTest.java 17 Dec 2008 01:04:07 -0000 >@@ -8,7 +8,7 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Ashley Cambrell - bug 198903 >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -21,8 +21,8 @@ > 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.swt.ISWTObservable; >-import org.eclipse.jface.internal.databinding.swt.CComboSingleSelectionObservableValue; >+import org.eclipse.jface.databinding.swt.CComboProperties; >+import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.CCombo; >@@ -31,11 +31,12 @@ > /** > * @since 3.2 > */ >-public class CComboSingleSelectionObservableValueTest extends AbstractSWTTestCase { >+public class CComboSingleSelectionObservableValueTest extends >+ AbstractSWTTestCase { > public void testSetValue() throws Exception { > CCombo combo = new CCombo(getShell(), SWT.NONE); >- CComboSingleSelectionObservableValue observableValue = new CComboSingleSelectionObservableValue( >- combo); >+ IObservableValue observableValue = SWTObservables >+ .observeSingleSelectionIndex(combo); > combo.add("Item1"); > combo.add("Item2"); > >@@ -52,9 +53,11 @@ > } > > public static Test suite() { >- TestSuite suite = new TestSuite(CComboSingleSelectionObservableValueTest.class.getName()); >+ TestSuite suite = new TestSuite( >+ CComboSingleSelectionObservableValueTest.class.getName()); > suite.addTestSuite(CComboSingleSelectionObservableValueTest.class); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); > return suite; > } > >@@ -75,13 +78,13 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new CComboSingleSelectionObservableValue(realm, combo); >+ return CComboProperties.singleSelectionIndex().observeValue(realm, >+ combo); > } > > public void change(IObservable observable) { >- int index = _createValue((IObservableValue) observable); >- combo.select(index); >- combo.notifyListeners(SWT.Selection, null); >+ IObservableValue value = (IObservableValue) observable; >+ value.setValue(createValue(value)); > } > > public Object getValueType(IObservableValue observable) { >@@ -91,12 +94,11 @@ > public Object createValue(IObservableValue observable) { > return new Integer(_createValue(observable)); > } >- >+ > private int _createValue(IObservableValue observable) { >- CCombo combo = ((CCombo) ((ISWTObservable) observable).getWidget()); > int value = Math.max(0, combo.getSelectionIndex()); >- >- //returns either 0 or 1 depending upon current value >+ >+ // returns either 0 or 1 depending upon current value > return Math.abs(value - 1); > } > } >Index: src/org/eclipse/jface/tests/internal/databinding/swt/SWTDelayedObservableValueDecoratorTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SWTDelayedObservableValueDecoratorTest.java,v >retrieving revision 1.1 >diff -u -r1.1 SWTDelayedObservableValueDecoratorTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/SWTDelayedObservableValueDecoratorTest.java 25 Sep 2008 18:43:58 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/SWTDelayedObservableValueDecoratorTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Matthew Hall - initial API and implementation (bug 212223) >- * Matthew Hall - bug 213145, 245647 >+ * Matthew Hall - bug 213145, 245647, 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -15,22 +15,21 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > >-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.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.util.ValueChangeEventTracker; > import org.eclipse.jface.databinding.swt.ISWTObservableValue; > import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >+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.eclipse.swt.widgets.Widget; > > /** > * Tests for DelayedObservableValue >@@ -43,15 +42,15 @@ > private Shell shell; > private Object oldValue; > private Object newValue; >- private SWTObservableValueStub target; >+ private ISWTObservableValue target; > private ISWTObservableValue delayed; > > protected void setUp() throws Exception { > super.setUp(); > display = Display.getCurrent(); > shell = new Shell(display); >- target = new SWTObservableValueStub(SWTObservables.getRealm(display), >- shell); >+ target = new SWTObservableValueDecorator(new WritableValue( >+ SWTObservables.getRealm(display)), shell); > oldValue = new Object(); > newValue = new Object(); > target.setValue(oldValue); >@@ -93,43 +92,6 @@ > assertEquals(newValue, tracker.event.diff.getNewValue()); > } > >- static class SWTObservableValueStub extends AbstractSWTObservableValue { >- private Object value; >- private boolean stale; >- >- Object overrideValue; >- >- public SWTObservableValueStub(Realm realm, Widget widget) { >- super(realm, widget); >- } >- >- protected Object doGetValue() { >- return value; >- } >- >- protected void doSetValue(Object value) { >- Object oldValue = this.value; >- if (overrideValue != null) >- value = overrideValue; >- this.value = value; >- stale = false; >- fireValueChange(Diffs.createValueDiff(oldValue, value)); >- } >- >- public Object getValueType() { >- return Object.class; >- } >- >- protected void fireStale() { >- stale = true; >- super.fireStale(); >- } >- >- public boolean isStale() { >- return stale; >- } >- } >- > public static Test suite() { > TestSuite suite = new TestSuite( > SWTDelayedObservableValueDecoratorTest.class.getName()); >@@ -155,7 +117,8 @@ > > public IObservableValue createObservableValue(Realm realm) { > return SWTObservables.observeDelayedValue(0, >- new SWTObservableValueStub(realm, shell)); >+ new SWTObservableValueDecorator(new WritableValue(realm, >+ null, Object.class), shell)); > } > > public Object getValueType(IObservableValue observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java,v >retrieving revision 1.3 >diff -u -r1.3 CComboObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java 14 Apr 2008 17:56:27 -0000 1.3 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTest.java 17 Dec 2008 01:04:07 -0000 >@@ -9,13 +9,18 @@ > * Brad Reynolds - initial API and implementation > * Ashley Cambrell - bug 198904 > * Eric Rizzo - bug 134884 >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; > >+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.internal.databinding.swt.CComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >+import org.eclipse.jface.databinding.swt.CComboProperties; >+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.custom.CCombo; >@@ -26,8 +31,7 @@ > public class CComboObservableValueTest extends AbstractSWTTestCase { > public void testDispose() throws Exception { > CCombo combo = new CCombo(getShell(), SWT.NONE); >- CComboObservableValue observableValue = new CComboObservableValue( >- combo, SWTProperties.TEXT); >+ ISWTObservableValue observableValue = SWTObservables.observeText(combo); > > ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); > observableValue.addValueChangeListener(testCounterValueChangeListener); >@@ -52,21 +56,21 @@ > } > > public void testSetValueWithNull() { >- testSetValueWithNull(SWTProperties.TEXT); >- testSetValueWithNull(SWTProperties.SELECTION); >+ testSetValueWithNull(CComboProperties.text()); >+ testSetValueWithNull(CComboProperties.selection()); > } > >- protected void testSetValueWithNull(String observableMode) { >+ protected void testSetValueWithNull(IValueProperty property) { > CCombo combo = new CCombo(getShell(), SWT.NONE); >- combo.setItems(new String[] {"one", "two", "three"}); >- CComboObservableValue observable = new CComboObservableValue( >- combo, observableMode); >+ combo.setItems(new String[] { "one", "two", "three" }); >+ IObservableValue observable = property.observeValue(Realm.getDefault(), >+ combo); > >- observable.doSetValue("two"); >+ observable.setValue("two"); > assertEquals("two", combo.getText()); > assertEquals(1, combo.getSelectionIndex()); > >- observable.doSetValue(null); >+ observable.setValue(null); > assertEquals("", combo.getText()); > assertEquals(-1, combo.getSelectionIndex()); > } >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueSelectionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueSelectionTest.java,v >retrieving revision 1.2 >diff -u -r1.2 ComboObservableValueSelectionTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueSelectionTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueSelectionTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > *******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -22,10 +22,10 @@ > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; > import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest; > import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; >+import org.eclipse.jface.databinding.swt.ComboProperties; > import org.eclipse.jface.databinding.swt.ISWTObservable; > import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >+import org.eclipse.jface.internal.databinding.swt.SWTObservableValueDecorator; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Combo; > import org.eclipse.swt.widgets.Display; >@@ -33,7 +33,7 @@ > > /** > * @since 3.2 >- * >+ * > */ > public class ComboObservableValueSelectionTest extends TestCase { > private Delegate delegate; >@@ -67,9 +67,11 @@ > } > > public static Test suite() { >- TestSuite suite = new TestSuite(ComboObservableValueSelectionTest.class.toString()); >+ TestSuite suite = new TestSuite(ComboObservableValueSelectionTest.class >+ .toString()); > suite.addTestSuite(ComboObservableValueSelectionTest.class); >- suite.addTest(SWTMutableObservableValueContractTest.suite(new Delegate())); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); > return suite; > } > >@@ -91,16 +93,15 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ComboObservableValue(realm, combo, >- SWTProperties.SELECTION); >+ return new SWTObservableValueDecorator(ComboProperties.selection() >+ .observeValue(realm, combo), combo); > } > > public void change(IObservable observable) { > int index = combo > .indexOf((String) createValue((IObservableValue) observable)); > >- combo.select(index); >- combo.notifyListeners(SWT.Selection, null); >+ ((IObservableValue) observable).setValue(combo.getItem(index)); > } > > public Object getValueType(IObservableValue observable) { >Index: src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java,v >retrieving revision 1.4 >diff -u -r1.4 JavaBeanObservableArrayBasedListTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java 11 Nov 2008 16:05:41 -0000 1.4 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,12 +7,11 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bugs 221351, 213145, 244098, 246103 >+ * Matthew Hall - bugs 221351, 213145, 244098, 246103, 194734 > ******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; > >-import java.beans.IntrospectionException; > import java.beans.PropertyChangeEvent; > import java.beans.PropertyChangeListener; > import java.beans.PropertyDescriptor; >@@ -25,14 +24,16 @@ > import junit.framework.Test; > import junit.framework.TestSuite; > >+import org.eclipse.core.databinding.beans.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.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.ListDiffEntry; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableList; >+import org.eclipse.core.databinding.observable.list.ListDiff; > import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; > import org.eclipse.jface.databinding.conformance.util.CurrentRealm; >@@ -46,7 +47,8 @@ > */ > public class JavaBeanObservableArrayBasedListTest extends > AbstractDefaultRealmTestCase { >- private JavaBeanObservableList list; >+ private IObservableList list; >+ private IBeanObservable beanObservable; > > private PropertyDescriptor propertyDescriptor; > >@@ -63,29 +65,37 @@ > super.setUp(); > > propertyName = "array"; >- propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); >+ propertyDescriptor = ((IBeanProperty) BeanProperties.listProperty( >+ Bean.class, propertyName)).getPropertyDescriptor(); > bean = new Bean(new Object[0]); > >- list = new JavaBeanObservableList(SWTObservables.getRealm(Display >- .getDefault()), bean, propertyDescriptor, Bean.class); >+ list = BeansObservables.observeList(SWTObservables.getRealm(Display >+ .getDefault()), bean, propertyName); >+ beanObservable = (IBeanObservable) list; > } > > public void testGetObserved() throws Exception { >- assertSame(bean, list.getObserved()); >+ assertSame(bean, beanObservable.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertSame(propertyDescriptor, list.getPropertyDescriptor()); >+ assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); > } > >- public void testRegistersListenerOnCreation() >+ public void testRegistersListenerAfterFirstListenerIsAdded() > throws Exception { >+ assertFalse(bean.changeSupport.hasListeners(propertyName)); >+ list.addListChangeListener(new ListChangeEventTracker()); > assertTrue(bean.changeSupport.hasListeners(propertyName)); > } > >- public void testRemovesListenerOnDisposal() >+ public void testRemovesListenerAfterLastListenerIsRemoved() > throws Exception { >- list.dispose(); >+ ListChangeEventTracker listener = new ListChangeEventTracker(); >+ list.addListChangeListener(listener); >+ >+ assertTrue(bean.changeSupport.hasListeners(propertyName)); >+ list.removeListChangeListener(listener); > assertFalse(bean.changeSupport.hasListeners(propertyName)); > } > >@@ -120,8 +130,9 @@ > assertEquals(1, listener.count); > ListChangeEvent event = listener.event; > >- assertEquals(list, event.getObservableList()); >- assertEntry(event.diff.getDifferences()[0], true, 0, element); >+ assertSame(list, event.getObservableList()); >+ assertDiff(event.diff, Collections.EMPTY_LIST, Collections >+ .singletonList("1")); > } > > public void testAdd_FiresPropertyChangeEvent() throws Exception { >@@ -150,7 +161,8 @@ > list.add(0, element); > > ListChangeEvent event = listener.event; >- assertEntry(event.diff.getDifferences()[0], true, 0, element); >+ assertDiff(event.diff, Collections.EMPTY_LIST, Collections >+ .singletonList("1")); > } > > public void testAddAtIndexPropertyChangeEvent() throws Exception { >@@ -182,8 +194,10 @@ > > assertEquals(1, listener.count); > ListChangeEvent event = listener.event; >- assertEquals(list, event.getObservableList()); >- assertEntry(event.diff.getDifferences()[0], false, 0, element); >+ assertSame(list, event.getObservableList()); >+ >+ assertDiff(event.diff, Collections.singletonList("1"), >+ Collections.EMPTY_LIST); > } > > public void testRemovePropertyChangeEvent() throws Exception { >@@ -218,8 +232,10 @@ > > assertEquals(1, listener.count); > ListChangeEvent event = listener.event; >- assertEquals(list, event.getObservableList()); >- assertEntry(event.diff.getDifferences()[0], false, 0, element); >+ assertSame(list, event.getObservableList()); >+ >+ assertDiff(event.diff, Collections.singletonList(element), >+ Collections.EMPTY_LIST); > } > > public void testRemoveAtIndexPropertyChangeEvent() throws Exception { >@@ -252,10 +268,10 @@ > > assertEquals(1, listener.count); > ListChangeEvent event = listener.event; >- assertEquals(list, event.getObservableList()); >+ assertSame(list, event.getObservableList()); > >- assertEntry(event.diff.getDifferences()[0], true, 0, elements.get(0)); >- assertEntry(event.diff.getDifferences()[1], true, 1, elements.get(1)); >+ assertDiff(event.diff, Collections.EMPTY_LIST, Arrays >+ .asList(new String[] { "1", "2" })); > } > > public void testAddAllPropertyChangeEvent() throws Exception { >@@ -292,9 +308,10 @@ > > assertEquals(1, listener.count); > ListChangeEvent event = listener.event; >- assertEquals(list, event.getObservableList()); >- assertEntry(event.diff.getDifferences()[0], true, 2, elements.get(0)); >- assertEntry(event.diff.getDifferences()[1], true, 3, elements.get(1)); >+ assertSame(list, event.getObservableList()); >+ >+ assertDiff(event.diff, Arrays.asList(new Object[] { "1", "2" }), Arrays >+ .asList(new Object[] { "1", "2", "1", "2" })); > } > > public void testAddAllAtIndexPropertyChangeEvent() throws Exception { >@@ -306,16 +323,14 @@ > } > > public void testRemoveAll() throws Exception { >- List elements = Arrays.asList(new String[] { "1", "2" }); >- list.addAll(elements); >- list.addAll(elements); >- >+ list.addAll(Arrays.asList(new String[] { "1", "2", "3", "4" })); > assertEquals(4, bean.getArray().length); >- list.removeAll(elements); >+ >+ list.removeAll(Arrays.asList(new String[] { "2", "4" })); > > assertEquals(2, bean.getArray().length); >- assertEquals(elements.get(0), bean.getArray()[0]); >- assertEquals(elements.get(1), bean.getArray()[1]); >+ assertEquals("1", bean.getArray()[0]); >+ assertEquals("3", bean.getArray()[1]); > } > > public void testRemoveAllListChangeEvent() throws Exception { >@@ -330,9 +345,11 @@ > list.removeAll(elements); > > ListChangeEvent event = listener.event; >- assertEquals(list, event.getObservableList()); >- assertEntry(event.diff.getDifferences()[0], false, 0, elements.get(0)); >- assertEntry(event.diff.getDifferences()[1], false, 0, elements.get(1)); >+ assertSame(list, event.getObservableList()); >+ >+ assertDiff(event.diff, Arrays >+ .asList(new Object[] { "1", "2", "1", "2" }), >+ Collections.EMPTY_LIST); > } > > public void testRemoveAllPropertyChangeEvent() throws Exception { >@@ -369,9 +386,11 @@ > > assertEquals(1, listener.count); > ListChangeEvent event = listener.event; >- assertEquals(list, event.getObservableList()); >- assertEntry(event.diff.getDifferences()[0], false, 2, elements.get(2)); >- assertEntry(event.diff.getDifferences()[1], false, 2, elements.get(3)); >+ assertSame(list, event.getObservableList()); >+ >+ assertDiff(event.diff, Arrays >+ .asList(new Object[] { "0", "1", "2", "3" }), Arrays >+ .asList(new Object[] { "0", "1" })); > } > > public void testRetainAllPropertyChangeEvent() throws Exception { >@@ -425,9 +444,10 @@ > > assertEquals(1, listener.count); > ListChangeEvent event = listener.event; >- assertEquals(list, event.getObservableList()); >- assertEntry(event.diff.getDifferences()[0], false, 0, oldElement); >- assertEntry(event.diff.getDifferences()[1], true, 0, newElement); >+ assertSame(list, event.getObservableList()); >+ >+ assertDiff(event.diff, Collections.singletonList(oldElement), >+ Collections.singletonList(newElement)); > } > > public void testSetPropertyChangeEvent() throws Exception { >@@ -473,11 +493,12 @@ > assertEquals(Collections.singletonList("new"), list); > } > >- private static void assertEntry(ListDiffEntry entry, boolean addition, >- int position, Object element) { >- assertEquals("addition", addition, entry.isAddition()); >- assertEquals("position", position, entry.getPosition()); >- assertEquals("element", element, entry.getElement()); >+ 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) { >@@ -492,8 +513,10 @@ > 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())); >+ 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)); > } > >@@ -503,11 +526,6 @@ > > PropertyChangeEvent evt; > >- /* >- * (non-Javadoc) >- * >- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) >- */ > public void propertyChange(PropertyChangeEvent evt) { > count++; > this.evt = evt; >@@ -515,7 +533,8 @@ > } > > public static Test suite() { >- TestSuite suite = new TestSuite(JavaBeanObservableArrayBasedListTest.class.getName()); >+ TestSuite suite = new TestSuite( >+ JavaBeanObservableArrayBasedListTest.class.getName()); > suite.addTestSuite(JavaBeanObservableArrayBasedListTest.class); > suite.addTest(MutableObservableListContractTest.suite(new Delegate())); > return suite; >@@ -525,17 +544,10 @@ > public IObservableCollection createObservableCollection(Realm realm, > int elementCount) { > String propertyName = "array"; >- PropertyDescriptor propertyDescriptor; >- try { >- propertyDescriptor = new PropertyDescriptor(propertyName, >- Bean.class); >- } catch (IntrospectionException e) { >- throw new RuntimeException(e); >- } > Object bean = new Bean(new Object[0]); > >- IObservableList list = new JavaBeanObservableList(realm, bean, >- propertyDescriptor, String.class); >+ IObservableList list = BeansObservables.observeList(realm, bean, >+ propertyName, String.class); > for (int i = 0; i < elementCount; i++) > list.add(createElement(list)); > return list; >Index: src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java,v >retrieving revision 1.4 >diff -u -r1.4 JavaBeanObservableSetTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java 11 Nov 2008 16:05:41 -0000 1.4 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,12 +7,11 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bugs 221351, 213145, 244098, 246103 >+ * Matthew Hall - bugs 221351, 213145, 244098, 246103, 194734 > ******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; > >-import java.beans.IntrospectionException; > import java.beans.PropertyDescriptor; > import java.util.Arrays; > import java.util.Collections; >@@ -22,14 +21,17 @@ > import junit.framework.TestCase; > import junit.framework.TestSuite; > >+import org.eclipse.core.databinding.beans.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.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.ISetChangeListener; > import org.eclipse.core.databinding.observable.set.SetChangeEvent; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableSet; > import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; > import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; >@@ -42,46 +44,49 @@ > * @since 3.3 > */ > public class JavaBeanObservableSetTest extends TestCase { >- private JavaBeanObservableSet observableSet; >+ private IObservableSet observableSet; >+ private IBeanObservable beanObservable; > private Bean bean; > private PropertyDescriptor propertyDescriptor; > private String propertyName; > private SetChangeListener listener; > >- /* >- * (non-Javadoc) >- * >- * @see junit.framework.TestCase#setUp() >- */ > protected void setUp() throws Exception { > bean = new Bean(); > propertyName = "set"; >- propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); >+ propertyDescriptor = ((IBeanProperty) BeanProperties.setProperty( >+ Bean.class, propertyName)).getPropertyDescriptor(); > >- observableSet = new JavaBeanObservableSet(SWTObservables >- .getRealm(Display.getDefault()), bean, propertyDescriptor, >- Bean.class); >+ observableSet = BeansObservables >+ .observeSet(SWTObservables.getRealm(Display.getDefault()), >+ bean, propertyName, Bean.class); >+ beanObservable = (IBeanObservable) observableSet; > listener = new SetChangeListener(); > } > > public void testGetObserved() throws Exception { >- assertEquals(bean, observableSet.getObserved()); >+ assertEquals(bean, beanObservable.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertEquals(propertyDescriptor, observableSet.getPropertyDescriptor()); >+ assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); > } > > public void testGetElementType() throws Exception { > assertEquals(Bean.class, observableSet.getElementType()); > } > >- public void testRegistersListenerOnCreation() throws Exception { >+ public void testRegistersListenerAfterFirstListenerIsAdded() throws Exception { >+ assertFalse(bean.changeSupport.hasListeners(propertyName)); >+ observableSet.addSetChangeListener(new SetChangeListener()); > assertTrue(bean.changeSupport.hasListeners(propertyName)); > } > >- public void testRemovesListenerOnDisposal() throws Exception { >- observableSet.dispose(); >+ public void testRemovesListenerAfterLastListenerIsRemoved() throws Exception { >+ observableSet.addSetChangeListener(listener); >+ >+ assertTrue(bean.changeSupport.hasListeners(propertyName)); >+ observableSet.removeSetChangeListener(listener); > assertFalse(bean.changeSupport.hasListeners(propertyName)); > } > >@@ -94,16 +99,18 @@ > > public void testConstructor_RegisterListeners() throws Exception { > bean = new Bean(); >- new JavaBeanObservableSet(new CurrentRealm(true), bean, >- propertyDescriptor, Bean.class); >+ observableSet = BeansObservables.observeSet(new CurrentRealm(true), bean, >+ propertyName); >+ assertFalse(bean.hasListeners(propertyName)); >+ ChangeEventTracker.observe(observableSet); > assertTrue(bean.hasListeners(propertyName)); > } > > public void testConstructor_SkipsRegisterListeners() throws Exception { > bean = new Bean(); > >- observableSet = new JavaBeanObservableSet(new CurrentRealm(true), bean, >- propertyDescriptor, Bean.class, false); >+ observableSet = PojoObservables.observeSet(new CurrentRealm(true), >+ bean, propertyName); > assertFalse(bean.hasListeners(propertyName)); > ChangeEventTracker.observe(observableSet); > assertFalse(bean.hasListeners(propertyName)); >@@ -151,16 +158,9 @@ > int elementCount) { > Bean bean = new Bean(); > String propertyName = "set"; >- PropertyDescriptor propertyDescriptor; >- try { >- propertyDescriptor = new PropertyDescriptor(propertyName, >- Bean.class); >- } catch (IntrospectionException e) { >- throw new RuntimeException(e); >- } > >- IObservableSet set = new JavaBeanObservableSet(realm, >- bean, propertyDescriptor, String.class); >+ IObservableSet set = BeansObservables.observeSet(realm, bean, >+ propertyName, String.class); > for (int i = 0; i < elementCount; i++) > set.add(createElement(set)); > return set; >Index: src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java,v >retrieving revision 1.3 >diff -u -r1.3 BeanObservableSetDecoratorTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java 8 Sep 2008 20:23:20 -0000 1.3 >+++ src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableSetDecoratorTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bug 246625 >+ * Matthew Hall - bug 246625, 194734 > ******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; >@@ -16,8 +16,9 @@ > > import junit.framework.TestCase; > >+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.core.internal.databinding.beans.JavaBeanObservableSet; > import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.swt.widgets.Display; > >@@ -26,37 +27,30 @@ > */ > public class BeanObservableSetDecoratorTest extends TestCase { > private PropertyDescriptor propertyDescriptor; >- private JavaBeanObservableSet observableSet; >+ private IObservableSet observableSet; > private BeanObservableSetDecorator decorator; > private Bean bean; > >- /* >- * (non-Javadoc) >- * >- * @see junit.framework.TestCase#setUp() >- */ > protected void setUp() throws Exception { > super.setUp(); > > bean = new Bean(); >- propertyDescriptor = new PropertyDescriptor("set", >- Bean.class); >- observableSet = new JavaBeanObservableSet( >- SWTObservables.getRealm(Display.getDefault()), bean, >- propertyDescriptor, String.class); >- decorator = new BeanObservableSetDecorator( >- observableSet, propertyDescriptor); >+ propertyDescriptor = new PropertyDescriptor("set", Bean.class); >+ observableSet = BeansObservables.observeSet(SWTObservables >+ .getRealm(Display.getDefault()), bean, "set"); >+ decorator = new BeanObservableSetDecorator(observableSet, >+ propertyDescriptor); > } > >- public void testGetDelegate() throws Exception { >- assertEquals(observableSet, decorator.getDecorated()); >+ public void testGetDecorated() throws Exception { >+ assertSame(observableSet, decorator.getDecorated()); > } > > public void testGetObserved() throws Exception { >- assertEquals(bean, decorator.getObserved()); >+ assertSame(bean, decorator.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertEquals(propertyDescriptor, decorator.getPropertyDescriptor()); >+ assertSame(propertyDescriptor, decorator.getPropertyDescriptor()); > } > } >Index: src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java,v >retrieving revision 1.3 >diff -u -r1.3 BeanObservableListDecoratorTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java 8 Sep 2008 20:23:20 -0000 1.3 >+++ src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableListDecoratorTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bugs 208858, 213145, 246625 >+ * Matthew Hall - bugs 208858, 213145, 246625, 194734 > ******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; >@@ -18,13 +18,13 @@ > import junit.framework.TestCase; > import junit.framework.TestSuite; > >+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.core.internal.databinding.beans.JavaBeanObservableList; > import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; > import org.eclipse.jface.databinding.swt.SWTObservables; >@@ -36,36 +36,30 @@ > public class BeanObservableListDecoratorTest extends TestCase { > private Bean bean; > private PropertyDescriptor propertyDescriptor; >- private JavaBeanObservableList observableList; >+ private IObservableList observableList; > private BeanObservableListDecorator decorator; > >- /* >- * (non-Javadoc) >- * >- * @see junit.framework.TestCase#setUp() >- */ > protected void setUp() throws Exception { > super.setUp(); > > bean = new Bean(); > propertyDescriptor = new PropertyDescriptor( > "list", Bean.class,"getList","setList"); >- observableList = new JavaBeanObservableList( >- SWTObservables.getRealm(Display.getDefault()), bean, >- propertyDescriptor, Bean.class); >+ observableList = BeansObservables.observeList( >+ SWTObservables.getRealm(Display.getDefault()), bean, "list"); > decorator = new BeanObservableListDecorator(observableList, propertyDescriptor); > } > > public void testGetDelegate() throws Exception { >- assertEquals(observableList, decorator.getDecorated()); >+ assertSame(observableList, decorator.getDecorated()); > } > > public void testGetObserved() throws Exception { >- assertEquals(bean, decorator.getObserved()); >+ assertSame(bean, decorator.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertEquals(propertyDescriptor, decorator.getPropertyDescriptor()); >+ assertSame(propertyDescriptor, decorator.getPropertyDescriptor()); > } > > public static Test suite() { >Index: src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java,v >retrieving revision 1.1 >diff -u -r1.1 SelectionProviderMultiSelectionObservableListTest.java >--- src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java 19 Mar 2008 23:03:19 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderMultiSelectionObservableListTest.java 17 Dec 2008 01:04:07 -0000 >@@ -8,15 +8,21 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Brad Reynolds - bug 116920 >+ * Matthew Hall - bug 194734 > *******************************************************************************/ > package org.eclipse.jface.tests.internal.databinding.viewers; > >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Collections; >+import java.util.List; >+ > import junit.framework.TestCase; > >-import org.eclipse.core.databinding.observable.list.ListDiffEntry; >+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.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.viewers.SelectionProviderMultipleSelectionObservableList; >+import org.eclipse.jface.databinding.viewers.ViewersObservables; > import org.eclipse.jface.viewers.ISelectionProvider; > import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.IStructuredSelection; >@@ -24,7 +30,6 @@ > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.jface.viewers.Viewer; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; > > /** >@@ -37,7 +42,8 @@ > > private TableViewer viewer; > >- private static String[] model = new String[] { "0", "1", "2", "3" }; >+ private static String[] model = new String[] { "element0", "element1", >+ "element2", "element3" }; > > protected void setUp() throws Exception { > Shell shell = new Shell(); >@@ -55,8 +61,7 @@ > > public void testConstructorIllegalArgumentException() { > try { >- new SelectionProviderMultipleSelectionObservableList(SWTObservables >- .getRealm(Display.getDefault()), null, Object.class); >+ ViewersObservables.observeMultiSelection(null); > fail(); > } catch (IllegalArgumentException e) { > } >@@ -70,17 +75,16 @@ > * </ul> > */ > public void testAddRemove() { >- SelectionProviderMultipleSelectionObservableList observable = new SelectionProviderMultipleSelectionObservableList( >- SWTObservables.getRealm(Display.getDefault()), >- selectionProvider, Object.class); >+ IObservableList observable = ViewersObservables >+ .observeMultiSelection(selectionProvider); > ListChangeEventTracker listener = new ListChangeEventTracker(); > observable.addListChangeListener(listener); > assertEquals(0, observable.size()); > > selectionProvider.setSelection(new StructuredSelection(model[0])); > assertEquals(1, listener.count); >- assertEquals(1, listener.event.diff.getDifferences().length); >- assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[0], true); >+ assertDiff(listener.event.diff, Collections.EMPTY_LIST, Collections >+ .singletonList(model[0])); > assertEquals(observable, listener.event.getObservableList()); > assertEquals(1, observable.size()); > assertEquals(model[0], observable.get(0)); >@@ -88,68 +92,67 @@ > selectionProvider.setSelection(new StructuredSelection(model[1])); > assertEquals(2, listener.count); > assertEquals(2, listener.event.diff.getDifferences().length); >- assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[1], true); >- assertDiffEntry(listener.event.diff.getDifferences()[1], 1, model[0], false); >+ 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]})); >+ selectionProvider.setSelection(new StructuredSelection(new Object[] { >+ model[2], model[3] })); > assertEquals(3, listener.count); > assertEquals(3, listener.event.diff.getDifferences().length); >- assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[2], true); >- assertDiffEntry(listener.event.diff.getDifferences()[1], 1, model[3], true); >- assertDiffEntry(listener.event.diff.getDifferences()[2], 2, model[1], false); >+ 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); >- assertDiffEntry(listener.event.diff.getDifferences()[0], 1, model[3], false); >- assertDiffEntry(listener.event.diff.getDifferences()[1], 0, model[2], false); >+ assertDiff(listener.event.diff, Arrays.asList(new Object[] { model[2], >+ model[3] }), Collections.EMPTY_LIST); > assertEquals(observable, listener.event.getObservableList()); > assertEquals(0, observable.size()); >- >+ > observable.add(model[1]); > assertEquals(5, listener.count); > assertEquals(1, listener.event.diff.getDifferences().length); >- assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[1], true); >+ assertDiff(listener.event.diff, Collections.EMPTY_LIST, Collections >+ .singletonList(model[1])); > assertEquals(observable, listener.event.getObservableList()); >- assertEquals(1, ((IStructuredSelection)viewer.getSelection()).size()); >+ assertEquals(1, ((IStructuredSelection) viewer.getSelection()).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 >+ // 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. >- assertDiffEntry(listener.event.diff.getDifferences()[0], 1, model[2], true); >+ assertDiff(listener.event.diff, Collections.singletonList(model[1]), >+ Arrays.asList(new Object[] { model[2], model[1] })); > assertEquals(observable, listener.event.getObservableList()); >- assertEquals(2, ((IStructuredSelection)viewer.getSelection()).size()); >+ assertEquals(2, ((IStructuredSelection) viewer.getSelection()).size()); > > observable.clear(); > assertEquals(7, listener.count); > assertEquals(2, listener.event.diff.getDifferences().length); >- assertDiffEntry(listener.event.diff.getDifferences()[0], 1, model[2], false); >- assertDiffEntry(listener.event.diff.getDifferences()[1], 0, model[1], false); >+ assertDiff(listener.event.diff, Arrays.asList(new Object[] { model[1], >+ model[2] }), Collections.EMPTY_LIST); > assertEquals(observable, listener.event.getObservableList()); >- assertEquals(0, ((IStructuredSelection)viewer.getSelection()).size()); >-} >+ assertEquals(0, ((IStructuredSelection) viewer.getSelection()).size()); >+ } > >- /** >- * @param diffEntry >- * @param position >- * @param element >- * @param isAddition >- */ >- private void assertDiffEntry(ListDiffEntry diffEntry, int position, >- String element, boolean isAddition) { >- assertEquals(isAddition, diffEntry.isAddition()); >- assertEquals(position, diffEntry.getPosition()); >- assertEquals(element, diffEntry.getElement()); >+ 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); > } > > private class ContentProvider implements IStructuredContentProvider { >Index: src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 SelectionProviderSingleSelectionObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java 19 Mar 2008 23:03:19 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/viewers/SelectionProviderSingleSelectionObservableValueTest.java 17 Dec 2008 01:04:07 -0000 >@@ -9,21 +9,21 @@ > * Brad Reynolds - initial API and implementation > * Brad Reynolds - bug 116920 > * Ashley Cambrell - bug 198906 >+ * Matthew Hall - bug 194734 > *******************************************************************************/ > package org.eclipse.jface.tests.internal.databinding.viewers; > > import junit.framework.TestCase; > >+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.viewers.SelectionProviderSingleSelectionObservableValue; >+import org.eclipse.jface.databinding.viewers.ViewersObservables; > import org.eclipse.jface.viewers.ISelectionProvider; > import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.jface.viewers.Viewer; > import org.eclipse.swt.SWT; >-import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; > > /** >@@ -65,8 +65,7 @@ > > public void testConstructorIllegalArgumentException() { > try { >- new SelectionProviderSingleSelectionObservableValue(SWTObservables >- .getRealm(Display.getDefault()), null); >+ ViewersObservables.observeSingleSelection(null); > fail(); > } catch (IllegalArgumentException e) { > } >@@ -80,9 +79,8 @@ > * </ul> > */ > public void testGetSetValue() { >- SelectionProviderSingleSelectionObservableValue observable = new SelectionProviderSingleSelectionObservableValue( >- SWTObservables.getRealm(Display.getDefault()), >- selectionProvider); >+ IObservableValue observable = ViewersObservables >+ .observeSingleSelection(selectionProvider); > ValueChangeEventTracker listener = new ValueChangeEventTracker(); > observable.addValueChangeListener(listener); > assertNull(observable.getValue()); >@@ -110,9 +108,8 @@ > } > > public void testDispose() throws Exception { >- SelectionProviderSingleSelectionObservableValue observable = new SelectionProviderSingleSelectionObservableValue( >- SWTObservables.getRealm(Display.getDefault()), >- selectionProvider); >+ IObservableValue observable = ViewersObservables >+ .observeSingleSelection(selectionProvider); > ValueChangeEventTracker listener = new ValueChangeEventTracker(); > observable.addValueChangeListener(listener); > >Index: src/org/eclipse/jface/tests/databinding/BindingTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/BindingTestSuite.java,v >retrieving revision 1.97 >diff -u -r1.97 BindingTestSuite.java >--- src/org/eclipse/jface/tests/databinding/BindingTestSuite.java 16 Dec 2008 18:13:22 -0000 1.97 >+++ src/org/eclipse/jface/tests/databinding/BindingTestSuite.java 17 Dec 2008 01:04:07 -0000 >@@ -77,6 +77,8 @@ > 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.BeanPropertyListenerSupportTest; >+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; >@@ -84,7 +86,6 @@ > 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.beans.ListenerSupportTest; > 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; >@@ -163,7 +164,6 @@ > 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.SWTDelayedObservableValueDecoratorTest; >-import org.eclipse.jface.tests.internal.databinding.swt.SWTObservableListTest; > 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; >@@ -172,6 +172,9 @@ > 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.StyledTextObservableValueModifyTest; >+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; >@@ -198,7 +201,7 @@ > } > > public BindingTestSuite() { >- >+ > // org.eclipse.core.tests.databinding > addTestSuite(AggregateValidationStatusTest.class); > addTestSuite(BindingTest.class); >@@ -253,19 +256,19 @@ > addTest(ObservableSetTest.suite()); > addTest(UnionSetTest.suite()); > addTest(WritableSetTest.suite()); >- >- //org.eclipse.core.tests.databinding.observable.value >+ >+ // org.eclipse.core.tests.databinding.observable.value > addTestSuite(AbstractObservableValueTest.class); > addTestSuite(AbstractVetoableValueTest.class); > addTestSuite(ComputedValueTest.class); > addTest(DecoratingObservableValueTest.suite()); > addTest(SelectObservableValueTest.suite()); > addTest(WritableValueTest.suite()); >- >- //org.eclipse.core.tests.databinding.validation >+ >+ // org.eclipse.core.tests.databinding.validation > addTestSuite(MultiValidatorTest.class); > addTestSuite(ValidationStatusTest.class); >- >+ > // org.eclipse.core.tests.internal.databinding > addTestSuite(BindingMessagesTest.class); > addTestSuite(BindingStatusTest.class); >@@ -298,11 +301,12 @@ > addTestSuite(StringToNumberParserTest.class); > addTestSuite(StringToShortConverterTest.class); > >- //org.eclipse.core.tests.internal.databinding.internal.beans >+ // org.eclipse.core.tests.internal.databinding.internal.beans > addTest(BeanObservableListDecoratorTest.suite()); > addTestSuite(BeanObservableSetDecoratorTest.class); > addTestSuite(BeanObservableValueDecoratorTest.class); > addTestSuite(BeanObservableListDecoratorTest.class); >+ addTestSuite(BeanValuePropertyTest.class); > addTest(JavaBeanObservableArrayBasedListTest.suite()); > addTest(JavaBeanObservableArrayBasedSetTest.suite()); > addTest(JavaBeanObservableListTest.suite()); >@@ -310,9 +314,9 @@ > addTest(JavaBeanObservableSetTest.suite()); > addTest(JavaBeanObservableValueTest.suite()); > addTestSuite(JavaBeanPropertyObservableMapTest.class); >- addTestSuite(ListenerSupportTest.class); >- >- //org.eclipse.core.tests.internal.databinding.observable >+ addTestSuite(BeanPropertyListenerSupportTest.class); >+ >+ // org.eclipse.core.tests.internal.databinding.observable > addTest(ConstantObservableValueTest.suite()); > addTest(DelayedObservableValueTest.suite()); > addTest(EmptyObservableListTest.suite()); >@@ -325,8 +329,8 @@ > addTest(ValidatedObservableValueTest.suite()); > addTest(ValidatedObservableListTest.suite()); > addTest(ValidatedObservableSetTest.suite()); >-// addTest(ValidatedObservableMapTest.suite()); >- >+ // addTest(ValidatedObservableMapTest.suite()); >+ > // org.eclipse.core.tests.internal.databinding.observable.masterdetail > addTest(DetailObservableListTest.suite()); > addTest(DetailObservableSetTest.suite()); >@@ -353,24 +357,24 @@ > addTest(BindingScenariosTestSuite.suite()); > // The files in this package are in the above test suite > >- //org.eclipse.jface.tests.databinding.swt >+ // org.eclipse.jface.tests.databinding.swt > addTestSuite(SWTObservablesTest.class); >- >+ > // org.eclipse.jface.tests.databinding.viewers > addTestSuite(ObservableListTreeContentProviderTest.class); > addTestSuite(ObservableMapLabelProviderTest.class); > addTestSuite(ObservableSetContentProviderTest.class); > addTestSuite(ObservableSetTreeContentProviderTest.class); > addTestSuite(ViewersObservablesTest.class); >- >+ > // org.eclipse.jface.tests.databinding.wizard > addTestSuite(WizardPageSupportTest.class); >- >- //org.eclipse.jface.tests.example.databinding.mask.internal >+ >+ // org.eclipse.jface.tests.example.databinding.mask.internal > addTestSuite(EditMaskLexerAndTokenTest.class); > addTestSuite(EditMaskParserTest.class); > >- //org.eclipse.jface.tests.internal.databinding.internal.swt >+ // org.eclipse.jface.tests.internal.databinding.internal.swt > addTest(ButtonObservableValueTest.suite()); > addTestSuite(CComboObservableValueTest.class); > addTest(CComboObservableValueSelectionTest.suite()); >@@ -383,31 +387,32 @@ > addTest(ComboObservableValueTextTest.suite()); > addTestSuite(ComboSingleSelectionObservableValueTest.class); > addTest(SWTDelayedObservableValueDecoratorTest.suite()); >- >- addTest(SWTObservableListTest.suite()); >- >+ > addTestSuite(ControlObservableValueTest.class); > addTest(LabelObservableValueTest.suite()); > addTestSuite(ListSingleSelectionObservableValueTest.class); > addTest(ScaleObservableValueMinTest.suite()); > addTest(ScaleObservableValueMaxTest.suite()); > addTest(ScaleObservableValueSelectionTest.suite()); >- >+ > addTest(ShellObservableValueTest.suite()); >- >+ > addTestSuite(SpinnerObservableValueTest.class); > addTest(SpinnerObservableValueMinTest.suite()); > addTest(SpinnerObservableValueMaxTest.suite()); > addTest(SpinnerObservableValueSelectionTest.suite()); >- >+ > addTestSuite(TableObservableValueTest.class); > addTest(TableSingleSelectionObservableValueTest.suite()); > addTest(TextEditableObservableValueTest.suite()); > addTest(TextObservableValueFocusOutTest.suite()); > addTest(TextObservableValueModifyTest.suite()); > addTestSuite(TextObservableValueTest.class); >- >- //org.eclipse.jface.tests.internal.databinding.internal.viewers >+ addTest(StyledTextObservableValueFocusOutTest.suite()); >+ addTest(StyledTextObservableValueModifyTest.suite()); >+ addTestSuite(StyledTextObservableValueTest.class); >+ >+ // org.eclipse.jface.tests.internal.databinding.internal.viewers > addTest(ObservableViewerElementSetTest.suite()); > addTestSuite(ObservableCollectionTreeContentProviderTest.class); > addTestSuite(SelectionProviderMultiSelectionObservableListTest.class); >Index: src/org/eclipse/core/tests/databinding/conversion/StringToNumberConverterTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/conversion/StringToNumberConverterTest.java,v >retrieving revision 1.3 >diff -u -r1.3 StringToNumberConverterTest.java >--- src/org/eclipse/core/tests/databinding/conversion/StringToNumberConverterTest.java 26 Oct 2008 14:34:06 -0000 1.3 >+++ src/org/eclipse/core/tests/databinding/conversion/StringToNumberConverterTest.java 17 Dec 2008 01:04:07 -0000 >@@ -112,7 +112,7 @@ > assertEquals("Non-integer BigDecimal", input, result); > > // Test 2: Long >- input = new BigDecimal((long) (Integer.MAX_VALUE + 100)); >+ input = new BigDecimal(Integer.MAX_VALUE + 100L); > result = (BigDecimal) converter.convert(formatBigDecimal(input)); > assertEquals("Integral BigDecimal in long range", input, result); > >Index: src/org/eclipse/jface/tests/databinding/viewers/ViewersObservablesTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/viewers/ViewersObservablesTest.java,v >retrieving revision 1.2 >diff -u -r1.2 ViewersObservablesTest.java >--- src/org/eclipse/jface/tests/databinding/viewers/ViewersObservablesTest.java 19 Mar 2008 23:03:20 -0000 1.2 >+++ src/org/eclipse/jface/tests/databinding/viewers/ViewersObservablesTest.java 17 Dec 2008 01:04:07 -0000 >@@ -7,15 +7,18 @@ > * > * Contributors: > * Matthew Hall - initial API and implementation (bug 206839) >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.databinding.viewers; > >+import org.eclipse.core.databinding.observable.IDecoratingObservable; > import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.IPropertyObservable; > import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.jface.databinding.viewers.IViewerObservableValue; > import org.eclipse.jface.databinding.viewers.ViewersObservables; >-import org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; >+import org.eclipse.jface.internal.databinding.viewers.ViewerInputProperty; > import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.swt.SWT; >@@ -48,7 +51,11 @@ > } > > public void testObserveInput_InstanceOfViewerInputObservableValue() { >- IObservableValue observable = ViewersObservables.observeInput(viewer); >- assertTrue(observable instanceof ViewerInputObservableValue); >+ IViewerObservableValue observable = (IViewerObservableValue) ViewersObservables >+ .observeInput(viewer); >+ assertTrue(observable.getViewer() == viewer); >+ IPropertyObservable propertyObservable = (IPropertyObservable) ((IDecoratingObservable) observable) >+ .getDecorated(); >+ assertTrue(propertyObservable.getProperty() instanceof ViewerInputProperty); > } > } >Index: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java >=================================================================== >RCS file: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java >diff -N src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueFocusOutTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,80 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Code 9 Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Code 9 Corporation - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 >+ * Matthew Hall - bug 194734 >+ *******************************************************************************/ >+ >+package org.eclipse.jface.tests.internal.databinding.swt; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+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.swt.StyledTextProperties; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Tests for the FocusOut version of StyledTextObservableValue. >+ */ >+public class StyledTextObservableValueFocusOutTest extends TestCase { >+ public static Test suite() { >+ TestSuite suite = new TestSuite( >+ StyledTextObservableValueFocusOutTest.class.toString()); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); >+ return suite; >+ } >+ >+ /* package */static class Delegate extends >+ AbstractObservableValueContractDelegate { >+ private Shell shell; >+ >+ private StyledText text; >+ >+ public void setUp() { >+ shell = new Shell(); >+ text = new StyledText(shell, SWT.NONE); >+ } >+ >+ public void tearDown() { >+ shell.dispose(); >+ } >+ >+ public IObservableValue createObservableValue(Realm realm) { >+ return StyledTextProperties.text(SWT.FocusOut).observeValue(realm, >+ text); >+ } >+ >+ public Object getValueType(IObservableValue observable) { >+ return String.class; >+ } >+ >+ public void change(IObservable observable) { >+ text.setFocus(); >+ >+ IObservableValue observableValue = (IObservableValue) observable; >+ text.setText((String) createValue(observableValue)); >+ >+ text.notifyListeners(SWT.FocusOut, null); >+ } >+ >+ public Object createValue(IObservableValue observable) { >+ String value = (String) observable.getValue(); >+ return value + "a"; >+ } >+ } >+} >Index: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java >=================================================================== >RCS file: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java >diff -N src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,112 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Code 9 Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Code 9 Corporation - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 >+ * Matthew Hall - bug 194734 >+ *******************************************************************************/ >+ >+package org.eclipse.jface.tests.internal.databinding.swt; >+ >+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; >+ >+/** >+ * Tests to assert the inputs of the StyledTextObservableValue constructor. >+ */ >+public class StyledTextObservableValueTest extends AbstractDefaultRealmTestCase { >+ private StyledText text; >+ private ValueChangeEventTracker listener; >+ >+ protected 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. >+ */ >+ public void testConstructorUpdateEventTypes() { >+ try { >+ new StyledTextTextProperty(SWT.NONE); >+ new StyledTextTextProperty(SWT.FocusOut); >+ new StyledTextTextProperty(SWT.Modify); >+ assertTrue(true); >+ } catch (IllegalArgumentException e) { >+ fail(); >+ } >+ >+ try { >+ new StyledTextTextProperty(SWT.Verify); >+ fail(); >+ } catch (IllegalArgumentException e) { >+ assertTrue(true); >+ } >+ } >+ >+ /** >+ * s >+ * >+ * @throws Exception >+ */ >+ 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()); >+ } >+ >+ 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()); >+ } >+} >Index: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java >=================================================================== >RCS file: src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java >diff -N src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/StyledTextObservableValueModifyTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,78 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Code 9 Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Code 9 Corporation - initial API and implementation >+ * Chris Aniszczyk <zx@code9.com> - bug 131435 >+ * Matthew Hall - bug 194734 >+ *******************************************************************************/ >+ >+package org.eclipse.jface.tests.internal.databinding.swt; >+ >+import junit.framework.Test; >+import junit.framework.TestCase; >+import junit.framework.TestSuite; >+ >+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.swt.StyledTextProperties; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * Tests for the Modify version of StyledTextObservableValue. >+ */ >+public class StyledTextObservableValueModifyTest extends TestCase { >+ public static Test suite() { >+ TestSuite suite = new TestSuite( >+ StyledTextObservableValueModifyTest.class.toString()); >+ suite.addTest(SWTMutableObservableValueContractTest >+ .suite(new Delegate())); >+ return suite; >+ } >+ >+ /* package */static class Delegate extends >+ AbstractObservableValueContractDelegate { >+ private Shell shell; >+ >+ private StyledText text; >+ >+ public void setUp() { >+ shell = new Shell(); >+ text = new StyledText(shell, SWT.NONE); >+ } >+ >+ public void tearDown() { >+ shell.dispose(); >+ } >+ >+ public IObservableValue createObservableValue(Realm realm) { >+ return StyledTextProperties.text(SWT.Modify).observeValue(realm, >+ text); >+ } >+ >+ public Object getValueType(IObservableValue observable) { >+ return String.class; >+ } >+ >+ public void change(IObservable observable) { >+ text.setFocus(); >+ >+ IObservableValue observableValue = (IObservableValue) observable; >+ text.setText((String) createValue(observableValue)); >+ } >+ >+ public Object createValue(IObservableValue observable) { >+ String value = (String) observable.getValue(); >+ return value + "a"; >+ } >+ } >+} >#P org.eclipse.jface.tests.databinding.conformance >Index: src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding.conformance/src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java,v >retrieving revision 1.6 >diff -u -r1.6 MutableObservableListContractTest.java >--- src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java 26 Oct 2008 13:06:54 -0000 1.6 >+++ src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java 17 Dec 2008 01:04:10 -0000 >@@ -21,13 +21,12 @@ > import junit.framework.Test; > > import org.eclipse.core.databinding.observable.list.IObservableList; >-import org.eclipse.core.databinding.observable.list.ListDiffEntry; >+import org.eclipse.core.databinding.observable.list.ListDiff; > import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate; > import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; > import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; > import org.eclipse.jface.databinding.conformance.util.SuiteBuilder; > >- > /** > * Mutability tests for IObservableList. > * >@@ -68,22 +67,25 @@ > } > > public void testAdd_ListChangeEvent() throws Exception { >+ final Object element = delegate.createElement(list); > assertListChangeEventFired(new Runnable() { > public void run() { >- list.add(delegate.createElement(list)); >+ list.add(element); > } >- }, "List.add(Object)", list); >+ }, "List.add(Object)", list, Collections.singletonList(element)); > } > > public void testAdd_ListDiffEntry() throws Exception { >- list.add(delegate.createElement(list)); >- final Object element = delegate.createElement(list); >+ Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); > >- assertAddDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.add(element); >+ list.add(element1); > } >- }, "List.add(Object)", list, element, 1); >+ }, "List.add(Object)", list, Arrays.asList(new Object[] { element0, >+ element1 })); > } > > public void testAddAtIndex_ChangeEvent() throws Exception { >@@ -95,11 +97,12 @@ > } > > public void testAddAtIndex_ListChangeEvent() throws Exception { >+ final Object element = delegate.createElement(list); > assertListChangeEventFired(new Runnable() { > public void run() { >- list.add(0, delegate.createElement(list)); >+ list.add(0, element); > } >- }, "List.add(int, Object)", list); >+ }, "List.add(int, Object)", list, Collections.singletonList(element)); > } > > public void testAddAtIndex_ChangeEventFiredAfterElementIsAdded() >@@ -114,44 +117,48 @@ > } > > public void testAddAtIndex_ListDiffEntry() throws Exception { >- list.add(delegate.createElement(list)); >- final Object element = delegate.createElement(list); >+ Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); > >- assertAddDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.add(1, element); >+ list.add(1, element1); > } >- }, "List.add(int, Object)", list, element, 1); >+ }, "List.add(int, Object)", list, Arrays.asList(new Object[] { >+ element0, element1 })); > } > > public void testAddAll_ListChangeEvent() throws Exception { >+ final Object element = delegate.createElement(list); > assertListChangeEventFired(new Runnable() { > public void run() { >- list.addAll(Arrays.asList(new Object[] { delegate >- .createElement(list) })); >+ list.addAll(Collections.singletonList(element)); > } >- }, "List.addAll(Collection", list); >+ }, "List.addAll(Collection", list, Collections.singletonList(element)); > } > > public void testAddAll_ListDiffEntry() throws Exception { > final Object element = delegate.createElement(list); > >- assertAddDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.addAll(Arrays.asList(new Object[] { element })); >+ list.addAll(Collections.singletonList(element)); > } >- }, "List.addAll(Collection)", list, element, 0); >+ }, "List.addAll(Collection)", list, Collections.singletonList(element)); > } > > public void testAddAll_ListDiffEntry2() throws Exception { >- list.add(delegate.createElement(list)); >- final Object element = delegate.createElement(list); >+ final Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); > >- assertAddDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.addAll(Collections.singletonList(element)); >+ list.addAll(Collections.singletonList(element1)); > } >- }, "List.addAll(Collection)", list, element, 1); >+ }, "List.addAll(Collection)", list, Arrays.asList(new Object[] { >+ element0, element1 })); > } > > public void testAddAllAtIndex_ChangeEvent() throws Exception { >@@ -164,12 +171,13 @@ > } > > public void testAddAllAtIndex_ListChangeEvent() throws Exception { >+ final Object element = delegate.createElement(list); > assertListChangeEventFired(new Runnable() { > public void run() { >- list.addAll(0, Arrays.asList(new Object[] { delegate >- .createElement(list) })); >+ list.addAll(0, Collections.singletonList(element)); > } >- }, "List.addAll(int, Collection)", list); >+ }, "List.addAll(int, Collection)", list, Collections >+ .singletonList(element)); > } > > public void testAddAllAtIndex_ChangeEventFiredAfterElementIsAdded() >@@ -184,14 +192,16 @@ > } > > public void testAddAllAtIndex_ListDiffEntry() throws Exception { >- list.add(delegate.createElement(list)); >- final Object element = delegate.createElement(list); >+ Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); > >- assertAddDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.addAll(1, Arrays.asList(new Object[] { element })); >+ list.addAll(1, Collections.singletonList(element1)); > } >- }, "List.addAll(int, Collection)", list, element, 1); >+ }, "List.addAll(int, Collection)", list, Arrays.asList(new Object[] { >+ element0, element1 })); > } > > public void testSet_ChangeEvent() throws Exception { >@@ -205,59 +215,43 @@ > } > > public void testSet_ListChangeEvent() throws Exception { >- list.add(delegate.createElement(list)); >+ final Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); > > assertListChangeEventFired(new Runnable() { > public void run() { >- list.set(0, delegate.createElement(list)); >+ assertSame(element0, list.set(0, element1)); > } >- }, "List.set(int, Object)", list); >+ }, "List.set(int, Object)", list, Arrays >+ .asList(new Object[] { element1 })); > } > > public void testSet_ChangeEventFiredAfterElementIsSet() throws Exception { >- Object element1 = delegate.createElement(list); >+ final Object element1 = delegate.createElement(list); > list.add(element1); > final Object element2 = delegate.createElement(list); > > assertContainsDuringChangeEvent(new Runnable() { > public void run() { >- list.set(0, element2); >+ assertSame(element1, list.set(0, element2)); > } > }, "List.set(int, Object)", list, element2); > } > >- public void testSet_ListDiffEntry() throws Exception { >- list.add(delegate.createElement(list)); >- Object oldElement = delegate.createElement(list); >- list.add(oldElement); >- >- ListChangeEventTracker listener = ListChangeEventTracker.observe(list); >- >- Object newElement = delegate.createElement(list); >- list.set(1, newElement); >- >- ListDiffEntry[] entries = listener.event.diff.getDifferences(); >- assertEquals( >- "List.set(int, Object) should result in 2 list diff entries.", >- 2, entries.length); >- >- ListDiffEntry remove = entries[0]; >- assertFalse(remove.isAddition()); >- assertEquals( >- "List.set(int, Object) removed element should be the old element.", >- oldElement, remove.getElement()); >- assertEquals( >- "List.set(int, Object) removed index should be the index the new element was set at.", >- 1, remove.getPosition()); >+ public void testSet_ListChangeEvent2() throws Exception { >+ Object element0 = delegate.createElement(list); >+ list.add(element0); >+ Object oldElement1 = delegate.createElement(list); >+ list.add(oldElement1); >+ final Object newElement1 = delegate.createElement(list); > >- ListDiffEntry add = entries[1]; >- assertTrue(add.isAddition()); >- assertEquals( >- "List.set(int, Object) added element should be the set element.", >- newElement, add.getElement()); >- assertEquals( >- "List.set(int, Object) add index should be the index the new element was set at.", >- 1, add.getPosition()); >+ assertListChangeEventFired(new Runnable() { >+ public void run() { >+ list.set(1, newElement1); >+ } >+ }, "List.set(int, Object)", list, Arrays.asList(new Object[] { >+ element0, newElement1 })); > } > > public void testMove_ChangeEvent() throws Exception { >@@ -289,16 +283,17 @@ > } > > public void testMove_ListChangeEvent() throws Exception { >- final Object element = delegate.createElement(list); >- list.add(element); >- list.add(delegate.createElement(list)); >+ final Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); >+ list.add(element1); > > assertListChangeEventFired(new Runnable() { > public void run() { >- Object movedElement = list.move(0, 1); >- assertEquals(element, movedElement); >+ assertSame(element0, list.move(0, 1)); > } >- }, "IObservableList.move(int, int)", list); >+ }, "IObservableList.move(int, int)", list, Arrays.asList(new Object[] { >+ element1, element0 })); > } > > public void testMove_ChangeEventFiredAfterElementIsMoved() throws Exception { >@@ -316,42 +311,18 @@ > assertSame(element0, list.get(1)); > } > >- public void testMove_ListDiffEntry() { >- Object element = delegate.createElement(list); >- list.add(element); >- list.add(delegate.createElement(list)); >- >- ListChangeEventTracker listener = ListChangeEventTracker.observe(list); >- >- list.move(0, 1); >- >- ListDiffEntry[] entries = listener.event.diff.getDifferences(); >- assertEquals( >- "List.set(int, Object) should result in 2 list diff entries.", >- 2, entries.length); >- >- ListDiffEntry remove = entries[0]; >- ListDiffEntry add = entries[1]; >- assertFalse( >- "IObservableList.move(int, int) removed element should be first in list diff", >- remove.isAddition()); >- assertTrue( >- "IObservableList.move(int, int) added element should be second in list diff", >- add.isAddition()); >- >- assertEquals( >- "IObservableList.move(int, int) remove entry contains incorrect element", >- element, remove.getElement()); >- assertEquals( >- "IObservableList.move(int, int) add entry contains incorrect element", >- element, add.getElement()); >+ public void testMove_ListChangeEvent2() { >+ Object element0 = delegate.createElement(list); >+ list.add(element0); >+ Object element1 = delegate.createElement(list); >+ list.add(element1); > >- assertEquals( >- "IObservableList.move(int, int) remove entry should be the old element index", >- 0, remove.getPosition()); >- assertEquals( >- "IObservableList.move(int, int) add entry should be the new element index", >- 1, add.getPosition()); >+ assertListChangeEventFired(new Runnable() { >+ public void run() { >+ list.move(0, 1); >+ } >+ }, "IObservableList.move(int, int)", list, Arrays.asList(new Object[] { >+ element1, element0 })); > } > > public void testRemove_ListChangeEvent() throws Exception { >@@ -362,19 +333,20 @@ > public void run() { > list.remove(element); > } >- }, "List.remove(Object)", list); >+ }, "List.remove(Object)", list, Collections.EMPTY_LIST); > } > > public void testRemove_ListDiffEntry() throws Exception { >- list.add(delegate.createElement(list)); >- final Object element = delegate.createElement(list); >- list.add(element); >+ final Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); >+ list.add(element1); > >- assertRemoveDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.remove(element); >+ list.remove(element1); > } >- }, "List.remove(Object)", list, element, 1); >+ }, "List.remove(Object)", list, Collections.singletonList(element0)); > } > > public void testRemoveAtIndex_ChangeEvent() throws Exception { >@@ -394,7 +366,7 @@ > public void run() { > list.remove(0); > } >- }, "List.remove(int)", list); >+ }, "List.remove(int)", list, Collections.EMPTY_LIST); > } > > public void testRemoveAtIndex_ChangeEventFiredAfterElementIsRemoved() >@@ -410,15 +382,16 @@ > } > > public void testRemoveAtIndex_ListDiffEntry() throws Exception { >- list.add(delegate.createElement(list)); >- Object element = delegate.createElement(list); >- list.add(element); >+ Object element0 = delegate.createElement(list); >+ list.add(element0); >+ Object element1 = delegate.createElement(list); >+ list.add(element1); > >- assertRemoveDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { > list.remove(1); > } >- }, "List.remove(int)", list, element, 1); >+ }, "List.remove(int)", list, Collections.singletonList(element0)); > } > > public void testRemoveAll_ListChangeEvent() throws Exception { >@@ -427,57 +400,60 @@ > > assertListChangeEventFired(new Runnable() { > public void run() { >- list.removeAll(Arrays.asList(new Object[] { element })); >+ list.removeAll(Collections.singletonList(element)); > } >- }, "List.removeAll(Collection)", list); >+ }, "List.removeAll(Collection)", list, Collections.EMPTY_LIST); > } > > public void testRemoveAll_ListDiffEntry() throws Exception { > final Object element = delegate.createElement(list); > list.add(element); > >- assertRemoveDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.removeAll(Arrays.asList(new Object[] { element })); >+ list.removeAll(Collections.singletonList(element)); > } >- }, "List.removeAll(Collection)", list, element, 0); >+ }, "List.removeAll(Collection)", list, Collections.EMPTY_LIST); > } > > public void testRemoveAll_ListDiffEntry2() throws Exception { >- list.add(delegate.createElement(list)); >- final Object element = delegate.createElement(list); >- list.add(element); >+ Object element0 = delegate.createElement(list); >+ list.add(element0); >+ final Object element1 = delegate.createElement(list); >+ list.add(element1); > >- assertRemoveDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.removeAll(Arrays.asList(new Object[] { element })); >+ list.removeAll(Arrays.asList(new Object[] { element1 })); > } >- }, "List.removeAll(Collection)", list, element, 1); >+ }, "List.removeAll(Collection)", list, Collections >+ .singletonList(element0)); > } > > public void testRetainAll_ListChangeEvent() throws Exception { >- final Object element1 = delegate.createElement(list); >- list.add(element1); >+ final Object element0 = delegate.createElement(list); >+ list.add(element0); > list.add(delegate.createElement(list)); > > assertListChangeEventFired(new Runnable() { > public void run() { >- list.retainAll(Arrays.asList(new Object[] { element1 })); >+ list.retainAll(Arrays.asList(new Object[] { element0 })); > } >- }, "List.retainAll(Collection", list); >+ }, "List.retainAll(Collection", list, Collections >+ .singletonList(element0)); > } > > public void testRetainAll_ListDiffEntry() throws Exception { >- final Object element1 = delegate.createElement(list); >- list.add(element1); >- Object element2 = delegate.createElement(list); >- list.add(element2); >+ final Object element = delegate.createElement(list); >+ list.add(element); >+ list.add(delegate.createElement(list)); > >- assertRemoveDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { >- list.retainAll(Arrays.asList(new Object[] { element1 })); >+ list.retainAll(Arrays.asList(new Object[] { element })); > } >- }, "List.retainAll(Collection)", list, element2, 1); >+ }, "List.retainAll(Collection)", list, Collections >+ .singletonList(element)); > } > > public void testClear_ListChangeEvent() throws Exception { >@@ -487,18 +463,17 @@ > public void run() { > list.clear(); > } >- }, "List.clear()", list); >+ }, "List.clear()", list, Collections.EMPTY_LIST); > } > > public void testClear_ListDiffEntry() throws Exception { >- Object element = delegate.createElement(list); >- list.add(element); >+ list.add(delegate.createElement(list)); > >- assertRemoveDiffEntry(new Runnable() { >+ assertListChangeEventFired(new Runnable() { > public void run() { > list.clear(); > } >- }, "List.clear()", list, element, 0); >+ }, "List.clear()", list, Collections.EMPTY_LIST); > } > > public void testClear_ClearsList() { >@@ -509,20 +484,10 @@ > Assert.assertEquals(Collections.EMPTY_LIST, list); > } > >- /** >- * Asserts standard behaviors of firing list change events. >- * <ul> >- * <li>Event fires once.</li> >- * <li>Source of the event is the provided <code>list</code>. >- * <li>The list change event is fired after the change event.</li> >- * </ul> >- * >- * @param runnable >- * @param methodName >- * @param list >- */ > private void assertListChangeEventFired(Runnable runnable, >- String methodName, IObservableList list) { >+ String methodName, IObservableList list, List newList) { >+ List oldList = new ArrayList(list); >+ > List queue = new ArrayList(); > ListChangeEventTracker listListener = new ListChangeEventTracker(queue); > ChangeEventTracker changeListener = new ChangeEventTracker(queue); >@@ -546,72 +511,18 @@ > assertEquals("ListChangeEvent of " + methodName > + " should have fired after the ChangeEvent.", listListener, > queue.get(1)); >- } >- >- /** >- * Asserts the list diff entry for a remove operation. >- * >- * @param runnable >- * @param methodName >- * @param list >- * @param element >- * @param index >- */ >- private void assertRemoveDiffEntry(Runnable runnable, String methodName, >- IObservableList list, Object element, int index) { >- ListChangeEventTracker listener = new ListChangeEventTracker(); >- list.addListChangeListener(listener); > >- runnable.run(); >+ assertEquals(formatFail(methodName >+ + " did not leave observable list with the expected contents"), >+ newList, list); > >- ListDiffEntry[] entries = listener.event.diff.getDifferences(); >- assertEquals(methodName + " should result in one diff entry.", 1, >- entries.length); >- >- ListDiffEntry entry = entries[0]; >- assertFalse(methodName >- + " should result in a diff entry that is an removal.", entry >- .isAddition()); >- assertEquals(methodName >- + " remove diff entry should have removed the element.", >- element, entry.getElement()); >+ ListDiff diff = listListener.event.diff; >+ diff.applyTo(oldList); > assertEquals( >- methodName >- + " remove diff entry should have removed the element from the provided index.", >- index, entry.getPosition()); >- } >+ formatFail(methodName >+ + " fired a diff which does not represent the expected list change"), >+ newList, oldList); > >- /** >- * Asserts the list diff entry for an add operation. >- * >- * @param runnable >- * @param methodName >- * @param list >- * @param element >- * @param index >- */ >- private void assertAddDiffEntry(Runnable runnable, String methodName, >- IObservableList list, Object element, int index) { >- ListChangeEventTracker listener = new ListChangeEventTracker(); >- list.addListChangeListener(listener); >- >- runnable.run(); >- >- ListDiffEntry[] entries = listener.event.diff.getDifferences(); >- assertEquals(methodName + " should result in one diff entry.", 1, >- entries.length); >- >- ListDiffEntry entry = entries[0]; >- assertTrue(methodName >- + " should result in a diff entry that is an addition.", entry >- .isAddition()); >- assertEquals(methodName >- + " add diff entry should have added the element.", element, >- entry.getElement()); >- assertEquals( >- methodName >- + "add diff entry should have added the element at the provided index.", >- index, entry.getPosition()); > } > > public static Test suite(IObservableCollectionContractDelegate delegate) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 194734
:
106529
|
107000
|
107001
|
107041
|
107042
|
111164
|
111165
|
111335
|
111336
|
111448
|
111449
|
111640
|
111641
|
111717
|
111719
|
111845
|
111846
|
111897
|
111898
|
111993
|
111994
|
112161
|
112162
|
112268
|
112269
|
112360
|
112361
|
112370
|
112371
|
112471
|
112472
|
112606
|
112607
|
112629
|
112630
|
113149
|
113150
|
113165
|
113166
|
114858
|
114859
|
115196
|
115197
|
115284
|
115458
|
115459
|
117500
|
117501
|
117990
|
117991
|
119231
|
119232
|
119274
|
120541
|
120542
| 120651 |
120652
|
120653
|
120654
|
120914
|
120915
|
120989
|
120990
|
121020
|
121021
|
121141
|
121142
|
122228
|
122229
|
122234
|
122235
|
122288
|
122289
|
122609
|
122610
|
122613
|
122614
|
122775
|
122776
|
122813
|
122814
|
122852
|
122853
|
122864
|
122865
|
123137
|
123138