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 117500 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), 819.51 KB, created by
Matthew Hall
on 2008-11-10 18:24:28 EST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Matthew Hall
Created:
2008-11-10 18:24:28 EST
Size:
819.51 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 17 Oct 2008 16:44:23 -0000 1.5 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,141 +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 >- *******************************************************************************/ >- >-package org.eclipse.core.internal.databinding.beans; >- >-import java.beans.PropertyChangeListener; >-import java.beans.PropertyDescriptor; >-import java.lang.reflect.Method; >- >-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.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() { >- fireMapChange(Diffs.createMapDiffSingleChange( >- event.getSource(), event.getOldValue(), event >- .getNewValue())); >- } >- }); >- } >- } >- }; >- >- private ListenerSupport listenerSupport; >- >- private boolean updating = false; >- >- private boolean attachListeners; >- >- /** >- * @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 hookListener(Object domainElement) { >- if (attachListeners && domainElement != null) { >- listenerSupport.hookListener(domainElement); >- } >- } >- >- protected void unhookListener(Object domainElement) { >- if (attachListeners && domainElement != null) { >- 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); >- propertyDescriptor.getWriteMethod().invoke(key, >- new Object[] { value }); >- keySet().add(key); >- 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 26 Oct 2008 13:06:52 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,253 +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 >- *******************************************************************************/ >- >-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 oldValue = wrappedMap; >- Map newValue = (Map) event.getNewValue(); >- wrappedMap = new HashMap(newValue); >- >- fireMapChange(Diffs.computeMapDiff(oldValue, newValue)); >- } >- }); >- } >- } >- }; >- >- 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 { >- Object result = wrappedMap.put(key, value); >- if (!Util.equals(result, value)) { >- setMap(); >- if (result == null) { >- 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(); >- Object oldValue = wrappedMap.put(key, newValue); >- if (oldValue == null) { >- 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(); >- updating = true; >- try { >- Object result = wrappedMap.remove(key); >- if (result!=null) { >- 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/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/internal/databinding/beans/JavaBeanObservableValue.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableValue.java >diff -N src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableValue.java >--- src/org/eclipse/core/internal/databinding/beans/JavaBeanObservableValue.java 24 Mar 2008 19:13:25 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,190 +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 >- * Brad Reynolds - bug 164134, 171616 >- *******************************************************************************/ >-package org.eclipse.core.internal.databinding.beans; >- >-import java.beans.PropertyChangeListener; >-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.beans.IBeanObservable; >-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.core.databinding.observable.value.ValueDiff; >-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 JavaBeanObservableValue extends AbstractObservableValue implements IBeanObservable { >- private final Object object; >- private boolean updating = false; >- >- private final PropertyDescriptor propertyDescriptor; >- private ListenerSupport listenerSupport; >- >- private boolean attachListeners; >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- */ >- public JavaBeanObservableValue(Realm realm, Object object, >- PropertyDescriptor descriptor) { >- this(realm, object, descriptor, true); >- } >- >- /** >- * @param realm >- * @param object >- * @param descriptor >- * @param attachListeners >- */ >- public JavaBeanObservableValue(Realm realm, Object object, >- PropertyDescriptor descriptor, boolean attachListeners) { >- super(realm); >- this.object = object; >- this.propertyDescriptor = descriptor; >- this.attachListeners = attachListeners; >- } >- >- protected void firstListenerAdded() { >- if (!attachListeners) { >- return; >- } >- >- PropertyChangeListener listener = new PropertyChangeListener() { >- public void propertyChange(java.beans.PropertyChangeEvent event) { >- if (!updating) { >- final ValueDiff diff = Diffs.createValueDiff(event.getOldValue(), >- event.getNewValue()); >- getRealm().exec(new Runnable(){ >- public void run() { >- fireValueChange(diff); >- }}); >- } >- } >- }; >- >- if (listenerSupport == null) { >- listenerSupport = new ListenerSupport(listener, propertyDescriptor.getName()); >- } >- >- listenerSupport.hookListener(object); >- } >- >- public void doSetValue(Object value) { >- updating = true; >- try { >- Object oldValue = doGetValue(); >- >- if (Util.equals(oldValue, value)) { >- return; >- } >- >- Method writeMethod = propertyDescriptor.getWriteMethod(); >- if (!writeMethod.isAccessible()) { >- writeMethod.setAccessible(true); >- } >- writeMethod.invoke(object, new Object[] { value }); >- fireValueChange(Diffs.createValueDiff(oldValue, doGetValue())); >- } 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 " + object + "." + propertyDescriptor.getName(), e)); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- } finally { >- updating = false; >- } >- } >- >- public Object doGetValue() { >- 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(object, 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 " + object + "." + propertyDescriptor.getName(), e)); //$NON-NLS-1$ //$NON-NLS-2$ >- } >- return null; >- } >- } >- >- protected void lastListenerRemoved() { >- unhookListener(); >- } >- >- private void unhookListener() { >- if (listenerSupport != null) { >- listenerSupport.dispose(); >- listenerSupport = null; >- } >- } >- >- public Object getValueType() { >- return propertyDescriptor.getPropertyType(); >- } >- >- public Object getObserved() { >- return object; >- } >- >- public PropertyDescriptor getPropertyDescriptor() { >- return propertyDescriptor; >- } >- >- public synchronized void dispose() { >- unhookListener(); >- 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 10 Nov 2008 23:22:54 -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,18 @@ > 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.PropertyObservables; >+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 +84,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(PropertyObservables >+ .observeValue(realm, bean, property), propertyDescriptor); > } > > /** >@@ -107,9 +107,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(PropertyObservables.observeDetailValues( >+ domain, property), propertyDescriptor); > } > > /** >@@ -153,10 +156,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(PropertyObservables.observeMap( >+ bean, property), propertyDescriptor); > } > > /** >@@ -197,27 +202,6 @@ > 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$ >- } >- > /** > * Returns an array of observable maps in the default realm tracking the > * current values of the named propertys for the beans in the given set. >@@ -303,12 +287,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(PropertyObservables.observeList( >+ realm, bean, property), propertyDescriptor); > } > > /** >@@ -495,10 +479,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, >@@ -569,10 +551,8 @@ > 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 +607,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 +657,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 +700,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 +744,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(PropertyObservables.observeSet( >+ realm, bean, property), propertyDescriptor); > } > > /** >@@ -911,32 +884,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/databinding/beans/PojoObservables.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding.beans/src/org/eclipse/core/databinding/beans/PojoObservables.java,v >retrieving revision 1.9 >diff -u -r1.9 PojoObservables.java >--- src/org/eclipse/core/databinding/beans/PojoObservables.java 24 Oct 2008 21:29:58 -0000 1.9 >+++ src/org/eclipse/core/databinding/beans/PojoObservables.java 10 Nov 2008 23:22:54 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bugs 221704, 234686, 246625, 226289, 246782 >+ * Matthew Hall - bugs 221704, 234686, 246625, 226289, 246782, 194734 > *******************************************************************************/ > > package org.eclipse.core.databinding.beans; >@@ -23,15 +23,16 @@ > 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.PropertyObservables; >+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.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; > > /** > * A factory for creating observable objects for POJOs (plain old java objects) >@@ -73,10 +74,12 @@ > */ > public static IObservableValue observeValue(Realm realm, Object pojo, > String propertyName) { >- >- PropertyDescriptor descriptor = BeansObservables.getPropertyDescriptor( >- pojo.getClass(), propertyName); >- return new JavaBeanObservableValue(realm, pojo, descriptor, false); >+ IValueProperty property = PojoProperties.valueProperty(pojo.getClass(), >+ propertyName); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableValueDecorator(PropertyObservables >+ .observeValue(realm, pojo, property), propertyDescriptor); > } > > /** >@@ -94,9 +97,12 @@ > */ > public static IObservableMap observeMap(IObservableSet domain, > Class pojoClass, String propertyName) { >- PropertyDescriptor descriptor = BeansObservables.getPropertyDescriptor( >- pojoClass, propertyName); >- return new JavaBeanObservableMap(domain, descriptor, false); >+ IValueProperty property = PojoProperties.valueProperty(pojoClass, >+ propertyName); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableMapDecorator(PropertyObservables.observeDetailValues( >+ domain, property), propertyDescriptor); > } > > /** >@@ -161,10 +167,12 @@ > */ > public static IObservableMap observeMap(Realm realm, Object pojo, > String propertyName, Class keyType, Class valueType) { >- PropertyDescriptor descriptor = BeansObservables.getPropertyDescriptor( >- pojo.getClass(), propertyName); >- return new JavaBeanPropertyObservableMap(realm, pojo, descriptor, >- keyType, valueType, false); >+ IMapProperty property = PojoProperties.mapProperty(pojo.getClass(), >+ propertyName, keyType, valueType); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableMapDecorator(PropertyObservables.observeMap( >+ pojo, property), propertyDescriptor); > } > > /** >@@ -270,13 +278,12 @@ > */ > public static IObservableList observeList(Realm realm, Object pojo, > String propertyName, Class elementType) { >- PropertyDescriptor propertyDescriptor = BeansObservables >- .getPropertyDescriptor(pojo.getClass(), propertyName); >- elementType = BeansObservables.getCollectionElementType(elementType, >- propertyDescriptor); >- >- return new JavaBeanObservableList(realm, pojo, propertyDescriptor, >- elementType, false); >+ IListProperty property = PojoProperties.listProperty(pojo.getClass(), >+ propertyName, elementType); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableListDecorator(PropertyObservables.observeList( >+ realm, pojo, property), propertyDescriptor); > } > > /** >@@ -360,13 +367,12 @@ > */ > public static IObservableSet observeSet(Realm realm, Object pojo, > String propertyName, Class elementType) { >- PropertyDescriptor propertyDescriptor = BeansObservables >- .getPropertyDescriptor(pojo.getClass(), propertyName); >- elementType = BeansObservables.getCollectionElementType(elementType, >- propertyDescriptor); >- >- return new JavaBeanObservableSet(realm, pojo, propertyDescriptor, >- elementType, false); >+ ISetProperty property = PojoProperties.setProperty(pojo.getClass(), >+ propertyName, elementType); >+ PropertyDescriptor propertyDescriptor = ((IBeanProperty) property) >+ .getPropertyDescriptor(); >+ return new BeanObservableSetDecorator(PropertyObservables.observeSet( >+ realm, pojo, property), propertyDescriptor); > } > > /** >@@ -594,11 +600,8 @@ > > IObservableValue value = MasterDetailObservables.detailValue(master, > valueFactory(realm, propertyName), propertyType); >- BeanObservableValueDecorator decorator = new BeanObservableValueDecorator( >- value, BeansObservables.getValueTypePropertyDescriptor(master, >- propertyName)); >- >- return decorator; >+ return new BeanObservableValueDecorator(value, BeanPropertyHelper >+ .getValueTypePropertyDescriptor(master, propertyName)); > } > > /** >@@ -645,11 +648,9 @@ > IObservableList observableList = MasterDetailObservables.detailList( > master, listFactory(realm, propertyName, propertyType), > propertyType); >- BeanObservableListDecorator decorator = new BeanObservableListDecorator( >- observableList, BeansObservables >- .getValueTypePropertyDescriptor(master, propertyName)); >- >- return decorator; >+ return new BeanObservableListDecorator(observableList, >+ BeanPropertyHelper.getValueTypePropertyDescriptor(master, >+ propertyName)); > } > > /** >@@ -697,11 +698,8 @@ > IObservableSet observableSet = MasterDetailObservables.detailSet( > master, setFactory(realm, propertyName, propertyType), > propertyType); >- BeanObservableSetDecorator decorator = new BeanObservableSetDecorator( >- observableSet, BeansObservables.getValueTypePropertyDescriptor( >- master, propertyName)); >- >- return decorator; >+ return new BeanObservableSetDecorator(observableSet, BeanPropertyHelper >+ .getValueTypePropertyDescriptor(master, propertyName)); > } > > /** >@@ -740,10 +738,8 @@ > BeansObservables.warnIfDifferentRealms(realm, master.getRealm()); > IObservableMap observableMap = MasterDetailObservables.detailMap( > master, mapPropertyFactory(realm, propertyName)); >- BeanObservableMapDecorator decorator = new BeanObservableMapDecorator( >- observableMap, BeansObservables.getValueTypePropertyDescriptor( >- master, propertyName)); >- return decorator; >+ return new BeanObservableMapDecorator(observableMap, BeanPropertyHelper >+ .getValueTypePropertyDescriptor(master, propertyName)); > } > > /** >Index: src/org/eclipse/core/databinding/beans/IBeanProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/beans/IBeanProperty.java >diff -N src/org/eclipse/core/databinding/beans/IBeanProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/beans/IBeanProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,30 @@ >+/******************************************************************************* >+ * 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.PropertyDescriptor; >+ >+import org.eclipse.core.databinding.property.IProperty; >+ >+/** >+ * Provides access to details of bean properties. >+ * >+ * @since 1.2 >+ */ >+public interface IBeanProperty extends IProperty { >+ /** >+ * Returns the property descriptor of the bean property being observed >+ * >+ * @return the property descriptor of the bean property being observed >+ */ >+ public PropertyDescriptor getPropertyDescriptor(); >+} >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,133 @@ >+/******************************************************************************* >+ * 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.map.SimpleMapProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanMapProperty extends SimpleMapProperty implements IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private boolean attachListener; >+ >+ private ListenerSupport listenerSupport; >+ private final Object keyType; >+ private final Object valueType; >+ >+ /** >+ * @param propertyDescriptor >+ * @param keyType >+ * @param valueType >+ * @param attachListener >+ */ >+ public BeanMapProperty(PropertyDescriptor propertyDescriptor, >+ Object keyType, Object valueType, boolean attachListener) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.keyType = keyType; >+ this.valueType = valueType; >+ this.attachListener = attachListener; >+ } >+ >+ private void initListenerSupport() { >+ if (listenerSupport == null) { >+ synchronized (this) { >+ if (listenerSupport == null) { >+ PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent evt) { >+ Object source = evt.getSource(); >+ if (isUpdating(source)) >+ return; >+ Object oldValue = evt.getOldValue(); >+ Object newValue = evt.getNewValue(); >+ MapDiff diff = null; >+ if (oldValue != null || newValue != null) { >+ diff = Diffs.computeMapDiff(asMap(oldValue), >+ asMap(newValue)); >+ } >+ fireMapChange(source, diff); >+ } >+ }; >+ listenerSupport = new ListenerSupport( >+ propertyChangeListener, propertyDescriptor >+ .getName()); >+ } >+ } >+ } >+ } >+ >+ protected void doAddListenerTo(Object source) { >+ if (source != null && attachListener) { >+ initListenerSupport(); >+ listenerSupport.hookListener(source); >+ } >+ } >+ >+ protected void doRemoveListenerFrom(Object source) { >+ if (source != null && attachListener && listenerSupport != null) { >+ listenerSupport.unhookListener(source); >+ } >+ } >+ >+ protected Map doGetMap(Object source) { >+ if (source == null) >+ return Collections.EMPTY_MAP; >+ Object propertyValue = BeanPropertyHelper.getProperty(source, >+ propertyDescriptor); >+ return asMap(propertyValue); >+ } >+ >+ private Map asMap(Object propertyValue) { >+ if (propertyValue == null) >+ return new HashMap(); >+ return (Map) propertyValue; >+ } >+ >+ protected void doSetMap(Object source, Map map, MapDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.setProperty(source, propertyDescriptor, map); >+ } >+ } >+ >+ public synchronized void dispose() { >+ propertyDescriptor = null; >+ attachListener = false; >+ if (listenerSupport != null) { >+ listenerSupport.dispose(); >+ listenerSupport = null; >+ } >+ super.dispose(); >+ } >+ >+ public PropertyDescriptor getPropertyDescriptor() { >+ return propertyDescriptor; >+ } >+ >+ public Object getKeyType() { >+ return keyType; >+ } >+ >+ public Object getValueType() { >+ return valueType; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/beans/BeanValueProperty.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/beans/BeanValueProperty.java >diff -N src/org/eclipse/core/internal/databinding/beans/BeanValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/beans/BeanValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,118 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.databinding.beans.IBeanProperty; >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.value.SimpleValueProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanValueProperty extends SimpleValueProperty implements >+ IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private Class valueType; >+ private boolean attachListener; >+ >+ private ListenerSupport listenerSupport; >+ >+ /** >+ * @param propertyDescriptor >+ * @param valueType >+ * @param attachListener >+ */ >+ public BeanValueProperty(PropertyDescriptor propertyDescriptor, >+ Class valueType, boolean attachListener) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.valueType = valueType == null ? propertyDescriptor >+ .getPropertyType() : valueType; >+ this.attachListener = attachListener; >+ } >+ >+ private void initListenerSupport() { >+ if (listenerSupport == null) { >+ synchronized (this) { >+ if (listenerSupport == null) { >+ PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent evt) { >+ Object source = evt.getSource(); >+ if (isUpdating(source)) >+ return; >+ Object oldValue = evt.getOldValue(); >+ Object newValue = evt.getNewValue(); >+ ValueDiff diff = null; >+ if (oldValue != null || newValue != null) { >+ diff = Diffs >+ .createValueDiff(oldValue, newValue); >+ } >+ fireValueChange(source, diff); >+ } >+ }; >+ listenerSupport = new ListenerSupport( >+ propertyChangeListener, propertyDescriptor >+ .getName()); >+ } >+ } >+ } >+ } >+ >+ protected void doAddListenerTo(Object source) { >+ if (source != null && attachListener) { >+ initListenerSupport(); >+ listenerSupport.hookListener(source); >+ } >+ } >+ >+ protected void doRemoveListenerFrom(Object source) { >+ if (source != null && attachListener && listenerSupport != null) { >+ listenerSupport.unhookListener(source); >+ } >+ } >+ >+ public Object getValueType() { >+ return valueType; >+ } >+ >+ public Object doGetValue(Object source) { >+ if (source == null) >+ return null; >+ return BeanPropertyHelper.getProperty(source, propertyDescriptor); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.setProperty(source, propertyDescriptor, value); >+ } >+ } >+ >+ public PropertyDescriptor getPropertyDescriptor() { >+ return propertyDescriptor; >+ } >+ >+ public synchronized void dispose() { >+ propertyDescriptor = null; >+ valueType = null; >+ attachListener = false; >+ if (listenerSupport != null) { >+ listenerSupport.dispose(); >+ listenerSupport = null; >+ } >+ super.dispose(); >+ } >+} >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.BeanListProperty; >+import org.eclipse.core.internal.databinding.beans.BeanMapProperty; >+import org.eclipse.core.internal.databinding.beans.BeanPropertyHelper; >+import org.eclipse.core.internal.databinding.beans.BeanSetProperty; >+import org.eclipse.core.internal.databinding.beans.BeanValueProperty; >+ >+/** >+ * 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 BeanValueProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), valueType, false); >+ } >+ >+ /** >+ * 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 BeanSetProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), elementType, false); >+ } >+ >+ /** >+ * 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 BeanListProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), elementType, false); >+ } >+ >+ /** >+ * 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 BeanMapProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), keyType, valueType, false); >+ } >+} >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,150 @@ >+/******************************************************************************* >+ * 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.list.SimpleListProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanListProperty extends SimpleListProperty implements >+ IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private Class elementType; >+ private boolean attachListener; >+ >+ private ListenerSupport listenerSupport; >+ >+ /** >+ * @param propertyDescriptor >+ * @param elementType >+ * @param attachListener >+ */ >+ public BeanListProperty(PropertyDescriptor propertyDescriptor, >+ Class elementType, boolean attachListener) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.elementType = elementType == null ? BeanPropertyHelper >+ .getCollectionPropertyElementType(propertyDescriptor) >+ : elementType; >+ this.attachListener = attachListener; >+ } >+ >+ private void initListenerSupport() { >+ if (listenerSupport == null) { >+ synchronized (this) { >+ if (listenerSupport == null) { >+ PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent evt) { >+ Object source = evt.getSource(); >+ if (isUpdating(source)) >+ return; >+ Object oldValue = evt.getOldValue(); >+ Object newValue = evt.getNewValue(); >+ ListDiff diff = null; >+ if (oldValue != null || newValue != null) { >+ diff = Diffs.computeListDiff(asList(oldValue), >+ asList(newValue)); >+ } >+ if (!isUpdating(source)) { >+ fireListChange(source, diff); >+ } >+ } >+ }; >+ listenerSupport = new ListenerSupport( >+ propertyChangeListener, propertyDescriptor >+ .getName()); >+ } >+ } >+ } >+ } >+ >+ protected void doAddListenerTo(Object source) { >+ if (source != null && attachListener) { >+ initListenerSupport(); >+ listenerSupport.hookListener(source); >+ } >+ } >+ >+ protected void doRemoveListenerFrom(Object source) { >+ if (source != null && attachListener && listenerSupport != null) { >+ listenerSupport.unhookListener(source); >+ } >+ } >+ >+ public Object getElementType() { >+ return elementType; >+ } >+ >+ protected List doGetList(Object source) { >+ if (source == null) >+ return Collections.EMPTY_LIST; >+ Object propertyValue = BeanPropertyHelper.getProperty(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 doSetList(Object source, List list, ListDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.setProperty(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 synchronized void dispose() { >+ propertyDescriptor = null; >+ elementType = null; >+ attachListener = false; >+ if (listenerSupport != null) { >+ listenerSupport.dispose(); >+ listenerSupport = null; >+ } >+ super.dispose(); >+ } >+} >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.set.SimpleSetProperty; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanSetProperty extends SimpleSetProperty implements IBeanProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private Class elementType; >+ private boolean attachListener; >+ >+ private ListenerSupport listenerSupport; >+ >+ /** >+ * @param propertyDescriptor >+ * @param elementType >+ * @param attachListener >+ */ >+ public BeanSetProperty(PropertyDescriptor propertyDescriptor, >+ Class elementType, boolean attachListener) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.elementType = elementType == null ? BeanPropertyHelper >+ .getCollectionPropertyElementType(propertyDescriptor) >+ : elementType; >+ this.attachListener = attachListener; >+ } >+ >+ private void initListenerSupport() { >+ if (listenerSupport == null) { >+ synchronized (this) { >+ if (listenerSupport == null) { >+ PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent evt) { >+ Object source = evt.getSource(); >+ if (isUpdating(source)) >+ return; >+ Object oldValue = evt.getOldValue(); >+ Object newValue = evt.getNewValue(); >+ SetDiff diff = null; >+ if (oldValue != null || newValue != null) { >+ diff = Diffs.computeSetDiff(asSet(oldValue), >+ asSet(newValue)); >+ } >+ fireSetChange(source, diff); >+ } >+ }; >+ listenerSupport = new ListenerSupport( >+ propertyChangeListener, propertyDescriptor >+ .getName()); >+ } >+ } >+ } >+ } >+ >+ protected void doAddListenerTo(Object source) { >+ if (source != null && attachListener) { >+ initListenerSupport(); >+ listenerSupport.hookListener(source); >+ } >+ } >+ >+ protected void doRemoveListenerFrom(Object source) { >+ if (source != null && attachListener && listenerSupport != null) { >+ listenerSupport.unhookListener(source); >+ } >+ } >+ >+ public Object getElementType() { >+ return elementType; >+ } >+ >+ public Set doGetSet(Object source) { >+ if (source == null) >+ return Collections.EMPTY_SET; >+ Object propertyValue = BeanPropertyHelper.getProperty(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 doSetSet(Object source, Set set, SetDiff diff) { >+ if (source != null) { >+ BeanPropertyHelper.setProperty(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 synchronized void dispose() { >+ propertyDescriptor = null; >+ elementType = null; >+ attachListener = false; >+ if (listenerSupport != null) { >+ listenerSupport.dispose(); >+ listenerSupport = null; >+ } >+ super.dispose(); >+ } >+} >Index: src/org/eclipse/core/databinding/beans/BeanProperties.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/beans/BeanProperties.java >diff -N src/org/eclipse/core/databinding/beans/BeanProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/beans/BeanProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,156 @@ >+/******************************************************************************* >+ * 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 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.BeanListProperty; >+import org.eclipse.core.internal.databinding.beans.BeanMapProperty; >+import org.eclipse.core.internal.databinding.beans.BeanPropertyHelper; >+import org.eclipse.core.internal.databinding.beans.BeanSetProperty; >+import org.eclipse.core.internal.databinding.beans.BeanValueProperty; >+ >+/** >+ * A factory for creating properties for Java objects that conform to the <a >+ * href="http://java.sun.com/products/javabeans/docs/spec.html">JavaBean >+ * specification</a> for bound properties. >+ * >+ * @since 1.2 >+ */ >+public class BeanProperties { >+ /** >+ * 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 BeanValueProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), valueType, true); >+ } >+ >+ /** >+ * 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 BeanSetProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), elementType, true); >+ } >+ >+ /** >+ * 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 BeanListProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), elementType, true); >+ } >+ >+ /** >+ * Returns a map property for the given property name of the given bean >+ * class. >+ * >+ * @param beanClass >+ * the bean class >+ * @param propertyName >+ * the property name >+ * @param keyType >+ * the key type for the returned map property >+ * @param valueType >+ * the value type for the returned map property >+ * @return a map property for the given property name of the given bean >+ * class. >+ */ >+ public static IMapProperty mapProperty(Class beanClass, >+ String propertyName, Object keyType, Object valueType) { >+ return new BeanMapProperty(BeanPropertyHelper.getPropertyDescriptor( >+ beanClass, propertyName), keyType, valueType, true); >+ } >+} >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 setProperty(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 getProperty(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.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 10 Nov 2008 23:22:59 -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/ScaleObservableValueMaxTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMaxTest.java,v >retrieving revision 1.2 >diff -u -r1.2 ScaleObservableValueMaxTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMaxTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueMaxTest.java 10 Nov 2008 23:23:00 -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; >@@ -18,12 +18,12 @@ > 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.property.PropertyObservables; > 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.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; >@@ -96,7 +96,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ScaleObservableValue(realm, scale, SWTProperties.MAX); >+ return PropertyObservables.observeValue(realm, scale, >+ ScaleProperties.maximum()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/TableSingleSelectionObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableSingleSelectionObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 TableSingleSelectionObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/TableSingleSelectionObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/TableSingleSelectionObservableValueTest.java 10 Nov 2008 23:23:01 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bugs 118516, 213145 >+ * Matthew Hall - bugs 118516, 213145, 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -18,12 +18,13 @@ > 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.property.PropertyObservables; > import org.eclipse.core.runtime.Assert; > 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.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; >+import org.eclipse.jface.databinding.swt.TableProperties; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; >@@ -104,7 +105,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new TableSingleSelectionObservableValue(realm, table); >+ return PropertyObservables.observeValue(realm, table, >+ TableProperties.singleSelectionIndex()); > } > > public Object getValueType(IObservableValue 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 10 Nov 2008 23:23:00 -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; >@@ -19,10 +19,11 @@ > 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.property.PropertyObservables; > 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; >@@ -87,7 +88,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new CLabelObservableValue(realm, label); >+ return PropertyObservables.observeValue(realm, label, >+ CLabelProperties.text()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 SpinnerObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueTest.java 10 Nov 2008 23:23:01 -0000 >@@ -8,13 +8,14 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Ashley Cambrell - bug 198904 >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; > > import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >-import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >+import org.eclipse.jface.databinding.swt.ISWTObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Spinner; >@@ -26,8 +27,7 @@ > public class SpinnerObservableValueTest extends AbstractSWTTestCase { > public void testDispose() throws Exception { > Spinner spinner = new Spinner(getShell(), SWT.NONE); >- SpinnerObservableValue observableValue = new SpinnerObservableValue( >- spinner, SWTProperties.SELECTION); >+ ISWTObservableValue observableValue = SWTObservables.observeSelection(spinner); > ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); > observableValue.addValueChangeListener(testCounterValueChangeListener); > >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueSelectionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueSelectionTest.java,v >retrieving revision 1.2 >diff -u -r1.2 ScaleObservableValueSelectionTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueSelectionTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ScaleObservableValueSelectionTest.java 10 Nov 2008 23:23:00 -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; >@@ -18,12 +18,12 @@ > 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.property.PropertyObservables; > 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.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; >@@ -56,7 +56,8 @@ > } > > protected IObservable doCreateObservable() { >- return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); >+ return getObservableContractDelegate().createObservable( >+ SWTObservables.getRealm(Display.getDefault())); > } > > public void testGetValue() throws Exception { >@@ -97,7 +98,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ScaleObservableValue(realm, scale, SWTProperties.SELECTION); >+ return PropertyObservables.observeValue(realm, scale, >+ ScaleProperties.selection()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/SWTObservableListTest.java >=================================================================== >RCS file: src/org/eclipse/jface/tests/internal/databinding/swt/SWTObservableListTest.java >diff -N src/org/eclipse/jface/tests/internal/databinding/swt/SWTObservableListTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/SWTObservableListTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,115 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007 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 208858) >- * Matthew Hall - bug 213145 >- ******************************************************************************/ >- >-package org.eclipse.jface.tests.internal.databinding.swt; >- >-import junit.framework.Test; >-import junit.framework.TestSuite; >- >-import org.eclipse.core.databinding.observable.IObservable; >-import org.eclipse.core.databinding.observable.IObservableCollection; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest; >-import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; >-import org.eclipse.jface.internal.databinding.swt.SWTObservableList; >-import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; >- >-/** >- * @since 3.3 >- */ >-public class SWTObservableListTest extends AbstractDefaultRealmTestCase { >- SWTObservableListStub list; >- >- protected void setUp() throws Exception { >- super.setUp(); >- list = new SWTObservableListStub(Realm.getDefault(), 0); >- } >- >- public void testMove_ForwardAndBackward() { >- String element0 = "element0"; >- String element1 = "element1"; >- >- list.add(element0); >- list.add(element1); >- >- // move forward >- assertEquals(element0, list.move(0, 1)); >- assertEquals(element1, list.move(0, 1)); >- >- // move backward >- assertEquals(element1, list.move(1, 0)); >- assertEquals(element0, list.move(1, 0)); >- } >- >- public static Test suite() { >- TestSuite suite = new TestSuite(SWTObservableListTest.class.toString()); >- suite.addTestSuite(SWTObservableListTest.class); >- suite.addTest(MutableObservableListContractTest.suite(new Delegate())); >- return suite; >- } >- >- static class Delegate extends AbstractObservableCollectionContractDelegate { >- public IObservableCollection createObservableCollection(Realm realm, >- int elementCount) { >- return new SWTObservableListStub(realm, elementCount); >- } >- >- private int counter; >- >- public Object createElement(IObservableCollection collection) { >- return "Item" + counter++; >- } >- >- public Object getElementType(IObservableCollection collection) { >- return String.class; >- } >- >- public void change(IObservable observable) { >- ((SWTObservableListStub) observable).fireChange(); >- } >- } >- >- static class SWTObservableListStub extends SWTObservableList { >- String[] items; >- >- public SWTObservableListStub(Realm realm, int elementCount) { >- super(realm); >- items = new String[elementCount]; >- for (int i = 0; i < items.length; i++) >- items[i] = Integer.toString(i); >- } >- >- protected String getItem(int index) { >- return items[index]; >- } >- >- protected int getItemCount() { >- return items.length; >- } >- >- protected String[] getItems() { >- return items; >- } >- >- protected void setItem(int index, String string) { >- items[index] = string; >- } >- >- protected void setItems(String[] newItems) { >- items = newItems; >- } >- >- protected void fireChange() { >- super.fireChange(); >- } >- } >-} >Index: src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 TableObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/TableObservableValueTest.java 10 Nov 2008 23:23:01 -0000 >@@ -8,11 +8,13 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Ashley Cambrell - bug 198904 >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; > >-import org.eclipse.jface.internal.databinding.swt.TableSingleSelectionObservableValue; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Table; >@@ -24,8 +26,8 @@ > public class TableObservableValueTest extends AbstractSWTTestCase { > public void testDispose() throws Exception { > Table table = new Table(getShell(), SWT.NONE); >- TableSingleSelectionObservableValue observableValue = new TableSingleSelectionObservableValue( >- table); >+ IObservableValue observableValue = SWTObservables >+ .observeSingleSelectionIndex(table); > > TableItem item1 = new TableItem(table, SWT.NONE); > item1.setText("Item1"); >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 10 Nov 2008 23:23:01 -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; >@@ -19,9 +19,10 @@ > 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.property.PropertyObservables; > 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; >@@ -52,7 +53,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new TextObservableValue(realm, text, SWT.FocusOut); >+ return PropertyObservables.observeValue(realm, text, TextProperties >+ .text(SWT.FocusOut)); > } > > public Object getValueType(IObservableValue observable) { >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 10 Nov 2008 23:23:01 -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; >@@ -18,10 +18,11 @@ > 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.property.PropertyObservables; > 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; >@@ -97,7 +98,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new TextEditableObservableValue(realm, text); >+ return PropertyObservables.observeValue(realm, text, TextProperties >+ .editable()); > } > > public Object getValueType(IObservableValue observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ControlObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ControlObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 ControlObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ControlObservableValueTest.java 19 Mar 2008 23:03:18 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ControlObservableValueTest.java 10 Nov 2008 23:23:00 -0000 >@@ -8,12 +8,13 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Brad Reynolds - bug 170848 >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; > >-import org.eclipse.jface.internal.databinding.swt.ControlObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >+import org.eclipse.jface.databinding.swt.ISWTObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.resource.JFaceResources; > import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; > import org.eclipse.swt.SWT; >@@ -47,49 +48,43 @@ > } > > public void testSetValueEnabled() throws Exception { >- ControlObservableValue observableValue = new ControlObservableValue( >- shell, SWTProperties.ENABLED); >+ ISWTObservableValue observableValue = SWTObservables >+ .observeEnabled(shell); > Boolean value = Boolean.FALSE; > observableValue.setValue(value); > assertFalse(shell.isEnabled()); > } > > public void testGetValueEnabled() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.ENABLED); >+ ISWTObservableValue value = SWTObservables.observeEnabled(shell); > shell.setEnabled(false); > assertEquals(Boolean.FALSE, value.getValue()); > } > > public void testGetValueTypeEnabled() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.ENABLED); >+ ISWTObservableValue value = SWTObservables.observeEnabled(shell); > assertEquals(boolean.class, value.getValueType()); > } > > public void testSetValueVisible() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.VISIBLE); >+ ISWTObservableValue value = SWTObservables.observeVisible(shell); > value.setValue(Boolean.FALSE); > assertFalse(shell.isVisible()); > } > > public void testGetValueVisible() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.VISIBLE); >+ ISWTObservableValue value = SWTObservables.observeVisible(shell); > shell.setVisible(false); > assertEquals(Boolean.FALSE, value.getValue()); > } > > public void testGetValueTypeVisible() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.VISIBLE); >+ ISWTObservableValue value = SWTObservables.observeVisible(shell); > assertEquals(Boolean.TYPE, value.getValueType()); > } > > public void testSetValueForeground() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.FOREGROUND); >+ ISWTObservableValue value = SWTObservables.observeForeground(shell); > > Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); > >@@ -98,8 +93,7 @@ > } > > public void testGetValueForeground() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.FOREGROUND); >+ ISWTObservableValue value = SWTObservables.observeForeground(shell); > > Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); > shell.setForeground(color); >@@ -107,14 +101,12 @@ > } > > public void testGetValueTypeForgroundColor() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.FOREGROUND); >+ ISWTObservableValue value = SWTObservables.observeForeground(shell); > assertEquals(Color.class, value.getValueType()); > } > > public void testGetValueBackground() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.BACKGROUND); >+ ISWTObservableValue value = SWTObservables.observeBackground(shell); > > Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); > shell.setBackground(color); >@@ -122,8 +114,7 @@ > } > > public void testSetValueBackground() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.BACKGROUND); >+ ISWTObservableValue value = SWTObservables.observeBackground(shell); > > Color color = shell.getDisplay().getSystemColor(SWT.COLOR_BLACK); > >@@ -132,20 +123,17 @@ > } > > public void testGetValueTypeBackgroundColor() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.BACKGROUND); >+ ISWTObservableValue value = SWTObservables.observeBackground(shell); > assertEquals(Color.class, value.getValueType()); > } > > public void testGetValueTypeTooltip() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.TOOLTIP_TEXT); >+ ISWTObservableValue value = SWTObservables.observeTooltipText(shell); > assertEquals(String.class, value.getValueType()); > } > > public void testSetValueFont() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.FONT); >+ ISWTObservableValue value = SWTObservables.observeFont(shell); > > Font font = JFaceResources.getDialogFont(); > >@@ -154,8 +142,7 @@ > } > > public void testGetValueFont() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.FONT); >+ ISWTObservableValue value = SWTObservables.observeFont(shell); > > Font font = JFaceResources.getDialogFont(); > shell.setFont(font); >@@ -163,30 +150,26 @@ > } > > public void testGetValueTypeFont() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.FONT); >+ ISWTObservableValue value = SWTObservables.observeFont(shell); > assertEquals(Font.class, value.getValueType()); > } > > public void testSetValueTooltipText() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.TOOLTIP_TEXT); >+ ISWTObservableValue value = SWTObservables.observeTooltipText(shell); > String text = "text"; > value.setValue(text); > assertEquals(text, shell.getToolTipText()); > } > > public void testGetValueTooltipText() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.TOOLTIP_TEXT); >+ ISWTObservableValue value = SWTObservables.observeTooltipText(shell); > String text = "text"; > shell.setToolTipText(text); > assertEquals(text, value.getValue()); > } > > public void testGetValueTypeTooltipText() throws Exception { >- ControlObservableValue value = new ControlObservableValue(shell, >- SWTProperties.TOOLTIP_TEXT); >+ ISWTObservableValue value = SWTObservables.observeTooltipText(shell); > assertEquals(String.class, value.getValueType()); > } > } >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 10 Nov 2008 23:23:00 -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; >@@ -18,11 +18,12 @@ > 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.property.PropertyObservables; > 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; >@@ -53,20 +54,21 @@ > } > > 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 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); >@@ -90,7 +92,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new LabelObservableValue(realm, label); >+ return PropertyObservables.observeValue(realm, label, >+ LabelProperties.text()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueTest.java,v >retrieving revision 1.2 >diff -u -r1.2 TextObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueTest.java 10 Nov 2008 23:23:01 -0000 >@@ -10,12 +10,15 @@ > * Brad Reynolds - bug 116920 > * Brad Reynolds - bug 164653 > * Ashley Cambrell - bug 198904 >+ * Matthew Hall - bug 194734 > *******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; > >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.PropertyObservables; > import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; >-import org.eclipse.jface.internal.databinding.swt.TextObservableValue; >+import org.eclipse.jface.databinding.swt.TextProperties; > import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Shell; >@@ -45,16 +48,16 @@ > */ > public void testConstructorUpdateEventTypes() { > try { >- new TextObservableValue(text, SWT.NONE); >- new TextObservableValue(text, SWT.FocusOut); >- new TextObservableValue(text, SWT.Modify); >+ TextProperties.text(SWT.None); >+ TextProperties.text(SWT.FocusOut); >+ TextProperties.text(SWT.Modify); > assertTrue(true); > } catch (IllegalArgumentException e) { > fail(); > } > > try { >- new TextObservableValue(text, SWT.Verify); >+ TextProperties.text(SWT.Verify); > fail(); > } catch (IllegalArgumentException e) { > assertTrue(true); >@@ -67,26 +70,35 @@ > * @throws Exception > */ > public void testGetValueBeforeFocusOutChangeEventsFire() throws Exception { >- TextObservableValue observableValue = new TextObservableValue(text, SWT.FocusOut); >+ IObservableValue observableValue = PropertyObservables.observeValue( >+ text, TextProperties.text(SWT.FocusOut)); > observableValue.addValueChangeListener(listener); > > String a = "a"; > String b = "b"; > > text.setText(a); >- assertEquals(a, observableValue.getValue()); //fetch the value updating the buffered value >- >+ >+ assertEquals(0, listener.count); >+ >+ // fetching the value updates the buffered value >+ assertEquals(a, observableValue.getValue()); >+ assertEquals(1, listener.count); >+ > text.setText(b); >+ >+ assertEquals(1, listener.count); >+ > text.notifyListeners(SWT.FocusOut, null); > >- assertEquals(1, listener.count); >+ assertEquals(2, listener.count); > assertEquals(a, listener.event.diff.getOldValue()); > assertEquals(b, listener.event.diff.getNewValue()); > } > > public void testDispose() throws Exception { >- TextObservableValue observableValue = new TextObservableValue(text, >- SWT.Modify); >+ IObservableValue observableValue = PropertyObservables.observeValue( >+ text, TextProperties.text(SWT.Modify)); > ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); > observableValue.addValueChangeListener(testCounterValueChangeListener); > >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 10 Nov 2008 23:23:00 -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; >@@ -19,10 +19,11 @@ > 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.property.PropertyObservables; > 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; >@@ -34,8 +35,8 @@ > 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"); > >@@ -75,13 +76,13 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new CComboSingleSelectionObservableValue(realm, combo); >+ return PropertyObservables.observeValue(realm, combo, >+ CComboProperties.singleSelectionIndex()); > } > > 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) { >@@ -93,7 +94,6 @@ > } > > 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 >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 10 Nov 2008 23:23:00 -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/SpinnerObservableValueMinTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMinTest.java,v >retrieving revision 1.2 >diff -u -r1.2 SpinnerObservableValueMinTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMinTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMinTest.java 10 Nov 2008 23:23:01 -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; >@@ -18,12 +18,12 @@ > 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.property.PropertyObservables; > 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.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >-import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >+import org.eclipse.jface.databinding.swt.SpinnerProperties; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; >@@ -56,7 +56,8 @@ > } > > protected IObservable doCreateObservable() { >- return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); >+ return getObservableContractDelegate().createObservable( >+ SWTObservables.getRealm(Display.getDefault())); > } > > public void testGetValue() throws Exception { >@@ -95,7 +96,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new SpinnerObservableValue(realm, spinner, SWTProperties.MIN); >+ return PropertyObservables.observeValue(realm, spinner, >+ SpinnerProperties.minimum()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMaxTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMaxTest.java,v >retrieving revision 1.2 >diff -u -r1.2 SpinnerObservableValueMaxTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMaxTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueMaxTest.java 10 Nov 2008 23:23:00 -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; >@@ -18,12 +18,12 @@ > 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.property.PropertyObservables; > 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.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >-import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >+import org.eclipse.jface.databinding.swt.SpinnerProperties; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; >@@ -56,7 +56,8 @@ > } > > protected IObservable doCreateObservable() { >- return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); >+ return getObservableContractDelegate().createObservable( >+ SWTObservables.getRealm(Display.getDefault())); > } > > public void testGetValue() throws Exception { >@@ -95,7 +96,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new SpinnerObservableValue(realm, spinner, SWTProperties.MAX); >+ return PropertyObservables.observeValue(realm, spinner, >+ SpinnerProperties.maximum()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ButtonObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ButtonObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 ButtonObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ButtonObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ButtonObservableValueTest.java 10 Nov 2008 23:22:59 -0000 >@@ -8,7 +8,7 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Ashley Cambrell - bug 198904 >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -19,10 +19,13 @@ > 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.property.PropertyObservables; > 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.internal.databinding.swt.ButtonObservableValue; >+import org.eclipse.jface.databinding.swt.ButtonProperties; >+import org.eclipse.jface.databinding.swt.ISWTObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Button; >@@ -33,19 +36,15 @@ > */ > public class ButtonObservableValueTest extends AbstractSWTTestCase { > private Button button; >- private ButtonObservableValue observableValue; >+ private ISWTObservableValue observableValue; > private ValueChangeEventTracker listener; > >- /* (non-Javadoc) >- * @see junit.framework.TestCase#setUp() >- */ > protected void setUp() throws Exception { > super.setUp(); > > Shell shell = getShell(); > button = new Button(shell, SWT.CHECK); >- observableValue = new ButtonObservableValue( >- button); >+ observableValue = SWTObservables.observeSelection(button); > listener = new ValueChangeEventTracker(); > } > >@@ -130,7 +129,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ButtonObservableValue(realm, button); >+ return PropertyObservables.observeValue(realm, button, >+ ButtonProperties.selection()); > } > > public Object getValueType(IObservableValue observable) { >@@ -138,8 +138,8 @@ > } > > public void change(IObservable observable) { >- button.setSelection(changeValue(button)); >- button.notifyListeners(SWT.Selection, null); >+ ((IObservableValue) observable).setValue(Boolean >+ .valueOf(changeValue(button))); > } > > public Object createValue(IObservableValue observable) { >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 10 Nov 2008 23:23:00 -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; >@@ -18,12 +18,12 @@ > 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.property.PropertyObservables; > 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.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; >@@ -95,7 +95,7 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ScaleObservableValue(realm, scale, SWTProperties.MIN); >+ return PropertyObservables.observeValue(realm, scale, ScaleProperties.minimum()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 ListSingleSelectionObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ListSingleSelectionObservableValueTest.java 10 Nov 2008 23:23:00 -0000 >@@ -7,11 +7,13 @@ > * > * Contributors: > * Ashley Cambrell - initial API and implementation >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; > >-import org.eclipse.jface.internal.databinding.swt.ListSingleSelectionObservableValue; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.List; >@@ -23,8 +25,8 @@ > public class ListSingleSelectionObservableValueTest extends AbstractSWTTestCase { > public void testSetValue() throws Exception { > List list = new List(getShell(), SWT.NONE); >- ListSingleSelectionObservableValue observableValue = new ListSingleSelectionObservableValue( >- list); >+ IObservableValue observableValue = SWTObservables >+ .observeSingleSelectionIndex(list); > list.add("Item1"); > > assertEquals(-1, list.getSelectionIndex()); >@@ -39,8 +41,8 @@ > > public void testDispose() throws Exception { > List list = new List(getShell(), SWT.NONE); >- ListSingleSelectionObservableValue observableValue = new ListSingleSelectionObservableValue( >- list); >+ IObservableValue observableValue = SWTObservables >+ .observeSingleSelectionIndex(list); > list.add("Item1"); > list.add("Item2"); > >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 ShellObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ShellObservableValueTest.java 10 Nov 2008 23:23:00 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Matthew Hall - initial API and implementation (bug 212235) >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; >@@ -18,10 +18,12 @@ > 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.property.PropertyObservables; > 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.internal.databinding.swt.ShellObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.jface.databinding.swt.ShellProperties; > import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; > import org.eclipse.swt.widgets.Shell; > >@@ -34,13 +36,13 @@ > String oldValue; > String newValue; > Shell shell; >- ShellObservableValue observable; >+ IObservableValue observable; > ValueChangeEventTracker tracker; > > protected void setUp() throws Exception { > super.setUp(); > shell = new Shell(); >- observable = new ShellObservableValue(shell); >+ observable = SWTObservables.observeText(shell); > oldValue = "old"; > newValue = "new"; > shell.setText(oldValue); >@@ -109,7 +111,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ShellObservableValue(realm, shell); >+ return PropertyObservables.observeValue(realm, shell, >+ ShellProperties.text()); > } > > public Object getValueType(IObservableValue observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 ComboSingleSelectionObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ComboSingleSelectionObservableValueTest.java 10 Nov 2008 23:23:00 -0000 >@@ -7,10 +7,12 @@ > * > * Contributors: > * Ashley Cambrell - initial API and implementation (bug 198903) >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > package org.eclipse.jface.tests.internal.databinding.swt; > >-import org.eclipse.jface.internal.databinding.swt.ComboSingleSelectionObservableValue; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Combo; >@@ -23,8 +25,8 @@ > AbstractSWTTestCase { > public void testSetValue() throws Exception { > Combo combo = new Combo(getShell(), SWT.NONE); >- ComboSingleSelectionObservableValue observableValue = new ComboSingleSelectionObservableValue( >- combo); >+ IObservableValue observableValue = SWTObservables >+ .observeSingleSelectionIndex(combo); > combo.add("Item1"); > combo.add("Item2"); > >Index: src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTextTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTextTest.java,v >retrieving revision 1.1 >diff -u -r1.1 CComboObservableValueTextTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTextTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/CComboObservableValueTextTest.java 10 Nov 2008 23:23:00 -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; >@@ -19,13 +19,13 @@ > 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.property.PropertyObservables; > 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.ISWTObservable; >+import org.eclipse.jface.databinding.swt.CComboProperties; > 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; >@@ -88,12 +88,14 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new CComboObservableValue(realm, combo, SWTProperties.TEXT); >+ return new SWTObservableValueDecorator( >+ PropertyObservables.observeValue(realm, combo, >+ CComboProperties.text()), combo); > } > > public void change(IObservable observable) { >- CCombo combo = (CCombo) ((ISWTObservable) observable).getWidget(); >- combo.setText(combo.getText() + "a"); >+ IObservableValue ov = (IObservableValue) observable; >+ ov.setValue(createValue(ov)); > } > > public Object getValueType(IObservableValue observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTextTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTextTest.java,v >retrieving revision 1.1 >diff -u -r1.1 ComboObservableValueTextTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTextTest.java 19 Mar 2008 23:03:17 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTextTest.java 10 Nov 2008 23:23:00 -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; >@@ -19,13 +19,13 @@ > 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.property.PropertyObservables; > 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.ISWTObservable; >+import org.eclipse.jface.databinding.swt.ComboProperties; > 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; >@@ -89,12 +89,14 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ComboObservableValue(realm, combo, SWTProperties.TEXT); >+ return new SWTObservableValueDecorator( >+ PropertyObservables.observeValue(realm, combo, >+ ComboProperties.text()), combo); > } > > public void change(IObservable observable) { >- Combo combo = (Combo) ((ISWTObservable) observable).getWidget(); >- combo.setText(combo.getText() + "a"); >+ ((IObservableValue) observable) >+ .setValue(createValue((IObservableValue) observable)); > } > > public Object getValueType(IObservableValue observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueSelectionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueSelectionTest.java,v >retrieving revision 1.2 >diff -u -r1.2 SpinnerObservableValueSelectionTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueSelectionTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/SpinnerObservableValueSelectionTest.java 10 Nov 2008 23:23:01 -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; >@@ -18,12 +18,12 @@ > 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.property.PropertyObservables; > 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.SWTObservables; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >-import org.eclipse.jface.internal.databinding.swt.SpinnerObservableValue; >+import org.eclipse.jface.databinding.swt.SpinnerProperties; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Shell; >@@ -56,7 +56,8 @@ > } > > protected IObservable doCreateObservable() { >- return getObservableContractDelegate().createObservable(SWTObservables.getRealm(Display.getDefault())); >+ return getObservableContractDelegate().createObservable( >+ SWTObservables.getRealm(Display.getDefault())); > } > > public void testGetValue() throws Exception { >@@ -95,7 +96,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new SpinnerObservableValue(realm, spinner, SWTProperties.SELECTION); >+ return PropertyObservables.observeValue(realm, spinner, >+ SpinnerProperties.selection()); > } > > public void change(IObservable observable) { >Index: src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java,v >retrieving revision 1.2 >diff -u -r1.2 ComboObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java 14 Apr 2008 17:42:35 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/ComboObservableValueTest.java 10 Nov 2008 23:23:00 -0000 >@@ -8,13 +8,19 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Ashley Cambrell - bug 198904 >+ * Matthew Hall - bug 194734 > ******************************************************************************/ > > package org.eclipse.jface.tests.internal.databinding.swt; > >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.PropertyObservables; >+import org.eclipse.core.databinding.property.value.IValueProperty; > import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; >-import org.eclipse.jface.internal.databinding.swt.ComboObservableValue; >-import org.eclipse.jface.internal.databinding.swt.SWTProperties; >+import org.eclipse.jface.databinding.swt.ComboProperties; >+import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.jface.internal.databinding.swt.ComboSelectionProperty; >+import org.eclipse.jface.internal.databinding.swt.ComboTextProperty; > import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; > import org.eclipse.swt.SWT; > import org.eclipse.swt.widgets.Combo; >@@ -26,8 +32,7 @@ > public class ComboObservableValueTest extends AbstractSWTTestCase { > public void testDispose() throws Exception { > Combo combo = new Combo(getShell(), SWT.NONE); >- ComboObservableValue observableValue = new ComboObservableValue(combo, >- SWTProperties.TEXT); >+ IObservableValue observableValue = SWTObservables.observeText(combo); > ValueChangeEventTracker testCounterValueChangeListener = new ValueChangeEventTracker(); > observableValue.addValueChangeListener(testCounterValueChangeListener); > >@@ -51,25 +56,26 @@ > } > > public void testSetValueWithNull() { >- testSetValueWithNull(SWTProperties.TEXT); >- testSetValueWithNull(SWTProperties.SELECTION); >+ testSetValueWithNull(ComboProperties.text()); >+ testSetValueWithNull(ComboProperties.selection()); > } > >- protected void testSetValueWithNull(String observableMode) { >+ protected void testSetValueWithNull(IValueProperty property) { > Combo combo = new Combo(getShell(), SWT.NONE); >- combo.setItems(new String[] {"one", "two", "three"}); >- ComboObservableValue observable = new ComboObservableValue( >- combo, observableMode); >+ combo.setItems(new String[] { "one", "two", "three" }); >+ IObservableValue observable = PropertyObservables.observeValue(combo, >+ property); > >- observable.doSetValue("two"); >+ observable.setValue("two"); > assertEquals("two", combo.getText()); >- if (observableMode.equals(SWTProperties.SELECTION)) { >- assertEquals("expect selection at index 1 in mode " + observableMode, 1, combo.getSelectionIndex()); >+ if (property instanceof ComboSelectionProperty) { >+ assertEquals("expect selection at index 1 in selection mode", 1, >+ combo.getSelectionIndex()); > } > >- if (observableMode.equals(SWTProperties.TEXT)) { >- observable.doSetValue(null); >- assertEquals("expect empty text in mode " + observableMode, "", combo.getText()); >+ if (property instanceof ComboTextProperty) { >+ observable.setValue(null); >+ assertEquals("expect empty text in text mode", "", combo.getText()); > } > } > } >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 10 Nov 2008 23:23:00 -0000 >@@ -19,13 +19,14 @@ > 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.property.PropertyObservables; > 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,7 +58,8 @@ > 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); >@@ -88,15 +90,14 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new CComboObservableValue(realm, combo, >- SWTProperties.SELECTION); >+ return new SWTObservableValueDecorator(PropertyObservables >+ .observeValue(realm, combo, CComboProperties >+ .selection()), 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/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 10 Nov 2008 23:23:00 -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.value.IObservableValue; >+import org.eclipse.core.databinding.property.PropertyObservables; >+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 = PropertyObservables.observeValue( >+ combo, property); > >- 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/TextObservableValueModifyTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueModifyTest.java,v >retrieving revision 1.2 >diff -u -r1.2 TextObservableValueModifyTest.java >--- src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueModifyTest.java 24 Mar 2008 19:13:50 -0000 1.2 >+++ src/org/eclipse/jface/tests/internal/databinding/swt/TextObservableValueModifyTest.java 10 Nov 2008 23:23:01 -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; >@@ -19,9 +19,10 @@ > 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.property.PropertyObservables; > 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; >@@ -52,7 +53,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new TextObservableValue(realm, text, SWT.Modify); >+ return PropertyObservables.observeValue(realm, text, TextProperties >+ .text(SWT.Modify)); > } > > public Object getValueType(IObservableValue observable) { >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 10 Nov 2008 23:23:00 -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; >@@ -19,13 +19,14 @@ > 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.property.PropertyObservables; > 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; >@@ -91,16 +92,16 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ComboObservableValue(realm, combo, >- SWTProperties.SELECTION); >+ return new SWTObservableValueDecorator(PropertyObservables >+ .observeValue(realm, combo, ComboProperties >+ .selection()), 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.3 >diff -u -r1.3 JavaBeanObservableArrayBasedListTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java 26 Oct 2008 13:06:53 -0000 1.3 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedListTest.java 10 Nov 2008 23:22:58 -0000 >@@ -7,12 +7,11 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bugs 221351, 213145, 244098 >+ * Matthew Hall - bugs 221351, 213145, 244098, 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; >@@ -23,13 +22,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.jface.databinding.conformance.MutableObservableListContractTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; > import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker; >@@ -42,7 +44,8 @@ > */ > public class JavaBeanObservableArrayBasedListTest extends > AbstractDefaultRealmTestCase { >- private JavaBeanObservableList list; >+ private IObservableList list; >+ private IBeanObservable beanObservable; > > private PropertyDescriptor propertyDescriptor; > >@@ -59,29 +62,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)); > } > >@@ -302,16 +313,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 { >@@ -476,11 +485,6 @@ > > PropertyChangeEvent evt; > >- /* >- * (non-Javadoc) >- * >- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) >- */ > public void propertyChange(PropertyChangeEvent evt) { > count++; > this.evt = evt; >@@ -498,17 +502,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/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 10 Nov 2008 23:22:58 -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/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java,v >retrieving revision 1.4 >diff -u -r1.4 JavaBeanObservableListTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java 26 Oct 2008 13:06:53 -0000 1.4 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableListTest.java 10 Nov 2008 23:22:58 -0000 >@@ -7,12 +7,11 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bugs 221351, 213145, 244098 >+ * Matthew Hall - bugs 221351, 213145, 244098, 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; >@@ -24,13 +23,17 @@ > 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.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.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.jface.databinding.conformance.MutableObservableListContractTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; > import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; >@@ -43,7 +46,8 @@ > * @since 1.1 > */ > public class JavaBeanObservableListTest extends AbstractDefaultRealmTestCase { >- private JavaBeanObservableList list; >+ private IObservableList list; >+ private IBeanObservable beanObservable; > > private PropertyDescriptor propertyDescriptor; > >@@ -60,27 +64,37 @@ > super.setUp(); > > propertyName = "list"; >- propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); >+ propertyDescriptor = ((IBeanProperty) BeanProperties.listProperty( >+ Bean.class, propertyName)).getPropertyDescriptor(); > bean = new Bean(new ArrayList()); > >- list = new JavaBeanObservableList(SWTObservables.getRealm(Display >- .getDefault()), bean, propertyDescriptor, String.class); >+ list = BeansObservables.observeList(SWTObservables.getRealm(Display >+ .getDefault()), bean, propertyName); >+ beanObservable = (IBeanObservable) list; > } > > public void testGetObserved() throws Exception { >- assertEquals(bean, list.getObserved()); >+ assertEquals(bean, beanObservable.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertEquals(propertyDescriptor, list.getPropertyDescriptor()); >+ assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); > } > >- public void testRegistersListenerOnCreation() throws Exception { >+ public void testRegistersListenerAfterFirstListenerIsAdded() >+ throws Exception { >+ assertFalse(bean.changeSupport.hasListeners(propertyName)); >+ list.addListChangeListener(new ListChangeEventTracker()); > assertTrue(bean.changeSupport.hasListeners(propertyName)); > } > >- public void testRemovesListenerOnDisposal() throws Exception { >- list.dispose(); >+ public void testRemovesListenerAfterLastListenerIsRemoved() >+ throws Exception { >+ ListChangeEventTracker listener = new ListChangeEventTracker(); >+ list.addListChangeListener(listener); >+ >+ assertTrue(bean.changeSupport.hasListeners(propertyName)); >+ list.removeListChangeListener(listener); > assertFalse(bean.changeSupport.hasListeners(propertyName)); > } > >@@ -314,16 +328,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.getList().size()); >- list.removeAll(elements); >+ >+ list.removeAll(Arrays.asList(new String[] { "2", "4" })); > > assertEquals(2, bean.getList().size()); >- assertEquals(elements.get(0), bean.getList().get(0)); >- assertEquals(elements.get(1), bean.getList().get(1)); >+ assertEquals("1", bean.getList().get(0)); >+ assertEquals("3", bean.getList().get(1)); > } > > public void testRemoveAllListChangeEvent() throws Exception { >@@ -459,17 +471,18 @@ > > public void testConstructor_RegistersListener() throws Exception { > Bean bean = new Bean(); >- new JavaBeanObservableList(Realm.getDefault(), bean, >- new PropertyDescriptor("list", Bean.class), Bean.class); >+ IObservableList observable = BeansObservables.observeList(Realm >+ .getDefault(), bean, "list"); > >+ assertFalse(bean.hasListeners("list")); >+ ChangeEventTracker.observe(observable); > assertTrue(bean.hasListeners("list")); > } > > public void testConstructor_SkipsRegisterListener() throws Exception { > Bean bean = new Bean(); >- JavaBeanObservableList observable = new JavaBeanObservableList(Realm >- .getDefault(), bean, >- new PropertyDescriptor("list", Bean.class), Bean.class, false); >+ IObservableList observable = PojoObservables.observeList(Realm >+ .getDefault(), bean, "list"); > > assertFalse(bean.hasListeners("list")); > ChangeEventTracker.observe(observable); >@@ -506,11 +519,6 @@ > > PropertyChangeEvent evt; > >- /* >- * (non-Javadoc) >- * >- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) >- */ > public void propertyChange(PropertyChangeEvent evt) { > count++; > this.evt = evt; >@@ -528,17 +536,10 @@ > public IObservableCollection createObservableCollection(Realm realm, > int elementCount) { > String propertyName = "list"; >- PropertyDescriptor propertyDescriptor; >- try { >- propertyDescriptor = new PropertyDescriptor(propertyName, >- Bean.class); >- } catch (IntrospectionException e) { >- throw new RuntimeException(e); >- } > Object bean = new Bean(new ArrayList()); > >- 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/BeanObservableValueDecoratorTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java,v >retrieving revision 1.3 >diff -u -r1.3 BeanObservableValueDecoratorTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java 8 Sep 2008 20:23:20 -0000 1.3 >+++ src/org/eclipse/core/tests/internal/databinding/beans/BeanObservableValueDecoratorTest.java 10 Nov 2008 23:22:58 -0000 >@@ -7,15 +7,16 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bug 246625 >+ * Matthew Hall - bug 246625, 194734 > ******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; > > import java.beans.PropertyDescriptor; > >+import org.eclipse.core.databinding.beans.BeansObservables; >+import org.eclipse.core.databinding.observable.value.IObservableValue; > import org.eclipse.core.internal.databinding.beans.BeanObservableValueDecorator; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; > import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; > import org.eclipse.swt.widgets.Display; >@@ -25,38 +26,30 @@ > */ > public class BeanObservableValueDecoratorTest extends AbstractDefaultRealmTestCase { > private Bean bean; >- private JavaBeanObservableValue observableValue; >+ private IObservableValue observableValue; > private BeanObservableValueDecorator decorator; > private PropertyDescriptor propertyDescriptor; > >- /* >- * (non-Javadoc) >- * >- * @see junit.framework.TestCase#setUp() >- */ > protected void setUp() throws Exception { > super.setUp(); > > bean = new Bean(); >- propertyDescriptor = new PropertyDescriptor("value", >- Bean.class); >- observableValue = new JavaBeanObservableValue( >- SWTObservables.getRealm(Display.getDefault()), bean, >+ propertyDescriptor = new PropertyDescriptor("value", Bean.class); >+ observableValue = BeansObservables.observeValue(SWTObservables >+ .getRealm(Display.getDefault()), bean, "value"); >+ decorator = new BeanObservableValueDecorator(observableValue, > propertyDescriptor); >- decorator = new BeanObservableValueDecorator( >- observableValue, observableValue >- .getPropertyDescriptor()); > } > > public void testGetDelegate() throws Exception { >- assertEquals(observableValue, decorator.getDecorated()); >+ assertSame(observableValue, 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/JavaBeanObservableMapTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java,v >retrieving revision 1.4 >diff -u -r1.4 JavaBeanObservableMapTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java 21 Jul 2008 20:59:39 -0000 1.4 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableMapTest.java 10 Nov 2008 23:22:59 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bugs 213145, 241585 >+ * Matthew Hall - bugs 213145, 241585, 194734 > *******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; >@@ -19,12 +19,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.Realm; > 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.WritableSet; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableMap; > import org.eclipse.core.tests.databinding.observable.ThreadRealm; > import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; > import org.eclipse.jface.databinding.conformance.util.CurrentRealm; >@@ -42,7 +47,8 @@ > > private PropertyDescriptor propertyDescriptor; > >- private JavaBeanObservableMap map; >+ private IObservableMap map; >+ private IBeanObservable beanObservable; > > protected void setUp() throws Exception { > ThreadRealm realm = new ThreadRealm(); >@@ -54,8 +60,11 @@ > set.add(model1); > set.add(model2); > >- propertyDescriptor = new PropertyDescriptor("value", Bean.class); >- map = new JavaBeanObservableMap(set, propertyDescriptor); >+ String propertyName = "value"; >+ propertyDescriptor = ((IBeanProperty) BeanProperties.valueProperty( >+ Bean.class, propertyName)).getPropertyDescriptor(); >+ map = BeansObservables.observeMap(set, Bean.class, propertyName); >+ beanObservable = (IBeanObservable) map; > } > > public void testGetValue() throws Exception { >@@ -135,11 +144,11 @@ > } > > public void testGetObserved() throws Exception { >- assertEquals(set, map.getObserved()); >+ assertEquals(set, beanObservable.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertEquals(propertyDescriptor, map.getPropertyDescriptor()); >+ assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); > } > > public void testConstructor_SkipRegisterListeners() throws Exception { >@@ -148,7 +157,9 @@ > Bean bean = new Bean(); > set.add(bean); > >- JavaBeanObservableMap observable = new JavaBeanObservableMap(set, new PropertyDescriptor("value", Bean.class), false); >+ IObservableMap observable = PojoObservables.observeMap(set, Bean.class, >+ "value"); >+ assertFalse(bean.hasListeners("value")); > ChangeEventTracker.observe(observable); > > assertFalse(bean.hasListeners("value")); >@@ -160,7 +171,9 @@ > Bean bean = new Bean(); > set.add(bean); > >- JavaBeanObservableMap observable = new JavaBeanObservableMap(set, new PropertyDescriptor("value", Bean.class)); >+ IObservableMap observable = BeansObservables.observeMap(set, >+ Bean.class, "value"); >+ assertFalse(bean.hasListeners("value")); > ChangeEventTracker.observe(observable); > > assertTrue(bean.hasListeners("value")); >Index: src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java,v >retrieving revision 1.2 >diff -u -r1.2 JavaBeanObservableValueTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java 20 Mar 2008 21:16:40 -0000 1.2 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableValueTest.java 10 Nov 2008 23:22:59 -0000 >@@ -9,25 +9,27 @@ > * Brad Reynolds - initial API and implementation > * Brad Reynolds - bug 171616 > * Katarzyna Marszalek - test case for bug 198519 >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bugs 213145, 194734 > ******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; > >-import java.beans.IntrospectionException; > import java.beans.PropertyDescriptor; > > 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.beans.PojoObservables; > import org.eclipse.core.databinding.observable.ChangeEvent; > import org.eclipse.core.databinding.observable.IChangeListener; > import org.eclipse.core.databinding.observable.IObservable; > import org.eclipse.core.databinding.observable.Realm; > import org.eclipse.core.databinding.observable.value.ComputedValue; > import org.eclipse.core.databinding.observable.value.IObservableValue; >-import org.eclipse.core.internal.databinding.beans.JavaBeanObservableValue; > import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; > import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; >@@ -39,35 +41,34 @@ > */ > public class JavaBeanObservableValueTest extends AbstractDefaultRealmTestCase { > private Bean bean; >- private JavaBeanObservableValue observableValue; >+ private IObservableValue observableValue; >+ private IBeanObservable beanObservable; > private PropertyDescriptor propertyDescriptor; > private String propertyName; > >- /* (non-Javadoc) >- * @see junit.framework.TestCase#setUp() >- */ > protected void setUp() throws Exception { > super.setUp(); > > bean = new Bean(); > propertyName = "value"; >- propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); >- observableValue = new JavaBeanObservableValue(Realm.getDefault(), bean, propertyDescriptor); >+ propertyDescriptor = ((IBeanProperty) BeanProperties.valueProperty( >+ Bean.class, propertyName)).getPropertyDescriptor(); >+ observableValue = BeansObservables.observeValue(bean, propertyName); >+ beanObservable = (IBeanObservable) observableValue; > } > > public void testGetObserved() throws Exception { >- assertEquals(bean, observableValue.getObserved()); >+ assertEquals(bean, beanObservable.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertEquals(propertyDescriptor, observableValue.getPropertyDescriptor()); >+ assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); > } > > public void testSetValueThrowsExceptionThrownByBean() throws Exception { > ThrowsSetException temp = new ThrowsSetException(); >- JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm >- .getDefault(), temp, >- new PropertyDescriptor("value", ThrowsSetException.class)); >+ IObservableValue observable = BeansObservables.observeValue(temp, >+ "value"); > > try { > observable.setValue(""); >@@ -79,9 +80,8 @@ > > public void testGetValueThrowsExceptionThrownByBean() throws Exception { > ThrowsGetException temp = new ThrowsGetException(); >- JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm >- .getDefault(), temp, >- new PropertyDescriptor("value", ThrowsGetException.class)); >+ IObservableValue observable = BeansObservables.observeValue(temp, >+ "value"); > > try { > observable.getValue(); >@@ -108,14 +108,16 @@ > } > > public void testConstructor_RegistersListeners() throws Exception { >- JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm.getDefault(), bean, propertyDescriptor); >+ IObservableValue observable = BeansObservables.observeValue(bean, >+ propertyName); > ChangeEventTracker.observe(observable); > > assertTrue(bean.hasListeners(propertyName)); > } > > public void testConstructor_SkipRegisterListeners() throws Exception { >- JavaBeanObservableValue observable = new JavaBeanObservableValue(Realm.getDefault(), bean, propertyDescriptor, false); >+ IObservableValue observable = PojoObservables.observeValue(bean, >+ propertyName); > ChangeEventTracker.observe(observable); > > assertFalse(bean.hasListeners(propertyName)); >@@ -138,13 +140,7 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- try { >- PropertyDescriptor propertyDescriptor = new PropertyDescriptor("value", Bean.class); >- return new JavaBeanObservableValue(realm, bean, >- propertyDescriptor); >- } catch (IntrospectionException e) { >- throw new RuntimeException(e); >- } >+ return BeansObservables.observeValue(realm, bean, "value"); > } > > public void change(IObservable observable) { >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.3 >diff -u -r1.3 JavaBeanObservableSetTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java 26 Oct 2008 13:06:53 -0000 1.3 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableSetTest.java 10 Nov 2008 23:22:59 -0000 >@@ -7,12 +7,11 @@ > * > * Contributors: > * Brad Reynolds - initial API and implementation >- * Matthew Hall - bugs 221351, 213145, 244098 >+ * Matthew Hall - bugs 221351, 213145, 244098, 194734 > ******************************************************************************/ > > package org.eclipse.core.tests.internal.databinding.beans; > >-import java.beans.IntrospectionException; > import java.beans.PropertyDescriptor; > import java.util.Arrays; > import java.util.HashSet; >@@ -21,13 +20,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; >@@ -39,46 +42,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)); > } > >@@ -91,16 +97,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)); >@@ -126,16 +134,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 10 Nov 2008 23:22:58 -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/JavaBeanObservableArrayBasedSetTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java,v >retrieving revision 1.3 >diff -u -r1.3 JavaBeanObservableArrayBasedSetTest.java >--- src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java 26 Oct 2008 13:06:53 -0000 1.3 >+++ src/org/eclipse/core/tests/internal/databinding/beans/JavaBeanObservableArrayBasedSetTest.java 10 Nov 2008 23:22:58 -0000 >@@ -8,12 +8,11 @@ > * Contributors: > * Matthew Hall - initial API and implementation (bug 221351) > * Brad Reynolds - through JavaBeanObservableArrayBasedListTest.java >- * Matthew Hall - bug 213145, 244098 >+ * Matthew Hall - bug 213145, 244098, 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,12 +24,15 @@ > 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.set.IObservableSet; > 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.SetChangeEventTracker; >@@ -43,7 +45,8 @@ > */ > public class JavaBeanObservableArrayBasedSetTest extends > AbstractDefaultRealmTestCase { >- private JavaBeanObservableSet set; >+ private IObservableSet set; >+ private IBeanObservable beanObservable; > > private PropertyDescriptor propertyDescriptor; > >@@ -55,27 +58,36 @@ > super.setUp(); > > propertyName = "array"; >- propertyDescriptor = new PropertyDescriptor(propertyName, Bean.class); >+ propertyDescriptor = ((IBeanProperty) BeanProperties.setProperty( >+ Bean.class, propertyName)).getPropertyDescriptor(); > bean = new Bean(new HashSet()); > >- set = new JavaBeanObservableSet(SWTObservables.getRealm(Display >- .getDefault()), bean, propertyDescriptor, String.class); >+ set = BeansObservables.observeSet(SWTObservables.getRealm(Display >+ .getDefault()), bean, propertyName); >+ beanObservable = (IBeanObservable) set; > } > > public void testGetObserved() throws Exception { >- assertEquals(bean, set.getObserved()); >+ assertEquals(bean, beanObservable.getObserved()); > } > > public void testGetPropertyDescriptor() throws Exception { >- assertEquals(propertyDescriptor, set.getPropertyDescriptor()); >+ assertEquals(propertyDescriptor, beanObservable.getPropertyDescriptor()); > } > >- public void testRegistersListenerOnCreation() throws Exception { >+ public void testRegistersListenerAfterFirstListenerIsAdded() >+ throws Exception { >+ assertFalse(bean.changeSupport.hasListeners(propertyName)); >+ SetChangeEventTracker.observe(set); > assertTrue(bean.changeSupport.hasListeners(propertyName)); > } > >- public void testRemovesListenerOnDisposal() throws Exception { >- set.dispose(); >+ public void testRemovesListenerAfterLastListenerIsRemoved() >+ throws Exception { >+ SetChangeEventTracker listener = SetChangeEventTracker.observe(set); >+ >+ assertTrue(bean.changeSupport.hasListeners(propertyName)); >+ set.removeSetChangeListener(listener); > assertFalse(bean.changeSupport.hasListeners(propertyName)); > } > >@@ -295,11 +307,6 @@ > > PropertyChangeEvent evt; > >- /* >- * (non-Javadoc) >- * >- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) >- */ > public void propertyChange(PropertyChangeEvent evt) { > count++; > this.evt = evt; >@@ -317,17 +324,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]); > >- IObservableSet list = new JavaBeanObservableSet(realm, bean, >- propertyDescriptor, String.class); >+ IObservableSet list = BeansObservables.observeSet(realm, bean, >+ propertyName, String.class); > for (int i = 0; i < elementCount; i++) > list.add(createElement(list)); > return list; >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.94 >diff -u -r1.94 BindingTestSuite.java >--- src/org/eclipse/jface/tests/databinding/BindingTestSuite.java 29 Sep 2008 16:55:38 -0000 1.94 >+++ src/org/eclipse/jface/tests/databinding/BindingTestSuite.java 10 Nov 2008 23:22:59 -0000 >@@ -13,8 +13,9 @@ > * Ashley Cambrell - bugs 198903, 198904 > * Matthew Hall - bugs 210115, 212468, 212223, 206839, 208858, 208322, > * 212518, 215531, 221351, 184830, 213145, 218269, 239015, >- * 237703, 237718, 222289, 247394, 233306, 247647 >+ * 237703, 237718, 222289, 247394, 233306, 247647, 194734 > * Ovidio Mallo - bug 237163, bug 235195 >+ * Chris Aniszczyk - bug 131435 > *******************************************************************************/ > package org.eclipse.jface.tests.databinding; > >@@ -64,6 +65,7 @@ > import org.eclipse.core.tests.databinding.observable.value.ComputedValueTest; > import org.eclipse.core.tests.databinding.observable.value.DecoratingObservableValueTest; > import org.eclipse.core.tests.databinding.observable.value.WritableValueTest; >+import org.eclipse.core.tests.databinding.property.PropertyTest; > import org.eclipse.core.tests.databinding.util.PolicyTest; > import org.eclipse.core.tests.databinding.validation.MultiValidatorTest; > import org.eclipse.core.tests.databinding.validation.ValidationStatusTest; >@@ -159,7 +161,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; >@@ -168,6 +169,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; >@@ -256,6 +260,9 @@ > addTest(DecoratingObservableValueTest.suite()); > addTest(WritableValueTest.suite()); > >+ //org.eclipse.core.tests.databinding.property >+ addTestSuite(PropertyTest.class); >+ > //org.eclipse.core.tests.databinding.validation > addTestSuite(MultiValidatorTest.class); > addTestSuite(ValidationStatusTest.class); >@@ -377,8 +384,6 @@ > addTestSuite(ComboSingleSelectionObservableValueTest.class); > addTest(SWTDelayedObservableValueDecoratorTest.suite()); > >- addTest(SWTObservableListTest.suite()); >- > addTestSuite(ControlObservableValueTest.class); > addTest(LabelObservableValueTest.suite()); > addTestSuite(ListSingleSelectionObservableValueTest.class); >@@ -399,6 +404,9 @@ > addTest(TextObservableValueFocusOutTest.suite()); > addTest(TextObservableValueModifyTest.suite()); > addTestSuite(TextObservableValueTest.class); >+ addTest(StyledTextObservableValueFocusOutTest.suite()); >+ addTest(StyledTextObservableValueModifyTest.suite()); >+ addTestSuite(StyledTextObservableValueTest.class); > > //org.eclipse.jface.tests.internal.databinding.internal.viewers > addTest(ObservableViewerElementSetTest.suite()); >Index: src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java,v >retrieving revision 1.4 >diff -u -r1.4 PojoObservablesTest.java >--- src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java 24 Mar 2008 19:13:50 -0000 1.4 >+++ src/org/eclipse/core/tests/databinding/beans/PojoObservablesTest.java 10 Nov 2008 23:22:58 -0000 >@@ -7,10 +7,12 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Matthew Hall - bug 194734 > *******************************************************************************/ > > package org.eclipse.core.tests.databinding.beans; > >+import org.eclipse.core.databinding.beans.IBeanObservable; > import org.eclipse.core.databinding.beans.PojoObservables; > import org.eclipse.core.databinding.observable.Realm; > import org.eclipse.core.databinding.observable.list.IObservableList; >@@ -19,10 +21,6 @@ > import org.eclipse.core.databinding.observable.set.IObservableSet; > import org.eclipse.core.databinding.observable.set.WritableSet; > import org.eclipse.core.databinding.observable.value.IObservableValue; >-import org.eclipse.core.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.tests.internal.databinding.beans.Bean; > import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker; > import org.eclipse.jface.databinding.conformance.util.CurrentRealm; >@@ -47,12 +45,12 @@ > propertyName = "value"; > } > >- public void testObserveValue_ReturnsJavaBeanObservableValue() >+ public void testObserveValue_ReturnsIBeanObservable() > throws Exception { > IObservableValue value = PojoObservables.observeValue(pojo, propertyName); > > assertNotNull(value); >- assertTrue(value instanceof JavaBeanObservableValue); >+ assertTrue(value instanceof IBeanObservable); > } > > public void testObserveValue_DoesNotAttachListeners() throws Exception { >@@ -62,17 +60,17 @@ > assertFalse(pojo.hasListeners(propertyName)); > } > >- public void testObservableValueWithRealm_ReturnsJavaBeanObservable() >+ public void testObservableValueWithRealm_ReturnsIBeanObservable() > throws Exception { > CurrentRealm realm = new CurrentRealm(true); > IObservableValue value = PojoObservables.observeValue(realm, pojo, > propertyName); > > assertNotNull(value); >- assertTrue(value instanceof JavaBeanObservableValue); >+ assertTrue(value instanceof IBeanObservable); > } > >- public void testObservableMap_ReturnsJavaBeanObservableMap() >+ public void testObservableMap_ReturnsIBeanObservable() > throws Exception { > IObservableSet set = new WritableSet(); > set.add(new Bean()); >@@ -80,7 +78,7 @@ > IObservableMap map = PojoObservables.observeMap(set, Bean.class, > propertyName); > assertNotNull(map); >- assertTrue(map instanceof JavaBeanObservableMap); >+ assertTrue(map instanceof IBeanObservable); > } > > public void testObservableMap_DoesNotAttachListeners() throws Exception { >@@ -101,9 +99,9 @@ > assertEquals(2, maps.length); > } > >- public void testObserveListWithElementType_ReturnsJavaBeanObservableList() throws Exception { >+ public void testObserveListWithElementType_ReturnsIBeanObservable() throws Exception { > IObservableList list = PojoObservables.observeList(Realm.getDefault(), pojo, "list", String.class); >- assertTrue(list instanceof JavaBeanObservableList); >+ assertTrue(list instanceof IBeanObservable); > } > > public void testObserveListWithElementType_DoesNotAttachListeners() throws Exception { >@@ -113,9 +111,9 @@ > assertFalse(pojo.hasListeners("list")); > } > >- public void testObserveList_ReturnsJavaBeanObservableList() throws Exception { >+ public void testObserveList_ReturnsIBeanObservable() throws Exception { > IObservableList observable = PojoObservables.observeList(Realm.getDefault(), pojo, "list"); >- assertTrue(observable instanceof JavaBeanObservableList); >+ assertTrue(observable instanceof IBeanObservable); > } > > public void testObserveList_DoesNotAttachListeners() throws Exception { >@@ -125,9 +123,9 @@ > assertFalse(pojo.hasListeners("list")); > } > >- public void testObserveSetWithElementType_ReturnsJavaBeanObservableList() throws Exception { >+ public void testObserveSetWithElementType_ReturnsIBeanObservable() throws Exception { > IObservableSet list = PojoObservables.observeSet(Realm.getDefault(), pojo, "set", String.class); >- assertTrue(list instanceof JavaBeanObservableSet); >+ assertTrue(list instanceof IBeanObservable); > } > > public void testObserveSetWithElementType_DoesNotAttachListeners() throws Exception { >@@ -137,9 +135,9 @@ > assertFalse(pojo.hasListeners("set")); > } > >- public void testObserveSet_ReturnsJavaBeanObservableList() throws Exception { >+ public void testObserveSet_ReturnsIBeanObservable() throws Exception { > IObservableSet list = PojoObservables.observeSet(Realm.getDefault(), pojo, "set"); >- assertTrue(list instanceof JavaBeanObservableSet); >+ assertTrue(list instanceof IBeanObservable); > } > > public void testObserveSet_DoesNotAttachListeners() throws Exception { >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 10 Nov 2008 23:22:59 -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/viewers/ViewerInputObservableValueTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java,v >retrieving revision 1.1 >diff -u -r1.1 ViewerInputObservableValueTest.java >--- src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java 19 Mar 2008 23:03:19 -0000 1.1 >+++ src/org/eclipse/jface/tests/internal/databinding/viewers/ViewerInputObservableValueTest.java 10 Nov 2008 23:23:01 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * Matthew Hall - initial API and implementation (bug 206839) >- * Matthew Hall - bug 213145 >+ * Matthew Hall - bug 213145, 194734 > *******************************************************************************/ > package org.eclipse.jface.tests.internal.databinding.viewers; > >@@ -18,10 +18,12 @@ > import org.eclipse.core.databinding.observable.Realm; > import org.eclipse.core.databinding.observable.value.IObservableValue; > import org.eclipse.core.databinding.observable.value.ValueChangeEvent; >+import org.eclipse.core.databinding.property.PropertyObservables; > import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest; > import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate; > import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker; >-import org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; >+import org.eclipse.jface.databinding.viewers.ViewerProperties; >+import org.eclipse.jface.databinding.viewers.ViewersObservables; > import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase; > import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.TableViewer; >@@ -55,34 +57,38 @@ > > public void testConstructor_IllegalArgumentException() { > try { >- new ViewerInputObservableValue(Realm.getDefault(), null); >+ ViewersObservables.observeInput(null); > fail("Expected IllegalArgumentException for null argument"); > } catch (IllegalArgumentException expected) { > } > } > >- public void testSetInputOnViewer_FiresNoChangeEvents() { >- IObservableValue observable = new ViewerInputObservableValue(Realm >- .getDefault(), viewer); >- ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable); >+ public void testSetInputOnViewer_FiresChangeEventOnGetValue() { >+ IObservableValue observable = ViewersObservables.observeInput(viewer); >+ ValueChangeEventTracker listener = ValueChangeEventTracker >+ .observe(observable); > > assertNull(viewer.getInput()); > assertEquals(0, listener.count); > > viewer.setInput(model); > >- assertEquals(model, observable.getValue()); >+ assertEquals(model, viewer.getInput()); > assertEquals(0, listener.count); > >+ // Call to getValue() causes observable to discover change >+ assertEquals(model, observable.getValue()); >+ assertEquals(1, listener.count); >+ > viewer.setInput(null); >+ assertEquals(null, viewer.getInput()); > > assertEquals(null, observable.getValue()); >- assertEquals(0, listener.count); >+ assertEquals(2, listener.count); > } > > public void testGetSetValue_FiresChangeEvents() { >- IObservableValue observable = new ViewerInputObservableValue(Realm >- .getDefault(), viewer); >+ IObservableValue observable = ViewersObservables.observeInput(viewer); > ValueChangeEventTracker listener = new ValueChangeEventTracker(); > observable.addValueChangeListener(listener); > >@@ -103,14 +109,12 @@ > } > > public void testGetValueType_AlwaysNull() throws Exception { >- IObservableValue observable = new ViewerInputObservableValue(Realm >- .getDefault(), viewer); >+ IObservableValue observable = ViewersObservables.observeInput(viewer); > assertEquals(null, observable.getValueType()); > } > > public void testDispose() throws Exception { >- IObservableValue observable = new ViewerInputObservableValue(Realm >- .getDefault(), viewer); >+ IObservableValue observable = ViewersObservables.observeInput(viewer); > observable.dispose(); > assertNull(observable.getRealm()); > try { >@@ -165,7 +169,8 @@ > } > > public IObservableValue createObservableValue(Realm realm) { >- return new ViewerInputObservableValue(realm, viewer); >+ return PropertyObservables.observeValue(realm, viewer, >+ ViewerProperties.input()); > } > > public void change(IObservable observable) { >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 10 Nov 2008 23:23:01 -0000 >@@ -8,15 +8,16 @@ > * Contributors: > * Brad Reynolds - initial API and implementation > * Brad Reynolds - bug 116920 >+ * Matthew Hall - bug 194734 > *******************************************************************************/ > package org.eclipse.jface.tests.internal.databinding.viewers; > > import junit.framework.TestCase; > >+import org.eclipse.core.databinding.observable.list.IObservableList; > import org.eclipse.core.databinding.observable.list.ListDiffEntry; > 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 +25,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 +37,7 @@ > > 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 +55,7 @@ > > public void testConstructorIllegalArgumentException() { > try { >- new SelectionProviderMultipleSelectionObservableList(SWTObservables >- .getRealm(Display.getDefault()), null, Object.class); >+ ViewersObservables.observeMultiSelection(null); > fail(); > } catch (IllegalArgumentException e) { > } >@@ -70,9 +69,8 @@ > * </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()); >@@ -126,15 +124,15 @@ > // 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); >+ assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[2], true); > assertEquals(observable, listener.event.getObservableList()); > 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); >+ assertDiffEntry(listener.event.diff.getDifferences()[0], 0, model[1], false); >+ assertDiffEntry(listener.event.diff.getDifferences()[1], 0, model[2], false); > assertEquals(observable, listener.event.getObservableList()); > assertEquals(0, ((IStructuredSelection)viewer.getSelection()).size()); > } >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 10 Nov 2008 23:23:01 -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/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,81 @@ >+/******************************************************************************* >+ * 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.core.databinding.property.PropertyObservables; >+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 PropertyObservables.observeValue(realm, text, >+ StyledTextProperties.text(SWT.FocusOut)); >+ } >+ >+ 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/core/tests/databinding/property/PropertyTest.java >=================================================================== >RCS file: src/org/eclipse/core/tests/databinding/property/PropertyTest.java >diff -N src/org/eclipse/core/tests/databinding/property/PropertyTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/tests/databinding/property/PropertyTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,185 @@ >+/******************************************************************************* >+ * 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.tests.databinding.property; >+ >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+import org.eclipse.core.databinding.property.Property; >+import org.eclipse.core.databinding.property.PropertyChangeEvent; >+ >+import junit.framework.TestCase; >+ >+/** >+ * @since 3.2 >+ * >+ */ >+public class PropertyTest extends TestCase { >+ private Source source; >+ private SourceProperty property; >+ private ChangeListener listener; >+ >+ protected void setUp() throws Exception { >+ source = new Source(); >+ property = new SourceProperty(); >+ listener = new ChangeListener(); >+ } >+ >+ public void testAddListenerTo() { >+ assertFalse(source.hasListener()); >+ property.addChangeListener(source, listener); >+ assertTrue(source.hasListener()); >+ >+ assertEquals(0, listener.count); >+ >+ source.change(); >+ >+ assertEquals(1, listener.count); >+ assertEquals(new ChangeEvent(source, "Version 1"), listener.event); >+ } >+ >+ public void testAddListenerTo_MultipleListeners() { >+ assertFalse(source.hasListener()); >+ >+ property.addChangeListener(source, listener); >+ >+ assertTrue(source.hasListener()); >+ >+ ChangeListener listener2 = new ChangeListener(); >+ property.addChangeListener(source, listener2); >+ >+ assertTrue(source.hasListener()); >+ >+ property.removeChangeListener(source, listener); >+ >+ assertTrue(source.hasListener()); >+ >+ property.removeChangeListener(source, listener2); >+ >+ assertFalse(source.hasListener()); >+ } >+ >+ public void testRemoveListenerFrom() { >+ property.addChangeListener(source, listener); >+ assertTrue(source.hasListener()); >+ property.removeChangeListener(source, listener); >+ assertFalse(source.hasListener()); >+ >+ source.change(); >+ >+ assertEquals(0, listener.count); >+ } >+ >+ public void testIsDisposed() { >+ assertFalse(property.isDisposed()); >+ property.dispose(); >+ assertTrue(property.isDisposed()); >+ } >+ >+ public void testDispose() { >+ property.addChangeListener(source, listener); >+ assertTrue(source.hasListener()); >+ property.dispose(); >+ assertFalse(source.hasListener()); >+ } >+ >+ static class Source { >+ private int version = 0; >+ >+ private ISourceListener listener; >+ >+ void change() { >+ ++version; >+ if (listener != null) >+ listener.notify(this, "Version " + version); >+ } >+ >+ boolean hasListener() { >+ return listener != null; >+ } >+ } >+ >+ interface ISourceListener { >+ void notify(Object source, String message); >+ } >+ >+ static class SourceProperty extends Property { >+ private ISourceListener listener = new ISourceListener() { >+ public void notify(Object source, String message) { >+ firePropertyChange(new ChangeEvent(source, message)); >+ } >+ }; >+ >+ public void addChangeListener(Object source, IChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public void removeChangeListener(Object source, IChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ protected void addListenerTo(Object source) { >+ ((Source) source).listener = listener; >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ ((Source) source).listener = null; >+ } >+ >+ void change(Object source) { >+ ((Source) source).change(); >+ } >+ } >+ >+ static interface IChangeListener extends IPropertyChangeListener { >+ void handlePropertyStubChange(ChangeEvent event); >+ } >+ >+ static class ChangeListener implements IChangeListener { >+ int count = 0; >+ ChangeEvent event; >+ >+ public void handlePropertyStubChange(ChangeEvent event) { >+ count++; >+ this.event = event; >+ } >+ } >+ >+ static class ChangeEvent extends PropertyChangeEvent { >+ private static final long serialVersionUID = 1L; >+ >+ final String message; >+ >+ ChangeEvent(Object source, String message) { >+ super(source); >+ this.message = message; >+ } >+ >+ protected void dispatch(IPropertyChangeListener listener) { >+ ((IChangeListener) listener).handlePropertyStubChange(this); >+ } >+ >+ public boolean equals(Object obj) { >+ if (obj == this) >+ return true; >+ if (!super.equals(obj)) >+ return false; >+ >+ ChangeEvent that = (ChangeEvent) obj; >+ return message.equals(that.message); >+ } >+ >+ public int hashCode() { >+ int hash = super.hashCode(); >+ hash = hash * 37 + message.hashCode(); >+ return hash; >+ } >+ } >+} >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,79 @@ >+/******************************************************************************* >+ * 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.core.databinding.property.PropertyObservables; >+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 PropertyObservables.observeValue(realm, text, >+ StyledTextProperties.text(SWT.Modify)); >+ } >+ >+ 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.core.databinding >Index: src/org/eclipse/core/databinding/observable/map/MapDiff.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/map/MapDiff.java,v >retrieving revision 1.4 >diff -u -r1.4 MapDiff.java >--- src/org/eclipse/core/databinding/observable/map/MapDiff.java 23 Oct 2008 18:27:48 -0000 1.4 >+++ src/org/eclipse/core/databinding/observable/map/MapDiff.java 10 Nov 2008 23:23:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 251884 >+ * Matthew Hall - bug 251884, 194734 > *******************************************************************************/ > > package org.eclipse.core.databinding.observable.map; >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/META-INF/MANIFEST.MF,v >retrieving revision 1.16 >diff -u -r1.16 MANIFEST.MF >--- META-INF/MANIFEST.MF 26 Oct 2008 14:34:07 -0000 1.16 >+++ META-INF/MANIFEST.MF 10 Nov 2008 23:23:07 -0000 >@@ -14,6 +14,11 @@ > org.eclipse.core.databinding.observable.masterdetail, > org.eclipse.core.databinding.observable.set;x-internal:=false, > org.eclipse.core.databinding.observable.value;x-internal:=false, >+ org.eclipse.core.databinding.property, >+ org.eclipse.core.databinding.property.list, >+ org.eclipse.core.databinding.property.map, >+ org.eclipse.core.databinding.property.set, >+ org.eclipse.core.databinding.property.value, > org.eclipse.core.databinding.util, > org.eclipse.core.databinding.validation;x-internal:=false, > org.eclipse.core.internal.databinding;x-friends:="org.eclipse.core.databinding.beans", >@@ -21,6 +26,7 @@ > org.eclipse.core.internal.databinding.observable;x-internal:=true, > org.eclipse.core.internal.databinding.observable.masterdetail;x-friends:="org.eclipse.jface.tests.databinding", > org.eclipse.core.internal.databinding.observable.tree;x-friends:="org.eclipse.jface.databinding,org.eclipse.jface.tests.databinding", >+ org.eclipse.core.internal.databinding.property;x-friends:="org.eclipse.jface.databinding,org.eclipse.jface.tests.databinding", > org.eclipse.core.internal.databinding.validation;x-friends:="org.eclipse.jface.tests.databinding" > Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.2.0,4.0.0)" > Import-Package-Comment: see http://wiki.eclipse.org/ >Index: src/org/eclipse/core/databinding/observable/list/ListDiff.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/list/ListDiff.java,v >retrieving revision 1.6 >diff -u -r1.6 ListDiff.java >--- src/org/eclipse/core/databinding/observable/list/ListDiff.java 23 Oct 2008 18:27:48 -0000 1.6 >+++ src/org/eclipse/core/databinding/observable/list/ListDiff.java 10 Nov 2008 23:23:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 208858, 251884 >+ * Matthew Hall - bug 208858, 251884, 194734 > *******************************************************************************/ > > package org.eclipse.core.databinding.observable.list; >Index: src/org/eclipse/core/databinding/observable/set/SetDiff.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/src/org/eclipse/core/databinding/observable/set/SetDiff.java,v >retrieving revision 1.4 >diff -u -r1.4 SetDiff.java >--- src/org/eclipse/core/databinding/observable/set/SetDiff.java 23 Oct 2008 18:27:48 -0000 1.4 >+++ src/org/eclipse/core/databinding/observable/set/SetDiff.java 10 Nov 2008 23:23:07 -0000 >@@ -7,7 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 251884 >+ * Matthew Hall - bug 251884, 194734 > *******************************************************************************/ > > package org.eclipse.core.databinding.observable.set; >Index: src/org/eclipse/core/databinding/property/value/IValueProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/IValueProperty.java >diff -N src/org/eclipse/core/databinding/property/value/IValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/IValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,73 @@ >+/******************************************************************************* >+ * 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.IProperty; >+ >+ >+/** >+ * Interface for value-typed properties >+ * >+ * @since 1.2 >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IValueProperty extends IProperty { >+ /** >+ * Returns the source's value property >+ * >+ * @param source >+ * the property source >+ * @return the current value of the source's value property >+ */ >+ public Object getValue(Object source); >+ >+ /** >+ * Sets the source's value property to the specified value >+ * >+ * @param source >+ * the property source >+ * @param value >+ * the new value >+ */ >+ public void setValue(Object source, Object value); >+ >+ /** >+ * Returns the value type of the property, or <code>null</code> if untyped. >+ * >+ * @return the value type of the property, or <code>null</code> if untyped. >+ */ >+ public Object getValueType(); >+ >+ /** >+ * Adds the given value property change listener to the list of listeners >+ * for the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void addValueChangeListener(Object source, >+ IValuePropertyChangeListener listener); >+ >+ /** >+ * Removes the given list property change listener from the list of >+ * listeners for the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void removeValueChangeListener(Object source, >+ IValuePropertyChangeListener listener); >+} >Index: src/org/eclipse/core/databinding/property/set/ISetPropertyChangeListener.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/set/ISetPropertyChangeListener.java >diff -N src/org/eclipse/core/databinding/property/set/ISetPropertyChangeListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/set/ISetPropertyChangeListener.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.set; >+ >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+ >+/** >+ * Listener for changes to set properties on a property source >+ * >+ * @since 1.2 >+ */ >+public interface ISetPropertyChangeListener extends IPropertyChangeListener { >+ /** >+ * Handle a change to a set property on a specific property source. >+ * >+ * @param event >+ * an event describing the set change that occured. >+ */ >+ public void handleSetPropertyChange(SetPropertyChangeEvent event); >+} >Index: src/org/eclipse/core/databinding/property/list/IListProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/list/IListProperty.java >diff -N src/org/eclipse/core/databinding/property/list/IListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/list/IListProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,165 @@ >+/******************************************************************************* >+ * 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.Collection; >+import java.util.List; >+ >+import org.eclipse.core.databinding.property.ICollectionProperty; >+ >+/** >+ * Interface for list-typed properties. >+ * >+ * @since 1.2 >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IListProperty extends ICollectionProperty { >+ /** >+ * Returns a List with the current contents of the source's list property >+ * >+ * @param source >+ * the property source >+ * @return a List with the current contents of the source's list property >+ */ >+ List getList(Object source); >+ >+ /** >+ * Inserts all elements in the specified collection into the source's list >+ * property at the specified index. >+ * >+ * @param source >+ * the property source >+ * @param index >+ * the insertion index >+ * @param c >+ * the collection of elements to add >+ * @return whether the source's list property was changed >+ */ >+ boolean addAll(Object source, int index, Collection c); >+ >+ /** >+ * Returns the element at the specified position in the source's list >+ * property >+ * >+ * @param source >+ * the property source >+ * @param index >+ * the element position >+ * @return the element at the given position in the source's list property >+ */ >+ Object get(Object source, int index); >+ >+ /** >+ * Replaces the element at the specified position in the source's list >+ * property with the given element. >+ * >+ * @param source >+ * the property source >+ * @param index >+ * the element position >+ * @param element >+ * the replacement element >+ * @return the element previously at the specified position in the source's >+ * list property >+ */ >+ Object set(Object source, int index, Object element); >+ >+ /** >+ * Moves the element at the specified old position in the source's list >+ * property to the specified new position >+ * >+ * @param source >+ * the property source >+ * @param oldIndex >+ * the old element position >+ * @param newIndex >+ * the new element position >+ * @return the element that was moved >+ */ >+ Object move(Object source, int oldIndex, int newIndex); >+ >+ /** >+ * Inserts the element into the source's list property at the specified >+ * position >+ * >+ * @param source >+ * the property source >+ * @param index >+ * the insertion index >+ * @param element >+ * the element to insert >+ */ >+ void add(Object source, int index, Object element); >+ >+ /** >+ * Removes the element from the source's list property which is located at >+ * the specified position >+ * >+ * @param source >+ * the property source >+ * @param index >+ * the index of the element to remove >+ * @return the element that was removed from the source's list property >+ */ >+ Object remove(Object source, int index); >+ >+ /** >+ * Returns the index of the first location of the given element in the >+ * source's list property, or -1 if the list does not contain the element. >+ * >+ * @param source >+ * the property source >+ * @param o >+ * the element >+ * @return the index of the first location of the given element in the >+ * source's list property, or -1 if the list does not contain the >+ * element >+ */ >+ int indexOf(Object source, Object o); >+ >+ /** >+ * Returns the index of the last location of the given element in the >+ * source's list property, or -1 if the list does not contain the given >+ * element. >+ * >+ * @param source >+ * @param o >+ * @return the index of the last location of the given element in the >+ * source's list property, or -1 if the list does not contain the >+ * element >+ */ >+ int lastIndexOf(Object source, Object o); >+ >+ /** >+ * Adds the given list property change listener to the list of listeners for >+ * the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void addListChangeListener(Object source, >+ IListPropertyChangeListener listener); >+ >+ /** >+ * Removes the given list property change listener from the list of >+ * listeners for the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void removeListChangeListener(Object source, >+ IListPropertyChangeListener listener); >+} >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,268 @@ >+/******************************************************************************* >+ * 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.set.SetDiff; >+import org.eclipse.core.databinding.property.SimpleProperty; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * 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 #doGetSet(Object)} >+ * <li>{@link #doSetSet(Object, Set, SetDiff)} >+ * </ul> >+ * Additionally, the following methods should be overridden when the property >+ * source has listener APIs. >+ * <ul> >+ * <li>{@link #doAddListenerTo(Object)} >+ * <li>{@link #doRemoveListenerFrom(Object)} >+ * </ul> >+ * >+ * @since 1.2 >+ */ >+public abstract class SimpleSetProperty extends SimpleProperty implements >+ ISetProperty { >+ public void addSetChangeListener(Object source, >+ ISetPropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public void removeSetChangeListener(Object source, >+ ISetPropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ protected final Object getProperty(Object source) { >+ return doGetSet(source); >+ } >+ >+ public boolean contains(Object source, Object o) { >+ return getSet(source).contains(o); >+ } >+ >+ public boolean containsAll(Object source, Collection c) { >+ return getSet(source).containsAll(c); >+ } >+ >+ public boolean equals(Object source, Object o) { >+ return getSet(source).equals(o); >+ } >+ >+ public int hashCode(Object source) { >+ return getSet(source).hashCode(); >+ } >+ >+ public boolean isEmpty(Object source) { >+ return getSet(source).isEmpty(); >+ } >+ >+ public int size(Object source) { >+ return getSet(source).size(); >+ } >+ >+ public Object[] toArray(Object source, Object[] array) { >+ return getSet(source).toArray(array); >+ } >+ >+ public Object[] toArray(Object source) { >+ return getSet(source).toArray(); >+ } >+ >+ public final Set getSet(Object source) { >+ Set set = doGetSet(source); >+ if (hasListeners(source) && !isUpdating(source)) { >+ Set cached = (Set) getCached(source); >+ if (!Util.equals(set, cached)) { >+ fireSetChange(source, Diffs.computeSetDiff(cached, set)); >+ } >+ } >+ return set; >+ } >+ >+ /** >+ * 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 >+ * @see ISetProperty#getSet(Object) >+ */ >+ protected abstract Set doGetSet(Object source); >+ >+ private void setSet(Object source, Set set, SetDiff diff) { >+ setUpdating(source, true); >+ try { >+ doSetSet(source, set, diff); >+ } finally { >+ setUpdating(source, false); >+ } >+ >+ if (hasListeners(source)) { >+ fireSetChange(source, diff); >+ } >+ } >+ >+ /** >+ * Updates the property on the source with the specified change. A set >+ * change event is fired in the calling method, so implementers do not need >+ * to call {@link #fireSetChange(Object, SetDiff)}. >+ * >+ * @param source >+ * the property source >+ * @param set >+ * the new set >+ * @param diff >+ * a diff describing the change >+ */ >+ protected abstract void doSetSet(Object source, Set set, SetDiff diff); >+ >+ /** >+ * Notifies that the source's property changed. Listeners registered in the >+ * {@link #addListenerTo(Object)} method should call this method when a >+ * property change is observed on the source object. >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * a diff describing the set change. If null, a diff will be >+ * computed from the cached state and the current state. >+ */ >+ protected final void fireSetChange(Object source, SetDiff diff) { >+ if (!isUpdating(source) && hasListeners(source)) { >+ if (diff == null) { >+ diff = Diffs.computeSetDiff((Set) getCached(source), >+ doGetSet(source)); >+ } >+ if (!diff.isEmpty()) { >+ firePropertyChange(new SetPropertyChangeEvent(source, this, >+ diff)); >+ } >+ } >+ } >+ >+ public 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; >+ } >+ >+ public 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; >+ } >+ >+ public void clear(Object source) { >+ if (!isEmpty(source)) { >+ setSet(source, new HashSet(), Diffs.createSetDiff( >+ Collections.EMPTY_SET, getSet(source))); >+ } >+ } >+ >+ public 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; >+ } >+ >+ public 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; >+ } >+ >+ public 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; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/observable/PropertyObservableMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/PropertyObservableMap.java >diff -N src/org/eclipse/core/internal/databinding/observable/PropertyObservableMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/PropertyObservableMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,177 @@ >+/******************************************************************************* >+ * 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.observable; >+ >+import java.util.Collection; >+import java.util.Collections; >+import java.util.Map; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.ObservableTracker; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.map.AbstractObservableMap; >+import org.eclipse.core.databinding.property.IProperty; >+import org.eclipse.core.databinding.property.IPropertyObservable; >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.core.databinding.property.map.IMapPropertyChangeListener; >+import org.eclipse.core.databinding.property.map.MapPropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class PropertyObservableMap extends AbstractObservableMap implements >+ IPropertyObservable { >+ private Object source; >+ private IMapProperty property; >+ >+ private volatile boolean updating = false; >+ >+ private boolean disposed = false; >+ >+ private transient volatile int modCount = 0; >+ >+ private IMapPropertyChangeListener listener = new IMapPropertyChangeListener() { >+ public void handleMapPropertyChange(final MapPropertyChangeEvent event) { >+ if (!disposed && !updating) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ modCount++; >+ fireMapChange(event.diff); >+ } >+ }); >+ } >+ }); >+ } >+ } >+ }; >+ >+ /** >+ * @param realm >+ * @param source >+ * @param property >+ */ >+ public PropertyObservableMap(Realm realm, Object source, >+ IMapProperty property) { >+ super(realm); >+ this.source = source; >+ this.property = property; >+ } >+ >+ private void getterCalled() { >+ ObservableTracker.getterCalled(this); >+ } >+ >+ protected void firstListenerAdded() { >+ if (!disposed) { >+ property.addMapChangeListener(source, listener); >+ } >+ } >+ >+ protected void lastListenerRemoved() { >+ if (!disposed) { >+ property.removeMapChangeListener(source, listener); >+ } >+ } >+ >+ public boolean containsKey(Object key) { >+ getterCalled(); >+ return property.containsKey(source, key); >+ } >+ >+ public boolean containsValue(Object value) { >+ getterCalled(); >+ return property.containsValue(source, value); >+ } >+ >+ public Set entrySet() { >+ getterCalled(); >+ // unmodifiable for now >+ return Collections.unmodifiableSet(property.getMap(source).entrySet()); >+ } >+ >+ public Object get(Object key) { >+ getterCalled(); >+ return property.get(source, key); >+ } >+ >+ public boolean isEmpty() { >+ getterCalled(); >+ return property.isEmpty(source); >+ } >+ >+ public Set keySet() { >+ getterCalled(); >+ return Collections.unmodifiableSet(property.getMap(source).keySet()); >+ } >+ >+ public Object put(Object key, Object value) { >+ checkRealm(); >+ return property.put(source, key, value); >+ } >+ >+ public void putAll(Map m) { >+ checkRealm(); >+ property.putAll(source, m); >+ } >+ >+ public Object remove(Object key) { >+ checkRealm(); >+ return property.remove(source, key); >+ } >+ >+ public int size() { >+ getterCalled(); >+ return property.size(source); >+ } >+ >+ public Collection values() { >+ getterCalled(); >+ return Collections.unmodifiableCollection(property.getMap(source) >+ .values()); >+ } >+ >+ public void clear() { >+ getterCalled(); >+ property.clear(source); >+ } >+ >+ 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 (!disposed) { >+ disposed = true; >+ property.removeMapChangeListener(source, listener); >+ property = null; >+ source = null; >+ } >+ super.dispose(); >+ } >+} >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,123 @@ >+/******************************************************************************* >+ * 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 java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValueProperty; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class ValuePropertyDetailValue extends ValueProperty implements >+ IValueProperty { >+ private IValueProperty masterProperty; >+ private IValueProperty detailProperty; >+ >+ private Map sourceToDetailListener = new HashMap(); >+ >+ private IValuePropertyChangeListener masterListener = new MasterPropertyListener(); >+ >+ private class MasterPropertyListener implements >+ IValuePropertyChangeListener { >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ Object oldSource = event.diff.getOldValue(); >+ Object newSource = event.diff.getNewValue(); >+ >+ Object oldValue = detailProperty.getValue(oldSource); >+ Object newValue = detailProperty.getValue(newSource); >+ >+ ValueDiff diff = Diffs.createValueDiff(oldValue, newValue); >+ >+ Object source = event.getSource(); >+ >+ removeDetailPropertyListener(source); >+ addDetailPropertyListener(source); >+ >+ fireValueChange(source, diff); >+ } >+ } >+ >+ private class DetailPropertyListener implements >+ IValuePropertyChangeListener { >+ private Object source; >+ private Object masterValue; >+ >+ DetailPropertyListener(Object source, Object masterValue) { >+ this.source = source; >+ this.masterValue = masterValue; >+ } >+ >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ fireValueChange(source, event.diff); >+ } >+ } >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ValuePropertyDetailValue(IValueProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ protected void addListenerTo(Object source) { >+ masterProperty.addValueChangeListener(source, masterListener); >+ addDetailPropertyListener(source); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ masterProperty.removeValueChangeListener(source, masterListener); >+ removeDetailPropertyListener(source); >+ } >+ >+ private void addDetailPropertyListener(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, masterValue); >+ detailProperty.addValueChangeListener(masterValue, detailListener); >+ sourceToDetailListener.put(source, detailListener); >+ } >+ >+ private void removeDetailPropertyListener(Object source) { >+ DetailPropertyListener detailListener = (DetailPropertyListener) sourceToDetailListener >+ .remove(source); >+ if (detailListener != null) { >+ detailProperty.removeValueChangeListener( >+ detailListener.masterValue, detailListener); >+ } >+ sourceToDetailListener.remove(source); >+ } >+ >+ public Object getValue(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.getValue(masterValue); >+ } >+ >+ public Object getValueType() { >+ return detailProperty.getValueType(); >+ } >+ >+ public void setValue(Object source, Object value) { >+ Object masterValue = masterProperty.getValue(source); >+ detailProperty.setValue(masterValue, value); >+ } >+} >Index: src/org/eclipse/core/internal/databinding/observable/PropertyObservableList.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/PropertyObservableList.java >diff -N src/org/eclipse/core/internal/databinding/observable/PropertyObservableList.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/PropertyObservableList.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,374 @@ >+/******************************************************************************* >+ * 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.observable; >+ >+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.ObservableTracker; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.AbstractObservableList; >+import org.eclipse.core.databinding.property.IProperty; >+import org.eclipse.core.databinding.property.IPropertyObservable; >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.list.IListPropertyChangeListener; >+import org.eclipse.core.databinding.property.list.ListPropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class PropertyObservableList extends AbstractObservableList implements >+ IPropertyObservable { >+ private Object source; >+ private IListProperty property; >+ >+ private volatile boolean updating = false; >+ >+ private boolean disposed = false; >+ >+ private transient volatile int modCount = 0; >+ >+ private IListPropertyChangeListener listener = new IListPropertyChangeListener() { >+ public void handleListPropertyChange(final ListPropertyChangeEvent event) { >+ if (!disposed && !updating) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ modCount++; >+ fireListChange(event.diff); >+ } >+ }); >+ } >+ }); >+ } >+ } >+ }; >+ >+ /** >+ * @param realm >+ * @param source >+ * @param property >+ */ >+ public PropertyObservableList(Realm realm, Object source, >+ IListProperty property) { >+ super(realm); >+ this.source = source; >+ this.property = property; >+ } >+ >+ protected void firstListenerAdded() { >+ if (!disposed) { >+ property.addListChangeListener(source, listener); >+ } >+ } >+ >+ protected void lastListenerRemoved() { >+ if (!disposed) { >+ property.removeListChangeListener(source, listener); >+ } >+ } >+ >+ 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(); >+ return property.add(source, o); >+ } >+ >+ public Iterator iterator() { >+ getterCalled(); >+ return new Iterator() { >+ int lastReturned = -1; >+ int expectedModCount = modCount; >+ ListIterator delegate = new ArrayList(property.getList(source)) >+ .listIterator(); >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.hasNext(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ Object next = delegate.next(); >+ lastReturned = delegate.previousIndex(); >+ return next; >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ if (lastReturned == -1) >+ throw new IllegalStateException(); >+ >+ delegate.remove(); // stay in sync >+ >+ property.remove(source, lastReturned); >+ >+ lastReturned = -1; >+ expectedModCount = modCount; >+ } >+ >+ private void checkForComodification() { >+ if (expectedModCount != modCount) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ >+ public Object move(int oldIndex, int newIndex) { >+ getterCalled(); >+ return property.move(source, oldIndex, newIndex); >+ } >+ >+ public boolean remove(Object o) { >+ getterCalled(); >+ return property.remove(source, o); >+ } >+ >+ public void add(int index, Object o) { >+ getterCalled(); >+ property.add(source, index, o); >+ } >+ >+ public ListIterator listIterator() { >+ return listIterator(0); >+ } >+ >+ public ListIterator listIterator(final int index) { >+ getterCalled(); >+ return new ListIterator() { >+ int lastReturned = -1; >+ int expectedModCount = modCount; >+ ListIterator delegate = new ArrayList(property.getList(source)) >+ .listIterator(index); >+ >+ public boolean hasNext() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.hasNext(); >+ } >+ >+ public int nextIndex() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.nextIndex(); >+ } >+ >+ public Object next() { >+ getterCalled(); >+ checkForComodification(); >+ Object next = delegate.next(); >+ lastReturned = delegate.previousIndex(); >+ return next; >+ } >+ >+ public boolean hasPrevious() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.hasPrevious(); >+ } >+ >+ public int previousIndex() { >+ getterCalled(); >+ checkForComodification(); >+ return delegate.previousIndex(); >+ } >+ >+ public Object previous() { >+ getterCalled(); >+ checkForComodification(); >+ Object previous = delegate.previous(); >+ lastReturned = delegate.nextIndex(); >+ return previous; >+ } >+ >+ public void add(Object o) { >+ checkRealm(); >+ checkForComodification(); >+ int index = delegate.nextIndex(); >+ >+ delegate.add(o); // keep in sync >+ >+ property.add(source, index, o); >+ >+ lastReturned = -1; >+ expectedModCount = modCount; >+ } >+ >+ public void set(Object o) { >+ checkRealm(); >+ checkForComodification(); >+ >+ delegate.set(o); >+ >+ property.set(source, lastReturned, o); >+ >+ expectedModCount = modCount; >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ if (lastReturned == -1) >+ throw new IllegalStateException(); >+ >+ delegate.remove(); // keep in sync >+ >+ property.remove(source, lastReturned); >+ >+ lastReturned = -1; >+ expectedModCount = modCount; >+ } >+ >+ private void checkForComodification() { >+ if (expectedModCount != modCount) >+ throw new ConcurrentModificationException(); >+ } >+ >+ }; >+ } >+ >+ public Object remove(int index) { >+ getterCalled(); >+ return property.remove(source, index); >+ } >+ >+ public Object set(int index, Object o) { >+ getterCalled(); >+ return property.set(source, index, o); >+ } >+ >+ 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) { >+ getterCalled(); >+ return property.addAll(source, c); >+ } >+ >+ public boolean addAll(int index, Collection c) { >+ getterCalled(); >+ return property.addAll(source, index, c); >+ } >+ >+ public boolean removeAll(Collection c) { >+ getterCalled(); >+ return property.removeAll(source, c); >+ } >+ >+ public boolean retainAll(Collection c) { >+ getterCalled(); >+ return property.retainAll(source, c); >+ } >+ >+ public void clear() { >+ getterCalled(); >+ property.clear(source); >+ } >+ >+ 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 (!disposed) { >+ disposed = true; >+ property.removeListChangeListener(source, listener); >+ property = null; >+ source = null; >+ } >+ super.dispose(); >+ } >+} >Index: src/org/eclipse/core/internal/databinding/observable/masterdetail/MapValuePropertyObservableMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/masterdetail/MapValuePropertyObservableMap.java >diff -N src/org/eclipse/core/internal/databinding/observable/masterdetail/MapValuePropertyObservableMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/masterdetail/MapValuePropertyObservableMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,323 @@ >+/******************************************************************************* >+ * 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.observable.masterdetail; >+ >+import java.util.AbstractSet; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.IdentityHashMap; >+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.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class MapValuePropertyObservableMap extends AbstractObservableMap >+ implements IObserving { >+ private IObservableMap map; >+ private IValueProperty property; >+ >+ private Map keyToMasterValueListener; >+ >+ private boolean updating = false; >+ private boolean disposed = false; >+ >+ private IMapChangeListener mapListener = new IMapChangeListener() { >+ public void handleMapChange(final MapChangeEvent event) { >+ if (!updating && !disposed) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ Map oldValues = new HashMap(); >+ Map newValues = new HashMap(); >+ >+ Set addedKeys = event.diff.getAddedKeys(); >+ for (Iterator it = addedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ Object newSource = event.diff.getNewValue(key); >+ Object newValue = property.getValue(newSource); >+ newValues.put(key, newValue); >+ addPropertySourceListener(key, newSource); >+ } >+ >+ Set removedKeys = event.diff.getRemovedKeys(); >+ for (Iterator it = removedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ Object oldSource = event.diff.getOldValue(key); >+ Object oldValue = property.getValue(oldSource); >+ oldValues.put(key, oldValue); >+ removePropertySourceListener(key, oldSource); >+ } >+ >+ Set changedKeys = new HashSet(event.diff >+ .getChangedKeys()); >+ for (Iterator it = changedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ >+ Object oldSource = event.diff.getOldValue(key); >+ Object newSource = event.diff.getNewValue(key); >+ >+ Object oldValue = property.getValue(oldSource); >+ Object newValue = property.getValue(newSource); >+ >+ if (Util.equals(oldValue, newValue)) { >+ it.remove(); >+ } else { >+ oldValues.put(key, oldValue); >+ newValues.put(key, newValue); >+ } >+ >+ removePropertySourceListener(key, oldSource); >+ addPropertySourceListener(key, newSource); >+ } >+ >+ fireMapChange(Diffs.createMapDiff(addedKeys, >+ removedKeys, changedKeys, oldValues, newValues)); >+ } >+ }); >+ } >+ } >+ }; >+ >+ private IStaleListener staleListener = new IStaleListener() { >+ public void handleStale(StaleEvent staleEvent) { >+ fireStale(); >+ } >+ }; >+ >+ /** >+ * @param map >+ * @param valueProperty >+ */ >+ public MapValuePropertyObservableMap(IObservableMap map, >+ IValueProperty valueProperty) { >+ super(map.getRealm()); >+ this.map = map; >+ this.property = valueProperty; >+ >+ this.keyToMasterValueListener = new IdentityHashMap(); >+ } >+ >+ private class ValuePropertySourceChangeListener implements >+ IValuePropertyChangeListener { >+ private final Object key; >+ >+ public ValuePropertySourceChangeListener(Object key) { >+ this.key = key; >+ } >+ >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ Object oldSource = event.diff.getOldValue(); >+ Object oldValue = property.getValue(oldSource); >+ property.removeValueChangeListener(oldSource, this); >+ >+ Object newSource = event.diff.getNewValue(); >+ Object newValue = property.getValue(newSource); >+ property.addValueChangeListener(newSource, this); >+ >+ if (!Util.equals(oldValue, newValue)) >+ fireMapChange(Diffs.createMapDiffSingleChange(key, oldValue, >+ newValue)); >+ } >+ } >+ >+ protected void firstListenerAdded() { >+ if (!disposed) { >+ map.addMapChangeListener(mapListener); >+ map.addStaleListener(staleListener); >+ for (Iterator iterator = map.entrySet().iterator(); iterator >+ .hasNext();) { >+ Map.Entry entry = (Map.Entry) iterator.next(); >+ Object key = entry.getKey(); >+ Object masterValue = entry.getValue(); >+ >+ addPropertySourceListener(key, masterValue); >+ } >+ } >+ } >+ >+ protected void lastListenerRemoved() { >+ if (!disposed) { >+ map.removeMapChangeListener(mapListener); >+ map.removeStaleListener(staleListener); >+ for (Iterator iterator = map.entrySet().iterator(); iterator >+ .hasNext();) { >+ Map.Entry entry = (Map.Entry) iterator.next(); >+ Object key = entry.getKey(); >+ Object propertySource = entry.getValue(); >+ >+ removePropertySourceListener(key, propertySource); >+ } >+ } >+ } >+ >+ private void addPropertySourceListener(Object key, Object propertySource) { >+ IValuePropertyChangeListener propertyListener = new ValuePropertySourceChangeListener( >+ key); >+ property.addValueChangeListener(propertySource, propertyListener); >+ keyToMasterValueListener.put(key, propertyListener); >+ } >+ >+ private void removePropertySourceListener(Object key, Object propertySource) { >+ IValuePropertyChangeListener propertyListener = (IValuePropertyChangeListener) keyToMasterValueListener >+ .remove(key); >+ if (propertyListener != null) { >+ property >+ .removeValueChangeListener(propertySource, propertyListener); >+ } >+ } >+ >+ protected Object doGet(Object key) { >+ if (!map.containsKey(key)) >+ return null; >+ return property.getValue(map.get(key)); >+ } >+ >+ protected Object doPut(Object key, Object value) { >+ if (!map.containsKey(key)) >+ return null; >+ Object source = map.get(key); >+ >+ Object oldValue = property.getValue(source); >+ >+ updating = true; >+ try { >+ property.setValue(source, value); >+ } finally { >+ updating = false; >+ } >+ >+ Object newValue = property.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 = map.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 map.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 map.isStale(); >+ } >+ >+ private void getterCalled() { >+ ObservableTracker.getterCalled(this); >+ } >+ >+ public Object getObserved() { >+ return map; >+ } >+ >+ public synchronized void dispose() { >+ if (!disposed) { >+ disposed = true; >+ property = null; >+ } >+ >+ super.dispose(); >+ } >+} >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,150 @@ >+/******************************************************************************* >+ * 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 java.util.Collection; >+import java.util.HashMap; >+import java.util.Map; >+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.set.ISetProperty; >+import org.eclipse.core.databinding.property.set.ISetPropertyChangeListener; >+import org.eclipse.core.databinding.property.set.SetProperty; >+import org.eclipse.core.databinding.property.set.SetPropertyChangeEvent; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ValuePropertyDetailSet extends SetProperty { >+ private final IValueProperty masterProperty; >+ private final ISetProperty detailProperty; >+ >+ private Map sourceToDetailListener = new HashMap(); >+ >+ private IValuePropertyChangeListener masterListener = new MasterPropertyListener(); >+ >+ private class MasterPropertyListener implements >+ IValuePropertyChangeListener { >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ Object oldSource = event.diff.getOldValue(); >+ Object newSource = event.diff.getNewValue(); >+ >+ Set oldSet = detailProperty.getSet(oldSource); >+ Set newSet = detailProperty.getSet(newSource); >+ SetDiff diff = Diffs.computeSetDiff(oldSet, newSet); >+ >+ Object source = event.getSource(); >+ >+ removeDetailPropertyListener(source); >+ addDetailPropertyListener(source); >+ >+ fireSetChange(source, diff); >+ } >+ } >+ >+ private class DetailPropertyListener implements ISetPropertyChangeListener { >+ private Object source; >+ private Object masterValue; >+ >+ DetailPropertyListener(Object source, Object masterValue) { >+ this.source = source; >+ this.masterValue = masterValue; >+ } >+ >+ public void handleSetPropertyChange(SetPropertyChangeEvent event) { >+ fireSetChange(source, event.diff); >+ } >+ } >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ValuePropertyDetailSet(IValueProperty masterProperty, >+ ISetProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ protected void addListenerTo(Object source) { >+ masterProperty.addValueChangeListener(source, masterListener); >+ addDetailPropertyListener(source); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ masterProperty.removeValueChangeListener(source, masterListener); >+ removeDetailPropertyListener(source); >+ } >+ >+ private void addDetailPropertyListener(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, masterValue); >+ detailProperty.addSetChangeListener(masterValue, detailListener); >+ sourceToDetailListener.put(source, detailListener); >+ } >+ >+ private void removeDetailPropertyListener(Object source) { >+ DetailPropertyListener detailListener = (DetailPropertyListener) sourceToDetailListener >+ .remove(source); >+ if (detailListener != null) { >+ detailProperty.removeSetChangeListener(detailListener.masterValue, >+ detailListener); >+ } >+ sourceToDetailListener.remove(source); >+ } >+ >+ public Set getSet(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.getSet(masterValue); >+ } >+ >+ public boolean add(Object source, Object o) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.add(masterValue, o); >+ } >+ >+ public boolean addAll(Object source, Collection c) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.addAll(masterValue, c); >+ } >+ >+ public void clear(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ detailProperty.clear(masterValue); >+ } >+ >+ public Object getElementType() { >+ return detailProperty.getElementType(); >+ } >+ >+ public boolean remove(Object source, Object o) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.remove(masterValue, o); >+ } >+ >+ public boolean removeAll(Object source, Collection c) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.removeAll(masterValue, c); >+ } >+ >+ public boolean retainAll(Object source, Collection c) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.retainAll(masterValue, c); >+ } >+} >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,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.value; >+ >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.Property; >+ >+/** >+ * Abstract implementation of IValueProperty. >+ * >+ * @since 1.2 >+ */ >+public abstract class ValueProperty extends Property implements IValueProperty { >+ public final void addValueChangeListener(Object source, >+ IValuePropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public final void removeValueChangeListener(Object source, >+ IValuePropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ /** >+ * Fires a ValuePropertyChangeEvent with the given source and diff >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * the value diff >+ */ >+ protected final void fireValueChange(Object source, ValueDiff diff) { >+ firePropertyChange(new ValuePropertyChangeEvent(source, this, diff)); >+ } >+} >Index: src/org/eclipse/core/databinding/property/Properties.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/Properties.java >diff -N src/org/eclipse/core/databinding/property/Properties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/Properties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,200 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.internal.databinding.property.ListPropertyDetailValueList; >+import org.eclipse.core.internal.databinding.property.MapPropertyDetailValueMap; >+import org.eclipse.core.internal.databinding.property.SetPropertyDetailValueMap; >+import org.eclipse.core.internal.databinding.property.ValuePropertyDetailList; >+import org.eclipse.core.internal.databinding.property.ValuePropertyDetailMap; >+import org.eclipse.core.internal.databinding.property.ValuePropertyDetailSet; >+import org.eclipse.core.internal.databinding.property.ValuePropertyDetailValue; >+ >+/** >+ * A factory for chaining properties together to create nested properties. >+ * <p> >+ * Example: Suppose class <code>A</code> has a property <code>b</code> of type >+ * <code>B</code>, and that class <code>B</code> has a property <code>c</code> >+ * of type <code>C</code>: >+ * >+ * <pre> >+ * A a = new A(); >+ * B b = a.getB(); >+ * IValueProperty ab = BeanProperties.valueProperty(A.class, "b"); >+ * assertTrue(ab.getValue(a) == b); >+ * >+ * IValueProperty bc = BeanProperties.valueProperty(B.class, "c"); >+ * C c = b.getC(); >+ * assertTrue(bc.getValue(b) == c); >+ * </pre> >+ * >+ * Using Properties, the <code>ab</code> and <code>bc</code> >+ * properties may be combined to form a nested <code>abc</code> property: >+ * >+ * <pre> >+ * IValueProperty abc = Properties.detailValue(ab, bc) >+ * assertTrue(abc.getValue(a) == c); >+ * </pre> >+ * >+ * @since 1.2 >+ */ >+public class Properties { >+ // Properties of IValueProperty properties >+ >+ /** >+ * Returns the nested combination of the master value and detail value >+ * properties. Value modifications made through the returned property are >+ * delegated to the detail property, using the value of the master property >+ * as the source. >+ * >+ * @param masterValue >+ * the master property >+ * @param detailValue >+ * the detail property >+ * @return the nested combination of the master and detail properties >+ */ >+ public static IValueProperty detailValue(IValueProperty masterValue, >+ IValueProperty detailValue) { >+ return new ValuePropertyDetailValue(masterValue, detailValue); >+ } >+ >+ /** >+ * Returns the nested combination of the master value and detail list >+ * properties. List modifications made through the returned property are >+ * delegated to the detail property, using the value of the master property >+ * as the source. >+ * >+ * @param masterValue >+ * the master property >+ * @param detailList >+ * the detail property >+ * @return the nested combination of the master value and detail list >+ * properties >+ */ >+ public static IListProperty detailList(IValueProperty masterValue, >+ IListProperty detailList) { >+ return new ValuePropertyDetailList(masterValue, detailList); >+ } >+ >+ /** >+ * Returns the nested combination of the master value and detail set >+ * properties. Set modifications made through the returned property are >+ * delegated to the detail property, using the value of the master property >+ * as the source. >+ * >+ * @param masterValue >+ * the master property >+ * @param detailSet >+ * the detail property >+ * @return the nested combination of the master value and detail set >+ * properties >+ */ >+ public static ISetProperty detailSet(IValueProperty masterValue, >+ ISetProperty detailSet) { >+ return new ValuePropertyDetailSet(masterValue, detailSet); >+ } >+ >+ /** >+ * Returns the nested combination of the master value and detail map >+ * properties. Map modifications made through the returned property are >+ * delegated to the detail property, using the value of the master property >+ * as the source. >+ * >+ * @param masterValue >+ * the master property >+ * @param detailMap >+ * the detail property >+ * @return the nested combination of the master value and detial map >+ * properties >+ */ >+ public static IMapProperty detailMap(IValueProperty masterValue, >+ IMapProperty detailMap) { >+ return new ValuePropertyDetailMap(masterValue, detailMap); >+ } >+ >+ // Properties of IListProperty master properties >+ >+ /** >+ * Returns the nested combination of the master list and detail value >+ * properties. Note that because this property is a projection of value >+ * properties over a list, the only modification supported is through the >+ * {@link IValueProperty#setValue(Object, Object)} method. Modifications >+ * made through the returned property are delegated to the detail property, >+ * using the corresponding list element from the master property as the >+ * source. >+ * >+ * @param masterList >+ * the master property >+ * @param detailValue >+ * the detail property >+ * @return the nested combination of the master list and detail value >+ * properties >+ */ >+ public static IListProperty detailValues(IListProperty masterList, >+ IValueProperty detailValue) { >+ return new ListPropertyDetailValueList(masterList, detailValue); >+ } >+ >+ // Properties of ISetProperty master properties >+ >+ /** >+ * Returns the nested combination of the master set and detail value >+ * properties. Note that because this property is a projection of value >+ * properties over a set, the only modifications supported are through the >+ * {@link IMapProperty#put(Object, Object, Object)} and >+ * {@link IMapProperty#putAll(Object, java.util.Map)} methods. In the latter >+ * case, this property does not put entries for keys not already in the >+ * master key set. Modifications made through the returned property are >+ * delegated to the detail property, using the corresponding set element >+ * from the master property as the source. >+ * >+ * @param masterKeySet >+ * the master property >+ * @param detailValues >+ * the detail property >+ * @return the nested combination of the master set and detail value >+ * properties >+ */ >+ public static IMapProperty detailValues(ISetProperty masterKeySet, >+ IValueProperty detailValues) { >+ return new SetPropertyDetailValueMap(masterKeySet, detailValues); >+ } >+ >+ // Properties of IMapProperty master properties >+ >+ /** >+ * Returns the nested combination of the master map and detail value >+ * properties. Note that because this property is a projection of value >+ * properties over a values collection, the only modifications supported are >+ * through the {@link IMapProperty#put(Object, Object, Object)} and >+ * {@link IMapProperty#putAll(Object, java.util.Map)} methods. In the latter >+ * case, this property does not entries for keys not already contained in >+ * the master map's key set. Modifications made through the returned >+ * property are delegated to the detail property, using the corresponding >+ * entry value from the master property as the source. >+ * >+ * @param masterMap >+ * the master property >+ * @param detailValues >+ * the detail property >+ * @return the nested combination of the master map and detail value >+ * properties. >+ */ >+ public static IMapProperty detailValues(IMapProperty masterMap, >+ IValueProperty detailValues) { >+ return new MapPropertyDetailValueMap(masterMap, detailValues); >+ } >+} >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,197 @@ >+/******************************************************************************* >+ * 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 java.util.Map; >+ >+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. >+ */ >+public interface IMapProperty extends IProperty { >+ /** >+ * Returns the element type of the map's key set or <code>null</code> if the >+ * key set is untyped. >+ * >+ * @return the element type of the map's key set or <code>null</code> if the >+ * key set is untyped. >+ */ >+ public Object getKeyType(); >+ >+ /** >+ * Returns the element type of the map's values collection or >+ * <code>null</code> if the collection is untyped. >+ * >+ * @return the element type of the map's values collection or >+ * <code>null</code> if the collection is untyped. >+ */ >+ public Object getValueType(); >+ >+ /** >+ * Returns a Map with the current contents of the source's map property >+ * >+ * @param source >+ * the property source >+ * @return a Map with the current contents of the source's map property >+ */ >+ Map getMap(Object source); >+ >+ /** >+ * Returns the size of the source's map property >+ * >+ * @param source >+ * the property source >+ * @return the size of the source's map property >+ */ >+ int size(Object source); >+ >+ /** >+ * Returns whether the source's map property is empty >+ * >+ * @param source >+ * the property source >+ * @return whether the source's map property is empty >+ */ >+ boolean isEmpty(Object source); >+ >+ /** >+ * Returns whether the specified key is contained in the key set of the >+ * source's map property >+ * >+ * @param source >+ * the property source >+ * @param key >+ * the key >+ * @return whether the specified key is contained in the key set of the >+ * source's map property >+ */ >+ boolean containsKey(Object source, Object key); >+ >+ /** >+ * Returns whether the specified value is contains in the values collection >+ * of the source's map property >+ * >+ * @param source >+ * the property source >+ * @param value >+ * the value >+ * @return whether the specified value is contains in the values collection >+ * of the source's map property >+ */ >+ boolean containsValue(Object source, Object value); >+ >+ /** >+ * Returns the value associated with the specified key in the source's map >+ * property >+ * >+ * @param source >+ * the property source >+ * @param key >+ * the key >+ * @return the value associated with the specified key in the source's map >+ * property >+ */ >+ Object get(Object source, Object key); >+ >+ /** >+ * Associates the specified value with the specified key in the source's map >+ * property >+ * >+ * @param source >+ * the property source >+ * @param key >+ * the key >+ * @param value >+ * the value >+ * @return the value that was previously associated with the given key in >+ * the source's map property >+ */ >+ Object put(Object source, Object key, Object value); >+ >+ /** >+ * Removes the mapping for the specified key from the source's map property >+ * >+ * @param source >+ * the property source >+ * @param key >+ * the key >+ * @return the value that was previously associated with the specified key >+ * in the source's map property, or null if no such mapping exists >+ */ >+ Object remove(Object source, Object key); >+ >+ /** >+ * Adds all mappings in the specified map to the source's map property. >+ * >+ * @param source >+ * the property source >+ * @param t >+ * the map >+ */ >+ void putAll(Object source, Map t); >+ >+ /** >+ * Removes all mapping from the source's map property >+ * >+ * @param source >+ * the property source >+ */ >+ void clear(Object source); >+ >+ /** >+ * Returns whether the source's map property is equal to the argument >+ * >+ * @param source >+ * the property source >+ * @param o >+ * the object to test for equality >+ * @return whether the source's map property is equal to the argument >+ */ >+ boolean equals(Object source, Object o); >+ >+ /** >+ * Returns the hash code of the source's map property >+ * >+ * @param source >+ * the property source >+ * @return the hash code of the source's map property >+ */ >+ int hashCode(Object source); >+ >+ /** >+ * Adds the given map property change listener to the list of listeners for >+ * the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void addMapChangeListener(Object source, >+ IMapPropertyChangeListener listener); >+ >+ /** >+ * Removes the given map property change listener from the list of listeners >+ * for the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void removeMapChangeListener(Object source, >+ IMapPropertyChangeListener listener); >+} >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,231 @@ >+/******************************************************************************* >+ * 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 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.map.MapDiff; >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.core.databinding.property.map.IMapPropertyChangeListener; >+import org.eclipse.core.databinding.property.map.MapProperty; >+import org.eclipse.core.databinding.property.map.MapPropertyChangeEvent; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class MapPropertyDetailValueMap extends MapProperty { >+ private final IMapProperty masterProperty; >+ private final IValueProperty detailProperty; >+ >+ private Map sourceToKeyToDetailListener = new HashMap(); >+ >+ private IMapPropertyChangeListener masterListener = new MasterPropertyListener(); >+ >+ private class MasterPropertyListener implements IMapPropertyChangeListener { >+ public void handleMapPropertyChange(final MapPropertyChangeEvent event) { >+ Object source = event.getSource(); >+ >+ Map oldValues = new HashMap(); >+ Map newValues = new HashMap(); >+ >+ Set addedKeys = event.diff.getAddedKeys(); >+ for (Iterator it = addedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ Object newMasterValue = event.diff.getNewValue(key); >+ Object newDetailValue = detailProperty.getValue(newMasterValue); >+ newValues.put(key, newDetailValue); >+ addPropertySourceListener(source, key, newMasterValue); >+ } >+ >+ Set removedKeys = event.diff.getRemovedKeys(); >+ for (Iterator it = removedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ Object oldMasterValue = event.diff.getOldValue(key); >+ Object oldDetailValue = detailProperty.getValue(oldMasterValue); >+ oldValues.put(key, oldDetailValue); >+ removePropertySourceListener(source, key, oldMasterValue); >+ } >+ >+ Set changedKeys = new HashSet(event.diff.getChangedKeys()); >+ for (Iterator it = changedKeys.iterator(); it.hasNext();) { >+ Object key = it.next(); >+ >+ Object oldMasterValue = event.diff.getOldValue(key); >+ Object newMasterValue = event.diff.getNewValue(key); >+ >+ Object oldDetailValue = detailProperty.getValue(oldMasterValue); >+ Object newDetailValue = detailProperty.getValue(newMasterValue); >+ >+ if (Util.equals(oldDetailValue, newDetailValue)) { >+ it.remove(); >+ } else { >+ oldValues.put(key, oldDetailValue); >+ newValues.put(key, newDetailValue); >+ } >+ >+ removePropertySourceListener(source, key, oldMasterValue); >+ addPropertySourceListener(source, key, newMasterValue); >+ } >+ >+ MapDiff diff = Diffs.createMapDiff(addedKeys, removedKeys, >+ changedKeys, oldValues, newValues); >+ >+ fireMapChange(source, diff); >+ } >+ >+ private void addPropertySourceListener(Object source, Object key, >+ Object masterValue) { >+ Map keyToDetailListener = (Map) sourceToKeyToDetailListener >+ .get(source); >+ if (keyToDetailListener == null) { >+ sourceToKeyToDetailListener.put(source, >+ keyToDetailListener = new HashMap()); >+ } >+ if (!keyToDetailListener.containsKey(key)) { >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, key); >+ detailProperty.addValueChangeListener(masterValue, >+ detailListener); >+ keyToDetailListener.put(key, detailListener); >+ } >+ } >+ >+ private void removePropertySourceListener(Object source, Object key, >+ Object masterValue) { >+ Map keyToDetailListener = (Map) sourceToKeyToDetailListener >+ .get(source); >+ if (keyToDetailListener != null >+ && keyToDetailListener.containsKey(key)) { >+ DetailPropertyListener detailListener = (DetailPropertyListener) keyToDetailListener >+ .remove(key); >+ detailProperty.removeValueChangeListener(masterValue, >+ detailListener); >+ } >+ } >+ } >+ >+ private class DetailPropertyListener implements >+ IValuePropertyChangeListener { >+ private Object source; >+ private Object key; >+ >+ DetailPropertyListener(Object source, Object key) { >+ this.source = source; >+ this.key = key; >+ } >+ >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ fireMapChange(source, Diffs.createMapDiffSingleChange(key, >+ event.diff.getOldValue(), event.diff.getNewValue())); >+ } >+ } >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public MapPropertyDetailValueMap(IMapProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ protected void addListenerTo(Object source) { >+ masterProperty.addMapChangeListener(source, masterListener); >+ >+ Map keyToDetailListener = new HashMap(); >+ for (Iterator it = masterProperty.getMap(source).entrySet().iterator(); it >+ .hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ Object key = entry.getKey(); >+ Object masterValue = entry.getValue(); >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, key); >+ detailProperty.addValueChangeListener(masterValue, detailListener); >+ keyToDetailListener.put(masterValue, detailListener); >+ } >+ >+ sourceToKeyToDetailListener.put(source, keyToDetailListener); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ masterProperty.removeMapChangeListener(source, masterListener); >+ Map masterElementToDetailListener = (Map) sourceToKeyToDetailListener >+ .remove(source); >+ if (masterElementToDetailListener != null) { >+ for (Iterator it = masterElementToDetailListener.entrySet() >+ .iterator(); it.hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ detailProperty.removeValueChangeListener(entry.getKey(), >+ (DetailPropertyListener) entry.getValue()); >+ } >+ } >+ } >+ >+ public Map getMap(Object source) { >+ Map result = new HashMap(); >+ for (Iterator it = masterProperty.getMap(source).entrySet().iterator(); it >+ .hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ result.put(entry.getKey(), detailProperty >+ .getValue(entry.getValue())); >+ } >+ return result; >+ } >+ >+ public void clear(Object source) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object put(Object source, Object key, Object value) { >+ if (!masterProperty.containsKey(source, key)) >+ return null; >+ Object masterValue = masterProperty.get(source, key); >+ >+ Object result = detailProperty.getValue(masterValue); >+ detailProperty.setValue(masterValue, value); >+ return result; >+ } >+ >+ public void putAll(Object source, Map t) { >+ for (Iterator it = t.entrySet().iterator(); it.hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ Object masterKey = entry.getKey(); >+ Object detailValue = entry.getValue(); >+ if (masterProperty.getMap(source).containsKey(masterKey)) { >+ detailProperty.setValue(masterKey, detailValue); >+ } >+ } >+ } >+ >+ public Object remove(Object source, Object key) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object getKeyType() { >+ return masterProperty.getKeyType(); >+ } >+ >+ public Object getValueType() { >+ return detailProperty.getValueType(); >+ } >+} >Index: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailMap.java >diff -N src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailMap.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.core.internal.databinding.property; >+ >+import java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.map.MapDiff; >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.core.databinding.property.map.IMapPropertyChangeListener; >+import org.eclipse.core.databinding.property.map.MapProperty; >+import org.eclipse.core.databinding.property.map.MapPropertyChangeEvent; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ValuePropertyDetailMap extends MapProperty { >+ private final IValueProperty masterProperty; >+ private final IMapProperty detailProperty; >+ >+ private Map sourceToDetailListener = new HashMap(); >+ >+ private IValuePropertyChangeListener masterListener = new MasterValueListener(); >+ >+ private class MasterValueListener implements IValuePropertyChangeListener { >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ Object oldSource = event.diff.getOldValue(); >+ Object newSource = event.diff.getNewValue(); >+ >+ Map oldMap = detailProperty.getMap(oldSource); >+ Map newMap = detailProperty.getMap(newSource); >+ MapDiff diff = Diffs.computeMapDiff(oldMap, newMap); >+ >+ Object source = event.getSource(); >+ >+ removeDetailPropertyListener(source); >+ addDetailPropertyListener(source); >+ >+ fireMapChange(source, diff); >+ } >+ } >+ >+ private class DetailPropertyListener implements IMapPropertyChangeListener { >+ private Object source; >+ private Object masterValue; >+ >+ DetailPropertyListener(Object source, Object masterValue) { >+ this.source = source; >+ this.masterValue = masterValue; >+ } >+ >+ public void handleMapPropertyChange(MapPropertyChangeEvent event) { >+ fireMapChange(source, event.diff); >+ } >+ } >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ValuePropertyDetailMap(IValueProperty masterProperty, >+ IMapProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ protected void addListenerTo(Object source) { >+ masterProperty.addValueChangeListener(source, masterListener); >+ addDetailPropertyListener(source); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ masterProperty.removeValueChangeListener(source, masterListener); >+ removeDetailPropertyListener(source); >+ } >+ >+ private void addDetailPropertyListener(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, masterValue); >+ detailProperty.addMapChangeListener(masterValue, detailListener); >+ sourceToDetailListener.put(source, detailListener); >+ } >+ >+ private void removeDetailPropertyListener(Object source) { >+ DetailPropertyListener detailListener = (DetailPropertyListener) sourceToDetailListener >+ .remove(source); >+ if (detailListener != null) { >+ detailProperty.removeMapChangeListener(detailListener.masterValue, >+ detailListener); >+ } >+ sourceToDetailListener.remove(source); >+ } >+ >+ public Map getMap(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.getMap(masterValue); >+ } >+ >+ public void clear(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ detailProperty.clear(masterValue); >+ } >+ >+ public Object put(Object source, Object key, Object value) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.put(masterValue, key, value); >+ } >+ >+ public void putAll(Object source, Map t) { >+ Object masterValue = masterProperty.getValue(source); >+ detailProperty.putAll(masterValue, t); >+ } >+ >+ public Object remove(Object source, Object key) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.remove(masterValue, key); >+ } >+ >+ public Object getKeyType() { >+ return detailProperty.getKeyType(); >+ } >+ >+ public Object getValueType() { >+ return detailProperty.getValueType(); >+ } >+} >Index: src/org/eclipse/core/databinding/property/value/ValuePropertyChangeEvent.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/ValuePropertyChangeEvent.java >diff -N src/org/eclipse/core/databinding/property/value/ValuePropertyChangeEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/ValuePropertyChangeEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,60 @@ >+/******************************************************************************* >+ * 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.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+import org.eclipse.core.databinding.property.PropertyChangeEvent; >+import org.eclipse.core.runtime.Assert; >+ >+/** >+ * Value change event describing a change of a value property on a particular >+ * property source. >+ * >+ * @since 1.2 >+ */ >+public class ValuePropertyChangeEvent extends PropertyChangeEvent { >+ private static final long serialVersionUID = 1L; >+ >+ /** >+ * The value property that changed >+ */ >+ public final IValueProperty property; >+ >+ /** >+ * ValueDiff with the old and new values of the property. >+ */ >+ public final ValueDiff diff; >+ >+ /** >+ * Constructs a ValuePropertyChangeEvent with the given attributes >+ * >+ * @param source >+ * the property source >+ * @param property >+ * the property that changed on the source >+ * @param diff >+ * a ValueDiff describing the changes to the value property >+ */ >+ public ValuePropertyChangeEvent(Object source, IValueProperty property, >+ ValueDiff diff) { >+ super(source); >+ this.property = property; >+ Assert.isNotNull(diff, "diff cannot be null"); //$NON-NLS-1$ >+ this.diff = diff; >+ } >+ >+ protected void dispatch(IPropertyChangeListener listener) { >+ ((IValuePropertyChangeListener) listener) >+ .handleValuePropertyChange(this); >+ } >+} >Index: src/org/eclipse/core/databinding/property/IProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/IProperty.java >diff -N src/org/eclipse/core/databinding/property/IProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/IProperty.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.core.databinding.property; >+ >+/** >+ * Interface for observing a property of a source object. >+ * >+ * @since 1.2 >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IProperty { >+ /** >+ * Returns whether the property is disposed >+ * @return whether the property is disposed >+ */ >+ public boolean isDisposed(); >+ >+ /** >+ * Disposes the property, removing all property listeners on source objects. >+ */ >+ public void dispose(); >+} >Index: src/org/eclipse/core/internal/databinding/observable/PropertyObservableValue.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/PropertyObservableValue.java >diff -N src/org/eclipse/core/internal/databinding/observable/PropertyObservableValue.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/PropertyObservableValue.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,115 @@ >+/******************************************************************************* >+ * 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.observable; >+ >+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.core.databinding.property.IProperty; >+import org.eclipse.core.databinding.property.IPropertyObservable; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class PropertyObservableValue extends AbstractObservableValue implements >+ IPropertyObservable { >+ private Object source; >+ private IValueProperty property; >+ >+ private boolean updating = false; >+ >+ private boolean disposed = false; >+ >+ private IValuePropertyChangeListener listener = new IValuePropertyChangeListener() { >+ public void handleValuePropertyChange( >+ final ValuePropertyChangeEvent event) { >+ if (!disposed && !updating) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ fireValueChange(event.diff); >+ } >+ }); >+ } >+ } >+ }; >+ >+ /** >+ * @param realm >+ * @param source >+ * @param property >+ */ >+ public PropertyObservableValue(Realm realm, Object source, >+ IValueProperty property) { >+ super(realm); >+ this.source = source; >+ this.property = property; >+ } >+ >+ protected void firstListenerAdded() { >+ if (!disposed) { >+ property.addValueChangeListener(source, listener); >+ } >+ } >+ >+ protected void lastListenerRemoved() { >+ if (!disposed) { >+ property.removeValueChangeListener(source, listener); >+ } >+ } >+ >+ protected Object doGetValue() { >+ return property.getValue(source); >+ } >+ >+ protected void doSetValue(Object value) { >+ Object oldValue = doGetValue(); >+ >+ updating = true; >+ try { >+ property.setValue(source, value); >+ } finally { >+ updating = false; >+ } >+ >+ Object newValue = doGetValue(); >+ if (!Util.equals(oldValue, newValue)) { >+ fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >+ } >+ } >+ >+ public Object getValueType() { >+ return property.getValueType(); >+ } >+ >+ public Object getObserved() { >+ return source; >+ } >+ >+ public IProperty getProperty() { >+ return property; >+ } >+ >+ public synchronized void dispose() { >+ if (!disposed) { >+ disposed = true; >+ property.removeValueChangeListener(source, listener); >+ property = null; >+ source = null; >+ } >+ super.dispose(); >+ } >+} >Index: src/org/eclipse/core/databinding/property/list/SimpleListProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/list/SimpleListProperty.java >diff -N src/org/eclipse/core/databinding/property/list/SimpleListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/list/SimpleListProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,320 @@ >+/******************************************************************************* >+ * 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.list; >+ >+import java.util.ArrayList; >+import java.util.Collection; >+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.list.ListDiff; >+import org.eclipse.core.databinding.observable.list.ListDiffEntry; >+import org.eclipse.core.databinding.property.SimpleProperty; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * Simplified abstract implementation of IListProperty. This class takes care of >+ * most of the functional requirements for an IListProperty implementation, >+ * leaving only the property-specific details to subclasses. >+ * <p> >+ * Subclasses must implement these methods: >+ * <ul> >+ * <li>{@link #getElementType()} >+ * <li>{@link #doGetList(Object)} >+ * <li>{@link #doSetList(Object, List, ListDiff)} >+ * </ul> >+ * Additionally, the following methods should be overridden when the property >+ * source has listener APIs. >+ * <ul> >+ * <li>{@link #doAddListenerTo(Object)} >+ * <li>{@link #doRemoveListenerFrom(Object)} >+ * </ul> >+ * >+ * @since 1.2 >+ */ >+public abstract class SimpleListProperty extends SimpleProperty implements >+ IListProperty { >+ public void addListChangeListener(Object source, >+ IListPropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public void removeListChangeListener(Object source, >+ IListPropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ protected final Object getProperty(Object source) { >+ return doGetList(source); >+ } >+ >+ public boolean contains(Object source, Object o) { >+ return getList(source).contains(o); >+ } >+ >+ public boolean containsAll(Object source, Collection c) { >+ return getList(source).containsAll(c); >+ } >+ >+ public boolean equals(Object source, Object o) { >+ return getList(source).equals(o); >+ } >+ >+ public Object get(Object source, int index) { >+ return getList(source).get(index); >+ } >+ >+ public int hashCode(Object source) { >+ return getList(source).hashCode(); >+ } >+ >+ public int indexOf(Object source, Object o) { >+ return getList(source).indexOf(o); >+ } >+ >+ public boolean isEmpty(Object source) { >+ return getList(source).isEmpty(); >+ } >+ >+ public int lastIndexOf(Object source, Object o) { >+ return getList(source).lastIndexOf(o); >+ } >+ >+ public int size(Object source) { >+ return getList(source).size(); >+ } >+ >+ public Object[] toArray(Object source, Object[] array) { >+ return getList(source).toArray(array); >+ } >+ >+ public Object[] toArray(Object source) { >+ return getList(source).toArray(); >+ } >+ >+ public final List getList(Object source) { >+ List list = doGetList(source); >+ if (hasListeners(source) && !isUpdating(source)) { >+ List cached = (List) getCached(source); >+ if (!Util.equals(list, cached)) { >+ fireListChange(source, Diffs.computeListDiff(cached, list)); >+ } >+ } >+ return list; >+ } >+ >+ /** >+ * Returns a List with the current contents of the source's list property >+ * >+ * @param source >+ * the property source >+ * @return a List with the current contents of the source's list property >+ * @see IListProperty#getList(Object) >+ */ >+ protected abstract List doGetList(Object source); >+ >+ private void setList(Object source, List list, ListDiff diff) { >+ setUpdating(source, true); >+ try { >+ doSetList(source, list, diff); >+ } finally { >+ setUpdating(source, false); >+ } >+ >+ if (hasListeners(source)) { >+ fireListChange(source, diff); >+ } >+ } >+ >+ /** >+ * Updates the property on the source with the specified change. A list >+ * change is fired in the calling method, so implementers do not need to >+ * call {@link #fireListChange(Object, ListDiff)}. >+ * >+ * @param source >+ * the property source >+ * @param list >+ * the new list >+ * @param diff >+ * a diff describing the change >+ */ >+ protected abstract void doSetList(Object source, List list, ListDiff diff); >+ >+ /** >+ * Notifies that the source's property changed. Listeners registered in the >+ * {@link #addListenerTo(Object)} method should call this method when a >+ * property change is observed on the source object. >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * a diff describing the list change. If null, a diff will be >+ * computed from the cached state and the current state. >+ */ >+ protected final void fireListChange(Object source, ListDiff diff) { >+ if (!isUpdating(source) && hasListeners(source)) { >+ if (diff == null) { >+ diff = Diffs.computeListDiff((List) getCached(source), >+ doGetList(source)); >+ } >+ if (!diff.isEmpty()) { >+ firePropertyChange(new ListPropertyChangeEvent(source, this, >+ diff)); >+ } >+ } >+ } >+ >+ public boolean add(Object source, Object o) { >+ add(source, size(source), o); >+ return true; >+ } >+ >+ public void add(Object source, int index, Object element) { >+ List list = new ArrayList(getList(source)); >+ list.add(index, element); >+ setList(source, list, Diffs.createListDiff(Diffs.createListDiffEntry( >+ index, true, element))); >+ } >+ >+ public boolean addAll(Object source, Collection c) { >+ if (c.isEmpty()) >+ return false; >+ addAll(source, size(source), c); >+ return true; >+ } >+ >+ public boolean addAll(Object source, int index, Collection c) { >+ if (c.isEmpty()) { >+ return false; >+ } >+ >+ List list = new ArrayList(getList(source)); >+ List entries = new ArrayList(); >+ int i = index; >+ for (Iterator it = c.iterator(); it.hasNext(); i++) { >+ Object o = it.next(); >+ list.add(i, o); >+ entries.add(Diffs.createListDiffEntry(i, true, o)); >+ } >+ boolean changed = !entries.isEmpty(); >+ if (changed) { >+ ListDiffEntry[] ea = (ListDiffEntry[]) entries >+ .toArray(new ListDiffEntry[entries.size()]); >+ setList(source, list, Diffs.createListDiff(ea)); >+ } >+ return changed; >+ } >+ >+ public void clear(Object source) { >+ if (!isEmpty(source)) { >+ List list = getList(source); >+ ListDiffEntry[] entries = new ListDiffEntry[list.size()]; >+ int i = 0; >+ for (Iterator it = getList(source).iterator(); it.hasNext(); i++) { >+ entries[i] = Diffs.createListDiffEntry(0, false, it.next()); >+ } >+ setList(source, new ArrayList(), Diffs.createListDiff(entries)); >+ } >+ } >+ >+ public Object move(Object source, int oldIndex, int newIndex) { >+ if (oldIndex == newIndex) >+ return get(source, oldIndex); >+ List list = new ArrayList(getList(source)); >+ Object result = list.remove(oldIndex); >+ list.add(newIndex, result); >+ setList(source, list, Diffs.createListDiff(Diffs.createListDiffEntry( >+ oldIndex, false, result), Diffs.createListDiffEntry(newIndex, >+ true, result))); >+ return result; >+ } >+ >+ public boolean remove(Object source, Object o) { >+ int i = indexOf(source, o); >+ if (i == -1) >+ return false; >+ remove(source, i); >+ return true; >+ } >+ >+ public Object remove(Object source, int index) { >+ List list = new ArrayList(getList(source)); >+ Object result = list.remove(index); >+ setList(source, list, Diffs.createListDiff(Diffs.createListDiffEntry( >+ index, false, result))); >+ return result; >+ } >+ >+ public boolean removeAll(Object source, Collection c) { >+ if (isEmpty(source)) { >+ return false; >+ } >+ if (c.isEmpty()) { >+ return false; >+ } >+ List list = new ArrayList(getList(source)); >+ List entries = new ArrayList(); >+ for (ListIterator it = list.listIterator(); it.hasNext();) { >+ Object o = it.next(); >+ if (c.contains(o)) { >+ entries.add(Diffs.createListDiffEntry(it.previousIndex(), >+ false, o)); >+ it.remove(); >+ } >+ } >+ boolean changed = !entries.isEmpty(); >+ if (changed) { >+ ListDiffEntry[] ea = (ListDiffEntry[]) entries >+ .toArray(new ListDiffEntry[entries.size()]); >+ setList(source, list, Diffs.createListDiff(ea)); >+ } >+ return changed; >+ } >+ >+ public boolean retainAll(Object source, Collection c) { >+ if (isEmpty(source)) { >+ return false; >+ } >+ if (c.isEmpty()) { >+ clear(source); >+ return true; >+ } >+ List list = new ArrayList(getList(source)); >+ List entries = new ArrayList(); >+ for (ListIterator it = list.listIterator(); it.hasNext();) { >+ Object o = it.next(); >+ if (!c.contains(o)) { >+ entries.add(Diffs.createListDiffEntry(it.previousIndex(), >+ false, o)); >+ it.remove(); >+ } >+ } >+ boolean changed = !entries.isEmpty(); >+ if (changed) { >+ ListDiffEntry[] ea = (ListDiffEntry[]) entries >+ .toArray(new ListDiffEntry[entries.size()]); >+ setList(source, list, Diffs.createListDiff(ea)); >+ } >+ return changed; >+ } >+ >+ public Object set(Object source, int index, Object element) { >+ List list = new ArrayList(getList(source)); >+ Object result = list.set(index, element); >+ setList(source, list, Diffs.createListDiff(Diffs.createListDiffEntry( >+ index, false, result), Diffs.createListDiffEntry(index, true, >+ element))); >+ return result; >+ } >+} >Index: src/org/eclipse/core/databinding/property/IPropertyObservable.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/IPropertyObservable.java >diff -N src/org/eclipse/core/databinding/property/IPropertyObservable.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/IPropertyObservable.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.databinding.observable.IObserving; >+ >+/** >+ * Provides access to the details of property observables >+ * >+ * @since 1.2 >+ */ >+public interface IPropertyObservable extends IObserving { >+ /** >+ * Returns the property being observed >+ * >+ * @return the property being observed >+ */ >+ IProperty getProperty(); >+} >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,59 @@ >+/******************************************************************************* >+ * 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; >+import org.eclipse.core.runtime.Assert; >+ >+/** >+ * 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. >+ */ >+ 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; >+ Assert.isNotNull(diff, "diff cannot be null"); //$NON-NLS-1$ >+ 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/SimpleProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/SimpleProperty.java >diff -N src/org/eclipse/core/databinding/property/SimpleProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/SimpleProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,152 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.internal.databinding.property.PropertyCache; >+import org.eclipse.core.internal.databinding.property.PropertyUpdateHelper; >+ >+/** >+ * Abstract IProperty implementation which uses property caching and updating >+ * flags to prevent firing duplicate change events. >+ * >+ * @since 1.2 >+ */ >+public abstract class SimpleProperty extends Property { >+ private PropertyCache cache = new PropertyCache(); >+ private PropertyUpdateHelper updateHelper = new PropertyUpdateHelper(); >+ >+ /** >+ * Returns the most recently known value for the given source, or null if no >+ * listeners have been registered for the source >+ * >+ * @param source >+ * the property source >+ * @return the most recently known value for the given source >+ */ >+ protected final Object getCached(Object source) { >+ PropertyCache cache = this.cache; >+ return cache == null ? null : cache.get(source); >+ } >+ >+ protected final void putCache(Object source, Object property) { >+ >+ } >+ >+ /** >+ * Returns whether this property is currently being updated on the source. >+ * Subclasses should query this value to avoid unnecessary calculations, >+ * such as computing a diff. >+ * >+ * @param source >+ * the property source >+ * @return whether this property is currently being updated on the source. >+ */ >+ protected final boolean isUpdating(Object source) { >+ if (!hasListeners(source)) >+ return false; >+ PropertyUpdateHelper updateHelper = this.updateHelper; >+ return updateHelper != null && updateHelper.isUpdating(source); >+ } >+ >+ /** >+ * Sets whether the property is being updated on the specified source >+ * object. Nested calls are accumulated. >+ * >+ * @param source >+ * the property source >+ * @param state >+ * whether the property is being updated >+ */ >+ protected final void setUpdating(Object source, boolean state) { >+ PropertyUpdateHelper updateHelper = this.updateHelper; >+ if (updateHelper != null) >+ updateHelper.setUpdating(source, state); >+ } >+ >+ protected final void addListenerTo(Object source) { >+ PropertyCache cache = this.cache; >+ if (cache != null) { >+ setUpdating(source, true); >+ try { >+ cache.put(source, getProperty(source)); >+ } finally { >+ setUpdating(source, false); >+ } >+ } >+ doAddListenerTo(source); >+ } >+ >+ /** >+ * Adds a property-specific listener to the specified property source. >+ * >+ * @param source >+ * the property source >+ */ >+ protected void doAddListenerTo(Object source) { >+ // Do nothing >+ } >+ >+ protected final void removeListenerFrom(Object source) { >+ doRemoveListenerFrom(source); >+ PropertyCache cache = this.cache; >+ if (cache != null) >+ cache.remove(source); >+ } >+ >+ /** >+ * Removes a listener from the specified property source. >+ * >+ * @param source >+ * the property source >+ */ >+ protected void doRemoveListenerFrom(Object source) { >+ // Do nothing >+ } >+ >+ /** >+ * Returns the current property state (for caching purposes) >+ * >+ * @param source >+ * the property source >+ * @return the current property state (for caching purposes) >+ * @noreference This method is not intended to be referenced by clients. >+ */ >+ protected abstract Object getProperty(Object source); >+ >+ /** >+ * Fires the specified property change event only if the property source is >+ * not currently being updated. >+ * >+ * @see #isUpdating(Object) >+ */ >+ protected void firePropertyChange(PropertyChangeEvent event) { >+ Object source = event.getSource(); >+ if (!isUpdating(source)) { >+ PropertyCache cache = this.cache; >+ if (cache != null) >+ cache.put(source, getProperty(source)); >+ super.firePropertyChange(event); >+ } >+ } >+ >+ public synchronized void dispose() { >+ if (cache != null) { >+ cache.dispose(); >+ cache = null; >+ } >+ if (updateHelper != null) { >+ updateHelper.dispose(); >+ updateHelper = null; >+ } >+ super.dispose(); >+ } >+} >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,91 @@ >+/******************************************************************************* >+ * 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.Collection; >+ >+import org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.property.Property; >+ >+/** >+ * Abstract implementation of IListProperty. >+ * >+ * @since 1.2 >+ */ >+public abstract class ListProperty extends Property implements >+ IListProperty { >+ public boolean contains(Object source, Object o) { >+ return getList(source).contains(o); >+ } >+ >+ public boolean containsAll(Object source, Collection c) { >+ return getList(source).containsAll(c); >+ } >+ >+ public boolean equals(Object source, Object o) { >+ return getList(source).equals(o); >+ } >+ >+ public Object get(Object source, int index) { >+ return getList(source).get(index); >+ } >+ >+ public int hashCode(Object source) { >+ return getList(source).hashCode(); >+ } >+ >+ public int indexOf(Object source, Object o) { >+ return getList(source).indexOf(o); >+ } >+ >+ public boolean isEmpty(Object source) { >+ return getList(source).isEmpty(); >+ } >+ >+ public int lastIndexOf(Object source, Object o) { >+ return getList(source).lastIndexOf(o); >+ } >+ >+ public int size(Object source) { >+ return getList(source).size(); >+ } >+ >+ public Object[] toArray(Object source, Object[] array) { >+ return getList(source).toArray(array); >+ } >+ >+ public Object[] toArray(Object source) { >+ return getList(source).toArray(); >+ } >+ >+ public final void addListChangeListener(Object source, >+ IListPropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public final void removeListChangeListener(Object source, >+ IListPropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ /** >+ * Fires a ListPropertyChangeEvent with the given source and diff >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * the list diff >+ */ >+ protected final void fireListChange(Object source, ListDiff diff) { >+ firePropertyChange(new ListPropertyChangeEvent(source, this, diff)); >+ } >+} >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/ICollectionProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/ICollectionProperty.java >diff -N src/org/eclipse/core/databinding/property/ICollectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/ICollectionProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,186 @@ >+/******************************************************************************* >+ * 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.Collection; >+ >+/** >+ * Interface for collection-typed properties. >+ * >+ * @since 1.2 >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface ICollectionProperty extends IProperty { >+ /** >+ * Returns the size of the source's collection property >+ * >+ * @param source >+ * the property source >+ * @return the size of the source's collection property >+ */ >+ int size(Object source); >+ >+ /** >+ * Returns whether the source's collection property is empty >+ * >+ * @param source >+ * the property source >+ * @return whether the source's collection property is empty >+ */ >+ boolean isEmpty(Object source); >+ >+ /** >+ * 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. >+ */ >+ boolean contains(Object source, Object o); >+ >+ /** >+ * 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 >+ */ >+ Object[] toArray(Object source); >+ >+ /** >+ * 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 >+ */ >+ Object[] toArray(Object source, Object[] array); >+ >+ /** >+ * 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 >+ */ >+ boolean add(Object source, Object o); >+ >+ /** >+ * 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 >+ */ >+ boolean remove(Object source, Object 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 >+ */ >+ boolean containsAll(Object source, Collection c); >+ >+ /** >+ * 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 >+ */ >+ boolean addAll(Object source, Collection c); >+ >+ /** >+ * 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 >+ */ >+ boolean removeAll(Object source, Collection c); >+ >+ /** >+ * 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 >+ */ >+ boolean retainAll(Object source, Collection c); >+ >+ /** >+ * Removes all elements from the source's collection property. >+ * >+ * @param source >+ * the property source >+ */ >+ void clear(Object source); >+ >+ /** >+ * 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 >+ */ >+ boolean equals(Object source, Object 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 >+ */ >+ int hashCode(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 >+ */ >+ Object getElementType(); >+} >Index: src/org/eclipse/core/internal/databinding/observable/masterdetail/SetValuePropertyObservableMap.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/masterdetail/SetValuePropertyObservableMap.java >diff -N src/org/eclipse/core/internal/databinding/observable/masterdetail/SetValuePropertyObservableMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/masterdetail/SetValuePropertyObservableMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,92 @@ >+/******************************************************************************* >+ * 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.observable.masterdetail; >+ >+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.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SetValuePropertyObservableMap extends ComputedObservableMap >+ implements IObserving { >+ private IValueProperty property; >+ >+ private boolean disposed = false; >+ >+ private IValuePropertyChangeListener listener = new IValuePropertyChangeListener() { >+ public void handleValuePropertyChange( >+ final ValuePropertyChangeEvent event) { >+ if (!disposed) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ Object key = event.getSource(); >+ Object oldValue = event.diff.getOldValue(); >+ Object newValue = event.diff.getNewValue(); >+ fireMapChange(Diffs.createMapDiffSingleChange(key, >+ oldValue, newValue)); >+ } >+ }); >+ } >+ } >+ }; >+ >+ /** >+ * @param keySet >+ * @param valueProperty >+ */ >+ public SetValuePropertyObservableMap(IObservableSet keySet, >+ IValueProperty valueProperty) { >+ super(keySet); >+ this.property = valueProperty; >+ } >+ >+ protected Object doGet(Object key) { >+ return property.getValue(key); >+ } >+ >+ protected Object doPut(Object key, Object value) { >+ Object result = property.getValue(key); >+ property.setValue(key, value); >+ return result; >+ } >+ >+ protected void hookListener(Object addedKey) { >+ if (!disposed) >+ property.addValueChangeListener(addedKey, listener); >+ } >+ >+ protected void unhookListener(Object removedKey) { >+ if (!disposed) >+ property.removeValueChangeListener(removedKey, listener); >+ } >+ >+ public Object getObserved() { >+ return keySet(); >+ } >+ >+ public synchronized void dispose() { >+ super.dispose(); >+ >+ if (!disposed) { >+ disposed = true; >+ property = null; >+ listener = null; >+ } >+ } >+} >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/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,72 @@ >+/******************************************************************************* >+ * 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.Property; >+ >+/** >+ * Abstract implementation of IMapProperty >+ * >+ * @since 1.2 >+ */ >+public abstract class MapProperty extends Property implements IMapProperty { >+ public boolean containsKey(Object source, Object key) { >+ return getMap(source).containsKey(key); >+ } >+ >+ public boolean containsValue(Object source, Object value) { >+ return getMap(source).containsValue(value); >+ } >+ >+ public boolean equals(Object source, Object o) { >+ return getMap(source).equals(o); >+ } >+ >+ public Object get(Object source, Object key) { >+ return getMap(source).get(key); >+ } >+ >+ public int hashCode(Object source) { >+ return getMap(source).hashCode(); >+ } >+ >+ public boolean isEmpty(Object source) { >+ return getMap(source).isEmpty(); >+ } >+ >+ public int size(Object source) { >+ return getMap(source).size(); >+ } >+ >+ public final void addMapChangeListener(Object source, >+ IMapPropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public final void removeMapChangeListener(Object source, >+ IMapPropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ /** >+ * Fires a MapPropertyChangeEvent with the given source and diff >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * the map diff >+ */ >+ protected final void fireMapChange(Object source, MapDiff diff) { >+ firePropertyChange(new MapPropertyChangeEvent(source, this, diff)); >+ } >+} >Index: src/org/eclipse/core/databinding/property/PropertyChangeSupport.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/PropertyChangeSupport.java >diff -N src/org/eclipse/core/databinding/property/PropertyChangeSupport.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/PropertyChangeSupport.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,150 @@ >+/******************************************************************************* >+ * 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.HashMap; >+import java.util.Iterator; >+import java.util.Map; >+ >+import org.eclipse.core.internal.databinding.IdentityWrapper; >+import org.eclipse.core.runtime.ListenerList; >+ >+/** >+ * Utility class which maintains a listener list per property source object. >+ * >+ * @since 1.2 >+ */ >+abstract class PropertyChangeSupport { >+ private Map changeListeners; >+ >+ PropertyChangeSupport() { >+ this.changeListeners = null; >+ } >+ >+ /** >+ * Adds the listener to the list of listeners for the specified source >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener to add >+ */ >+ synchronized final void addListener(Object source, >+ IPropertyChangeListener listener) { >+ boolean hadListeners = hasListeners(source); >+ >+ if (changeListeners == null) { >+ changeListeners = new HashMap(); >+ } >+ >+ ListenerList listeners; >+ IdentityWrapper identityWrapper = new IdentityWrapper(source); >+ if (changeListeners.containsKey(identityWrapper)) { >+ listeners = (ListenerList) changeListeners.get(identityWrapper); >+ } else { >+ changeListeners >+ .put(identityWrapper, listeners = new ListenerList()); >+ } >+ >+ listeners.add(listener); >+ >+ if (!hadListeners) { >+ addListenerTo(source); >+ } >+ } >+ >+ /** >+ * Removes the listener from the list of listeners for the specified source >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener to remove >+ */ >+ synchronized final void removeListener(Object source, >+ IPropertyChangeListener listener) { >+ if (changeListeners != null) { >+ IdentityWrapper identityWrapper = new IdentityWrapper(source); >+ ListenerList listeners = (ListenerList) changeListeners >+ .get(identityWrapper); >+ if (listeners != null) { >+ listeners.remove(listener); >+ if (listeners.isEmpty()) { >+ synchronized (listeners) { >+ if (listeners.isEmpty()) { >+ changeListeners.remove(identityWrapper); >+ removeListenerFrom(source); >+ } >+ } >+ } >+ } >+ } >+ } >+ >+ /** >+ * Returns whether the change support has listeners registered for the given >+ * property source >+ * >+ * @param source >+ * the property source >+ * @return whether the change support has listeners registered for the given >+ * property source >+ */ >+ synchronized final boolean hasListeners(Object source) { >+ return changeListeners != null >+ && changeListeners.containsKey(new IdentityWrapper(source)); >+ } >+ >+ protected abstract void addListenerTo(Object source); >+ >+ protected abstract void removeListenerFrom(Object source); >+ >+ private synchronized final Object[] getListeners(Object source) { >+ if (changeListeners == null) >+ return null; >+ ListenerList list = (ListenerList) changeListeners >+ .get(new IdentityWrapper(source)); >+ if (list == null) >+ return null; >+ return list.getListeners(); >+ } >+ >+ /** >+ * Notifies all registered listeners of the specified property change >+ * >+ * @param event >+ * the property change event >+ */ >+ public final void firePropertyChange(PropertyChangeEvent event) { >+ Object[] listeners = getListeners(event.getSource()); >+ if (listeners != null) { >+ for (int i = 0; i < listeners.length; i++) { >+ event.dispatch((IPropertyChangeListener) listeners[i]); >+ } >+ } >+ } >+ >+ /** >+ * Diposes the change support, removing all registered listeners >+ */ >+ public synchronized void dispose() { >+ if (changeListeners != null) { >+ for (Iterator iterator = changeListeners.keySet().iterator(); iterator >+ .hasNext();) { >+ Object source = ((IdentityWrapper) iterator.next()).unwrap(); >+ removeListenerFrom(source); >+ iterator.remove(); >+ } >+ changeListeners = null; >+ } >+ } >+} >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,225 @@ >+/******************************************************************************* >+ * 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 java.util.Collections; >+import java.util.HashMap; >+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.map.MapDiff; >+import org.eclipse.core.databinding.property.map.MapProperty; >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.core.databinding.property.set.ISetPropertyChangeListener; >+import org.eclipse.core.databinding.property.set.SetPropertyChangeEvent; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SetPropertyDetailValueMap extends MapProperty { >+ private final ISetProperty masterProperty; >+ private final IValueProperty detailProperty; >+ >+ private Map sourceToMasterElementToDetailListener = new HashMap(); >+ >+ private ISetPropertyChangeListener masterListener = new MasterPropertyListener(); >+ >+ private class MasterPropertyListener implements ISetPropertyChangeListener { >+ public void handleSetPropertyChange(final SetPropertyChangeEvent event) { >+ Object source = event.getSource(); >+ >+ MapDiff diff; >+ if (event.diff == null) { >+ diff = null; >+ } else { >+ final Set removals = event.diff.getRemovals(); >+ final Set additions = event.diff.getAdditions(); >+ >+ diff = new MapDiff() { >+ public Set getAddedKeys() { >+ return additions; >+ } >+ >+ public Set getChangedKeys() { >+ return Collections.EMPTY_SET; >+ } >+ >+ public Object getNewValue(Object key) { >+ return getValue(key); >+ } >+ >+ public Object getOldValue(Object key) { >+ return getValue(key); >+ } >+ >+ private Object getValue(Object key) { >+ return detailProperty.getValue(key); >+ } >+ >+ public Set getRemovedKeys() { >+ return removals; >+ } >+ }; >+ >+ for (Iterator it = removals.iterator(); it.hasNext();) { >+ removeElementPropertyListener(source, it.next()); >+ } >+ for (Iterator it = additions.iterator(); it.hasNext();) { >+ addElementPropertyListener(source, it.next()); >+ } >+ } >+ >+ fireMapChange(source, diff); >+ } >+ >+ private void addElementPropertyListener(Object source, Object element) { >+ Map elementToDetailListener = (Map) sourceToMasterElementToDetailListener >+ .get(source); >+ if (elementToDetailListener == null) { >+ sourceToMasterElementToDetailListener.put(source, >+ elementToDetailListener = new HashMap()); >+ } >+ if (!elementToDetailListener.containsKey(element)) { >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, element); >+ detailProperty.addValueChangeListener(element, detailListener); >+ elementToDetailListener.put(element, detailListener); >+ } >+ } >+ >+ private void removeElementPropertyListener(Object source, Object element) { >+ Map elementToDetailListener = (Map) sourceToMasterElementToDetailListener >+ .get(source); >+ if (elementToDetailListener != null >+ && elementToDetailListener.containsKey(element)) { >+ DetailPropertyListener detailListener = (DetailPropertyListener) elementToDetailListener >+ .remove(element); >+ detailProperty.removeValueChangeListener(element, >+ detailListener); >+ } >+ } >+ } >+ >+ private class DetailPropertyListener implements >+ IValuePropertyChangeListener { >+ private Object source; >+ private Object masterValue; >+ >+ DetailPropertyListener(Object source, Object masterValue) { >+ this.source = source; >+ this.masterValue = masterValue; >+ } >+ >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ MapDiff diff; >+ if (event.diff == null) { >+ diff = null; >+ } else { >+ diff = Diffs.createMapDiffSingleChange(masterValue, event.diff >+ .getOldValue(), event.diff.getNewValue()); >+ } >+ fireMapChange(source, diff); >+ } >+ } >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public SetPropertyDetailValueMap(ISetProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ protected void addListenerTo(Object source) { >+ masterProperty.addSetChangeListener(source, masterListener); >+ >+ Map masterElementToDetailListener = new HashMap(); >+ for (Iterator it = masterProperty.getSet(source).iterator(); it >+ .hasNext();) { >+ Object masterElement = it.next(); >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, masterElement); >+ detailProperty >+ .addValueChangeListener(masterElement, detailListener); >+ masterElementToDetailListener.put(masterElement, detailListener); >+ } >+ >+ sourceToMasterElementToDetailListener.put(source, >+ masterElementToDetailListener); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ masterProperty.removeSetChangeListener(source, masterListener); >+ Map masterElementToDetailListener = (Map) sourceToMasterElementToDetailListener >+ .remove(source); >+ if (masterElementToDetailListener != null) { >+ for (Iterator it = masterElementToDetailListener.entrySet() >+ .iterator(); it.hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ detailProperty.removeValueChangeListener(entry.getKey(), >+ (DetailPropertyListener) entry.getValue()); >+ } >+ } >+ } >+ >+ public Map getMap(Object source) { >+ Map result = new HashMap(); >+ for (Iterator it = masterProperty.getSet(source).iterator(); it >+ .hasNext();) { >+ Object element = it.next(); >+ result.put(element, detailProperty.getValue(element)); >+ } >+ return result; >+ } >+ >+ public void clear(Object source) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object put(Object source, Object key, Object value) { >+ if (!masterProperty.contains(source, key)) >+ return null; >+ Object result = detailProperty.getValue(key); >+ detailProperty.setValue(key, value); >+ return result; >+ } >+ >+ public void putAll(Object source, Map t) { >+ Set masterSet = masterProperty.getSet(source); >+ for (Iterator it = t.entrySet().iterator(); it.hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ if (masterSet.contains(entry.getKey())) { >+ detailProperty.setValue(entry.getKey(), entry.getValue()); >+ } >+ } >+ } >+ >+ public Object remove(Object source, Object key) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object getKeyType() { >+ return masterProperty.getElementType(); >+ } >+ >+ public Object getValueType() { >+ return detailProperty.getValueType(); >+ } >+} >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,79 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.core.databinding.property.Property; >+ >+/** >+ * Abstract implementation of ISetProperty >+ * >+ * @since 1.2 >+ */ >+public abstract class SetProperty extends Property implements >+ ISetProperty { >+ public boolean contains(Object source, Object o) { >+ return getSet(source).contains(o); >+ } >+ >+ public boolean containsAll(Object source, Collection c) { >+ return getSet(source).containsAll(c); >+ } >+ >+ public boolean equals(Object source, Object o) { >+ return getSet(source).equals(o); >+ } >+ >+ public int hashCode(Object source) { >+ return getSet(source).hashCode(); >+ } >+ >+ public boolean isEmpty(Object source) { >+ return getSet(source).isEmpty(); >+ } >+ >+ public int size(Object source) { >+ return getSet(source).size(); >+ } >+ >+ public Object[] toArray(Object source, Object[] array) { >+ return getSet(source).toArray(array); >+ } >+ >+ public Object[] toArray(Object source) { >+ return getSet(source).toArray(); >+ } >+ >+ public final void addSetChangeListener(Object source, >+ ISetPropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public final void removeSetChangeListener(Object source, >+ ISetPropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ /** >+ * Fires a SetPropertyChangeEvent with the given source and diff >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * the set diff >+ */ >+ protected final void fireSetChange(Object source, SetDiff diff) { >+ firePropertyChange(new SetPropertyChangeEvent(source, this, diff)); >+ } >+} >Index: src/org/eclipse/core/databinding/property/value/SimpleValueProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/value/SimpleValueProperty.java >diff -N src/org/eclipse/core/databinding/property/value/SimpleValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/value/SimpleValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,133 @@ >+/******************************************************************************* >+ * 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.value; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.SimpleProperty; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * Simplified abstract implementation of IValueProperty. This class takes care >+ * of most of the functional requirements for an IValueProperty implementation, >+ * leaving only the property-specific details to subclasses. >+ * <p> >+ * Subclasses must implement these methods: >+ * <ul> >+ * <li>{@link #getValueType()} >+ * <li>{@link #doGetValue(Object)} >+ * <li>{@link #doSetValue(Object, Object, ValueDiff)} >+ * </ul> >+ * Additionally, the following methods should be overridden when the property >+ * source has listener APIs. >+ * <ul> >+ * <li>{@link #doAddListenerTo(Object)} >+ * <li>{@link #doRemoveListenerFrom(Object)} >+ * </ul> >+ * >+ * @since 1.2 >+ */ >+public abstract class SimpleValueProperty extends SimpleProperty implements >+ IValueProperty { >+ public void addValueChangeListener(Object source, >+ IValuePropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public void removeValueChangeListener(Object source, >+ IValuePropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ protected final Object getProperty(Object source) { >+ return doGetValue(source); >+ } >+ >+ public final void setValue(Object source, Object value) { >+ Object oldValue = getCached(source); >+ >+ setUpdating(source, true); >+ try { >+ doSetValue(source, value, Diffs.createValueDiff(oldValue, value)); >+ } finally { >+ setUpdating(source, false); >+ } >+ >+ if (hasListeners(source)) { >+ Object newValue = doGetValue(source); >+ if (!Util.equals(oldValue, newValue)) { >+ fireValueChange(source, Diffs.createValueDiff(oldValue, >+ newValue)); >+ } >+ } >+ } >+ >+ /** >+ * Updates the property on the source with the specified change. A value >+ * change event is fired in the calling method, so implementers do not need >+ * to call {@link #fireValueChange(Object, ValueDiff)}. >+ * >+ * @param source >+ * the property source >+ * @param value >+ * the new value >+ * @param diff >+ * a diff describing the change >+ */ >+ protected abstract void doSetValue(Object source, Object value, >+ ValueDiff diff); >+ >+ public final Object getValue(Object source) { >+ Object value = doGetValue(source); >+ if (hasListeners(source) && !isUpdating(source)) { >+ Object cached = getCached(source); >+ if (!Util.equals(value, cached)) { >+ fireValueChange(source, Diffs.createValueDiff(cached, value)); >+ } >+ } >+ return value; >+ } >+ >+ /** >+ * Returns the current property value >+ * >+ * @param source >+ * the property source >+ * @return the current property value >+ * @see IValueProperty#getValue(Object) >+ */ >+ protected abstract Object doGetValue(Object source); >+ >+ /** >+ * Notifies that the source's property changed. Listeners registered in the >+ * {@link #addListenerTo(Object)} method should call this method when a >+ * property change is observed on the source object. >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * a diff describing the value change. If null, a diff will be >+ * created from the cached value and the current value. >+ */ >+ protected final void fireValueChange(Object source, ValueDiff diff) { >+ if (!isUpdating(source) && hasListeners(source)) { >+ if (diff == null) { >+ diff = Diffs.createValueDiff(getCached(source), >+ doGetValue(source)); >+ } >+ if (!Util.equals(diff.getOldValue(), diff.getNewValue())) { >+ firePropertyChange(new ValuePropertyChangeEvent(source, this, >+ diff)); >+ } >+ } >+ } >+} >Index: src/org/eclipse/core/databinding/property/PropertyObservables.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/PropertyObservables.java >diff -N src/org/eclipse/core/databinding/property/PropertyObservables.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/PropertyObservables.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,375 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.databinding.observable.IObservable; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; >+import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.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.observable.PropertyObservableList; >+import org.eclipse.core.internal.databinding.observable.PropertyObservableMap; >+import org.eclipse.core.internal.databinding.observable.PropertyObservableSet; >+import org.eclipse.core.internal.databinding.observable.PropertyObservableValue; >+import org.eclipse.core.internal.databinding.observable.masterdetail.ListValuePropertyObservableList; >+import org.eclipse.core.internal.databinding.observable.masterdetail.MapValuePropertyObservableMap; >+import org.eclipse.core.internal.databinding.observable.masterdetail.SetValuePropertyObservableMap; >+ >+/** >+ * A factory for creating observables observing properties of source objects >+ * >+ * @since 1.2 >+ */ >+public class PropertyObservables { >+ /** >+ * Returns an observable value on the default realm that tracks the given >+ * property of the source object. >+ * >+ * @param source >+ * the property value >+ * @param property >+ * the value property to observe >+ * @return an observable value on the default realm that tracks the given >+ * property of the source object. >+ * @since 1.2 >+ */ >+ public static IObservableValue observeValue(Object source, >+ IValueProperty property) { >+ return observeValue(Realm.getDefault(), source, property); >+ } >+ >+ /** >+ * Returns an observable value on the given realm that tracks the given >+ * property of the source object >+ * >+ * @param realm >+ * the realm >+ * @param source >+ * the property source >+ * @param property >+ * the value property observe >+ * @return an observable value that tracks the given property of the source >+ * object >+ * @since 1.2 >+ */ >+ public static IObservableValue observeValue(Realm realm, Object source, >+ IValueProperty property) { >+ return new PropertyObservableValue(realm, source, property); >+ } >+ >+ /** >+ * Returns a factory for creating observable values on the default realm >+ * tracking the given property of a particular source object >+ * >+ * @param property >+ * the property to observe >+ * @return a factory for creating observable values on the default realm >+ * tracking the given property of a particular source object >+ */ >+ public static IObservableFactory valueFactory(IValueProperty property) { >+ return valueFactory(Realm.getDefault(), property); >+ } >+ >+ /** >+ * Returns a factory for creating observable values on the given realm >+ * tracking the given property of a particular source object >+ * >+ * @param realm >+ * the realm >+ * @param property >+ * the property to observe >+ * @return a factory for creating observable values on the given realm >+ * tracking the given property of a particular source object >+ */ >+ public static IObservableFactory valueFactory(final Realm realm, >+ final IValueProperty property) { >+ return new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return observeValue(realm, target, property); >+ } >+ }; >+ } >+ >+ /** >+ * Returns an observable value on the master observable's realm which tracks >+ * the given property of the current value of <code>master</code>. >+ * >+ * @param master >+ * the master observable >+ * @param property >+ * the property to observe >+ * @return an observable value which tracks the given property of the >+ * current value of <code>master</code>. >+ */ >+ public static IObservableValue observeDetailValue(IObservableValue master, >+ IValueProperty property) { >+ return MasterDetailObservables.detailValue(master, valueFactory(master >+ .getRealm(), property), property.getValueType()); >+ } >+ >+ /** >+ * Returns an observable set on the default realm that tracks the given >+ * property of the source object >+ * >+ * @param source >+ * the property source >+ * @param property >+ * the property to observe >+ * @return an observable set on the default realm that tracks the given >+ * property of the source object >+ */ >+ public static IObservableSet observeSet(Object source, ISetProperty property) { >+ return observeSet(Realm.getDefault(), source, property); >+ } >+ >+ /** >+ * Returns an observable set on the given realm that tracks the given >+ * property of the source object >+ * >+ * @param realm >+ * the realm >+ * @param source >+ * the property source >+ * @param property >+ * the property to observe >+ * @return an observable set on the given realm that tracks the given >+ * property of the source object >+ */ >+ public static IObservableSet observeSet(Realm realm, Object source, >+ ISetProperty property) { >+ return new PropertyObservableSet(realm, source, property); >+ } >+ >+ /** >+ * Returns a factory for creating observable sets on the default realm >+ * tracking the given property of a particular source object >+ * >+ * @param property >+ * the property to be observed >+ * @return a factory for creating observable sets on the default realm >+ * tracking the given property of a particular source object >+ */ >+ public static IObservableFactory setFactory(ISetProperty property) { >+ return setFactory(Realm.getDefault(), property); >+ } >+ >+ /** >+ * Returns a factory for creating obervable sets on the given realm tracking >+ * the given property of a particular source object >+ * >+ * @param realm >+ * the realm >+ * @param property >+ * the property to be observed >+ * @return a factory for creating obervable sets on the given realm tracking >+ * the given property of a particular source object >+ */ >+ public static IObservableFactory setFactory(final Realm realm, >+ final ISetProperty property) { >+ return new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return observeSet(realm, target, property); >+ } >+ }; >+ } >+ >+ /** >+ * Returns an observable set on the master observable's realm which tracks >+ * the given property of the current value of <code>master</code>. >+ * >+ * @param master >+ * the master observable >+ * @param property >+ * the property to observe >+ * @return an observable set on the given realm which tracks the given >+ * property of the current value of <code>master</code>. >+ */ >+ public static IObservableSet observeDetailSet(IObservableValue master, >+ ISetProperty property) { >+ return MasterDetailObservables.detailSet(master, setFactory(master >+ .getRealm(), property), property.getElementType()); >+ } >+ >+ /** >+ * Returns an observable list on the default realm that tracks the given >+ * property of the source object >+ * >+ * @param source >+ * the property source >+ * @param property >+ * the property to observe >+ * @return an observable list on the default realm that tracks the given >+ * property of the source object >+ */ >+ public static IObservableList observeList(Object source, >+ IListProperty property) { >+ return observeList(Realm.getDefault(), source, property); >+ } >+ >+ /** >+ * Returns an observable list on the given realm that tracks the given >+ * property of the source object >+ * >+ * @param realm >+ * the realm >+ * @param source >+ * the property source >+ * @param property >+ * the property to observe >+ * @return an observable list on the given realm that tracks the given >+ * property of the source object >+ */ >+ public static IObservableList observeList(Realm realm, Object source, >+ IListProperty property) { >+ return new PropertyObservableList(realm, source, property); >+ } >+ >+ /** >+ * Returns a factory for creating observable lists on the default realm >+ * tracking the given property of a particular source object >+ * >+ * @param property >+ * the property to be observed >+ * @return an observable value factory on >+ */ >+ public static IObservableFactory listFactory(IListProperty property) { >+ return listFactory(Realm.getDefault(), property); >+ } >+ >+ /** >+ * Returns a factory for creating obervable lists on the given realm >+ * tracking the given property of a particular source object >+ * >+ * @param realm >+ * the realm >+ * @param property >+ * the property to be observed >+ * @return an observable value factory on >+ */ >+ public static IObservableFactory listFactory(final Realm realm, >+ final IListProperty property) { >+ return new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return observeList(realm, target, property); >+ } >+ }; >+ } >+ >+ /** >+ * Returns an observable list on the master observable's realm which tracks >+ * the given property of the current value of <code>master</code>. >+ * >+ * @param master >+ * the master observable >+ * @param property >+ * the property to observe >+ * @return an observable list on the given realm which tracks the given >+ * property of the current value of <code>master</code>. >+ */ >+ public static IObservableList observeDetailList(IObservableValue master, >+ IListProperty property) { >+ return MasterDetailObservables.detailList(master, listFactory(master >+ .getRealm(), property), property.getElementType()); >+ } >+ >+ /** >+ * Returns an observable list on the master observable's realm which tracks >+ * the given property of each element of <code>master</code>. >+ * >+ * @param master >+ * the master observable >+ * @param property >+ * the property to observe on each element in the master >+ * observable >+ * @return an observable >+ */ >+ public static IObservableList observeDetailValues(IObservableList master, >+ IValueProperty property) { >+ return new ListValuePropertyObservableList(master, property); >+ } >+ >+ /** >+ * Returns an observable map on the default realm which tracks the given >+ * property of the source object >+ * >+ * @param source >+ * the property source >+ * @param property >+ * the property to observe >+ * @return an observable map on the default realm which tracks the given >+ * property of the source object >+ */ >+ public static IObservableMap observeMap(Object source, IMapProperty property) { >+ return observeMap(Realm.getDefault(), source, property); >+ } >+ >+ /** >+ * Returns an observable map on the given realm which tracks the given >+ * property of the source object >+ * >+ * @param realm >+ * the realm >+ * @param source >+ * the property source >+ * @param property >+ * the property to observe >+ * @return an observable map on the given realm which tracks the given >+ * property of the source object >+ */ >+ public static IObservableMap observeMap(Realm realm, Object source, >+ IMapProperty property) { >+ return new PropertyObservableMap(realm, source, property); >+ } >+ >+ /** >+ * Returns an observable map on the master observable's realm tracking the >+ * current values of the given property for the elements in the given set. >+ * >+ * @param keySet >+ * the master observable >+ * @param valueProperty >+ * the property to observe on each element of the master >+ * observable >+ * @return an observable map that tracks the current value of the given >+ * property for the elements in the given set. >+ */ >+ public static IObservableMap observeDetailValues(IObservableSet keySet, >+ IValueProperty valueProperty) { >+ return new SetValuePropertyObservableMap(keySet, valueProperty); >+ } >+ >+ /** >+ * Returns an observable map on the master observable's realm which tracks >+ * the current values of the given property for the entry values in the >+ * given map. >+ * >+ * @param map >+ * the master observable >+ * @param valueProperty >+ * the property to observe on each entry value in the master >+ * observable >+ * @return an observable map on the master observable's realm which tracks >+ * the current value of the given property for the elements in the >+ * given map's values collection >+ */ >+ public static IObservableMap observeDetailValues(IObservableMap map, >+ IValueProperty valueProperty) { >+ return new MapValuePropertyObservableMap(map, valueProperty); >+ } >+} >Index: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailList.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailList.java >diff -N src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailList.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/ValuePropertyDetailList.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,173 @@ >+/******************************************************************************* >+ * 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 java.util.Collection; >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.list.IListPropertyChangeListener; >+import org.eclipse.core.databinding.property.list.ListProperty; >+import org.eclipse.core.databinding.property.list.ListPropertyChangeEvent; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ValuePropertyDetailList extends ListProperty { >+ private final IValueProperty masterProperty; >+ private final IListProperty detailProperty; >+ >+ private Map sourceToDetailListener = new HashMap(); >+ >+ private IValuePropertyChangeListener masterListener = new MasterPropertyListener(); >+ >+ private class MasterPropertyListener implements >+ IValuePropertyChangeListener { >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ Object oldSource = event.diff.getOldValue(); >+ Object newSource = event.diff.getNewValue(); >+ >+ List oldList = detailProperty.getList(oldSource); >+ List newList = detailProperty.getList(newSource); >+ >+ Object source = event.getSource(); >+ >+ removeDetailPropertyListener(source); >+ addDetailPropertyListener(source); >+ >+ fireListChange(source, Diffs.computeListDiff(oldList, newList)); >+ } >+ } >+ >+ private class DetailPropertyListener implements IListPropertyChangeListener { >+ private Object source; >+ private Object masterValue; >+ >+ DetailPropertyListener(Object source, Object masterValue) { >+ this.source = source; >+ this.masterValue = masterValue; >+ } >+ >+ public void handleListPropertyChange(ListPropertyChangeEvent event) { >+ fireListChange(source, event.diff); >+ } >+ } >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ValuePropertyDetailList(IValueProperty masterProperty, >+ IListProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ protected void addListenerTo(Object source) { >+ masterProperty.addValueChangeListener(source, masterListener); >+ addDetailPropertyListener(source); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ masterProperty.removeValueChangeListener(source, masterListener); >+ removeDetailPropertyListener(source); >+ } >+ >+ private void addDetailPropertyListener(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, masterValue); >+ detailProperty.addListChangeListener(masterValue, detailListener); >+ sourceToDetailListener.put(source, detailListener); >+ } >+ >+ private void removeDetailPropertyListener(Object source) { >+ DetailPropertyListener detailListener = (DetailPropertyListener) sourceToDetailListener >+ .remove(source); >+ if (detailListener != null) { >+ detailProperty.removeListChangeListener(detailListener.masterValue, >+ detailListener); >+ } >+ sourceToDetailListener.remove(source); >+ } >+ >+ public List getList(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.getList(masterValue); >+ } >+ >+ public boolean add(Object source, Object o) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.add(masterValue, o); >+ } >+ >+ public boolean addAll(Object source, Collection c) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.addAll(masterValue, c); >+ } >+ >+ public void clear(Object source) { >+ Object masterValue = masterProperty.getValue(source); >+ detailProperty.clear(masterValue); >+ } >+ >+ public Object getElementType() { >+ return detailProperty.getElementType(); >+ } >+ >+ public boolean remove(Object source, Object o) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.remove(masterValue, o); >+ } >+ >+ public boolean removeAll(Object source, Collection c) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.removeAll(masterValue, c); >+ } >+ >+ public boolean retainAll(Object source, Collection c) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.retainAll(masterValue, c); >+ } >+ >+ public void add(Object source, int index, Object element) { >+ Object masterValue = masterProperty.getValue(source); >+ detailProperty.add(masterValue, index, element); >+ } >+ >+ public boolean addAll(Object source, int index, Collection c) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.addAll(masterValue, index, c); >+ } >+ >+ public Object move(Object source, int oldIndex, int newIndex) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.move(masterValue, oldIndex, newIndex); >+ } >+ >+ public Object remove(Object source, int index) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.remove(masterValue, index); >+ } >+ >+ public Object set(Object source, int index, Object element) { >+ Object masterValue = masterProperty.getValue(source); >+ return detailProperty.set(masterValue, index, element); >+ } >+} >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,259 @@ >+/******************************************************************************* >+ * 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 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.list.ListDiff; >+import org.eclipse.core.databinding.observable.list.ListDiffEntry; >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.list.IListPropertyChangeListener; >+import org.eclipse.core.databinding.property.list.ListProperty; >+import org.eclipse.core.databinding.property.list.ListPropertyChangeEvent; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ListPropertyDetailValueList extends ListProperty { >+ private final IListProperty masterProperty; >+ private final IValueProperty detailProperty; >+ >+ private Map sourceToMasterElementToDetailListener = new HashMap(); >+ >+ private IListPropertyChangeListener masterListener = new MasterPropertyListener(); >+ >+ private class MasterPropertyListener implements IListPropertyChangeListener { >+ public void handleListPropertyChange(ListPropertyChangeEvent event) { >+ Object source = event.getSource(); >+ ListDiffEntry[] masterEntries = event.diff.getDifferences(); >+ ListDiffEntry[] detailEntries = new ListDiffEntry[masterEntries.length]; >+ Set masterElementsAdded = new HashSet(); >+ Set masterElementsRemoved = new HashSet(); >+ 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); >+ if (addition) >+ masterElementsAdded.add(masterElement); >+ else >+ masterElementsRemoved.add(masterElement); >+ } >+ >+ ListDiff diff = Diffs.createListDiff(detailEntries); >+ >+ for (Iterator it = masterElementsRemoved.iterator(); it.hasNext();) { >+ Object element = it.next(); >+ if (!masterProperty.contains(source, element)) >+ removeElementPropertyListener(source, element); >+ } >+ for (Iterator it = masterElementsAdded.iterator(); it.hasNext();) { >+ Object element = it.next(); >+ if (masterProperty.contains(source, element)) >+ addElementPropertyListener(source, element); >+ } >+ >+ fireListChange(source, diff); >+ } >+ >+ private void addElementPropertyListener(Object source, Object element) { >+ Map elementToDetailListener = (Map) sourceToMasterElementToDetailListener >+ .get(source); >+ if (elementToDetailListener == null) { >+ sourceToMasterElementToDetailListener.put(source, >+ elementToDetailListener = new HashMap()); >+ } >+ if (!elementToDetailListener.containsKey(element)) { >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, element); >+ detailProperty.addValueChangeListener(element, detailListener); >+ elementToDetailListener.put(element, detailListener); >+ } >+ } >+ >+ private void removeElementPropertyListener(Object source, Object element) { >+ Map elementToDetailListener = (Map) sourceToMasterElementToDetailListener >+ .get(source); >+ if (elementToDetailListener != null >+ && elementToDetailListener.containsKey(element)) { >+ DetailPropertyListener detailListener = (DetailPropertyListener) elementToDetailListener >+ .remove(element); >+ detailProperty.removeValueChangeListener(element, >+ detailListener); >+ } >+ } >+ } >+ >+ private class DetailPropertyListener implements >+ IValuePropertyChangeListener { >+ private Object source; >+ private Object masterElement; >+ >+ DetailPropertyListener(Object source, Object masterElement) { >+ this.source = source; >+ this.masterElement = masterElement; >+ } >+ >+ private int[] findIndices() { >+ List indices = new ArrayList(); >+ >+ List list = masterProperty.getList(source); >+ for (ListIterator it = list.listIterator(); it.hasNext();) { >+ if (Util.equals(masterElement, 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; >+ } >+ >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event) { >+ int[] indices = findIndices(); >+ 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); >+ fireListChange(source, diff); >+ } >+ } >+ >+ /** >+ * @param masterProperty >+ * @param detailProperty >+ */ >+ public ListPropertyDetailValueList(IListProperty masterProperty, >+ IValueProperty detailProperty) { >+ this.masterProperty = masterProperty; >+ this.detailProperty = detailProperty; >+ } >+ >+ protected void addListenerTo(Object source) { >+ masterProperty.addListChangeListener(source, masterListener); >+ >+ Map masterElementToDetailListener = new HashMap(); >+ for (Iterator it = masterProperty.getList(source).iterator(); it >+ .hasNext();) { >+ Object masterElement = it.next(); >+ DetailPropertyListener detailListener = new DetailPropertyListener( >+ source, masterElement); >+ detailProperty >+ .addValueChangeListener(masterElement, detailListener); >+ masterElementToDetailListener.put(masterElement, detailListener); >+ } >+ >+ sourceToMasterElementToDetailListener.put(source, >+ masterElementToDetailListener); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ masterProperty.removeListChangeListener(source, masterListener); >+ Map masterElementToDetailListener = (Map) sourceToMasterElementToDetailListener >+ .remove(source); >+ if (masterElementToDetailListener != null) { >+ for (Iterator it = masterElementToDetailListener.entrySet() >+ .iterator(); it.hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ detailProperty.removeValueChangeListener(entry.getKey(), >+ (DetailPropertyListener) entry.getValue()); >+ } >+ } >+ } >+ >+ public List getList(Object source) { >+ List result = new ArrayList(); >+ for (Iterator it = masterProperty.getList(source).iterator(); it >+ .hasNext();) { >+ result.add(detailProperty.getValue(it.next())); >+ } >+ return result; >+ } >+ >+ public boolean add(Object source, Object o) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean addAll(Object source, Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public void clear(Object source) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object getElementType() { >+ return detailProperty.getValueType(); >+ } >+ >+ public boolean remove(Object source, Object o) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean removeAll(Object source, Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean retainAll(Object source, Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public void add(Object source, int index, Object element) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public boolean addAll(Object source, int index, Collection c) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object move(Object source, int oldIndex, int newIndex) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object remove(Object source, int index) { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public Object set(Object source, int index, Object element) { >+ Object masterElement = masterProperty.get(source, index); >+ Object result = detailProperty.getValue(masterElement); >+ detailProperty.setValue(masterElement, element); >+ return result; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/property/PropertyCache.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/PropertyCache.java >diff -N src/org/eclipse/core/internal/databinding/property/PropertyCache.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/PropertyCache.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,65 @@ >+/******************************************************************************* >+ * 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 java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.core.internal.databinding.IdentityWrapper; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class PropertyCache { >+ private Map map; >+ >+ private Map getMap() { >+ if (map == null) >+ map = new HashMap(); >+ return map; >+ } >+ >+ /** >+ * @param source >+ * @param property >+ */ >+ public synchronized void put(Object source, Object property) { >+ getMap().put(new IdentityWrapper(source), property); >+ } >+ >+ /** >+ * @param source >+ * @return the cached property >+ */ >+ public synchronized Object get(Object source) { >+ return map == null ? null : map.get(new IdentityWrapper(source)); >+ } >+ >+ /** >+ * @param source >+ */ >+ public synchronized void remove(Object source) { >+ if (map != null) >+ map.remove(new IdentityWrapper(source)); >+ } >+ >+ /** >+ * >+ */ >+ public void dispose() { >+ if (map != null) { >+ map.clear(); >+ map = null; >+ } >+ } >+} >Index: src/org/eclipse/core/internal/databinding/observable/masterdetail/ListValuePropertyObservableList.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/masterdetail/ListValuePropertyObservableList.java >diff -N src/org/eclipse/core/internal/databinding/observable/masterdetail/ListValuePropertyObservableList.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/masterdetail/ListValuePropertyObservableList.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,379 @@ >+/******************************************************************************* >+ * 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.observable.masterdetail; >+ >+import java.lang.reflect.Array; >+import java.util.ArrayList; >+import java.util.Collection; >+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.IObserving; >+import org.eclipse.core.databinding.observable.ObservableTracker; >+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.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.value.ValuePropertyChangeEvent; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ListValuePropertyObservableList extends AbstractObservableList >+ implements IObserving { >+ private IObservableList masterList; >+ private IValueProperty detailProperty; >+ >+ private IObservableSet knownMasterElements; >+ >+ private boolean disposed = false; >+ >+ private IListChangeListener masterListener = new IListChangeListener() { >+ public void handleListChange(ListChangeEvent event) { >+ ListDiffEntry[] masterEntries = event.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); >+ } >+ >+ // Removes listeners from elements removed from list >+ knownMasterElements.retainAll(masterList); >+ >+ // Adds listeners to elements added to list >+ knownMasterElements.addAll(masterList); >+ >+ fireListChange(Diffs.createListDiff(detailEntries)); >+ } >+ }; >+ >+ private IValuePropertyChangeListener detailListener = new IValuePropertyChangeListener() { >+ public void handleValuePropertyChange( >+ final ValuePropertyChangeEvent event) { >+ if (!disposed) { >+ Object source = event.getSource(); >+ int[] indices = findIndices(source); >+ 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); >+ fireListChange(diff); >+ } >+ } >+ >+ private int[] findIndices(Object masterElement) { >+ List indices = new ArrayList(); >+ >+ for (ListIterator it = masterList.listIterator(); it.hasNext();) { >+ if (Util.equals(masterElement, 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, >+ IValueProperty valueProperty) { >+ super(masterList.getRealm()); >+ this.masterList = masterList; >+ this.detailProperty = valueProperty; >+ } >+ >+ protected void firstListenerAdded() { >+ knownMasterElements = new WritableSet(getRealm()); >+ knownMasterElements.addSetChangeListener(new ISetChangeListener() { >+ public void handleSetChange(SetChangeEvent event) { >+ for (Iterator it = event.diff.getRemovals().iterator(); it >+ .hasNext();) { >+ detailProperty.addValueChangeListener(it.next(), >+ detailListener); >+ } >+ for (Iterator it = event.diff.getAdditions().iterator(); it >+ .hasNext();) { >+ detailProperty.removeValueChangeListener(it.next(), >+ detailListener); >+ } >+ } >+ }); >+ knownMasterElements.addAll(masterList); >+ masterList.addListChangeListener(masterListener); >+ } >+ >+ protected void lastListenerRemoved() { >+ masterList.removeListChangeListener(masterListener); >+ if (knownMasterElements != null) { >+ knownMasterElements.clear(); >+ knownMasterElements.dispose(); >+ knownMasterElements = 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(); >+ >+ Iterator it; >+ if (knownMasterElements != null) >+ it = knownMasterElements.iterator(); >+ else >+ it = masterList.iterator(); >+ for (; 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); >+ Object lastReturned; >+ 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(); >+ Object result = lastReturned = detailProperty.getValue(it >+ .next()); >+ haveIterated = true; >+ return result; >+ } >+ >+ public int nextIndex() { >+ getterCalled(); >+ return it.nextIndex(); >+ } >+ >+ public Object previous() { >+ getterCalled(); >+ Object result = lastReturned = detailProperty.getValue(it >+ .previous()); >+ haveIterated = true; >+ return result; >+ } >+ >+ public int previousIndex() { >+ getterCalled(); >+ return it.previousIndex(); >+ } >+ >+ public void remove() { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public void set(Object o) { >+ checkRealm(); >+ if (!haveIterated) >+ throw new IllegalStateException(); >+ // if listeners are registered, the value property listener will >+ // cause the list change event to fire. otherwise it doesn't >+ // matter because noone is listening >+ detailProperty.setValue(lastReturned, 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); >+ detailProperty.setValue(masterElement, o); >+ return oldValue; >+ } >+ >+ public Object getObserved() { >+ return masterList; >+ } >+ >+ public synchronized void dispose() { >+ if (masterList != null) { >+ masterList.removeListChangeListener(masterListener); >+ masterList = null; >+ masterListener = null; >+ } >+ if (knownMasterElements != null) { >+ knownMasterElements.clear(); >+ knownMasterElements.dispose(); >+ knownMasterElements = null; >+ detailListener = null; >+ } >+ detailProperty = null; >+ disposed = true; >+ >+ super.dispose(); >+ } >+} >Index: src/org/eclipse/core/databinding/property/list/IListPropertyChangeListener.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/list/IListPropertyChangeListener.java >diff -N src/org/eclipse/core/databinding/property/list/IListPropertyChangeListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/list/IListPropertyChangeListener.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.list; >+ >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+ >+/** >+ * Listener for changes to list properties on a property source >+ * >+ * @since 1.2 >+ */ >+public interface IListPropertyChangeListener extends IPropertyChangeListener { >+ /** >+ * Handle a change to a list property on a specific property source. >+ * >+ * @param event >+ * an event describing the list change that occured. >+ */ >+ public void handleListPropertyChange(ListPropertyChangeEvent event); >+} >Index: src/org/eclipse/core/internal/databinding/property/PropertyUpdateHelper.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/PropertyUpdateHelper.java >diff -N src/org/eclipse/core/internal/databinding/property/PropertyUpdateHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/PropertyUpdateHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,68 @@ >+/******************************************************************************* >+ * 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 java.util.HashMap; >+import java.util.Map; >+ >+import org.eclipse.core.internal.databinding.IdentityWrapper; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class PropertyUpdateHelper { >+ private ThreadLocal localMap = new ThreadLocal() { >+ protected Object initialValue() { >+ return new HashMap(); >+ } >+ }; >+ >+ /** >+ * @param source >+ * @return blah >+ */ >+ public boolean isUpdating(Object source) { >+ Map map = (Map) localMap.get(); >+ return map.containsKey(new IdentityWrapper(source)); >+ } >+ >+ /** >+ * @param source >+ * @param state >+ */ >+ public void setUpdating(Object source, boolean state) { >+ Map map = (Map) localMap.get(); >+ IdentityWrapper identityWrapper = new IdentityWrapper(source); >+ Integer count = (Integer) map.get(identityWrapper); >+ int newCount = (count == null ? 0 : count.intValue()) >+ + (state ? 1 : -1); >+ if (newCount > 0) >+ map.put(identityWrapper, new Integer(newCount)); >+ else >+ map.remove(identityWrapper); >+ } >+ >+ /** >+ * >+ */ >+ public void dispose() { >+ if (localMap != null) { >+ Map map = (Map) localMap.get(); >+ if (map != null) { >+ map.clear(); >+ localMap.set(null); >+ } >+ localMap = null; >+ } >+ } >+} >Index: src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java >diff -N src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/map/SimpleMapProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,221 @@ >+/******************************************************************************* >+ * 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.map; >+ >+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.map.MapDiff; >+import org.eclipse.core.databinding.property.SimpleProperty; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * Simplified abstract implementation of IMapProperty. This class takes care of >+ * most of the functional requirements for an IMapProperty implementation, >+ * leaving only the property-specific details to subclasses. >+ * <p> >+ * Subclasses must implement these methods: >+ * <ul> >+ * <li>{@link #getKeyType()} >+ * <li>{@link #getValueType()} >+ * <li>{@link #doGetMap(Object)} >+ * <li>{@link #doSetMap(Object, Map, MapDiff)} >+ * </ul> >+ * Additionally, the following methods should be overridden when the property >+ * source has listener APIs. >+ * <ul> >+ * <li>{@link #doAddListenerTo(Object)} >+ * <li>{@link #doRemoveListenerFrom(Object)} >+ * </ul> >+ * >+ * @since 1.2 >+ */ >+public abstract class SimpleMapProperty extends SimpleProperty implements >+ IMapProperty { >+ public final void addMapChangeListener(Object source, >+ IMapPropertyChangeListener listener) { >+ addPropertyChangeListener(source, listener); >+ } >+ >+ public final void removeMapChangeListener(Object source, >+ IMapPropertyChangeListener listener) { >+ removePropertyChangeListener(source, listener); >+ } >+ >+ protected final Object getProperty(Object source) { >+ return doGetMap(source); >+ } >+ >+ public boolean containsKey(Object source, Object key) { >+ return getMap(source).containsKey(key); >+ } >+ >+ public boolean containsValue(Object source, Object value) { >+ return getMap(source).containsValue(value); >+ } >+ >+ public boolean equals(Object source, Object o) { >+ return getMap(source).equals(o); >+ } >+ >+ public Object get(Object source, Object key) { >+ return getMap(source).get(key); >+ } >+ >+ public int hashCode(Object source) { >+ return getMap(source).hashCode(); >+ } >+ >+ public boolean isEmpty(Object source) { >+ return getMap(source).isEmpty(); >+ } >+ >+ public int size(Object source) { >+ return getMap(source).size(); >+ } >+ >+ public final Map getMap(Object source) { >+ Map map = doGetMap(source); >+ if (hasListeners(source) && !isUpdating(source)) { >+ Map cached = (Map) getCached(source); >+ if (!Util.equals(map, cached)) { >+ fireMapChange(source, Diffs.computeMapDiff(cached, map)); >+ } >+ } >+ return map; >+ } >+ >+ /** >+ * Returns a Map with the current contents of the source's map property >+ * >+ * @param source >+ * the property source >+ * @return a Map with the current contents of the source's map property >+ * @see IMapProperty#getMap(Object) >+ */ >+ protected abstract Map doGetMap(Object source); >+ >+ private void setMap(Object source, Map map, MapDiff diff) { >+ setUpdating(source, true); >+ try { >+ doSetMap(source, map, diff); >+ } finally { >+ setUpdating(source, false); >+ } >+ >+ if (hasListeners(source)) { >+ fireMapChange(source, diff); >+ } >+ } >+ >+ /** >+ * Updates the property on the source with the specified change. A map >+ * change event is fired in the calling method, so implementers do not need >+ * to call {@link #fireMapChange(Object, MapDiff)}. >+ * >+ * @param source >+ * the property source >+ * @param map >+ * the new map >+ * @param diff >+ * a diff describing the change >+ */ >+ protected abstract void doSetMap(Object source, Map map, MapDiff diff); >+ >+ /** >+ * Notifies that the source's property changed. Listeners registered in the >+ * {@link #addListenerTo(Object)} method should call this method when a >+ * property change is observed on the source object. >+ * >+ * @param source >+ * the property source >+ * @param diff >+ * a diff describing the map change. If null, a diff will be >+ * computed from the cached state and the current state. >+ */ >+ protected final void fireMapChange(Object source, MapDiff diff) { >+ if (!isUpdating(source) && hasListeners(source)) { >+ if (diff == null) { >+ diff = Diffs.computeMapDiff((Map) getCached(source), >+ doGetMap(source)); >+ } >+ if (!diff.isEmpty()) { >+ firePropertyChange(new MapPropertyChangeEvent(source, this, >+ diff)); >+ } >+ } >+ } >+ >+ public void clear(Object source) { >+ if (!isEmpty(source)) { >+ setMap(source, new HashMap(), Diffs >+ .createMapDiffRemoveAll(new HashMap(getMap(source)))); >+ } >+ } >+ >+ public Object put(Object source, Object key, Object value) { >+ Map map = new HashMap(getMap(source)); >+ boolean addition = !map.containsKey(key); >+ Object result = map.put(key, value); >+ MapDiff diff; >+ if (addition) { >+ diff = Diffs.createMapDiffSingleAdd(key, value); >+ } else { >+ diff = Diffs.createMapDiffSingleChange(key, result, value); >+ } >+ setMap(source, map, diff); >+ return result; >+ } >+ >+ public void putAll(Object source, Map t) { >+ if (t.isEmpty()) >+ return; >+ >+ Map map = new HashMap(getMap(source)); >+ Set addedKeys = new HashSet(); >+ Set changedKeys = new HashSet(); >+ Map oldValues = new HashMap(); >+ Map newValues = new HashMap(); >+ for (Iterator it = t.entrySet().iterator(); it.hasNext();) { >+ Map.Entry entry = (Map.Entry) it.next(); >+ Object key = entry.getKey(); >+ Object newValue = entry.getValue(); >+ boolean addition = !map.containsKey(key); >+ Object oldValue = map.put(key, newValue); >+ if (addition) { >+ addedKeys.add(key); >+ } else if (!Util.equals(oldValue, newValue)) { >+ changedKeys.add(key); >+ oldValues.put(key, oldValue); >+ } >+ newValues.put(key, newValue); >+ } >+ setMap(source, map, Diffs.createMapDiff(addedKeys, >+ Collections.EMPTY_SET, changedKeys, oldValues, newValues)); >+ } >+ >+ public Object remove(Object source, Object key) { >+ Map map = getMap(source); >+ if (map.containsKey(key)) { >+ map = new HashMap(map); >+ Object result = map.remove(key); >+ setMap(source, map, Diffs.createMapDiffSingleRemove(key, result)); >+ return result; >+ } >+ return null; >+ } >+} >Index: src/org/eclipse/core/databinding/property/IPropertyChangeListener.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/IPropertyChangeListener.java >diff -N src/org/eclipse/core/databinding/property/IPropertyChangeListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/IPropertyChangeListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,23 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * Marker interface for all listener types in the properties framework. >+ * >+ * @noimplement This interface is not intended to be implemented by clients. >+ * >+ * @since 1.2 >+ */ >+public interface IPropertyChangeListener { >+ >+} >Index: src/org/eclipse/core/databinding/property/set/ISetProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/set/ISetProperty.java >diff -N src/org/eclipse/core/databinding/property/set/ISetProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/set/ISetProperty.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.core.databinding.property.set; >+ >+import java.util.Set; >+ >+import org.eclipse.core.databinding.property.ICollectionProperty; >+ >+/** >+ * Interface for set-typed properties >+ * >+ * @since 1.2 >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface ISetProperty extends ICollectionProperty { >+ /** >+ * 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 >+ */ >+ public Set getSet(Object source); >+ >+ /** >+ * Adds the given set property change listener to the list of listeners for >+ * the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void addSetChangeListener(Object source, >+ ISetPropertyChangeListener listener); >+ >+ /** >+ * Removes the given set property change listener from the list of listeners >+ * for the given source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener >+ */ >+ public void removeSetChangeListener(Object source, >+ ISetPropertyChangeListener listener); >+} >Index: src/org/eclipse/core/databinding/property/list/ListPropertyChangeEvent.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/list/ListPropertyChangeEvent.java >diff -N src/org/eclipse/core/databinding/property/list/ListPropertyChangeEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/list/ListPropertyChangeEvent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,59 @@ >+/******************************************************************************* >+ * 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 org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.property.IPropertyChangeListener; >+import org.eclipse.core.databinding.property.PropertyChangeEvent; >+import org.eclipse.core.runtime.Assert; >+ >+/** >+ * List change event describing an incremental change of a list property on a >+ * particular property source. >+ * >+ * @since 1.2 >+ */ >+public class ListPropertyChangeEvent extends PropertyChangeEvent { >+ private static final long serialVersionUID = 1L; >+ >+ /** >+ * The list property that changed >+ */ >+ public final IListProperty property; >+ >+ /** >+ * ListDiff enumerating the added and removed elements in the list. >+ */ >+ public final ListDiff diff; >+ >+ /** >+ * Constructs a ListPropertyChangeEvent with the given attributes >+ * >+ * @param source >+ * the property source >+ * @param property >+ * the property that changed on the source >+ * @param diff >+ * a ListDiff describing the changes to the list property >+ */ >+ public ListPropertyChangeEvent(Object source, IListProperty property, >+ ListDiff diff) { >+ super(source); >+ this.property = property; >+ Assert.isNotNull(diff, "diff cannot be null"); //$NON-NLS-1$ >+ this.diff = diff; >+ } >+ >+ protected void dispatch(IPropertyChangeListener listener) { >+ ((IListPropertyChangeListener) listener).handleListPropertyChange(this); >+ } >+} >Index: src/org/eclipse/core/internal/databinding/observable/PropertyObservableSet.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/observable/PropertyObservableSet.java >diff -N src/org/eclipse/core/internal/databinding/observable/PropertyObservableSet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/observable/PropertyObservableSet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,197 @@ >+/******************************************************************************* >+ * 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.observable; >+ >+import java.util.Collection; >+import java.util.ConcurrentModificationException; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.set.AbstractObservableSet; >+import org.eclipse.core.databinding.property.IProperty; >+import org.eclipse.core.databinding.property.IPropertyObservable; >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.core.databinding.property.set.ISetPropertyChangeListener; >+import org.eclipse.core.databinding.property.set.SetPropertyChangeEvent; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class PropertyObservableSet extends AbstractObservableSet implements >+ IPropertyObservable { >+ private Object source; >+ private ISetProperty property; >+ >+ private boolean updating = false; >+ >+ private boolean disposed = false; >+ >+ private transient volatile int modCount = 0; >+ >+ private ISetPropertyChangeListener listener = new ISetPropertyChangeListener() { >+ public void handleSetPropertyChange(final SetPropertyChangeEvent event) { >+ if (!disposed && !updating) { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ getRealm().exec(new Runnable() { >+ public void run() { >+ modCount++; >+ fireSetChange(event.diff); >+ } >+ }); >+ } >+ }); >+ } >+ } >+ }; >+ >+ /** >+ * @param realm >+ * @param source >+ * @param property >+ */ >+ public PropertyObservableSet(Realm realm, Object source, >+ ISetProperty property) { >+ super(realm); >+ this.source = source; >+ this.property = property; >+ } >+ >+ protected void firstListenerAdded() { >+ if (!disposed) { >+ property.addSetChangeListener(source, listener); >+ } >+ } >+ >+ protected void lastListenerRemoved() { >+ if (!disposed) { >+ property.removeSetChangeListener(source, listener); >+ } >+ } >+ >+ 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(); >+ return property.add(source, o); >+ } >+ >+ 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(); >+ Object next = delegate.next(); >+ last = next; >+ return next; >+ } >+ >+ public void remove() { >+ checkRealm(); >+ checkForComodification(); >+ >+ delegate.remove(); // stay in sync >+ >+ property.remove(source, last); >+ >+ last = null; >+ expectedModCount = modCount; >+ } >+ >+ private void checkForComodification() { >+ if (expectedModCount != modCount) >+ throw new ConcurrentModificationException(); >+ } >+ }; >+ } >+ >+ public boolean remove(Object o) { >+ getterCalled(); >+ return property.remove(source, o); >+ } >+ >+ // Bulk change operations >+ >+ public boolean addAll(Collection c) { >+ getterCalled(); >+ return property.addAll(source, c); >+ } >+ >+ public boolean removeAll(Collection c) { >+ getterCalled(); >+ return property.removeAll(source, c); >+ } >+ >+ public boolean retainAll(Collection c) { >+ getterCalled(); >+ return property.retainAll(source, c); >+ } >+ >+ public void clear() { >+ getterCalled(); >+ property.clear(source); >+ } >+ >+ public boolean equals(Object o) { >+ return property.equals(source, o); >+ } >+ >+ public int hashCode() { >+ return property.hashCode(source); >+ } >+ >+ public Object getObserved() { >+ return source; >+ } >+ >+ public IProperty getProperty() { >+ return property; >+ } >+ >+ public synchronized void dispose() { >+ if (!disposed) { >+ disposed = true; >+ property.removeSetChangeListener(source, listener); >+ property = null; >+ source = 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,59 @@ >+/******************************************************************************* >+ * 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; >+import org.eclipse.core.runtime.Assert; >+ >+/** >+ * 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. >+ */ >+ 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; >+ Assert.isNotNull(diff, "diff cannot be null"); //$NON-NLS-1$ >+ this.diff = diff; >+ } >+ >+ protected void dispatch(IPropertyChangeListener listener) { >+ ((IMapPropertyChangeListener) listener).handleMapPropertyChange(this); >+ } >+} >Index: src/org/eclipse/core/databinding/property/Property.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/Property.java >diff -N src/org/eclipse/core/databinding/property/Property.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/Property.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,144 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * Abstract implementation of IProperty >+ * >+ * @since 1.2 >+ */ >+public abstract class Property implements IProperty { >+ private PropertyChangeSupport changeSupport; >+ >+ private boolean disposed; >+ >+ private synchronized PropertyChangeSupport getChangeSupport() { >+ if (changeSupport == null) { >+ changeSupport = new PropertyChangeSupport() { >+ protected void addListenerTo(Object source) { >+ Property.this.addListenerTo(source); >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ Property.this.removeListenerFrom(source); >+ } >+ }; >+ } >+ return changeSupport; >+ } >+ >+ /** >+ * Adds the listener to the list of listeners for the specified property >+ * source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener to add >+ */ >+ protected final synchronized void addPropertyChangeListener(Object source, >+ IPropertyChangeListener listener) { >+ if (!isDisposed()) { >+ getChangeSupport().addListener(source, listener); >+ } >+ } >+ >+ /** >+ * Removes the listener from the list of listeners for the specified >+ * property source. >+ * >+ * @param source >+ * the property source >+ * @param listener >+ * the listener to remove >+ */ >+ protected final synchronized void removePropertyChangeListener( >+ Object source, IPropertyChangeListener listener) { >+ if (changeSupport != null) { >+ changeSupport.removeListener(source, listener); >+ } >+ } >+ >+ /** >+ * Returns whether this property has listeners registered for the given >+ * property source >+ * >+ * @param source >+ * the property source >+ * @return whether this property has listeners registered for the given >+ * property source >+ */ >+ protected final boolean hasListeners(Object source) { >+ PropertyChangeSupport changeSupport = this.changeSupport; >+ return changeSupport != null && changeSupport.hasListeners(source); >+ } >+ >+ /** >+ * Fires a property change notification for all listeners registered on the >+ * property source indicated by the event object >+ * >+ * @param event >+ * the property change event >+ */ >+ protected void firePropertyChange(PropertyChangeEvent event) { >+ PropertyChangeSupport changeSupport = this.changeSupport; >+ if (changeSupport != null >+ && changeSupport.hasListeners(event.getSource())) { >+ changeSupport.firePropertyChange(event); >+ } >+ } >+ >+ /** >+ * Adds a listener on the given property source for changes to the property. >+ * The listener should fire a property change event whenever the a property >+ * change is observed. This method is called when the first property change >+ * listener is added for the given source object. >+ * <p> >+ * This method does nothing if the source object has no listener support for >+ * the property. >+ * >+ * @param source >+ * the source object to observe for property changes. >+ * @see #removeListenerFrom(Object) >+ * @noreference This method is not intended to be referenced by clients. >+ */ >+ protected abstract void addListenerTo(Object source); >+ >+ /** >+ * Remove the listeners previous added on the property source for changes to >+ * the property. This method is called when the last property change >+ * listener is removed for the given source object. >+ * <p> >+ * This method does nothing if the source object has no listener support for >+ * the property. >+ * >+ * @param source >+ * the source object to stop observing for property changes. >+ * @see #addListenerTo(Object) >+ * @noreference This method is not intended to be referenced by clients. >+ */ >+ protected abstract void removeListenerFrom(Object source); >+ >+ public boolean isDisposed() { >+ return disposed; >+ } >+ >+ public synchronized void dispose() { >+ if (!disposed) { >+ if (changeSupport != null) { >+ changeSupport.dispose(); >+ changeSupport = null; >+ } >+ disposed = true; >+ } >+ } >+} >#P org.eclipse.jface.databinding >Index: src/org/eclipse/jface/internal/databinding/swt/ListObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ListObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ListObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ListObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,109 +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 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.widgets.Event; >-import org.eclipse.swt.widgets.List; >-import org.eclipse.swt.widgets.Listener; >- >-/** >- * @since 3.2 >- * >- */ >-public class ListObservableValue extends AbstractSWTObservableValue { >- >- private final List list; >- >- private boolean updating = false; >- >- private String currentValue; >- >- private Listener listener; >- >- /** >- * @param list >- */ >- public ListObservableValue(List list) { >- super(list); >- this.list = list; >- this.currentValue = (String) doGetValue(); >- >- if ((list.getStyle() & SWT.MULTI) > 0) >- throw new IllegalArgumentException( >- "SWT.SINGLE support only for a List selection"); //$NON-NLS-1$ >- >- listener = new Listener() { >- >- public void handleEvent(Event event) { >- if (!updating) { >- Object oldValue = currentValue; >- currentValue = (String) doGetValue(); >- fireValueChange(Diffs.createValueDiff(oldValue, >- currentValue)); >- } >- } >- >- }; >- list.addListener(SWT.Selection, listener); >- } >- >- public void doSetValue(Object value) { >- String oldValue = null; >- if (list.getSelection() != null && list.getSelection().length > 0) >- oldValue = list.getSelection()[0]; >- try { >- updating = true; >- 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); // -1 will not "unselect" >- } >- currentValue = (String) value; >- } finally { >- updating = false; >- } >- fireValueChange(Diffs.createValueDiff(oldValue, value)); >- } >- >- public Object doGetValue() { >- int index = list.getSelectionIndex(); >- if (index >= 0) >- return list.getItem(index); >- return null; >- } >- >- public Object getValueType() { >- return String.class; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- if (listener != null && !list.isDisposed()) { >- list.removeListener(SWT.Selection, listener); >- } >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/CComboSingleSelectionObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,81 +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 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.swt.custom.CCombo; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >- >-/** >- * @since 1.0 >- * >- */ >-public class CComboSingleSelectionObservableValue extends >- SingleSelectionObservableValue { >- >- private SelectionListener selectionListener; >- >- /** >- * @param combo >- */ >- public CComboSingleSelectionObservableValue(CCombo combo) { >- super(combo); >- } >- >- /** >- * @param realm >- * @param combo >- */ >- public CComboSingleSelectionObservableValue(Realm realm, CCombo combo) { >- super(realm, combo); >- } >- >- private CCombo getCCombo() { >- return (CCombo) getWidget(); >- } >- >- protected void doAddSelectionListener(final Runnable runnable) { >- selectionListener = new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- runnable.run(); >- } >- >- public void widgetSelected(SelectionEvent e) { >- runnable.run(); >- } >- }; >- getCCombo().addSelectionListener(selectionListener); >- } >- >- protected int doGetSelectionIndex() { >- return getCCombo().getSelectionIndex(); >- } >- >- protected void doSetSelectionIndex(int index) { >- getCCombo().setText(getCCombo().getItem(index)); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- if (selectionListener != null && !getCCombo().isDisposed()) { >- getCCombo().removeSelectionListener(selectionListener); >- } >- >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ShellObservableValue.java 19 Mar 2008 23:03:22 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,74 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007 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 207844) >- * IBM Corporation - initial API and implementation >- * Brad Reynolds - initial API and implementation >- * Matthew Hall - bug 212235 >- *******************************************************************************/ >-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.databinding.observable.value.IObservableValue; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.widgets.Shell; >- >-/** >- * An {@link IObservableValue} that tracks the text of a Shell. >- * >- * @since 1.2 >- */ >-public class ShellObservableValue extends AbstractSWTObservableValue { >- >- private final Shell shell; >- >- /** >- * Constructs a ShellObservableValue which tracks the text of the given >- * Shell. >- * >- * @param shell >- * the shell to track >- */ >- public ShellObservableValue(Shell shell) { >- super(shell); >- this.shell = shell; >- } >- >- /** >- * Constructs a ShellObservableValue belonging to the given realm, which >- * tracks the text of the given shell. >- * >- * @param realm >- * the realm of the constructed observable >- * @param shell >- * the shell to track >- */ >- public ShellObservableValue(Realm realm, Shell shell) { >- super(realm, shell); >- this.shell = shell; >- } >- >- protected void doSetValue(final Object value) { >- String oldValue = shell.getText(); >- String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ >- shell.setText(newValue); >- >- if (!newValue.equals(oldValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >- >- protected Object doGetValue() { >- return shell.getText(); >- } >- >- public Object getValueType() { >- return String.class; >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/CComboObservableList.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CComboObservableList.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CComboObservableList.java >--- src/org/eclipse/jface/internal/databinding/swt/CComboObservableList.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.custom.CCombo; >- >-/** >- * @since 3.2 >- * >- */ >-public class CComboObservableList extends SWTObservableList { >- >- private final CCombo ccombo; >- >- /** >- * @param ccombo >- */ >- public CComboObservableList(CCombo ccombo) { >- super(SWTObservables.getRealm(ccombo.getDisplay())); >- this.ccombo = ccombo; >- } >- >- protected int getItemCount() { >- return ccombo.getItemCount(); >- } >- >- protected void setItems(String[] newItems) { >- ccombo.setItems(newItems); >- } >- >- protected String[] getItems() { >- return ccombo.getItems(); >- } >- >- protected String getItem(int index) { >- return ccombo.getItem(index); >- } >- >- protected void setItem(int index, String string) { >- ccombo.setItem(index, string); >- } >-} >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/TableSingleSelectionObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,80 +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 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; >-import org.eclipse.swt.widgets.Table; >- >-/** >- * @since 1.0 >- * >- */ >-public class TableSingleSelectionObservableValue extends >- SingleSelectionObservableValue { >- >- private SelectionListener selectionListener; >- >- /** >- * @param table >- */ >- public TableSingleSelectionObservableValue(Table table) { >- super(table); >- } >- >- /** >- * @param realm >- * @param table >- */ >- public TableSingleSelectionObservableValue(Realm realm, Table table) { >- super(realm, table); >- } >- >- private Table getTable() { >- return (Table) getWidget(); >- } >- >- protected void doAddSelectionListener(final Runnable runnable) { >- selectionListener = new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- runnable.run(); >- } >- >- public void widgetSelected(SelectionEvent e) { >- runnable.run(); >- } >- }; >- getTable().addSelectionListener(selectionListener); >- } >- >- protected int doGetSelectionIndex() { >- return getTable().getSelectionIndex(); >- } >- >- protected void doSetSelectionIndex(int index) { >- getTable().setSelection(index); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- if (selectionListener != null && !getTable().isDisposed()) { >- getTable().removeSelectionListener(selectionListener); >- } >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/SWTObservableList.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SWTObservableList.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SWTObservableList.java >--- src/org/eclipse/jface/internal/databinding/swt/SWTObservableList.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,193 +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 208858 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.Collection; >-import java.util.List; >- >-import org.eclipse.core.databinding.BindingException; >-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; >- >-/** >- * Abstract base class of CComboObservableList, ComboObservableList, and >- * ListObservableList. >- * >- * @since 3.2 >- * >- */ >-public abstract class SWTObservableList extends AbstractObservableList { >- >- /** >- * >- */ >- public SWTObservableList() { >- super(); >- } >- >- /** >- * @param realm >- */ >- public SWTObservableList(Realm realm) { >- super(realm); >- } >- >- public void add(int index, Object element) { >- int size = doGetSize(); >- if (index < 0 || index > size) >- index = size; >- String[] newItems = new String[size + 1]; >- System.arraycopy(getItems(), 0, newItems, 0, index); >- newItems[index] = (String) element; >- System.arraycopy(getItems(), index, newItems, index + 1, size - index); >- setItems(newItems); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, >- true, element))); >- } >- >- public int doGetSize() { >- return getItemCount(); >- } >- >- public Object get(int index) { >- getterCalled(); >- return getItem(index); >- } >- >- public Object getElementType() { >- return String.class; >- } >- >- /** >- * @param index >- * @return the item at the given index >- */ >- protected abstract String getItem(int index); >- >- /** >- * @return the item count >- */ >- protected abstract int getItemCount(); >- >- /** >- * @return the items >- */ >- protected abstract String[] getItems(); >- >- private void getterCalled() { >- ObservableTracker.getterCalled(this); >- } >- >- public Object remove(int index) { >- getterCalled(); >- int size = doGetSize(); >- if (index < 0 || index > size - 1) >- throw new BindingException( >- "Request to remove an element out of the collection bounds"); //$NON-NLS-1$ >- >- String[] newItems = new String[size - 1]; >- String oldElement = getItem(index); >- if (newItems.length > 0) { >- System.arraycopy(getItems(), 0, newItems, 0, index); >- if (size - 1 > index) { >- System.arraycopy(getItems(), index + 1, newItems, index, size >- - index - 1); >- } >- } >- setItems(newItems); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, >- false, oldElement))); >- return oldElement; >- } >- >- public Object set(int index, Object element) { >- String oldElement = getItem(index); >- setItem(index, (String) element); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index, >- false, oldElement), Diffs.createListDiffEntry(index, true, >- element))); >- return oldElement; >- } >- >- public Object move(int oldIndex, int newIndex) { >- checkRealm(); >- if (oldIndex == newIndex) >- return get(oldIndex); >- int size = doGetSize(); >- 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$ >- >- String[] items = getItems(); >- String[] newItems = new String[size]; >- String element = items[oldIndex]; >- if (newItems.length > 0) { >- System.arraycopy(items, 0, newItems, 0, size); >- if (oldIndex < newIndex) { >- System.arraycopy(items, oldIndex + 1, newItems, oldIndex, >- newIndex - oldIndex); >- } else { >- System.arraycopy(items, newIndex, newItems, newIndex + 1, >- oldIndex - newIndex); >- } >- newItems[newIndex] = element; >- } >- setItems(newItems); >- fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(oldIndex, >- false, element), Diffs.createListDiffEntry(newIndex, true, >- element))); >- return element; >- } >- >- public boolean removeAll(Collection c) { >- checkRealm(); >- List oldItems = Arrays.asList(getItems()); >- List newItems = new ArrayList(oldItems); >- boolean removedAll = newItems.removeAll(c); >- if (removedAll) { >- setItems((String[]) newItems.toArray(new String[newItems.size()])); >- fireListChange(Diffs.computeListDiff(oldItems, newItems)); >- } >- return removedAll; >- } >- >- public boolean retainAll(Collection c) { >- checkRealm(); >- List oldItems = Arrays.asList(getItems()); >- List newItems = new ArrayList(oldItems); >- boolean retainedAll = newItems.retainAll(c); >- if (retainedAll) { >- setItems((String[]) newItems.toArray(new String[newItems.size()])); >- fireListChange(Diffs.computeListDiff(oldItems, newItems)); >- } >- return retainedAll; >- } >- >- /** >- * @param index >- * @param string >- */ >- protected abstract void setItem(int index, String string); >- >- /** >- * @param newItems >- */ >- protected abstract void setItems(String[] newItems); >- >-} >Index: src/org/eclipse/jface/internal/databinding/swt/TextEditableObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TextEditableObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TextEditableObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/TextEditableObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,75 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007, 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.Text; >- >-/** >- * Observable value for the editable property of a Text. >- * >- * @since 1.1 >- */ >-public class TextEditableObservableValue extends AbstractSWTObservableValue { >- private Text text; >- >- /** >- * @param text >- */ >- public TextEditableObservableValue(Text text) { >- super(text); >- this.text = text; >- } >- >- /** >- * @param realm >- * @param text >- */ >- public TextEditableObservableValue(Realm realm, Text text) { >- super(realm, text); >- this.text = text; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() >- */ >- protected Object doGetValue() { >- return (text.getEditable()) ? Boolean.TRUE : Boolean.FALSE; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() >- */ >- public Object getValueType() { >- return Boolean.TYPE; >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doSetValue(java.lang.Object) >- */ >- protected void doSetValue(Object value) { >- if (value == null) { >- throw new IllegalArgumentException("Parameter value was null."); //$NON-NLS-1$ >- } >- >- Boolean oldValue = new Boolean(text.getEditable()); >- Boolean newValue = (Boolean) value; >- >- text.setEditable(newValue.booleanValue()); >- >- if (!oldValue.equals(newValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >-} >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/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/TextObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TextObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TextObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/TextObservableValue.java 1 Oct 2008 20:18:37 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,198 +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 135446) >- * Brad Reynolds - bug 164653 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.IObservable; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.jface.databinding.swt.SWTObservables; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTVetoableValue; >-import org.eclipse.swt.SWT; >-import org.eclipse.swt.events.VerifyEvent; >-import org.eclipse.swt.events.VerifyListener; >-import org.eclipse.swt.widgets.Event; >-import org.eclipse.swt.widgets.Listener; >-import org.eclipse.swt.widgets.Text; >- >-/** >- * {@link IObservable} implementation that wraps a {@link Text} widget. The time >- * at which listeners should be notified about changes to the text is specified >- * on construction. >- * >- * <dl> >- * <dt>Events:</dt> >- * <dd> If the update event type (specified on construction) is >- * <code>SWT.Modify</code> a value change event will be fired on every key >- * stroke. If the update event type is <code>SWT.FocusOut</code> a value >- * change event will be fired on focus out. When in either mode if the user is >- * entering text and presses [Escape] the value will be reverted back to the >- * last value set using doSetValue(). Regardless of the update event type a >- * value changing event will fire on verify to enable vetoing of changes.</dd> >- * </dl> >- * >- * @since 1.0 >- */ >-public class TextObservableValue extends AbstractSWTVetoableValue { >- >- /** >- * {@link Text} widget that this is being observed. >- */ >- private final Text text; >- >- /** >- * Flag to track when the model is updating the widget. When >- * <code>true</code> the handlers for the SWT events should not process >- * the event as this would cause an infinite loop. >- */ >- private boolean updating = false; >- >- /** >- * SWT event that on firing this observable will fire change events to its >- * listeners. >- */ >- private final int updateEventType; >- >- /** >- * Valid types for the {@link #updateEventType}. >- */ >- private static final int[] validUpdateEventTypes = new int[] { SWT.Modify, >- SWT.FocusOut, SWT.None }; >- >- /** >- * Previous value of the Text. >- */ >- private String oldValue; >- >- private Listener updateListener = new Listener() { >- public void handleEvent(Event event) { >- if (!updating) { >- String newValue = text.getText(); >- >- if (!newValue.equals(oldValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- oldValue = newValue; >- } >- } >- } >- }; >- >- private VerifyListener verifyListener; >- >- /** >- * Constructs a new instance bound to the given <code>text</code> widget >- * and configured to fire change events to its listeners at the time of the >- * <code>updateEventType</code>. >- * >- * @param text >- * @param updateEventType >- * SWT event constant as to what SWT event to update the model in >- * response to. Appropriate values are: <code>SWT.Modify</code>, >- * <code>SWT.FocusOut</code>, <code>SWT.None</code>. >- * @throws IllegalArgumentException >- * if <code>updateEventType</code> is an incorrect type. >- */ >- public TextObservableValue(final Text text, int updateEventType) { >- this(SWTObservables.getRealm(text.getDisplay()), text, updateEventType); >- } >- >- /** >- * Constructs a new instance. >- * >- * @param realm can not be <code>null</code> >- * @param text >- * @param updateEventType >- */ >- public TextObservableValue(final Realm realm, Text text, int updateEventType) { >- super(realm, text); >- >- boolean eventValid = false; >- for (int i = 0; !eventValid && i < validUpdateEventTypes.length; i++) { >- eventValid = (updateEventType == validUpdateEventTypes[i]); >- } >- if (!eventValid) { >- throw new IllegalArgumentException( >- "UpdateEventType [" + updateEventType + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ >- } >- this.text = text; >- this.updateEventType = updateEventType; >- if (updateEventType != SWT.None) { >- text.addListener(updateEventType, updateListener); >- } >- >- oldValue = text.getText(); >- >- verifyListener = new VerifyListener() { >- public void verifyText(VerifyEvent e) { >- if (!updating) { >- String currentText = TextObservableValue.this.text >- .getText(); >- String newText = currentText.substring(0, e.start) + e.text >- + currentText.substring(e.end); >- if (!fireValueChanging(Diffs.createValueDiff(currentText, >- newText))) { >- e.doit = false; >- } >- } >- } >- }; >- text.addVerifyListener(verifyListener); >- } >- >- /** >- * Sets the bound {@link Text Text's} text to the passed <code>value</code>. >- * >- * @param value >- * new value, String expected >- * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doSetApprovedValue(java.lang.Object) >- * @throws ClassCastException >- * if the value is anything other than a String >- */ >- protected void doSetApprovedValue(final Object value) { >- try { >- updating = true; >- text.setText(value == null ? "" : value.toString()); //$NON-NLS-1$ >- oldValue = text.getText(); >- } finally { >- updating = false; >- } >- } >- >- /** >- * Returns the current value of the {@link Text}. >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doGetValue() >- */ >- public Object doGetValue() { >- return oldValue = text.getText(); >- } >- >- /** >- * Returns the type of the value from {@link #doGetValue()}, i.e. >- * String.class >- * >- * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() >- */ >- public Object getValueType() { >- return String.class; >- } >- >- public synchronized void dispose() { >- if (!text.isDisposed()) { >- if (updateEventType != SWT.None) { >- text.removeListener(updateEventType, updateListener); >- } >- text.removeVerifyListener(verifyListener); >- } >- super.dispose(); >- } >-} >Index: src/org/eclipse/jface/internal/databinding/swt/SpinnerObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SpinnerObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SpinnerObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/SpinnerObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,151 +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.Spinner; >- >-/** >- * @since 1.0 >- * >- */ >-public class SpinnerObservableValue extends AbstractSWTObservableValue { >- >- private final Spinner spinner; >- >- private final String attribute; >- >- private boolean updating = false; >- >- private int currentSelection; >- >- private ModifyListener modifyListener; >- >- /** >- * @param spinner >- * @param attribute >- */ >- public SpinnerObservableValue(Spinner spinner, String attribute) { >- super(spinner); >- this.spinner = spinner; >- this.attribute = attribute; >- init(); >- } >- >- /** >- * @param realm >- * @param spinner >- * @param attribute >- */ >- public SpinnerObservableValue(Realm realm, Spinner spinner, String attribute) { >- super(realm, spinner); >- this.spinner = spinner; >- this.attribute = attribute; >- init(); >- } >- >- private void init() { >- if (attribute.equals(SWTProperties.SELECTION)) { >- currentSelection = spinner.getSelection(); >- modifyListener = new ModifyListener() { >- public void modifyText(ModifyEvent e) { >- if (!updating) { >- int newSelection = SpinnerObservableValue.this.spinner >- .getSelection(); >- notifyIfChanged(currentSelection, newSelection); >- currentSelection = newSelection; >- } >- } >- }; >- spinner.addModifyListener(modifyListener); >- } 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 = spinner.getSelection(); >- spinner.setSelection(newValue); >- currentSelection = newValue; >- } else if (attribute.equals(SWTProperties.MIN)) { >- oldValue = spinner.getMinimum(); >- spinner.setMinimum(newValue); >- } else if (attribute.equals(SWTProperties.MAX)) { >- oldValue = spinner.getMaximum(); >- spinner.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 = spinner.getSelection(); >- } else if (attribute.equals(SWTProperties.MIN)) { >- value = spinner.getMinimum(); >- } else if (attribute.equals(SWTProperties.MAX)) { >- value = spinner.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 (modifyListener != null && !spinner.isDisposed()) { >- spinner.removeModifyListener(modifyListener); >- } >- } >- >- 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/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/internal/databinding/swt/ItemTooltipObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ItemTooltipObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ItemTooltipObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ItemTooltipObservableValue.java 1 Oct 2008 16:52:50 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,104 +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.custom.CTabItem; >-import org.eclipse.swt.widgets.Item; >-import org.eclipse.swt.widgets.TabItem; >-import org.eclipse.swt.widgets.TableColumn; >-import org.eclipse.swt.widgets.ToolItem; >-import org.eclipse.swt.widgets.TrayItem; >-import org.eclipse.swt.widgets.TreeColumn; >- >-/** >- * @since 3.5 >- * >- */ >-public class ItemTooltipObservableValue extends AbstractSWTObservableValue { >- >- private final Item item; >- >- /** >- * @param item >- */ >- public ItemTooltipObservableValue(Item item) { >- super(item); >- this.item = item; >- } >- >- /** >- * @param realm >- * @param item >- */ >- public ItemTooltipObservableValue(Realm realm, Item item) { >- super(realm, item); >- this.item = item; >- } >- >- public void doSetValue(final Object value) { >- String oldValue = (String) doGetValue(); >- >- String newValue = value == null ? "" : value.toString(); //$NON-NLS-1$ >- if (item instanceof CTabItem) { >- ((CTabItem)item).setToolTipText(newValue); >- } >- else if (item instanceof TabItem) { >- ((TabItem)item).setToolTipText(newValue); >- } >- else if (item instanceof TableColumn) { >- ((TableColumn)item).setToolTipText(newValue); >- } >- else if (item instanceof ToolItem) { >- ((ToolItem)item).setToolTipText(newValue); >- } >- else if (item instanceof TrayItem) { >- ((TrayItem)item).setToolTipText(newValue); >- } >- else if (item instanceof TreeColumn) { >- ((TreeColumn)item).setToolTipText(newValue); >- } >- >- if (!newValue.equals(oldValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >- >- public Object doGetValue() { >- if (item instanceof CTabItem) { >- return ((CTabItem)item).getToolTipText(); >- } >- else if (item instanceof TabItem) { >- return ((TabItem)item).getToolTipText(); >- } >- else if (item instanceof TableColumn) { >- return ((TableColumn)item).getToolTipText(); >- } >- else if (item instanceof ToolItem) { >- return ((ToolItem)item).getToolTipText(); >- } >- else if (item instanceof TrayItem) { >- return ((TrayItem)item).getToolTipText(); >- } >- else if (item instanceof TreeColumn) { >- return ((TreeColumn)item).getToolTipText(); >- } >- >- return null; >- } >- >- public Object getValueType() { >- return String.class; >- } >- >-} >Index: src/org/eclipse/jface/internal/databinding/swt/SWTProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SWTProperties.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SWTProperties.java >--- src/org/eclipse/jface/internal/databinding/swt/SWTProperties.java 26 Oct 2008 18:51:28 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,97 +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 >- * Matt Carter - bug 170668 >- * Brad Reynolds - bug 170848 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-/** >- * Constants used to describe properties of SWT controls. >- * >- * @since 1.0 >- * >- */ >-public interface SWTProperties { >- >- /** >- * Applies to Control >- */ >- public static final String ENABLED = "enabled"; //$NON-NLS-1$ >- /** >- * Applies to Control >- */ >- public static final String VISIBLE = "visible"; //$NON-NLS-1$ >- /** >- * Applies to Control >- */ >- public static final String TOOLTIP_TEXT = "tooltip"; //$NON-NLS-1$ >- /** >- * Applies to >- */ >- public static final String ITEMS = "items"; //$NON-NLS-1$ >- /** >- * Applies to Spinner >- */ >- public static final String MAX = "max"; //$NON-NLS-1$ >- /** >- * Applies to Spinner >- */ >- public static final String MIN = "min"; //$NON-NLS-1$ >- /** >- * Applies to Spinner, Button >- */ >- public static final String SELECTION = "selection"; //$NON-NLS-1$ >- /** >- * Applies to Spinner, Button >- */ >- public static final String SELECTION_INDEX = "index"; //$NON-NLS-1$ >- /** >- * Applies to Text, Label, Combo >- */ >- public static final String TEXT = "text"; //$NON-NLS-1$ >- >- /** >- * Applies to Label, CLabel. >- */ >- public static final String IMAGE = "image"; //$NON-NLS-1$ >- /** >- * Applies to Control >- */ >- public static final String FOREGROUND = "foreground"; //$NON-NLS-1$ >- /** >- * Applies to Control >- */ >- public static final String BACKGROUND = "background"; //$NON-NLS-1$ >- /** >- * Applies to Control >- */ >- public static final String FONT = "font"; //$NON-NLS-1$ >- >- /** >- * Applies to Control >- */ >- public static final String SIZE = "size"; //$NON-NLS-1$ >- >- /** >- * Applies to Control >- */ >- public static final String LOCATION = "location"; //$NON-NLS-1$ >- >- /** >- * Applies to Control >- */ >- public static final String FOCUS = "focus"; //$NON-NLS-1$ >- >- /** >- * Applies to Control >- */ >- public static final String BOUNDS = "bounds"; //$NON-NLS-1$ >- >-} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ControlObservableValue.java 26 Oct 2008 19:19:28 -0000 1.4 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,283 +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 >- * Matt Carter - bug 170668 >- * Brad Reynolds - bug 170848 >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.swt; >- >-import java.util.HashMap; >-import java.util.Map; >- >-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.jface.util.Util; >-import org.eclipse.swt.events.ControlEvent; >-import org.eclipse.swt.events.ControlListener; >-import org.eclipse.swt.events.FocusEvent; >-import org.eclipse.swt.events.FocusListener; >-import org.eclipse.swt.graphics.Color; >-import org.eclipse.swt.graphics.Font; >-import org.eclipse.swt.graphics.Point; >-import org.eclipse.swt.graphics.Rectangle; >-import org.eclipse.swt.widgets.Control; >- >-/** >- * @since 1.0 >- * >- */ >-public class ControlObservableValue extends AbstractSWTObservableValue { >- >- private final Control control; >- >- private final String attribute; >- >- private Object valueType; >- >- private FocusListener focusListener; >- >- private ControlListener controlListener; >- >- private Boolean currentFocus; >- >- private Point currentPoint; >- >- private Rectangle currentBounds; >- >- private boolean updating; >- >- >- private static final Map SUPPORTED_ATTRIBUTES = new HashMap(); >- static { >- SUPPORTED_ATTRIBUTES.put(SWTProperties.ENABLED, Boolean.TYPE); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.VISIBLE, Boolean.TYPE); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.TOOLTIP_TEXT, String.class); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.FOREGROUND, Color.class); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.BACKGROUND, Color.class); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.FONT, Font.class); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.LOCATION, Point.class); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.SIZE, Point.class); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.FOCUS, Boolean.class); >- SUPPORTED_ATTRIBUTES.put(SWTProperties.BOUNDS, Rectangle.class); >- } >- >- /** >- * @param control >- * @param attribute >- */ >- public ControlObservableValue(Control control, String attribute) { >- super(control); >- this.control = control; >- this.attribute = attribute; >- if (SUPPORTED_ATTRIBUTES.keySet().contains(attribute)) { >- this.valueType = SUPPORTED_ATTRIBUTES.get(attribute); >- } else { >- throw new IllegalArgumentException(); >- } >- >- init(); >- } >- >- /** >- * @param realm >- * @param control >- * @param attribute >- */ >- public ControlObservableValue(Realm realm, Control control, String attribute) { >- super(realm, control); >- this.control = control; >- this.attribute = attribute; >- if (SUPPORTED_ATTRIBUTES.keySet().contains(attribute)) { >- this.valueType = SUPPORTED_ATTRIBUTES.get(attribute); >- } else { >- throw new IllegalArgumentException(); >- } >- >- init(); >- } >- >- private void init() { >- if (SWTProperties.SIZE.equals(attribute) >- || SWTProperties.LOCATION.equals(attribute) >- || SWTProperties.BOUNDS.equals(attribute)) { >- this.currentPoint = SWTProperties.SIZE.equals(attribute) ? control >- .getSize() : control.getLocation(); >- >- controlListener = new ControlListener() { >- >- public void controlMoved(ControlEvent e) { >- if (SWTProperties.LOCATION.equals(attribute)) { >- if (!updating) { >- Point oldValue = currentPoint; >- currentPoint = control.getLocation(); >- >- notifyIfChanged(oldValue, currentPoint); >- } >- } else if (SWTProperties.BOUNDS.equals(attribute)) { >- if (!updating) { >- Rectangle oldValue = currentBounds; >- currentBounds = control.getBounds(); >- >- notifyIfChanged(oldValue, currentBounds); >- } >- } >- } >- >- public void controlResized(ControlEvent e) { >- if (SWTProperties.LOCATION.equals(attribute)) { >- if (!updating) { >- Point oldValue = currentPoint; >- currentPoint = control.getSize(); >- >- notifyIfChanged(oldValue, currentPoint); >- } >- } else if (SWTProperties.BOUNDS.equals(attribute)) { >- if (!updating) { >- Rectangle oldValue = currentBounds; >- currentBounds = control.getBounds(); >- >- notifyIfChanged(oldValue, currentBounds); >- } >- } >- } >- }; >- control.addControlListener(controlListener); >- } else if (SWTProperties.FOCUS.equals(attribute)) { >- this.currentFocus = control == control.getDisplay() >- .getFocusControl() ? Boolean.TRUE : Boolean.FALSE; >- focusListener = new FocusListener() { >- >- public void focusGained(FocusEvent e) { >- if (!updating) { >- Boolean oldValue = currentFocus; >- currentFocus = Boolean.TRUE; >- notifyIfChanged(oldValue, currentFocus); >- } >- } >- >- public void focusLost(FocusEvent e) { >- if (!updating) { >- Boolean oldValue = currentFocus; >- currentFocus = Boolean.FALSE; >- notifyIfChanged(oldValue, currentFocus); >- } >- } >- }; >- control.addFocusListener(focusListener); >- } >- } >- >- public void doSetValue(Object value) { >- Object oldValue = doGetValue(); >- >- if (SWTProperties.SIZE.equals(attribute)) { >- try { >- updating = true; >- control.setSize((Point) value); >- } finally { >- updating = false; >- currentPoint = control.getSize(); >- } >- } else if (SWTProperties.LOCATION.equals(attribute)) { >- try { >- updating = true; >- control.setLocation((Point) value); >- } finally { >- updating = false; >- currentPoint = control.getLocation(); >- } >- } else if (SWTProperties.FOCUS.equals(attribute)) { >- try { >- updating = true; >- if (Boolean.TRUE.equals(value)) { >- currentFocus = control.setFocus() ? Boolean.TRUE >- : Boolean.FALSE; >- } else { >- // TODO Not possible force the focus to leave the control >- // Maybe focus should the move to the Shell containing the >- // control >- this.currentFocus = control == control.getDisplay() >- .getFocusControl() ? Boolean.TRUE : Boolean.FALSE; >- } >- } finally { >- updating = false; >- } >- } else if (SWTProperties.BOUNDS.equals(attribute)) { >- try { >- updating = true; >- control.setBounds((Rectangle) value); >- } finally { >- updating = false; >- currentBounds = control.getBounds(); >- } >- } else if (attribute.equals(SWTProperties.ENABLED)) { >- control.setEnabled(((Boolean) value).booleanValue()); >- } else if (attribute.equals(SWTProperties.VISIBLE)) { >- control.setVisible(((Boolean) value).booleanValue()); >- } else if (attribute.equals(SWTProperties.TOOLTIP_TEXT)) { >- control.setToolTipText((String) value); >- } else if (attribute.equals(SWTProperties.FOREGROUND)) { >- control.setForeground((Color) value); >- } else if (attribute.equals(SWTProperties.BACKGROUND)) { >- control.setBackground((Color) value); >- } else if (attribute.equals(SWTProperties.FONT)) { >- control.setFont((Font) value); >- } >- >- notifyIfChanged(oldValue, value); >- } >- >- public Object doGetValue() { >- if (attribute.equals(SWTProperties.ENABLED)) { >- return control.getEnabled() ? Boolean.TRUE : Boolean.FALSE; >- } >- if (attribute.equals(SWTProperties.VISIBLE)) { >- return control.getVisible() ? Boolean.TRUE : Boolean.FALSE; >- } >- if (attribute.equals(SWTProperties.TOOLTIP_TEXT)) { >- return control.getToolTipText(); >- } >- if (attribute.equals(SWTProperties.FOREGROUND)) { >- return control.getForeground(); >- } >- if (attribute.equals(SWTProperties.BACKGROUND)) { >- return control.getBackground(); >- } >- if (attribute.equals(SWTProperties.FONT)) { >- return control.getFont(); >- } >- if (SWTProperties.SIZE.equals(attribute)) { >- return control.getSize(); >- } >- if (SWTProperties.LOCATION.equals(attribute)) { >- return control.getLocation(); >- } >- if (SWTProperties.FOCUS.equals(attribute)) { >- return control == control.getDisplay().getFocusControl() ? Boolean.TRUE >- : Boolean.FALSE; >- } >- if (SWTProperties.BOUNDS.equals(attribute)) { >- return control.getBounds(); >- } >- >- return null; >- } >- >- public Object getValueType() { >- return valueType; >- } >- >- private void notifyIfChanged(Object oldValue, Object newValue) { >- if (!Util.equals(oldValue, newValue)) { >- fireValueChange(Diffs.createValueDiff(oldValue, newValue)); >- } >- } >-} >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/SWTObservableValueDecorator.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/SWTObservableValueDecorator.java,v >retrieving revision 1.1 >diff -u -r1.1 SWTObservableValueDecorator.java >--- src/org/eclipse/jface/internal/databinding/swt/SWTObservableValueDecorator.java 25 Sep 2008 18:44:00 -0000 1.1 >+++ src/org/eclipse/jface/internal/databinding/swt/SWTObservableValueDecorator.java 10 Nov 2008 23:23:11 -0000 >@@ -6,7 +6,7 @@ > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * Matthew Hall - initial API and implementation (bug 245647) >+ * Matthew Hall - initial API and implementation (bug 194734) > ******************************************************************************/ > > package org.eclipse.jface.internal.databinding.swt; >Index: src/org/eclipse/jface/internal/databinding/swt/SingleSelectionObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SingleSelectionObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SingleSelectionObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/SingleSelectionObservableValue.java 24 Mar 2008 19:13:53 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,103 +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.Control; >- >-/** >- * @since 1.0 >- * >- */ >-abstract public class SingleSelectionObservableValue extends >- AbstractSWTObservableValue { >- >- private boolean updating = false; >- >- private int currentSelection; >- >- /** >- * @param control >- * the control >- */ >- public SingleSelectionObservableValue(Control control) { >- super(control); >- init(); >- } >- >- /** >- * @param realm >- * @param control >- */ >- public SingleSelectionObservableValue(Realm realm, Control control) { >- super(realm, control); >- init(); >- } >- >- private void init() { >- currentSelection = doGetSelectionIndex(); >- doAddSelectionListener(new Runnable(){ >- public void run() { >- if (!updating) { >- int newSelection = doGetSelectionIndex(); >- notifyIfChanged(currentSelection, newSelection); >- currentSelection = newSelection; >- } >- } >- }); >- } >- >- /** >- * @param runnable >- */ >- protected abstract void doAddSelectionListener(Runnable runnable); >- >- public void doSetValue(Object value) { >- try { >- updating = true; >- int intValue = ((Integer) value).intValue(); >- doSetSelectionIndex(intValue); >- notifyIfChanged(currentSelection, intValue); >- currentSelection = intValue; >- } finally { >- updating = false; >- } >- } >- >- /** >- * @param intValue >- * the selection index >- */ >- protected abstract void doSetSelectionIndex(int intValue); >- >- public Object doGetValue() { >- return new Integer(doGetSelectionIndex()); >- } >- >- /** >- * @return the selection index >- */ >- protected abstract int doGetSelectionIndex(); >- >- public Object getValueType() { >- return Integer.TYPE; >- } >- >- 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/ButtonObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ButtonObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ButtonObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ButtonObservableValue.java 31 Jul 2008 19:32:55 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,110 +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 >- *******************************************************************************/ >-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.SWT; >-import org.eclipse.swt.widgets.Button; >-import org.eclipse.swt.widgets.Event; >-import org.eclipse.swt.widgets.Listener; >- >-/** >- * @since 1.0 >- * >- */ >-public class ButtonObservableValue extends AbstractSWTObservableValue { >- >- private final Button button; >- >- private boolean selectionValue; >- >- private Listener updateListener = new Listener() { >- public void handleEvent(Event event) { >- boolean oldSelectionValue = selectionValue; >- selectionValue = button.getSelection(); >- >- notifyIfChanged(oldSelectionValue, selectionValue); >- } >- }; >- >- /** >- * @param button >- */ >- public ButtonObservableValue(Button button) { >- super(button); >- this.button = button; >- init(); >- } >- >- /** >- * @param realm >- * @param button >- */ >- public ButtonObservableValue(Realm realm, Button button) { >- super(realm, button); >- this.button = button; >- init(); >- } >- >- private void init() { >- button.addListener(SWT.Selection, updateListener); >- button.addListener(SWT.DefaultSelection, updateListener); >- this.selectionValue = button.getSelection(); >- } >- >- public void doSetValue(final Object value) { >- boolean oldSelectionValue = selectionValue; >- selectionValue = value == null ? false : ((Boolean) value) >- .booleanValue(); >- >- button.setSelection(selectionValue); >- notifyIfChanged(oldSelectionValue, selectionValue); >- } >- >- public Object doGetValue() { >- return button.getSelection() ? Boolean.TRUE : Boolean.FALSE; >- } >- >- public Object getValueType() { >- return Boolean.TYPE; >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- >- if (!button.isDisposed()) { >- button.removeListener(SWT.Selection, updateListener); >- button.removeListener(SWT.DefaultSelection, updateListener); >- } >- } >- >- /** >- * Notifies consumers with a value change event only if a change occurred. >- * >- * @param oldValue >- * @param newValue >- */ >- private void notifyIfChanged(boolean oldValue, boolean newValue) { >- if (oldValue != newValue) { >- fireValueChange(Diffs.createValueDiff(oldValue ? Boolean.TRUE : Boolean.FALSE, >- newValue ? Boolean.TRUE : Boolean.FALSE)); >- } >- } >-} >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/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/ListSingleSelectionObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionObservableValue.java >--- src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionObservableValue.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 - bug 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.List; >- >-/** >- * @since 1.0 >- * >- */ >-public class ListSingleSelectionObservableValue extends >- SingleSelectionObservableValue { >- >- private SelectionListener selectionListener; >- >- /** >- * @param combo >- */ >- public ListSingleSelectionObservableValue(List combo) { >- super(combo); >- } >- >- private List getList() { >- return (List) getWidget(); >- } >- >- protected void doAddSelectionListener(final Runnable runnable) { >- selectionListener = new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- runnable.run(); >- } >- >- public void widgetSelected(SelectionEvent e) { >- runnable.run(); >- } >- }; >- getList().addSelectionListener(selectionListener); >- } >- >- protected int doGetSelectionIndex() { >- return getList().getSelectionIndex(); >- } >- >- protected void doSetSelectionIndex(int index) { >- getList().setSelection(index); >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#dispose() >- */ >- public synchronized void dispose() { >- super.dispose(); >- if (selectionListener != null && !getList().isDisposed()) { >- getList().removeSelectionListener(selectionListener); >- } >- } >-} >Index: src/org/eclipse/jface/databinding/viewers/ViewersObservables.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/viewers/ViewersObservables.java,v >retrieving revision 1.13 >diff -u -r1.13 ViewersObservables.java >--- src/org/eclipse/jface/databinding/viewers/ViewersObservables.java 25 Sep 2008 18:44:00 -0000 1.13 >+++ src/org/eclipse/jface/databinding/viewers/ViewersObservables.java 10 Nov 2008 23:23:11 -0000 >@@ -7,26 +7,25 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >- * Matthew Hall - bug 206839, 124684, 239302, 245647 >+ * Matthew Hall - bug 206839, 124684, 239302, 245647, 194734 > *******************************************************************************/ > > package org.eclipse.jface.databinding.viewers; > > import org.eclipse.core.databinding.observable.Observables; >+import org.eclipse.core.databinding.observable.Realm; > import org.eclipse.core.databinding.observable.list.IObservableList; > import org.eclipse.core.databinding.observable.set.IObservableSet; > import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.PropertyObservables; >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.set.ISetProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; > import org.eclipse.jface.databinding.swt.SWTObservables; > import org.eclipse.jface.internal.databinding.swt.SWTDelayedObservableValueDecorator; >-import org.eclipse.jface.internal.databinding.viewers.CheckableCheckedElementsObservableSet; >-import org.eclipse.jface.internal.databinding.viewers.CheckboxViewerCheckedElementsObservableSet; >-import org.eclipse.jface.internal.databinding.viewers.SelectionProviderMultipleSelectionObservableList; >-import org.eclipse.jface.internal.databinding.viewers.SelectionProviderSingleSelectionObservableValue; >-import org.eclipse.jface.internal.databinding.viewers.ViewerFiltersObservableSet; >-import org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; >-import org.eclipse.jface.internal.databinding.viewers.ViewerMultipleSelectionObservableList; >+import org.eclipse.jface.internal.databinding.viewers.ViewerObservableListDecorator; >+import org.eclipse.jface.internal.databinding.viewers.ViewerObservableSetDecorator; > import org.eclipse.jface.internal.databinding.viewers.ViewerObservableValueDecorator; >-import org.eclipse.jface.internal.databinding.viewers.ViewerSingleSelectionObservableValue; > import org.eclipse.jface.viewers.CheckboxTableViewer; > import org.eclipse.jface.viewers.CheckboxTreeViewer; > import org.eclipse.jface.viewers.ICheckable; >@@ -42,6 +41,71 @@ > * @since 1.1 > */ > public class ViewersObservables { >+ private static Realm getDefaultRealm() { >+ return SWTObservables.getRealm(Display.getDefault()); >+ } >+ >+ private static Realm getRealm(Viewer viewer) { >+ return SWTObservables.getRealm(viewer.getControl().getDisplay()); >+ } >+ >+ private static void checkNull(Object obj) { >+ if (obj == null) >+ throw new IllegalArgumentException(); >+ } >+ >+ private static IObservableValue observeProperty(Object source, >+ IValueProperty property) { >+ checkNull(source); >+ if (source instanceof Viewer) { >+ return observeViewerProperty((Viewer) source, property); >+ } >+ return PropertyObservables.observeValue(getDefaultRealm(), source, >+ property); >+ } >+ >+ private static IViewerObservableValue observeViewerProperty(Viewer viewer, >+ IValueProperty property) { >+ checkNull(viewer); >+ return new ViewerObservableValueDecorator(PropertyObservables >+ .observeValue(getRealm(viewer), viewer, property), viewer); >+ } >+ >+ private static IObservableSet observeProperty(Object source, >+ ISetProperty property) { >+ checkNull(source); >+ if (source instanceof Viewer) { >+ return observeViewerProperty((Viewer) source, property); >+ } >+ return PropertyObservables.observeSet(getDefaultRealm(), source, >+ property); >+ } >+ >+ private static IViewerObservableSet observeViewerProperty(Viewer viewer, >+ ISetProperty property) { >+ checkNull(viewer); >+ return new ViewerObservableSetDecorator(PropertyObservables.observeSet( >+ getRealm(viewer), viewer, property), viewer); >+ } >+ >+ private static IObservableList observeProperty(Object source, >+ IListProperty property) { >+ checkNull(source); >+ if (source instanceof Viewer) { >+ return observeViewerProperty((Viewer) source, property); >+ } >+ Realm realm = getDefaultRealm(); >+ return PropertyObservables.observeList(realm, source, property); >+ } >+ >+ private static IViewerObservableList observeViewerProperty(Viewer viewer, >+ IListProperty property) { >+ checkNull(viewer); >+ Realm realm = getRealm(viewer); >+ return new ViewerObservableListDecorator(PropertyObservables >+ .observeList(realm, viewer, property), viewer); >+ } >+ > /** > * Returns an observable which delays notification of value change events > * from <code>observable</code> until <code>delay</code> milliseconds have >@@ -85,12 +149,8 @@ > */ > public static IObservableValue observeSingleSelection( > ISelectionProvider selectionProvider) { >- if (selectionProvider instanceof Viewer) { >- return observeSingleSelection((Viewer) selectionProvider); >- } >- return new SelectionProviderSingleSelectionObservableValue( >- SWTObservables.getRealm(Display.getDefault()), >- selectionProvider); >+ return observeProperty(selectionProvider, SelectionProviderProperties >+ .singleSelection()); > } > > /** >@@ -114,12 +174,8 @@ > */ > public static IObservableList observeMultiSelection( > ISelectionProvider selectionProvider) { >- if (selectionProvider instanceof Viewer) { >- return observeMultiSelection((Viewer) selectionProvider); >- } >- return new SelectionProviderMultipleSelectionObservableList( >- SWTObservables.getRealm(Display.getDefault()), >- selectionProvider, Object.class); >+ return observeProperty(selectionProvider, SelectionProviderProperties >+ .multipleSelection()); > } > > /** >@@ -136,9 +192,8 @@ > * @since 1.2 > */ > public static IViewerObservableValue observeSingleSelection(Viewer viewer) { >- return new ViewerSingleSelectionObservableValue( >- SWTObservables.getRealm(Display.getDefault()), >- viewer); >+ return observeViewerProperty(viewer, SelectionProviderProperties >+ .singleSelection()); > } > > /** >@@ -160,11 +215,9 @@ > * > * @since 1.2 > */ >- public static IViewerObservableList observeMultiSelection( >- Viewer viewer) { >- return new ViewerMultipleSelectionObservableList( >- SWTObservables.getRealm(Display.getDefault()), >- viewer, Object.class); >+ public static IViewerObservableList observeMultiSelection(Viewer viewer) { >+ return observeViewerProperty(viewer, SelectionProviderProperties >+ .multipleSelection()); > } > > /** >@@ -179,8 +232,7 @@ > * @since 1.2 > */ > public static IObservableValue observeInput(Viewer viewer) { >- return new ViewerInputObservableValue(SWTObservables.getRealm(viewer >- .getControl().getDisplay()), viewer); >+ return observeViewerProperty(viewer, ViewerProperties.input()); > } > > /** >@@ -205,8 +257,8 @@ > return observeCheckedElements((CheckboxTreeViewer) checkable, > elementType); > } >- return new CheckableCheckedElementsObservableSet(SWTObservables >- .getRealm(Display.getDefault()), checkable, elementType); >+ return observeProperty(checkable, CheckableProperties >+ .checkedElements(elementType)); > } > > /** >@@ -224,9 +276,8 @@ > */ > public static IViewerObservableSet observeCheckedElements( > CheckboxTableViewer viewer, Object elementType) { >- return new CheckboxViewerCheckedElementsObservableSet(SWTObservables >- .getRealm(viewer.getControl().getDisplay()), viewer, >- elementType); >+ return observeViewerProperty(viewer, CheckboxTableViewerProperties >+ .checkedElements(elementType)); > } > > /** >@@ -244,9 +295,8 @@ > */ > public static IViewerObservableSet observeCheckedElements( > CheckboxTreeViewer viewer, Object elementType) { >- return new CheckboxViewerCheckedElementsObservableSet(SWTObservables >- .getRealm(viewer.getControl().getDisplay()), viewer, >- elementType); >+ return observeViewerProperty(viewer, CheckboxTreeViewerProperties >+ .checkedElements(elementType)); > } > > /** >@@ -267,7 +317,7 @@ > * @since 1.3 > */ > public static IViewerObservableSet observeFilters(StructuredViewer viewer) { >- return new ViewerFiltersObservableSet(SWTObservables.getRealm(viewer >- .getControl().getDisplay()), viewer); >+ return observeViewerProperty(viewer, StructuredViewerProperties >+ .filters()); > } > } >Index: src/org/eclipse/jface/internal/databinding/internal/swt/LinkObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/internal/swt/LinkObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/internal/swt/LinkObservableValue.java >--- src/org/eclipse/jface/internal/databinding/internal/swt/LinkObservableValue.java 24 Mar 2008 07:07:06 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,47 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Michael Krauter, Catuno GmbH 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: >- * Michael Krauter, Catuno GmbH - initial API and implementation (bug 180223) >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.internal.swt; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.jface.internal.databinding.provisional.swt.AbstractSWTObservableValue; >-import org.eclipse.swt.widgets.Link; >- >-/** >- * @since 1.2 >- * >- */ >-public class LinkObservableValue extends AbstractSWTObservableValue { >- >- private final Link link; >- >- /** >- * @param link >- */ >- public LinkObservableValue(Link link) { >- super(link); >- this.link = link; >- } >- >- public void doSetValue(final Object value) { >- String oldValue = link.getText(); >- link.setText(value == null ? "" : value.toString()); //$NON-NLS-1$ >- fireValueChange(Diffs.createValueDiff(oldValue, link.getText())); >- } >- >- public Object doGetValue() { >- return link.getText(); >- } >- >- public Object getValueType() { >- return String.class; >- } >- >-} >Index: src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionObservableList.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionObservableList.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionObservableList.java >--- src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionObservableList.java 19 Mar 2008 23:03:24 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,111 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007 Peter Centgraf 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: >- * Peter Centgraf - initial API and implementation, bug 124683 >- * Boris Bokowski, IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.jface.internal.databinding.viewers; >- >-import java.util.ArrayList; >-import java.util.Collections; >-import java.util.List; >- >-import org.eclipse.core.databinding.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.list.ListDiff; >-import org.eclipse.core.databinding.observable.list.WritableList; >-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 multiple-selection of an {@link ISelectionProvider}. >- * >- * @since 1.2 >- */ >-public class SelectionProviderMultipleSelectionObservableList extends >- WritableList { >- >- protected ISelectionProvider selectionProvider; >- protected boolean handlingSelection; >- protected boolean updating; >- protected SelectionListener selectionListener = new SelectionListener(); >- >- class SelectionListener implements ISelectionChangedListener { >- public void selectionChanged(SelectionChangedEvent event) { >- if (updating) { >- return; >- } >- handlingSelection = true; >- try { >- updateWrappedList(new ArrayList(getSelectionList(event.getSelection()))); >- } finally { >- handlingSelection = false; >- } >- } >- } >- >- /** >- * Create a new observable list based on the current selection of the given >- * selection provider. Assumes that the selection provider provides >- * structured selections. >- * >- * @param realm >- * @param selectionProvider >- * @param elementType >- */ >- public SelectionProviderMultipleSelectionObservableList(Realm realm, >- ISelectionProvider selectionProvider, Object elementType) { >- super(realm, new ArrayList(getSelectionList(selectionProvider)), elementType); >- this.selectionProvider = selectionProvider; >- selectionProvider.addSelectionChangedListener(selectionListener); >- } >- >- protected void fireListChange(ListDiff diff) { >- if (handlingSelection) { >- super.fireListChange(diff); >- } else { >- // this is a bit of a hack - we are changing the diff to match the order >- // of elements returned by the selection provider after we've set the >- // selection. >- updating = true; >- try { >- List oldList = getSelectionList(selectionProvider); >- selectionProvider >- .setSelection(new StructuredSelection(wrappedList)); >- wrappedList = new ArrayList(getSelectionList(selectionProvider)); >- super.fireListChange(Diffs.computeListDiff(oldList, wrappedList)); >- } finally { >- updating = false; >- } >- } >- } >- >- protected static List getSelectionList(ISelectionProvider selectionProvider) { >- if (selectionProvider == null) { >- throw new IllegalArgumentException(); >- } >- return getSelectionList(selectionProvider.getSelection()); >- } >- >- protected static List getSelectionList(ISelection sel) { >- if (sel instanceof IStructuredSelection) { >- return ((IStructuredSelection) sel).toList(); >- } >- return Collections.EMPTY_LIST; >- } >- >- public synchronized void dispose() { >- selectionProvider.removeSelectionChangedListener(selectionListener); >- selectionProvider = null; >- super.dispose(); >- } >-} >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/ViewerFiltersObservableSet.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/ViewerFiltersObservableSet.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/ViewerFiltersObservableSet.java >--- src/org/eclipse/jface/internal/databinding/viewers/ViewerFiltersObservableSet.java 10 Jul 2008 05:08:26 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,174 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 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 239302) >- *******************************************************************************/ >- >-package org.eclipse.jface.internal.databinding.viewers; >- >-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.observable.Diffs; >-import org.eclipse.core.databinding.observable.Realm; >-import org.eclipse.core.databinding.observable.set.ObservableSet; >-import org.eclipse.jface.databinding.viewers.IViewerObservableSet; >-import org.eclipse.jface.viewers.StructuredViewer; >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.jface.viewers.ViewerFilter; >- >-/** >- * An observable set that tracks the filters of the given viewer. Note that this >- * set will not track changes that are made using direct API on StructuredViewer >- * (by calling >- * {@link StructuredViewer#addFilter(org.eclipse.jface.viewers.ViewerFilter) >- * addFilter()}, >- * {@link StructuredViewer#removeFilter(org.eclipse.jface.viewers.ViewerFilter) >- * removeFilter()}, or >- * {@link StructuredViewer#setFilters(org.eclipse.jface.viewers.ViewerFilter[]) >- * setFilters()}) -- it is assumed that filters are only changed through the >- * set. >- * >- * @since 1.2 >- */ >-public class ViewerFiltersObservableSet extends ObservableSet implements >- IViewerObservableSet { >- >- private StructuredViewer viewer; >- >- /** >- * @param realm >- * @param viewer >- */ >- public ViewerFiltersObservableSet(Realm realm, StructuredViewer viewer) { >- super(realm, new HashSet(Arrays.asList(viewer.getFilters())), >- ViewerFilter.class); >- this.viewer = viewer; >- } >- >- public Viewer getViewer() { >- return viewer; >- } >- >- private void replaceFilters() { >- viewer.getControl().setRedraw(false); >- try { >- viewer.setFilters((ViewerFilter[]) wrappedSet >- .toArray(new ViewerFilter[wrappedSet.size()])); >- } finally { >- viewer.getControl().setRedraw(true); >- } >- } >- >- private void addFilter(ViewerFilter filter) { >- viewer.getControl().setRedraw(false); >- try { >- viewer.addFilter(filter); >- } finally { >- viewer.getControl().setRedraw(true); >- } >- } >- >- private void removeFilter(ViewerFilter filter) { >- viewer.getControl().setRedraw(false); >- try { >- viewer.removeFilter(filter); >- } finally { >- viewer.getControl().setRedraw(true); >- } >- } >- >- public boolean add(Object element) { >- checkRealm(); >- boolean added = wrappedSet.add(element); >- if (added) { >- addFilter((ViewerFilter) element); >- fireSetChange(Diffs.createSetDiff(Collections.singleton(element), >- Collections.EMPTY_SET)); >- } >- return added; >- } >- >- public boolean addAll(Collection c) { >- getterCalled(); >- Set additions = new HashSet(); >- Iterator it = c.iterator(); >- while (it.hasNext()) { >- Object element = it.next(); >- if (wrappedSet.add(element)) { >- additions.add(element); >- } >- } >- if (additions.size() > 0) { >- replaceFilters(); >- fireSetChange(Diffs.createSetDiff(additions, Collections.EMPTY_SET)); >- return true; >- } >- return false; >- } >- >- public void clear() { >- getterCalled(); >- Set removes = new HashSet(wrappedSet); >- wrappedSet.clear(); >- replaceFilters(); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); >- } >- >- public boolean remove(Object o) { >- getterCalled(); >- boolean removed = wrappedSet.remove(o); >- if (removed) { >- removeFilter((ViewerFilter) o); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, >- Collections.singleton(o))); >- } >- return removed; >- } >- >- public boolean removeAll(Collection c) { >- getterCalled(); >- Set removes = new HashSet(); >- Iterator it = c.iterator(); >- while (it.hasNext()) { >- Object element = it.next(); >- if (wrappedSet.remove(element)) { >- removes.add(element); >- } >- } >- if (removes.size() > 0) { >- replaceFilters(); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); >- return true; >- } >- return false; >- } >- >- public boolean retainAll(Collection c) { >- getterCalled(); >- Set removes = new HashSet(); >- Iterator it = wrappedSet.iterator(); >- while (it.hasNext()) { >- Object element = it.next(); >- if (!c.contains(element)) { >- it.remove(); >- removes.add(element); >- } >- } >- if (removes.size() > 0) { >- replaceFilters(); >- fireSetChange(Diffs.createSetDiff(Collections.EMPTY_SET, removes)); >- return true; >- } >- return false; >- } >-} >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/ViewerInputObservableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/ViewerInputObservableValue.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/ViewerInputObservableValue.java >--- src/org/eclipse/jface/internal/databinding/viewers/ViewerInputObservableValue.java 19 Mar 2008 23:03:24 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,73 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2007 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 206839) >- *******************************************************************************/ >- >-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.Viewer; >- >-/** >- * Observes the input of a <code>Viewer</code>. >- * <p> >- * This observer is blind to changes in the viewer's input unless its >- * {@link #setValue(Object)} method is called directly. >- * >- * @since 1.2 >- */ >-public class ViewerInputObservableValue extends AbstractObservableValue { >- >- private final Viewer viewer; >- >- /** >- * Constructs a new instance associated with the provided <code>viewer</code>. >- * >- * @param realm >- * @param viewer >- */ >- public ViewerInputObservableValue( Realm realm, Viewer viewer ) { >- super( realm ); >- if ( viewer == null ) { >- throw new IllegalArgumentException( "The 'viewer' parameter is null." ); //$NON-NLS-1$ >- } >- >- this.viewer = viewer; >- } >- >- /** >- * Sets the input to the provided <code>value</code>. Value change events are >- * fired after input is set in the viewer. >- * >- * @param value object to set as input >- */ >- protected void doSetValue( final Object value ) { >- Object oldValue = doGetValue(); >- viewer.setInput( value ); >- if ( !Util.equals( oldValue, value ) ) { >- fireValueChange( Diffs.createValueDiff( oldValue, value ) ); >- } >- } >- >- /** >- * Retrieves the current input. >- * >- * @return the current input >- */ >- protected Object doGetValue() { >- return viewer.getInput(); >- } >- >- public Object getValueType() { >- return null; >- } >-} >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/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java >diff -N src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java >--- src/org/eclipse/jface/internal/databinding/provisional/swt/AbstractSWTVetoableValue.java 11 Apr 2008 20:46:33 -0000 1.8 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,71 +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.AbstractVetoableValue; >-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 vetoable 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 AbstractSWTVetoableValue extends AbstractVetoableValue implements ISWTObservableValue { >- >- private final Widget widget; >- >- /** >- * Standard constructor for an SWT VetoableValue. Makes sure that >- * the observable gets disposed when the SWT widget is disposed. >- * >- * @param widget >- */ >- protected AbstractSWTVetoableValue(Widget widget) { >- this(SWTObservables.getRealm(widget.getDisplay()), widget); >- } >- >- /** >- * Constructs a new instance for the provided <code>realm</code> and <code>widget</code>. >- * >- * @param realm >- * @param widget >- * @since 1.2 >- */ >- protected AbstractSWTVetoableValue(Realm realm, Widget widget) { >- super(realm); >- this.widget = widget; >- if (widget == null) { >- throw new IllegalArgumentException("The widget parameter is null."); //$NON-NLS-1$ >- } >- widget.addDisposeListener(disposeListener); >- } >- >- private DisposeListener disposeListener = new DisposeListener() { >- public void widgetDisposed(DisposeEvent e) { >- AbstractSWTVetoableValue.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 10 Nov 2008 23:23:11 -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,18 @@ > 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.PropertyObservables; >+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,22 +124,37 @@ > .observeDelayedValue(delay, observable), observable.getWidget()); > } > >+ private static ISWTObservableValue observeWidgetProperty(Widget widget, >+ IValueProperty property) { >+ return new SWTObservableValueDecorator(PropertyObservables >+ .observeValue(getRealm(widget.getDisplay()), widget, property), >+ 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()); > } > > /** >@@ -176,27 +176,41 @@ > */ > 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 +231,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 +266,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 +293,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,6 +311,7 @@ > * <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 >@@ -303,12 +321,18 @@ > * 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(PropertyObservables.observeValue( >+ control, property), control); > } > > /** >@@ -333,23 +357,10 @@ > * @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(PropertyObservables.observeList( >+ control, property), control); > } > > /** >@@ -422,80 +460,106 @@ > */ > 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()); > } > > /** >@@ -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/SWTObservableListDecorator.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SWTObservableListDecorator.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SWTObservableListDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/SWTObservableListDecorator.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 >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.core.databinding.observable.list.DecoratingObservableList; >+import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.jface.databinding.swt.ISWTObservable; >+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 SWTObservableListDecorator extends DecoratingObservableList >+ implements ISWTObservable { >+ private Widget widget; >+ >+ /** >+ * @param decorated >+ * @param widget >+ */ >+ public SWTObservableListDecorator(IObservableList decorated, Widget widget) { >+ super(decorated, true); >+ this.widget = widget; >+ widget.addListener(SWT.Dispose, disposeListener); >+ } >+ >+ private Listener disposeListener = new Listener() { >+ public void handleEvent(Event event) { >+ SWTObservableListDecorator.this.dispose(); >+ } >+ }; >+ >+ public void dispose() { >+ this.widget = null; >+ super.dispose(); >+ } >+ >+ /** >+ * @return Returns the widget. >+ */ >+ public Widget getWidget() { >+ return widget; >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/ToolItemProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ToolItemProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ToolItemProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ToolItemProperties.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.ToolItemTooltipTextProperty; >+ >+/** >+ * A factory for creating properties of SWT ToolItems >+ * >+ * @since 1.3 >+ */ >+public class ToolItemProperties { >+ /** >+ * Returns a value property for the tooltip text of a SWT ToolItems. >+ * >+ * @return a value property for the tooltip text of a SWT ToolItems. >+ */ >+ public static IValueProperty tooltipText() { >+ return new ToolItemTooltipTextProperty(); >+ } >+} >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/internal/databinding/viewers/SelectionProviderMultipleSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderMultipleSelectionProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,60 @@ >+/******************************************************************************* >+ * 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.List; >+ >+import org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.property.list.SimpleListProperty; >+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; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SelectionProviderMultipleSelectionProperty extends >+ SimpleListProperty implements ISelectionChangedListener { >+ protected void doAddListenerTo(Object source) { >+ ((ISelectionProvider) source).addSelectionChangedListener(this); >+ } >+ >+ protected void doRemoveListenerFrom(Object source) { >+ ((ISelectionProvider) source).removeSelectionChangedListener(this); >+ } >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ fireListChange(event.getSelectionProvider(), null); >+ } >+ >+ public Object getElementType() { >+ return Object.class; >+ } >+ >+ protected List doGetList(Object source) { >+ ISelection selection = ((ISelectionProvider) source).getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ return ((IStructuredSelection) selection).toList(); >+ } >+ return Collections.EMPTY_LIST; >+ } >+ >+ protected void doSetList(Object source, List list, ListDiff diff) { >+ ((ISelectionProvider) source) >+ .setSelection(new StructuredSelection(list)); >+ } >+} >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/databinding/viewers/StructuredViewerProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/viewers/StructuredViewerProperties.java >diff -N src/org/eclipse/jface/databinding/viewers/StructuredViewerProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/viewers/StructuredViewerProperties.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.set.ISetProperty; >+import org.eclipse.jface.internal.databinding.viewers.StructuredViewerFiltersProperty; >+ >+/** >+ * A factory for creating properties of JFace StructuredViewers >+ * >+ * @since 1.3 >+ */ >+public class StructuredViewerProperties { >+ /** >+ * Returns a value property for the input of a JFace StructuredViewer. >+ * >+ * @return a value property for the input of a JFace StructuredViewer. >+ */ >+ public static ISetProperty filters() { >+ return new StructuredViewerFiltersProperty(); >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/CLabelProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/CLabelProperties.java >diff -N src/org/eclipse/jface/databinding/swt/CLabelProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/CLabelProperties.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.CLabelTextProperty; >+ >+/** >+ * A factory for creating properties of SWT Labels. >+ * >+ * @since 1.3 >+ */ >+public class CLabelProperties { >+ /** >+ * Returns a value property for the text of a SWT Label. >+ * >+ * @return a value property for the text of a SWT Label. >+ */ >+ public static IValueProperty text() { >+ return new CLabelTextProperty(); >+ } >+} >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,28 @@ >+/******************************************************************************* >+ * 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); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlFocusedProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlFocusedProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlFocusedProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlFocusedProperty.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 >+ * Tom Schindl - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlFocusedProperty extends WidgetBooleanValueProperty { >+ /** >+ * >+ */ >+ public ControlFocusedProperty() { >+ super(new int[] { SWT.FocusIn, SWT.FocusOut }); >+ } >+ >+ public boolean doGetBooleanValue(Object source) { >+ return ((Control) source).isFocusControl(); >+ } >+ >+ public void doSetBooleanValue(Object source, boolean value) { >+ if (value) >+ ((Control) source).setFocus(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/CTabItemTooltipTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/CTabItemTooltipTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/CTabItemTooltipTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/CTabItemTooltipTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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.CTabItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class CTabItemTooltipTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((CTabItem) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((CTabItem) source).setText(value == null ? "" : (String) value); //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/StyledTextProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/StyledTextProperties.java >diff -N src/org/eclipse/jface/databinding/swt/StyledTextProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/StyledTextProperties.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.swt; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.swt.StyledTextTextProperty; >+import org.eclipse.swt.SWT; >+ >+/** >+ * A factory for creating properties of SWT StyledTexts. >+ * >+ * @since 1.3 >+ */ >+public class StyledTextProperties { >+ /** >+ * Returns a value property for the text of a SWT StyledText. >+ * >+ * @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 StyledText. >+ */ >+ public static IValueProperty text(int event) { >+ return new StyledTextTextProperty(event); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlLocationProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlLocationProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlLocationProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlLocationProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,39 @@ >+/******************************************************************************* >+ * 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.core.databinding.observable.value.ValueDiff; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlLocationProperty extends WidgetValueProperty { >+ /** >+ * >+ */ >+ public ControlLocationProperty() { >+ super(SWT.Move, Point.class); >+ } >+ >+ public Object doGetValue(Object source) { >+ return ((Control) source).getLocation(); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((Control) source).setLocation((Point) value); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/TreeItemTooltipTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TreeItemTooltipTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TreeItemTooltipTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/TreeItemTooltipTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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.TreeItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TreeItemTooltipTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((TreeItem) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((TreeItem) source).setText(value == null ? "" : value); //$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,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.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); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/TabItemTooltipTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TabItemTooltipTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TabItemTooltipTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/TabItemTooltipTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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.TabItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TabItemTooltipTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((TabItem) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((TabItem) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlFontProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlFontProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlFontProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlFontProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,37 @@ >+/******************************************************************************* >+ * 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.value.ValueDiff; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlFontProperty extends WidgetValueProperty { >+ /** >+ * >+ */ >+ public ControlFontProperty() { >+ super(Font.class); >+ } >+ >+ public Object doGetValue(Object source) { >+ return ((Control) source).getFont(); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((Control) source).setFont((Font) value); >+ } >+} >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,28 @@ >+/******************************************************************************* >+ * 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); >+ } >+} >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,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.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); >+ } >+ } >+} >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,28 @@ >+/******************************************************************************* >+ * 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$ >+ } >+} >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/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,28 @@ >+/******************************************************************************* >+ * 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$ >+ } >+} >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/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,28 @@ >+/******************************************************************************* >+ * 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$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlBackgroundProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlBackgroundProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlBackgroundProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlBackgroundProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,37 @@ >+/******************************************************************************* >+ * 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.value.ValueDiff; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlBackgroundProperty extends WidgetValueProperty { >+ /** >+ * >+ */ >+ public ControlBackgroundProperty() { >+ super(Color.class); >+ } >+ >+ public Object doGetValue(Object source) { >+ return ((Control) source).getBackground(); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((Control) source).setBackground((Color) value); >+ } >+} >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,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.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" >+ } >+ } >+ } >+} >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,50 @@ >+/******************************************************************************* >+ * 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()); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlStringListProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlStringListProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlStringListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlStringListProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,43 @@ >+/******************************************************************************* >+ * 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 java.util.Arrays; >+import java.util.List; >+ >+import org.eclipse.core.databinding.observable.list.ListDiff; >+import org.eclipse.core.databinding.property.list.SimpleListProperty; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public abstract class ControlStringListProperty extends SimpleListProperty { >+ protected void doSetList(Object source, List list, ListDiff diff) { >+ String[] strings = (String[]) list.toArray(new String[list.size()]); >+ doSetStringList((Control) source, strings); >+ } >+ >+ abstract void doSetStringList(Control control, String[] list); >+ >+ protected List doGetList(Object source) { >+ String[] list = doGetStringList((Control) source); >+ return Arrays.asList(list); >+ } >+ >+ abstract String[] doGetStringList(Control control); >+ >+ public Object getElementType() { >+ return String.class; >+ } >+} >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,28 @@ >+/******************************************************************************* >+ * 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$ >+ } >+} >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/databinding/swt/SpinnerProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/SpinnerProperties.java >diff -N src/org/eclipse/jface/databinding/swt/SpinnerProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/SpinnerProperties.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.SpinnerMaximumProperty; >+import org.eclipse.jface.internal.databinding.swt.SpinnerMinimumProperty; >+import org.eclipse.jface.internal.databinding.swt.SpinnerSelectionProperty; >+ >+/** >+ * A factory for creating properties of SWT Spinners. >+ * >+ * @since 1.3 >+ */ >+public class SpinnerProperties { >+ /** >+ * Returns a value property for the selected value of a SWT Spinner. >+ * >+ * @return a value property for the selected value of a SWT Spinner. >+ */ >+ public static IValueProperty selection() { >+ return new SpinnerSelectionProperty(); >+ } >+ >+ /** >+ * Returns a value property for the minimum value of a SWT Spinner. >+ * >+ * @return a value property for the minimum value of a SWT Spinner. >+ */ >+ public static IValueProperty minimum() { >+ return new SpinnerMinimumProperty(); >+ } >+ >+ /** >+ * Returns a value property for the maximum value of a SWT Spinner. >+ * >+ * @return a value property for the maximum value of a SWT Spinner. >+ */ >+ public static IValueProperty maximum() { >+ return new SpinnerMaximumProperty(); >+ } >+} >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,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.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(); >+ } >+} >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,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.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); >+ } >+} >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,28 @@ >+/******************************************************************************* >+ * 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$ >+ } >+} >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,138 @@ >+/******************************************************************************* >+ * 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() { >+ 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/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/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/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/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/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,46 @@ >+/******************************************************************************* >+ * 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.value.ValueDiff; >+ >+/** >+ * @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); >+ } >+ >+ protected Object doGetValue(Object source) { >+ return doGetBooleanValue(source) ? Boolean.TRUE : Boolean.FALSE; >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ 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/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,106 @@ >+/******************************************************************************* >+ * 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.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 >+ implements ICheckStateListener { >+ private Object elementType; >+ >+ /** >+ * @param elementType >+ */ >+ public CheckableCheckedElementsProperty(Object elementType) { >+ this.elementType = elementType; >+ >+ } >+ >+ protected void doAddListenerTo(Object source) { >+ ((ICheckable) source).addCheckStateListener(this); >+ } >+ >+ protected void doRemoveListenerFrom(Object source) { >+ ((ICheckable) source).removeCheckStateListener(this); >+ } >+ >+ public void checkStateChanged(CheckStateChangedEvent event) { >+ // ICheckable is documented to not fire events when setChecked() is >+ // called, so no need to check whether the element is being updated. >+ >+ Object source = event.getCheckable(); >+ Set set = (Set) getCached(source); >+ >+ Object element = event.getElement(); >+ if (event.getChecked()) { >+ if (set.add(element)) { >+ fireSetChange(source, Diffs.createSetDiff(Collections >+ .singleton(element), Collections.EMPTY_SET)); >+ } >+ } else { >+ if (set.remove(element)) { >+ fireSetChange(source, Diffs.createSetDiff( >+ Collections.EMPTY_SET, Collections.singleton(element))); >+ } >+ } >+ } >+ >+ public Object getElementType() { >+ return elementType; >+ } >+ >+ protected final Set doGetSet(Object source) { >+ ICheckable checkable = (ICheckable) source; >+ >+ Set set = doGetSet(checkable); >+ if (set == null) { >+ set = (Set) getCached(source); >+ } >+ 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 doSetSet(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); >+ } >+ } >+} >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,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; >+ >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+ >+/** >+ * @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); >+ } >+ >+ protected Object doGetValue(Object source) { >+ return new Integer(doGetIntValue(source)); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ 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,39 @@ >+/******************************************************************************* >+ * 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.core.databinding.observable.value.ValueDiff; >+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 doGetValue(Object source) { >+ return ((Control) source).getSize(); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((Control) source).setSize((Point) value); >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/CComboProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/CComboProperties.java >diff -N src/org/eclipse/jface/databinding/swt/CComboProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/CComboProperties.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.CComboItemsProperty; >+import org.eclipse.jface.internal.databinding.swt.CComboSelectionProperty; >+import org.eclipse.jface.internal.databinding.swt.CComboSingleSelectionIndexProperty; >+import org.eclipse.jface.internal.databinding.swt.CComboTextProperty; >+ >+/** >+ * A factory for creating properties of SWT CCombos >+ * >+ * @since 1.3 >+ */ >+public class CComboProperties { >+ /** >+ * Returns a value property for the selection text of a SWT CCombo. >+ * >+ * @return a value property for the selection text of a SWT CCombo. >+ */ >+ public static IValueProperty selection() { >+ return new CComboSelectionProperty(); >+ } >+ >+ /** >+ * Returns a value property for the text of a SWT CCombo. >+ * >+ * @return a value property for the text of a SWT CCombo. >+ */ >+ public static IValueProperty text() { >+ return new CComboTextProperty(); >+ } >+ >+ /** >+ * Returns a list property for the items of a SWT CCombo. >+ * >+ * @return a list property for the items of a SWT CCombo. >+ */ >+ public static IListProperty items() { >+ return new CComboItemsProperty(); >+ } >+ >+ /** >+ * 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 CComboSingleSelectionIndexProperty(); >+ } >+} >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,50 @@ >+/******************************************************************************* >+ * 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()); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlVisibleProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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 ControlVisibleProperty extends WidgetBooleanValueProperty { >+ boolean doGetBooleanValue(Object source) { >+ return ((Control) source).getVisible(); >+ } >+ >+ void doSetBooleanValue(Object source, boolean value) { >+ ((Control) source).setVisible(value); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlTooltipTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlTooltipTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlTooltipTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlTooltipTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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 ControlTooltipTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((Control) source).getToolTipText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((Control) source).setToolTipText(value); >+ } >+} >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/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/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/ListSingleSelectionIndexProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionIndexProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionIndexProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ListSingleSelectionIndexProperty.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.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.List; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ListSingleSelectionIndexProperty extends WidgetIntValueProperty { >+ /** >+ * >+ */ >+ public ListSingleSelectionIndexProperty() { >+ super(new int[] { SWT.Selection, SWT.DefaultSelection }); >+ } >+ >+ int doGetIntValue(Object source) { >+ return ((List) source).getSelectionIndex(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((List) source).setSelection(value); >+ } >+} >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,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.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" >+ } >+ } >+ } >+} >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/internal/databinding/swt/SpinnerSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SpinnerSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SpinnerSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/SpinnerSelectionProperty.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.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Spinner; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SpinnerSelectionProperty extends WidgetIntValueProperty { >+ /** >+ * >+ */ >+ public SpinnerSelectionProperty() { >+ super(SWT.Modify); >+ } >+ >+ int doGetIntValue(Object source) { >+ return ((Spinner) source).getSelection(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Spinner) source).setSelection(value); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlBoundsProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlBoundsProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlBoundsProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlBoundsProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,39 @@ >+/******************************************************************************* >+ * 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.core.databinding.observable.value.ValueDiff; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlBoundsProperty extends WidgetValueProperty { >+ /** >+ * >+ */ >+ public ControlBoundsProperty() { >+ super(new int[] { SWT.Resize, SWT.Move }, Rectangle.class); >+ } >+ >+ public Object doGetValue(Object source) { >+ return ((Control) source).getBounds(); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((Control) source).setBounds((Rectangle) value); >+ } >+} >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,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.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$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/StyledTextTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/StyledTextTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/StyledTextTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/StyledTextTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,48 @@ >+/******************************************************************************* >+ * 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.StyledText; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class StyledTextTextProperty extends WidgetStringValueProperty { >+ /** >+ * @param event >+ */ >+ public StyledTextTextProperty(int event) { >+ super(checkEvent(event)); >+ } >+ >+ private static int checkEvent(int event) { >+ switch (event) { >+ case SWT.None: >+ case SWT.Modify: >+ case SWT.FocusOut: >+ return event; >+ default: >+ throw new IllegalArgumentException("UpdateEventType [" //$NON-NLS-1$ >+ + event + "] is not supported."); //$NON-NLS-1$ >+ } >+ } >+ >+ String doGetStringValue(Object source) { >+ return ((StyledText) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((StyledText) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/LabelTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/LabelTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/LabelTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/LabelTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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.Label; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class LabelTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((Label) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((Label) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/databinding/swt/LabelProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/LabelProperties.java >diff -N src/org/eclipse/jface/databinding/swt/LabelProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/LabelProperties.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.LabelTextProperty; >+ >+/** >+ * A factory for creating properties of SWT Labels. >+ * >+ * @since 1.3 >+ */ >+public class LabelProperties { >+ /** >+ * Returns a value property for the text of a SWT Label. >+ * >+ * @return a value property for the text of a SWT Label. >+ */ >+ public static IValueProperty text() { >+ return new LabelTextProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/TextTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TextTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TextTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/TextTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,48 @@ >+/******************************************************************************* >+ * 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.Text; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TextTextProperty extends WidgetStringValueProperty { >+ /** >+ * @param event >+ */ >+ public TextTextProperty(int event) { >+ super(checkEvent(event)); >+ } >+ >+ private static int checkEvent(int event) { >+ switch (event) { >+ case SWT.None: >+ case SWT.Modify: >+ case SWT.FocusOut: >+ return event; >+ default: >+ throw new IllegalArgumentException("UpdateEventType [" //$NON-NLS-1$ >+ + event + "] is not supported."); //$NON-NLS-1$ >+ } >+ } >+ >+ String doGetStringValue(Object source) { >+ return ((Text) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((Text) source).setText(value == null ? "" : value); //$NON-NLS-1$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/SpinnerMaximumProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/SpinnerMaximumProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/SpinnerMaximumProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/SpinnerMaximumProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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 SpinnerMaximumProperty extends WidgetIntValueProperty { >+ int doGetIntValue(Object source) { >+ return ((Spinner) source).getMaximum(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Spinner) source).setMaximum(value); >+ } >+} >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/databinding/swt/ListProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/swt/ListProperties.java >diff -N src/org/eclipse/jface/databinding/swt/ListProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/swt/ListProperties.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.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.ListItemsProperty; >+import org.eclipse.jface.internal.databinding.swt.ListSelectionProperty; >+import org.eclipse.jface.internal.databinding.swt.ListSingleSelectionIndexProperty; >+ >+/** >+ * A factory for creating properties of SWT List controls. >+ * >+ * @since 1.3 >+ */ >+public class ListProperties { >+ /** >+ * Returns a value property for observing the selection text of a SWT List. >+ * >+ * @return a value property for observing the selection text of a SWT List. >+ */ >+ public static IValueProperty selection() { >+ return new ListSelectionProperty(); >+ } >+ >+ /** >+ * Returns a list property for observing the items in a SWT List. >+ * >+ * @return a list property for observing the items in a SWT List. >+ */ >+ public static IListProperty items() { >+ return new ListItemsProperty(); >+ } >+ >+ /** >+ * Returns a value property for the single selection index of a SWT List. >+ * >+ * @return a value property for the single selection index of a SWT List. >+ */ >+ public static IValueProperty singleSelectionIndex() { >+ return new ListSingleSelectionIndexProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/ViewerInputProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/ViewerInputProperty.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/ViewerInputProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/ViewerInputProperty.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.internal.databinding.viewers; >+ >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.value.SimpleValueProperty; >+import org.eclipse.jface.viewers.Viewer; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ViewerInputProperty extends SimpleValueProperty { >+ public Object getValueType() { >+ return null; >+ } >+ >+ protected Object doGetValue(Object source) { >+ return ((Viewer) source).getInput(); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((Viewer) source).setInput(value); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/SelectionProviderSingleSelectionProperty.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.jface.internal.databinding.viewers; >+ >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.value.SimpleValueProperty; >+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; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class SelectionProviderSingleSelectionProperty extends >+ SimpleValueProperty implements ISelectionChangedListener { >+ protected void doAddListenerTo(Object source) { >+ ((ISelectionProvider) source).addSelectionChangedListener(this); >+ } >+ >+ protected void doRemoveListenerFrom(Object source) { >+ ((ISelectionProvider) source).removeSelectionChangedListener(this); >+ } >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ fireValueChange(event.getSelectionProvider(), null); >+ } >+ >+ public Object getValueType() { >+ return null; >+ } >+ >+ protected Object doGetValue(Object source) { >+ ISelection selection = ((ISelectionProvider) source).getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ return ((IStructuredSelection) selection).getFirstElement(); >+ } >+ return null; >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((ISelectionProvider) source) >+ .setSelection(value == null ? StructuredSelection.EMPTY >+ : new StructuredSelection(value)); >+ } >+} >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/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,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.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(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/viewers/StructuredViewerFiltersProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/viewers/StructuredViewerFiltersProperty.java >diff -N src/org/eclipse/jface/internal/databinding/viewers/StructuredViewerFiltersProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/viewers/StructuredViewerFiltersProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,47 @@ >+/******************************************************************************* >+ * 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.HashSet; >+import java.util.Set; >+ >+import org.eclipse.core.databinding.observable.set.SetDiff; >+import org.eclipse.core.databinding.property.set.SimpleSetProperty; >+import org.eclipse.jface.viewers.StructuredViewer; >+import org.eclipse.jface.viewers.ViewerFilter; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class StructuredViewerFiltersProperty extends SimpleSetProperty { >+ public Object getElementType() { >+ return ViewerFilter.class; >+ } >+ >+ public Set doGetSet(Object source) { >+ return new HashSet(Arrays.asList(((StructuredViewer) source) >+ .getFilters())); >+ } >+ >+ protected void doSetSet(Object source, Set set, SetDiff diff) { >+ StructuredViewer viewer = (StructuredViewer) source; >+ viewer.getControl().setRedraw(false); >+ try { >+ viewer.setFilters((ViewerFilter[]) set.toArray(new ViewerFilter[set >+ .size()])); >+ } finally { >+ viewer.getControl().setRedraw(true); >+ } >+ } >+} >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,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.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); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ListItemsProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ListItemsProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ListItemsProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ListItemsProperty.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.jface.internal.databinding.swt; >+ >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.List; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ListItemsProperty extends ControlStringListProperty { >+ protected void doSetStringList(Control control, String[] list) { >+ ((List) control).setItems(list); >+ } >+ >+ public String[] doGetStringList(Control control) { >+ return ((List) control).getItems(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/ControlForegroundProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ControlForegroundProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ControlForegroundProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ControlForegroundProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,37 @@ >+/******************************************************************************* >+ * 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.value.ValueDiff; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.widgets.Control; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ControlForegroundProperty extends WidgetValueProperty { >+ /** >+ * >+ */ >+ public ControlForegroundProperty() { >+ super(Color.class); >+ } >+ >+ public Object doGetValue(Object source) { >+ return ((Control) source).getForeground(); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ ((Control) source).setForeground((Color) 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,28 @@ >+/******************************************************************************* >+ * 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); >+ } >+} >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,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.core.databinding.observable.value.ValueDiff; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public abstract class WidgetStringValueProperty extends WidgetValueProperty { >+ WidgetStringValueProperty(int event) { >+ super(event, String.class); >+ } >+ >+ WidgetStringValueProperty() { >+ super(String.class); >+ } >+ >+ protected Object doGetValue(Object source) { >+ return doGetStringValue(source); >+ } >+ >+ protected void doSetValue(Object source, Object value, ValueDiff diff) { >+ doSetStringValue(source, (String) value); >+ } >+ >+ abstract String doGetStringValue(Object source); >+ >+ abstract void doSetStringValue(Object source, String value); >+} >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,28 @@ >+/******************************************************************************* >+ * 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); >+ } >+} >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/ScaleSelectionProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/ScaleSelectionProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/ScaleSelectionProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/ScaleSelectionProperty.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.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Scale; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class ScaleSelectionProperty extends WidgetIntValueProperty { >+ /** >+ * >+ */ >+ public ScaleSelectionProperty() { >+ super(SWT.Selection); >+ } >+ >+ int doGetIntValue(Object source) { >+ return ((Scale) source).getSelection(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Scale) source).setSelection(value); >+ } >+} >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,69 @@ >+/******************************************************************************* >+ * 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.value.SimpleValueProperty; >+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 implements >+ Listener { >+ 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; >+ } >+ >+ protected final void doAddListenerTo(Object source) { >+ if (events != null) { >+ for (int i = 0; i < events.length; i++) { >+ int event = events[i]; >+ if (event != SWT.None) { >+ ((Widget) source).addListener(event, this); >+ } >+ } >+ } >+ } >+ >+ protected final void doRemoveListenerFrom(Object source) { >+ 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, this); >+ } >+ } >+ } >+ } >+ >+ public void handleEvent(Event event) { >+ fireValueChange(event.widget, null); >+ } >+ >+ public final Object getValueType() { >+ return valueType; >+ } >+} >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/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,28 @@ >+/******************************************************************************* >+ * 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); >+ } >+} >Index: src/org/eclipse/jface/databinding/viewers/SelectionProviderProperties.java >=================================================================== >RCS file: src/org/eclipse/jface/databinding/viewers/SelectionProviderProperties.java >diff -N src/org/eclipse/jface/databinding/viewers/SelectionProviderProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/databinding/viewers/SelectionProviderProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,46 @@ >+/******************************************************************************* >+ * 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.list.IListProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.jface.internal.databinding.viewers.SelectionProviderMultipleSelectionProperty; >+import org.eclipse.jface.internal.databinding.viewers.SelectionProviderSingleSelectionProperty; >+ >+/** >+ * A factory for creating properties of JFace ISelectionProviders >+ * >+ * @since 1.3 >+ */ >+public class SelectionProviderProperties { >+ /** >+ * Returns a value property for the single selection of a JFace >+ * ISelectionProvider. >+ * >+ * @return a value property for the single selection of a JFace >+ * ISelectionProvider. >+ */ >+ public static IValueProperty singleSelection() { >+ return new SelectionProviderSingleSelectionProperty(); >+ } >+ >+ /** >+ * Returns a list property for the multiple selection of a JFace >+ * ISelectionProvider. >+ * >+ * @return a list property for the multiple selection of a JFace >+ * ISelectionProvider. >+ */ >+ public static IListProperty multipleSelection() { >+ return new SelectionProviderMultipleSelectionProperty(); >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/TrayItemTooltipTextProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TrayItemTooltipTextProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TrayItemTooltipTextProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/TrayItemTooltipTextProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * 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.TrayItem; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TrayItemTooltipTextProperty extends WidgetStringValueProperty { >+ String doGetStringValue(Object source) { >+ return ((TrayItem) source).getText(); >+ } >+ >+ void doSetStringValue(Object source, String value) { >+ ((TrayItem) source).setText(value == null ? "" : value); //$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,28 @@ >+/******************************************************************************* >+ * 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$ >+ } >+} >Index: src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionIndexProperty.java >=================================================================== >RCS file: src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionIndexProperty.java >diff -N src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionIndexProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/internal/databinding/swt/TableSingleSelectionIndexProperty.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.internal.databinding.swt; >+ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Table; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class TableSingleSelectionIndexProperty extends WidgetIntValueProperty { >+ /** >+ * >+ */ >+ public TableSingleSelectionIndexProperty() { >+ super(new int[] { SWT.Selection, SWT.DefaultSelection }); >+ } >+ >+ int doGetIntValue(Object source) { >+ return ((Table) source).getSelectionIndex(); >+ } >+ >+ void doSetIntValue(Object source, int value) { >+ ((Table) source).setSelection(value); >+ } >+} >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,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.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$ >+ } >+}
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