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 107041 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]
Progress patch (untested)
clipboard.txt (text/plain), 33.36 KB, created by
Matthew Hall
on 2008-07-10 02:00:16 EDT
(
hide
)
Description:
Progress patch (untested)
Filename:
MIME Type:
Creator:
Matthew Hall
Created:
2008-07-10 02:00:16 EDT
Size:
33.36 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.databinding >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.databinding/META-INF/MANIFEST.MF,v >retrieving revision 1.15 >diff -u -r1.15 MANIFEST.MF >--- META-INF/MANIFEST.MF 3 Jul 2008 23:47:30 -0000 1.15 >+++ META-INF/MANIFEST.MF 10 Jul 2008 05:54:39 -0000 >@@ -14,6 +14,7 @@ > 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.util, > org.eclipse.core.databinding.validation;x-internal:=false, > org.eclipse.core.internal.databinding;x-friends:="org.eclipse.core.databinding.beans", >Index: src/org/eclipse/core/databinding/property/ValueProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/ValueProperty.java >diff -N src/org/eclipse/core/databinding/property/ValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/ValueProperty.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 >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property; >+ >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+ >+/** >+ * @since 1.2 >+ */ >+public abstract class ValueProperty extends Property implements IValueProperty { >+ public final void addValueChangeListener(Object source, >+ IValuePropertyChangeListener listener) { >+ getChangeSupport().addListener(source, listener); >+ } >+ >+ public final void removeValueChangeListener(Object source, >+ IValuePropertyChangeListener listener) { >+ getChangeSupport().removeListener(source, listener); >+ } >+ >+ protected final void fireValueChange(Object source, ValueDiff diff) { >+ getChangeSupport().fireChange( >+ new ValuePropertyChangeEvent(source, this, diff)); >+ } >+} >Index: src/org/eclipse/core/databinding/property/IValuePropertyChangeListener.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/IValuePropertyChangeListener.java >diff -N src/org/eclipse/core/databinding/property/IValuePropertyChangeListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/IValuePropertyChangeListener.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 >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public interface IValuePropertyChangeListener { >+ /** >+ * @param event >+ */ >+ public void handleValuePropertyChange(ValuePropertyChangeEvent event); >+} >Index: src/org/eclipse/core/databinding/property/ValuePropertyChangeEvent.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/ValuePropertyChangeEvent.java >diff -N src/org/eclipse/core/databinding/property/ValuePropertyChangeEvent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/ValuePropertyChangeEvent.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 >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property; >+ >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class ValuePropertyChangeEvent extends PropertyChangeEvent { >+ private final IValueProperty property; >+ private final ValueDiff diff; >+ >+ /** >+ * @param source >+ * @param property >+ * @param diff >+ */ >+ public ValuePropertyChangeEvent(Object source, IValueProperty property, >+ ValueDiff diff) { >+ super(source); >+ this.property = property; >+ this.diff = diff; >+ } >+ >+ /** >+ * @return Returns the property. >+ */ >+ public IValueProperty getProperty() { >+ return property; >+ } >+ >+ /** >+ * @return Returns the diff. >+ */ >+ public ValueDiff getDiff() { >+ return diff; >+ } >+ >+ protected void dispatch(Object listener) { >+ ((IValuePropertyChangeListener)listener).handleValuePropertyChange(this); >+ } >+} >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,36 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public abstract class PropertyChangeEvent { >+ private final Object source; >+ >+ /** >+ * @param source >+ */ >+ public PropertyChangeEvent(Object source) { >+ this.source = source; >+ } >+ >+ protected abstract void dispatch(Object listener); >+ >+ /** >+ * @return Returns the source. >+ */ >+ public final Object getSource() { >+ return source; >+ } >+} >Index: src/org/eclipse/core/internal/databinding/property/PropertyObservableValue.java >=================================================================== >RCS file: src/org/eclipse/core/internal/databinding/property/PropertyObservableValue.java >diff -N src/org/eclipse/core/internal/databinding/property/PropertyObservableValue.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/databinding/property/PropertyObservableValue.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,104 @@ >+/******************************************************************************* >+ * 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.internal.databinding.property; >+ >+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.IValueProperty; >+import org.eclipse.core.databinding.property.IValuePropertyChangeListener; >+import org.eclipse.core.databinding.property.ValuePropertyChangeEvent; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class PropertyObservableValue extends AbstractObservableValue { >+ private Object source; >+ private IValueProperty property; >+ >+ private volatile 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.getDiff()); >+ } >+ }); >+ } >+ } >+ }; >+ >+ /** >+ * @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(source); >+ } >+ >+ 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/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,25 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * Interface for observing a property of a source object. >+ * >+ * @noimplement >+ * @since 1.2 >+ */ >+public interface IProperty { >+ /** >+ * Disposes the property, removing all property listeners on source objects. >+ */ >+ public void dispose(); >+} >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,106 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property; >+ >+import java.util.Collections; >+import java.util.IdentityHashMap; >+import java.util.Iterator; >+import java.util.Map; >+ >+import org.eclipse.core.runtime.ListenerList; >+ >+/** >+ * @since 1.2 >+ */ >+public class PropertyChangeSupport { >+ private Property property; >+ private Map changeListeners; >+ >+ PropertyChangeSupport(Property property) { >+ this.property = property; >+ this.changeListeners = null; >+ } >+ >+ protected final void addListener(Object source, Object listener) { >+ boolean wasListening = changeListeners.containsKey(source); >+ >+ if (changeListeners == null) { >+ synchronized (this) { >+ if (changeListeners == null) { >+ changeListeners = Collections >+ .synchronizedMap(new IdentityHashMap()); >+ } >+ } >+ } >+ >+ ListenerList listeners; >+ synchronized (changeListeners) { >+ if (changeListeners.containsKey(source)) { >+ listeners = (ListenerList) changeListeners.get(source); >+ } else { >+ changeListeners.put(source, listeners = new ListenerList()); >+ } >+ } >+ >+ synchronized (listeners) { >+ listeners.add(listener); >+ } >+ >+ if (!wasListening) >+ property.addListenerTo(source); >+ } >+ >+ protected final void removeListener(Object source, Object listener) { >+ if (changeListeners != null) { >+ ListenerList listeners = (ListenerList) changeListeners.get(source); >+ if (listeners != null) { >+ listeners.remove(listener); >+ if (listeners.isEmpty()) { >+ synchronized (listeners) { >+ if (listeners.isEmpty()) { >+ changeListeners.remove(source); >+ property.removeListenerFrom(source); >+ } >+ } >+ } >+ } >+ } >+ } >+ >+ protected final void fireChange(PropertyChangeEvent event) { >+ ListenerList listenerList; >+ synchronized (this) { >+ if (changeListeners == null) >+ return; >+ listenerList = (ListenerList) changeListeners >+ .get(event.getSource()); >+ } >+ if (listenerList != null) { >+ Object[] listeners = listenerList.getListeners(); >+ for (int i = 0; i < listeners.length; i++) { >+ event.dispatch(listeners[i]); >+ } >+ } >+ } >+ >+ void dispose() { >+ if (changeListeners != null) { >+ for (Iterator iterator = changeListeners.keySet().iterator(); iterator >+ .hasNext();) { >+ Object source = iterator.next(); >+ property.removeListenerFrom(source); >+ iterator.remove(); >+ } >+ changeListeners = null; >+ } >+ } >+} >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,80 @@ >+/******************************************************************************* >+ * 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; >+ >+import org.eclipse.core.databinding.observable.IObservable; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.internal.databinding.property.PropertyObservableValue; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class PropertyObservables { >+ /** >+ * @param source >+ * @param property >+ * @return an observable value 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); >+ } >+ >+ /** >+ * @param realm >+ * @param source >+ * @param property >+ * @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 obervable values 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 valueFactory(IValueProperty property) { >+ return valueFactory(Realm.getDefault(), property); >+ } >+ >+ /** >+ * Returns a factory for creating obervable values tracking the given >+ * property of a particular source object >+ * >+ * @param realm >+ * the realm to use >+ * @param property >+ * the property to be observed >+ * @return an observable value factory >+ */ >+ public static IObservableFactory valueFactory(final Realm realm, >+ final IValueProperty property) { >+ return new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return observeValue(realm, target, property); >+ } >+ }; >+ } >+} >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,56 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public abstract class Property implements IProperty { >+ private PropertyChangeSupport changeSupport; >+ >+ synchronized PropertyChangeSupport getChangeSupport() { >+ if (changeSupport == null) >+ changeSupport = new PropertyChangeSupport(this); >+ return changeSupport; >+ } >+ >+ /** >+ * Notifies the property that the first listener has been added for the >+ * given source object. Implementers should register a listener on the >+ * source object which fires an appropriate change event when a property >+ * change is observed on the source. >+ * >+ * @param source >+ * the source object to observe for property changes. >+ * @see #removeListenerFrom(Object) >+ */ >+ protected abstract void addListenerTo(Object source); >+ >+ /** >+ * Notifies the property that the last listener has been removed for the >+ * given source object. Implementers should unregister any previously >+ * registered listeners from the source. >+ * >+ * @param source >+ * the source object to stop observing for property changes. >+ * @see #addListenerTo(Object) >+ */ >+ protected abstract void removeListenerFrom(Object source); >+ >+ public synchronized void dispose() { >+ if (changeSupport != null) { >+ changeSupport.dispose(); >+ changeSupport = null; >+ } >+ } >+} >Index: src/org/eclipse/core/databinding/property/IValueProperty.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/property/IValueProperty.java >diff -N src/org/eclipse/core/databinding/property/IValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/property/IValueProperty.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 >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.property; >+ >+/** >+ * Interface for observing a value property of a source object. >+ * >+ * @since 1.2 >+ */ >+public interface IValueProperty extends IProperty { >+ /** >+ * @param source >+ * @return the value type >+ */ >+ public Object getValueType(Object source); >+ >+ /** >+ * @param source >+ * @return the property value >+ */ >+ public Object getValue(Object source); >+ >+ /** >+ * @param source >+ * @param value >+ */ >+ public void setValue(Object source, Object value); >+ >+ /** >+ * @param source >+ * @param listener >+ */ >+ public void addValueChangeListener(Object source, >+ IValuePropertyChangeListener listener); >+ >+ /** >+ * @param source >+ * @param listener >+ */ >+ public void removeValueChangeListener(Object source, >+ IValuePropertyChangeListener listener); >+} >#P org.eclipse.core.databinding.beans >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,122 @@ >+/******************************************************************************* >+ * 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.internal.databinding.beans; >+ >+import java.beans.PropertyChangeEvent; >+import java.beans.PropertyChangeListener; >+import java.beans.PropertyDescriptor; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.property.ValueProperty; >+import org.eclipse.core.internal.databinding.Util; >+ >+/** >+ * @since 3.3 >+ * >+ */ >+public class BeanValueProperty extends ValueProperty { >+ private PropertyDescriptor propertyDescriptor; >+ private final boolean attachListener; >+ >+ private boolean updating; >+ >+ private ListenerSupport listenerSupport; >+ >+ /** >+ * @param propertyDescriptor >+ */ >+ public BeanValueProperty(PropertyDescriptor propertyDescriptor) { >+ this(propertyDescriptor, true); >+ } >+ >+ /** >+ * @param propertyDescriptor >+ * @param attachListener >+ */ >+ public BeanValueProperty(PropertyDescriptor propertyDescriptor, >+ boolean attachListener) { >+ this.propertyDescriptor = propertyDescriptor; >+ this.attachListener = attachListener; >+ >+ } >+ >+ private void initListenerSupport() { >+ if (listenerSupport == null) { >+ synchronized (this) { >+ if (listenerSupport != null) { >+ PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { >+ public void propertyChange(PropertyChangeEvent evt) { >+ if (!updating) { >+ fireValueChange(evt.getSource(), Diffs >+ .createValueDiff(evt.getOldValue(), evt >+ .getNewValue())); >+ } >+ } >+ }; >+ listenerSupport = new ListenerSupport( >+ propertyChangeListener, propertyDescriptor >+ .getName()); >+ } >+ } >+ } >+ } >+ >+ protected void addListenerTo(Object source) { >+ if (attachListener) { >+ initListenerSupport(); >+ listenerSupport.hookListener(source); >+ } >+ } >+ >+ protected void removeListenerFrom(Object source) { >+ if (attachListener && listenerSupport != null) { >+ listenerSupport.unhookListener(source); >+ } >+ } >+ >+ public Object getValueType(Object source) { >+ return propertyDescriptor.getPropertyType(); >+ } >+ >+ public Object getValue(Object source) { >+ return BeanPropertyHelper.getProperty(source, propertyDescriptor); >+ } >+ >+ public void setValue(Object source, Object value) { >+ Object oldValue = getValue(source); >+ >+ if (Util.equals(oldValue, value)) { >+ return; >+ } >+ >+ updating = true; >+ try { >+ BeanPropertyHelper.setProperty(source, propertyDescriptor, value); >+ } finally { >+ updating = false; >+ } >+ >+ Object newValue = getValue(source); >+ if (!Util.equals(oldValue, newValue)) { >+ fireValueChange(source, Diffs.createValueDiff(oldValue, newValue)); >+ } >+ } >+ >+ public synchronized void dispose() { >+ if (listenerSupport != null) { >+ listenerSupport.dispose(); >+ listenerSupport = null; >+ } >+ propertyDescriptor = 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,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.beans; >+ >+import org.eclipse.core.databinding.property.IValueProperty; >+import org.eclipse.core.internal.databinding.beans.BeanValueProperty; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class PojoProperties { >+ /** >+ * @param beanClass >+ * @param propertyName >+ * @return a bean value property for the given property name. >+ */ >+ public static IValueProperty valueProperty(Class beanClass, >+ String propertyName) { >+ return new BeanValueProperty(BeansObservables.getPropertyDescriptor( >+ beanClass, propertyName), false); >+ } >+} >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,33 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Matthew Hall and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Matthew Hall - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.beans; >+ >+import org.eclipse.core.databinding.property.IValueProperty; >+import org.eclipse.core.internal.databinding.beans.BeanValueProperty; >+ >+/** >+ * @since 1.2 >+ * >+ */ >+public class BeanProperties { >+ /** >+ * @param beanClass >+ * @param propertyName >+ * @return a value property for the given property name of the given bean >+ * class. >+ */ >+ public static IValueProperty valueProperty(Class beanClass, >+ String propertyName) { >+ return new BeanValueProperty(BeansObservables.getPropertyDescriptor( >+ beanClass, propertyName)); >+ } >+} >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,109 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.core.internal.databinding.beans; >+ >+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.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; >+ } >+ } >+}
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