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 124701 Details for
Bug 262160
Implement the new Property-based Databinding-API
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 including Editing-Properties
patch.txt (text/plain), 117.18 KB, created by
Thomas Schindl
on 2009-02-04 12:57:18 EST
(
hide
)
Description:
Patch including Editing-Properties
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2009-02-04 12:57:18 EST
Size:
117.18 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.databinding >Index: src/org/eclipse/emf/databinding/EMFUpdateListStrategy.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/src/org/eclipse/emf/databinding/EMFUpdateListStrategy.java,v >retrieving revision 1.1 >diff -u -r1.1 EMFUpdateListStrategy.java >--- src/org/eclipse/emf/databinding/EMFUpdateListStrategy.java 16 Nov 2007 21:25:21 -0000 1.1 >+++ src/org/eclipse/emf/databinding/EMFUpdateListStrategy.java 24 Jan 2009 17:10:27 -0000 >@@ -9,78 +9,122 @@ > * > * Contributors: > * IBM - Initial API and implementation >- * >+ * Tom Schindl<tom.schindl@bestsolution.at> > * </copyright> > * > * $Id: EMFUpdateListStrategy.java,v 1.1 2007/11/16 21:25:21 emerks Exp $ > */ > package org.eclipse.emf.databinding; > >+import org.eclipse.core.databinding.Binding; >+import org.eclipse.core.databinding.DataBindingContext; > import org.eclipse.core.databinding.UpdateListStrategy; > import org.eclipse.core.databinding.conversion.Converter; > import org.eclipse.core.databinding.conversion.IConverter; >+import org.eclipse.core.databinding.observable.list.IObservableList; > import org.eclipse.emf.ecore.EAttribute; > import org.eclipse.emf.ecore.EDataType; > import org.eclipse.emf.ecore.EFactory; > > /** >- * PROVISIONAL >- * This API is subject to arbitrary change, including renaming or removal. >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * Customizes a {@link Binding} between two {@link IObservableList observable >+ * lists}. The following behaviors can be customized via the strategy: >+ * <ul> >+ * <li>Conversion</li> >+ * <li>Automatic processing</li> >+ * </ul> >+ * <p> >+ * Conversion:<br/> >+ * When elements are added they can be {@link #convert(Object) converted} to the >+ * destination element type. >+ * </p> >+ * <p> >+ * Automatic processing:<br/> >+ * The processing to perform when the source observable changes. This behavior >+ * is configured via policies provided on construction of the strategy (e.g. >+ * {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, {@link #POLICY_UPDATE}). >+ * </p> >+ * >+ * >+ * @see DataBindingContext#bindList(IObservableList, IObservableList, >+ * UpdateListStrategy, UpdateListStrategy) >+ * @see IConverter >+ * @since 1.0 > */ >-public class EMFUpdateListStrategy extends UpdateListStrategy >-{ >- public EMFUpdateListStrategy() >- { >- this(true, POLICY_UPDATE); >- } >+public class EMFUpdateListStrategy extends UpdateListStrategy { >+ /** >+ * Creates a new update list strategy for automatically updating the >+ * destination observable list whenever the source observable list changes. >+ * A default converter will be provided. The defaults can be changed by >+ * calling one of the setter methods. >+ */ >+ public EMFUpdateListStrategy() { >+ this(true, POLICY_UPDATE); >+ } >+ >+ /** >+ * Creates a new update list strategy with a configurable update policy. A >+ * default converter will be provided. The defaults can be changed by >+ * calling one of the setter methods. >+ * >+ * @param updatePolicy >+ * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or >+ * {@link #POLICY_UPDATE} >+ */ >+ public EMFUpdateListStrategy(int updatePolicy) { >+ this(true, updatePolicy); >+ } > >- public EMFUpdateListStrategy(int updatePolicy) >- { >- this(true, updatePolicy); >- } >+ /** >+ * Creates a new update list strategy with a configurable update policy. A >+ * default converter will be provided if <code>provideDefaults</code> is >+ * <code>true</code>. The defaults can be changed by calling one of the >+ * setter methods. >+ * >+ * @param provideDefaults >+ * if <code>true</code>, default validators and a default >+ * converter will be provided based on the observable list's >+ * type. >+ * @param updatePolicy >+ * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or >+ * {@link #POLICY_UPDATE} >+ */ >+ public EMFUpdateListStrategy(boolean provideDefaults, int updatePolicy) { >+ super(provideDefaults, updatePolicy); >+ } > >- public EMFUpdateListStrategy(boolean provideDefaults, int updatePolicy) >- { >- super(provideDefaults, updatePolicy); >- } >- >- @Override >- protected IConverter createConverter(Object fromType, Object toType) >- { >- if (fromType == String.class) >- { >- if (toType instanceof EAttribute) >- { >- final EAttribute eAttribute = (EAttribute)toType; >- final EDataType eDataType = eAttribute.getEAttributeType(); >- final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance(); >- return >- new Converter(fromType, toType) >- { >- public Object convert(Object fromObject) >- { >- return eFactory.createFromString(eDataType, (String)fromObject); >- } >- }; >- } >- } >- else if (toType == String.class) >- { >- if (fromType instanceof EAttribute) >- { >- final EAttribute eAttribute = (EAttribute)fromType; >- final EDataType eDataType = eAttribute.getEAttributeType(); >- final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance(); >- return >- new Converter(fromType, toType) >- { >- public Object convert(Object fromObject) >- { >- return eFactory.convertToString(eDataType, fromObject); >- } >- }; >- } >- } >- return super.createConverter(fromType, toType); >- } >+ @Override >+ protected IConverter createConverter(Object fromType, Object toType) { >+ if (fromType == String.class) { >+ if (toType instanceof EAttribute) { >+ final EAttribute eAttribute = (EAttribute) toType; >+ final EDataType eDataType = eAttribute.getEAttributeType(); >+ final EFactory eFactory = eDataType.getEPackage() >+ .getEFactoryInstance(); >+ return new Converter(fromType, toType) { >+ public Object convert(Object fromObject) { >+ return eFactory.createFromString(eDataType, >+ (String) fromObject); >+ } >+ }; >+ } >+ } else if (toType == String.class) { >+ if (fromType instanceof EAttribute) { >+ final EAttribute eAttribute = (EAttribute) fromType; >+ final EDataType eDataType = eAttribute.getEAttributeType(); >+ final EFactory eFactory = eDataType.getEPackage() >+ .getEFactoryInstance(); >+ return new Converter(fromType, toType) { >+ public Object convert(Object fromObject) { >+ return eFactory.convertToString(eDataType, fromObject); >+ } >+ }; >+ } >+ } >+ return super.createConverter(fromType, toType); >+ } > } >Index: src/org/eclipse/emf/databinding/EMFDataBindingContext.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/src/org/eclipse/emf/databinding/EMFDataBindingContext.java,v >retrieving revision 1.1 >diff -u -r1.1 EMFDataBindingContext.java >--- src/org/eclipse/emf/databinding/EMFDataBindingContext.java 16 Nov 2007 21:25:21 -0000 1.1 >+++ src/org/eclipse/emf/databinding/EMFDataBindingContext.java 24 Jan 2009 17:10:27 -0000 >@@ -9,43 +9,84 @@ > * > * Contributors: > * IBM - Initial API and implementation >- * >+ * Tom Schindl<tom.schindl@bestsolution.at> > * </copyright> > * > * $Id: EMFDataBindingContext.java,v 1.1 2007/11/16 21:25:21 emerks Exp $ > */ > package org.eclipse.emf.databinding; > >+import org.eclipse.core.databinding.Binding; > import org.eclipse.core.databinding.DataBindingContext; > import org.eclipse.core.databinding.UpdateValueStrategy; > import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.IObservableList; > import org.eclipse.core.databinding.observable.value.IObservableValue; > > /** >- * PROVISIONAL >- * This API is subject to arbitrary change, including renaming or removal. >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * >+ * A DataBindingContext is the point of contact for the creation and management >+ * of {@link Binding bindings}, and aggregates validation statuses of its >+ * bindings, or more generally, its validation status providers. >+ * <p> >+ * A DataBindingContext provides the following abilities: >+ * <ul> >+ * <li>Ability to create bindings between {@link IObservableValue observable >+ * values}.</li> >+ * <li>Ability to create bindings between {@link IObservableList observable >+ * lists}.</li> >+ * <li>Access to the bindings created by the instance.</li> >+ * <li>Access to the list of validation status providers (this includes all >+ * bindings).</li> >+ * </ul> >+ * </p> >+ * <p> >+ * Multiple contexts can be used at any point in time. One strategy for the >+ * management of contexts is the aggregation of validation statuses. For example >+ * an <code>IWizardPage</code> could use a single context and the statuses could >+ * be aggregated to set the page status and fulfillment. Each page in the >+ * <code>IWizard</code> would have its own context instance. >+ * </p> >+ * >+ * @since 1.0 > */ >-public class EMFDataBindingContext extends DataBindingContext >-{ >- public EMFDataBindingContext() >- { >- this(Realm.getDefault()); >- } >+public class EMFDataBindingContext extends DataBindingContext { >+ /** >+ * Creates a data binding context, using the current default realm for the >+ * validation observables. >+ * >+ * @see Realm >+ */ >+ public EMFDataBindingContext() { >+ this(Realm.getDefault()); >+ } >+ >+ /** >+ * Creates a data binding context using the given realm for the validation >+ * observables. >+ * >+ * @param validationRealm >+ * the realm to be used for the validation observables >+ * >+ * @see Realm >+ */ >+ public EMFDataBindingContext(Realm validationRealm) { >+ super(validationRealm); >+ } > >- public EMFDataBindingContext(Realm validationRealm) >- { >- super(validationRealm); >- } >+ @Override >+ protected UpdateValueStrategy createModelToTargetUpdateValueStrategy( >+ IObservableValue fromValue, IObservableValue toValue) { >+ return new EMFUpdateValueStrategy(); >+ } > >- @Override >- protected UpdateValueStrategy createModelToTargetUpdateValueStrategy(IObservableValue fromValue, IObservableValue toValue) >- { >- return new EMFUpdateValueStrategy(); >- } >- >- @Override >- protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(IObservableValue fromValue, IObservableValue toValue) >- { >- return new EMFUpdateValueStrategy(); >- } >+ @Override >+ protected UpdateValueStrategy createTargetToModelUpdateValueStrategy( >+ IObservableValue fromValue, IObservableValue toValue) { >+ return new EMFUpdateValueStrategy(); >+ } > } >Index: src/org/eclipse/emf/databinding/EObjectObservableValue.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/src/org/eclipse/emf/databinding/EObjectObservableValue.java,v >retrieving revision 1.2 >diff -u -r1.2 EObjectObservableValue.java >--- src/org/eclipse/emf/databinding/EObjectObservableValue.java 26 Jan 2008 21:01:07 -0000 1.2 >+++ src/org/eclipse/emf/databinding/EObjectObservableValue.java 24 Jan 2009 17:10:27 -0000 >@@ -9,7 +9,7 @@ > * > * Contributors: > * IBM - Initial API and implementation >- * >+ * Tom Schindl<tom.schindl@bestsolution.at> > * </copyright> > * > * $Id: EObjectObservableValue.java,v 1.2 2008/01/26 21:01:07 emerks Exp $ >@@ -28,122 +28,107 @@ > import org.eclipse.emf.ecore.EStructuralFeature; > > /** >- * PROVISIONAL >- * This API is subject to arbitrary change, including renaming or removal. >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> > */ >-public class EObjectObservableValue extends AbstractObservableValue implements IObserving >-{ >- protected EObject eObject; >- protected EStructuralFeature eStructuralFeature; >- protected Adapter listener; >- >- public EObjectObservableValue(EObject eObject, EStructuralFeature eStructuralFeature) >- { >- this(Realm.getDefault(), eObject, eStructuralFeature); >- } >- >- public EObjectObservableValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature) >- { >- super(realm); >- this.eObject = eObject; >- this.eStructuralFeature = eStructuralFeature; >- } >- >- @Override >- public synchronized void dispose() >- { >- if (listener != null) >- { >- eObject.eAdapters().remove(listener); >- listener = null; >- } >- eObject = null; >- eStructuralFeature = null; >- super.dispose(); >- } >- >- public Object getObserved() >- { >- return eObject; >- } >- >- @Override >- protected void firstListenerAdded() >- { >- listener = >- new AdapterImpl() >- { >- @Override >- public void notifyChanged(Notification notification) >- { >- if (eStructuralFeature == notification.getFeature() && !notification.isTouch()) >- { >- final ValueDiff diff = Diffs.createValueDiff(notification.getOldValue(), notification.getNewValue()); >- getRealm().exec >- (new Runnable() >- { >- public void run() >- { >- fireValueChange(diff); >- } >- }); >- } >- } >- }; >- eObject.eAdapters().add(listener); >- } >- >- @Override >- protected void lastListenerRemoved() >- { >- eObject.eAdapters().remove(listener); >- listener = null; >- } >- >- @Override >- protected Object doGetValue() >- { >- return eObject.eGet(eStructuralFeature); >- } >- >- @Override >- protected void doSetValue(Object value) >- { >- eObject.eSet(eStructuralFeature, value); >- } >- >- public Object getValueType() >- { >- return eStructuralFeature; >- } >- >- @Override >- public String toString() >- { >- StringBuilder result = new StringBuilder(getClass().getName()); >- result.append('@'); >- result.append(Integer.toHexString(hashCode())); >- >- result.append(" (eObject:"); >- result.append(eObject); >- result.append(")"); >- >- result.append(" (eStructuralFeature: "); >- result.append(eStructuralFeature); >- result.append(")"); >- >- try >- { >- Object value = eObject.eGet(eStructuralFeature, false); >- result.append(" (value: "); >- result.append(value); >- result.append(")"); >- } >- catch (Exception exception) >- { >- // Ignore. >- } >+public class EObjectObservableValue extends AbstractObservableValue implements >+ IObserving { >+ protected EObject eObject; >+ protected EStructuralFeature eStructuralFeature; >+ protected Adapter listener; >+ >+ public EObjectObservableValue(EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ this(Realm.getDefault(), eObject, eStructuralFeature); >+ } >+ >+ public EObjectObservableValue(Realm realm, EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ super(realm); >+ this.eObject = eObject; >+ this.eStructuralFeature = eStructuralFeature; >+ } >+ >+ @Override >+ public synchronized void dispose() { >+ if (listener != null) { >+ eObject.eAdapters().remove(listener); >+ listener = null; >+ } >+ eObject = null; >+ eStructuralFeature = null; >+ super.dispose(); >+ } >+ >+ public Object getObserved() { >+ return eObject; >+ } >+ >+ @Override >+ protected void firstListenerAdded() { >+ listener = new AdapterImpl() { >+ @Override >+ public void notifyChanged(Notification notification) { >+ if (eStructuralFeature == notification.getFeature() >+ && !notification.isTouch()) { >+ final ValueDiff diff = Diffs.createValueDiff(notification >+ .getOldValue(), notification.getNewValue()); >+ getRealm().exec(new Runnable() { >+ public void run() { >+ fireValueChange(diff); >+ } >+ }); >+ } >+ } >+ }; >+ eObject.eAdapters().add(listener); >+ } >+ >+ @Override >+ protected void lastListenerRemoved() { >+ eObject.eAdapters().remove(listener); >+ listener = null; >+ } >+ >+ @Override >+ protected Object doGetValue() { >+ return eObject.eGet(eStructuralFeature); >+ } >+ >+ @Override >+ protected void doSetValue(Object value) { >+ eObject.eSet(eStructuralFeature, value); >+ } >+ >+ public Object getValueType() { >+ return eStructuralFeature; >+ } >+ >+ @Override >+ public String toString() { >+ StringBuilder result = new StringBuilder(getClass().getName()); >+ result.append('@'); >+ result.append(Integer.toHexString(hashCode())); >+ >+ result.append(" (eObject:"); >+ result.append(eObject); >+ result.append(")"); >+ >+ result.append(" (eStructuralFeature: "); >+ result.append(eStructuralFeature); >+ result.append(")"); >+ >+ try { >+ Object value = eObject.eGet(eStructuralFeature, false); >+ result.append(" (value: "); >+ result.append(value); >+ result.append(")"); >+ } catch (Exception exception) { >+ // Ignore. >+ } > >- return result.toString(); >- } >+ return result.toString(); >+ } > } >Index: src/org/eclipse/emf/databinding/EMFObservables.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/src/org/eclipse/emf/databinding/EMFObservables.java,v >retrieving revision 1.3 >diff -u -r1.3 EMFObservables.java >--- src/org/eclipse/emf/databinding/EMFObservables.java 22 Apr 2008 13:36:00 -0000 1.3 >+++ src/org/eclipse/emf/databinding/EMFObservables.java 24 Jan 2009 17:10:27 -0000 >@@ -10,14 +10,13 @@ > * Contributors: > * IBM - Initial API and implementation > * Trevor S. Kaufman - Bug 215131 - added mapFactory >- * >+ * Tom Schindl<tom.schindl@bestsolution.at> > * </copyright> > * > * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $ > */ > package org.eclipse.emf.databinding; > >- > import org.eclipse.core.databinding.observable.IObservable; > import org.eclipse.core.databinding.observable.Realm; > import org.eclipse.core.databinding.observable.list.IObservableList; >@@ -30,165 +29,216 @@ > import org.eclipse.emf.ecore.EStructuralFeature; > > /** >- * PROVISIONAL >- * This API is subject to arbitrary change, including renaming or removal. >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * A factory for creating observable objects of 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.0 > */ >-public class EMFObservables >-{ >- /** >- * Returns an observable value for the given feature of the object. >- * @param eObject the object to observe. >- * @param eStructuralFeature the feature of the object to observe. >- * @return an observable value for the given feature of the object. >- */ >- public static IObservableValue observeValue(EObject eObject, EStructuralFeature eStructuralFeature) >- { >- return new EObjectObservableValue(eObject, eStructuralFeature); >- } >- >- /** >- * Returns an observable value for the given feature of the object. >- * @param realm the realm in which to observe. >- * @param eObject the object to observe. >- * @param eStructuralFeature the feature of the object to observe. >- * @return an observable value for the given feature of the object. >- */ >- public static IObservableValue observeValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature) >- { >- return new EObjectObservableValue(realm, eObject, eStructuralFeature); >- } >- >- /** >- * Returns an observable list for the given multi-valued feature of the object. >- * @param eObject the object to observe. >- * @param eStructuralFeature the feature of the object to observe. >- * @return an observable list for the given multi-valued feature of the object. >- */ >- public static IObservableList observeList(EObject eObject, EStructuralFeature eStructuralFeature) >- { >- return new EObjectObservableList(eObject, eStructuralFeature); >- } >- >- /** >- * Returns an observable list for the given multi-valued feature of the object. >- * @param realm the realm in which to observe. >- * @param eObject the object to observe. >- * @param eStructuralFeature the feature of the object to observe. >- * @return an observable list for the given multi-valued feature of the object. >- */ >- public static IObservableList observeList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature) >- { >- return new EObjectObservableList(realm, eObject, eStructuralFeature); >- } >- >- /** >- * Returns an observable map in the default realm >- * tracking the current value of the given feature for each object in the given set. >- * @param objects the objects to track. >- * @param eStructuralFeature the feature for which to track the value. >- * @return an observable map tracking the current value of the given feature for each object in the given set. >- */ >- public static IObservableMap observeMap(IObservableSet objects, EStructuralFeature eStructuralFeature) >- { >- return new EObjectObservableMap(objects, eStructuralFeature); >- } >- >- /** >- * Returns an array of observable maps in the default realm >- * tracking the current value of the given features for each object in the given set. >- * @param objects the objects to track. >- * @param eStructuralFeatures the features for which to track the value. >- * @return an array of observable maps tracking the current value of the given features for each object in the given set. >- */ >- public static IObservableMap[] observeMaps(IObservableSet objects, EStructuralFeature[] eStructuralFeatures) >- { >- IObservableMap[] result = new IObservableMap [eStructuralFeatures.length]; >- for (int i = 0; i < eStructuralFeatures.length; i++) >- { >- result[i] = observeMap(objects, eStructuralFeatures[i]); >- } >- return result; >- } >- >- /** >- * Returns an observable value that tracks the current value of the feature of the current value of the master observable value. >- * @param realm the realm in which to observe. >- * @param value the master observable value. >- * @param eStructuralFeature the feature for which to track the value. >- * @return an observable value that tracks the current value of the named property for the current value of the master observable value >- * @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object) >- */ >- public static IObservableValue observeDetailValue(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature) >- { >- return MasterDetailObservables.detailValue(value, valueFactory(realm, eStructuralFeature), eStructuralFeature); >- } >- >- /** >- * Returns a factory for creating observable values >- * tracking the value of the given feature of a particular {@link EObject object}. >- * @param realm the realm in which to observe. >- * @param eStructuralFeature the feature for which to track the value. >- * @return an observable factory. >- */ >- public static IObservableFactory valueFactory(final Realm realm, final EStructuralFeature eStructuralFeature) >- { >- return >- new IObservableFactory() >- { >- public IObservable createObservable(Object target) >- { >- return observeValue(realm, (EObject)target, eStructuralFeature); >- } >- }; >- } >- >- /** >- * Returns an observable list that tracks the current value of the feature of the current value of the master observable value. >- * @param realm the realm in which to observe. >- * @param value the master observable value. >- * @param eStructuralFeature the feature for which to track the value. >- * @return an observable value that tracks the current value of the named property for the current value of the master observable value >- * @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object) >- */ >- public static IObservableList observeDetailList(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature) >- { >- return MasterDetailObservables.detailList(value, listFactory(realm, eStructuralFeature), eStructuralFeature); >- } >- >- /** >- * Returns a factory for creating observable lists >- * tracking the value of the given feature of a particular {@link EObject object}. >- * @param realm the realm in which to observe. >- * @param eStructuralFeature the feature for which to track the value. >- * @return an observable factory. >- */ >- public static IObservableFactory listFactory(final Realm realm, final EStructuralFeature eStructuralFeature) >- { >- return >- new IObservableFactory() >- { >- public IObservable createObservable(Object target) >- { >- return observeList(realm, (EObject)target, eStructuralFeature); >- } >- }; >- } >- >- /** >- * Returns a factory for creating observable maps >- * tracking the value of the given feature of a particular {@link EObject object}. >- * @param eStructuralFeature the feature for which to track the value. >- * @return an observable factory. >- */ >- public static IObservableFactory mapFactory(final EStructuralFeature eStructuralFeature) >- { >- return >- new IObservableFactory() >- { >- public IObservable createObservable(Object target) >- { >- return observeMap((IObservableSet)target, eStructuralFeature); >- } >- }; >- } >+public class EMFObservables { >+ /** >+ * >+ */ >+ public static final boolean DEBUG = false; >+ >+ /** >+ * Returns an observable value for the given feature of the object. >+ * >+ * @param eObject >+ * the object to observe. >+ * @param eStructuralFeature >+ * the feature of the object to observe. >+ * @return an observable value for the given feature of the object. >+ */ >+ public static IObservableValue observeValue(EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ return new EObjectObservableValue(eObject, eStructuralFeature); >+ } >+ >+ /** >+ * Returns an observable value for the given feature of the object. >+ * >+ * @param realm >+ * the realm in which to observe. >+ * @param eObject >+ * the object to observe. >+ * @param eStructuralFeature >+ * the feature of the object to observe. >+ * @return an observable value for the given feature of the object. >+ */ >+ public static IObservableValue observeValue(Realm realm, EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ return new EObjectObservableValue(realm, eObject, eStructuralFeature); >+ } >+ >+ /** >+ * Returns an observable list for the given multi-valued feature of the >+ * object. >+ * >+ * @param eObject >+ * the object to observe. >+ * @param eStructuralFeature >+ * the feature of the object to observe. >+ * @return an observable list for the given multi-valued feature of the >+ * object. >+ */ >+ public static IObservableList observeList(EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ return new EObjectObservableList(eObject, eStructuralFeature); >+ } >+ >+ /** >+ * Returns an observable list for the given multi-valued feature of the >+ * object. >+ * >+ * @param realm >+ * the realm in which to observe. >+ * @param eObject >+ * the object to observe. >+ * @param eStructuralFeature >+ * the feature of the object to observe. >+ * @return an observable list for the given multi-valued feature of the >+ * object. >+ */ >+ public static IObservableList observeList(Realm realm, EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ return new EObjectObservableList(realm, eObject, eStructuralFeature); >+ } >+ >+ /** >+ * Returns an observable map in the default realm tracking the current value >+ * of the given feature for each object in the given set. >+ * >+ * @param objects >+ * the objects to track. >+ * @param eStructuralFeature >+ * the feature for which to track the value. >+ * @return an observable map tracking the current value of the given feature >+ * for each object in the given set. >+ */ >+ public static IObservableMap observeMap(IObservableSet objects, >+ EStructuralFeature eStructuralFeature) { >+ return new EObjectObservableMap(objects, eStructuralFeature); >+ } >+ >+ /** >+ * Returns an array of observable maps in the default realm tracking the >+ * current value of the given features for each object in the given set. >+ * >+ * @param objects >+ * the objects to track. >+ * @param eStructuralFeatures >+ * the features for which to track the value. >+ * @return an array of observable maps tracking the current value of the >+ * given features for each object in the given set. >+ */ >+ public static IObservableMap[] observeMaps(IObservableSet objects, >+ EStructuralFeature[] eStructuralFeatures) { >+ IObservableMap[] result = new IObservableMap[eStructuralFeatures.length]; >+ for (int i = 0; i < eStructuralFeatures.length; i++) { >+ result[i] = observeMap(objects, eStructuralFeatures[i]); >+ } >+ return result; >+ } >+ >+ /** >+ * Returns an observable value that tracks the current value of the feature >+ * of the current value of the master observable value. >+ * >+ * @param realm >+ * the realm in which to observe. >+ * @param value >+ * the master observable value. >+ * @param eStructuralFeature >+ * the feature for which to track the value. >+ * @return an observable value that tracks the current value of the named >+ * property for the current value of the master observable value >+ * @see MasterDetailObservables#detailValue(IObservableValue, >+ * IObservableFactory, Object) >+ */ >+ public static IObservableValue observeDetailValue(Realm realm, >+ IObservableValue value, EStructuralFeature eStructuralFeature) { >+ return MasterDetailObservables.detailValue(value, valueFactory(realm, >+ eStructuralFeature), eStructuralFeature); >+ } >+ >+ /** >+ * Returns a factory for creating observable values tracking the value of >+ * the given feature of a particular {@link EObject object}. >+ * >+ * @param realm >+ * the realm in which to observe. >+ * @param eStructuralFeature >+ * the feature for which to track the value. >+ * @return an observable factory. >+ */ >+ public static IObservableFactory valueFactory(final Realm realm, >+ final EStructuralFeature eStructuralFeature) { >+ return new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return observeValue(realm, (EObject) target, eStructuralFeature); >+ } >+ }; >+ } >+ >+ /** >+ * Returns an observable list that tracks the current value of the feature >+ * of the current value of the master observable value. >+ * >+ * @param realm >+ * the realm in which to observe. >+ * @param value >+ * the master observable value. >+ * @param eStructuralFeature >+ * the feature for which to track the value. >+ * @return an observable value that tracks the current value of the named >+ * property for the current value of the master observable value >+ * @see MasterDetailObservables#detailList(IObservableValue, >+ * IObservableFactory, Object) >+ */ >+ public static IObservableList observeDetailList(Realm realm, >+ IObservableValue value, EStructuralFeature eStructuralFeature) { >+ return MasterDetailObservables.detailList(value, listFactory(realm, >+ eStructuralFeature), eStructuralFeature); >+ } >+ >+ /** >+ * Returns a factory for creating observable lists tracking the value of the >+ * given feature of a particular {@link EObject object}. >+ * >+ * @param realm >+ * the realm in which to observe. >+ * @param eStructuralFeature >+ * the feature for which to track the value. >+ * @return an observable factory. >+ */ >+ public static IObservableFactory listFactory(final Realm realm, >+ final EStructuralFeature eStructuralFeature) { >+ return new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return observeList(realm, (EObject) target, eStructuralFeature); >+ } >+ }; >+ } >+ >+ /** >+ * Returns a factory for creating observable maps tracking the value of the >+ * given feature of a particular {@link EObject object}. >+ * >+ * @param eStructuralFeature >+ * the feature for which to track the value. >+ * @return an observable factory. >+ */ >+ public static IObservableFactory mapFactory( >+ final EStructuralFeature eStructuralFeature) { >+ return new IObservableFactory() { >+ public IObservable createObservable(Object target) { >+ return observeMap((IObservableSet) target, eStructuralFeature); >+ } >+ }; >+ } > } >Index: src/org/eclipse/emf/databinding/EObjectObservableList.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/src/org/eclipse/emf/databinding/EObjectObservableList.java,v >retrieving revision 1.4 >diff -u -r1.4 EObjectObservableList.java >--- src/org/eclipse/emf/databinding/EObjectObservableList.java 21 Feb 2008 15:26:16 -0000 1.4 >+++ src/org/eclipse/emf/databinding/EObjectObservableList.java 24 Jan 2009 17:10:27 -0000 >@@ -9,7 +9,7 @@ > * > * Contributors: > * IBM - Initial API and implementation >- * >+ * Tom Schindl<tom.schindl@bestsolution.at> > * </copyright> > * > * $Id: EObjectObservableList.java,v 1.4 2008/02/21 15:26:16 emerks Exp $ >@@ -33,262 +33,249 @@ > import org.eclipse.emf.ecore.EStructuralFeature; > > /** >- * PROVISIONAL >- * This API is subject to arbitrary change, including renaming or removal. >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> > */ >-public class EObjectObservableList extends ObservableList implements IObserving, InternalRawEList >-{ >- protected EObject eObject; >- protected EStructuralFeature eStructuralFeature; >- protected Adapter listener; >- >- public EObjectObservableList(EObject eObject, EStructuralFeature eStructuralFeature) >- { >- this(Realm.getDefault(), eObject, eStructuralFeature); >- } >- >- public EObjectObservableList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature) >- { >- super(realm, (EList<?>)eObject.eGet(eStructuralFeature), eStructuralFeature); >- this.eObject = eObject; >- this.eStructuralFeature = eStructuralFeature; >- } >- >- @Override >- protected void firstListenerAdded() >- { >- listener = >- new AdapterImpl() >- { >- @Override >- public void notifyChanged(Notification notification) >- { >- if (eStructuralFeature == notification.getFeature() && !notification.isTouch()) >- { >- final ListDiff diff; >- switch (notification.getEventType()) >- { >- case Notification.ADD: >- { >- diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue())); >- break; >- } >- case Notification.ADD_MANY: >- { >- Collection<?> newValues = (Collection<?>)notification.getNewValue(); >- ListDiffEntry [] listDiffEntries = new ListDiffEntry [newValues.size()]; >- int position = notification.getPosition(); >- int index = 0; >- for (Object newValue : newValues) >- { >- listDiffEntries[index++] = Diffs.createListDiffEntry(position++, true, newValue); >- } >- diff = Diffs.createListDiff(listDiffEntries); >- break; >- } >- case Notification.REMOVE: >- { >- diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue())); >- break; >- } >- case Notification.REMOVE_MANY: >- { >- Collection<?> oldValues = (Collection<?>)notification.getOldValue(); >- ListDiffEntry [] listDiffEntries = new ListDiffEntry [oldValues.size()]; >- int position = notification.getPosition(); >- int index = 0; >- for (Object oldValue : oldValues) >- { >- listDiffEntries[index++] = Diffs.createListDiffEntry(position++, false, oldValue); >- } >- diff = Diffs.createListDiff(listDiffEntries); >- break; >- } >- case Notification.SET: >- case Notification.RESOLVE: >- { >- ListDiffEntry [] listDiffEntries = new ListDiffEntry [2]; >- listDiffEntries[0] = Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue()); >- listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue()); >- diff = Diffs.createListDiff(listDiffEntries); >- break; >- } >- case Notification.MOVE: >- { >- Object movedValue = notification.getNewValue(); >- ListDiffEntry [] listDiffEntries = new ListDiffEntry [2]; >- listDiffEntries[0] = Diffs.createListDiffEntry((Integer)notification.getOldValue(), false, movedValue); >- listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, movedValue); >- diff = Diffs.createListDiff(listDiffEntries); >- break; >- } >- case Notification.UNSET: >- { >- // This just represents going back to the unset state, but that doesn't affect the contents of the list. >- // >- return; >- } >- default: >- { >- throw new RuntimeException("unhandled case"); >- } >- } >- getRealm().exec >- (new Runnable() >- { >- public void run() >- { >- fireListChange(diff); >- } >- }); >- } >- } >- }; >- eObject.eAdapters().add(listener); >- } >- >- @Override >- protected void lastListenerRemoved() >- { >- eObject.eAdapters().remove(listener); >- listener = null; >- } >- >- @Override >- public synchronized void dispose() >- { >- if (listener != null) >- { >- eObject.eAdapters().remove(listener); >- listener = null; >- } >- eObject = null; >- eStructuralFeature = null; >- super.dispose(); >- } >- >- @SuppressWarnings("unchecked") >- protected final List<Object> wrappedList() >- { >- return wrappedList; >- } >- >- public Object getObserved() >- { >- return eObject; >- } >- >- @Override >- public boolean add(Object object) >- { >- checkRealm(); >- return wrappedList().add(object); >- } >- >- @Override >- public void add(int index, Object object) >- { >- checkRealm(); >- wrappedList().add(index, object); >- } >- >- @SuppressWarnings("unchecked") >- @Override >- public boolean addAll(Collection collection) >- { >- checkRealm(); >- return wrappedList().addAll(collection); >- } >- >- @SuppressWarnings("unchecked") >- @Override >- public boolean addAll(int index, Collection collection) >- { >- checkRealm(); >- return wrappedList().addAll(index, collection); >- } >- >- @Override >- public Object set(int index, Object element) >- { >- checkRealm(); >- return wrappedList().set(index, element); >- } >- >- @Override >- public Object remove(int index) >- { >- checkRealm(); >- return wrappedList.remove(index); >- } >- >- @Override >- public boolean remove(Object element) >- { >- checkRealm(); >- return wrappedList.remove(element); >- } >- >- @SuppressWarnings("unchecked") >- @Override >- public boolean removeAll(Collection collection) >- { >- checkRealm(); >- return wrappedList().removeAll(collection); >- } >- >- @SuppressWarnings("unchecked") >- @Override >- public boolean retainAll(Collection collection) >- { >- checkRealm(); >- return wrappedList().retainAll(collection); >- } >- >- @Override >- public void clear() >- { >- checkRealm(); >- wrappedList.clear(); >- } >- >- @Override >- public Object move(int newPosition, int oldPosition) >- { >- checkRealm(); >- return ((EList<?>)wrappedList).move(newPosition, oldPosition); >- } >- >- public void move(int newPosition, Object object) >- { >- move(newPosition, indexOf(object)); >- } >- >- @Override >- public String toString() >- { >- StringBuilder result = new StringBuilder(getClass().getName()); >- result.append('@'); >- result.append(Integer.toHexString(hashCode())); >- >- result.append(" (eObject:"); >- result.append(eObject); >- result.append(")"); >- >- result.append(" (eStructuralFeature: "); >- result.append(eStructuralFeature); >- result.append(")"); >- >- result.append(" (wrappedList: "); >- result.append(wrappedList); >- result.append(")"); >+public class EObjectObservableList extends ObservableList implements >+ IObserving, InternalRawEList { >+ protected EObject eObject; >+ protected EStructuralFeature eStructuralFeature; >+ protected Adapter listener; >+ >+ public EObjectObservableList(EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ this(Realm.getDefault(), eObject, eStructuralFeature); >+ } >+ >+ public EObjectObservableList(Realm realm, EObject eObject, >+ EStructuralFeature eStructuralFeature) { >+ super(realm, (EList<?>) eObject.eGet(eStructuralFeature), >+ eStructuralFeature); >+ this.eObject = eObject; >+ this.eStructuralFeature = eStructuralFeature; >+ } >+ >+ @Override >+ protected void firstListenerAdded() { >+ listener = new AdapterImpl() { >+ @Override >+ public void notifyChanged(Notification notification) { >+ if (eStructuralFeature == notification.getFeature() >+ && !notification.isTouch()) { >+ final ListDiff diff; >+ switch (notification.getEventType()) { >+ case Notification.ADD: { >+ diff = Diffs.createListDiff(Diffs.createListDiffEntry( >+ notification.getPosition(), true, notification >+ .getNewValue())); >+ break; >+ } >+ case Notification.ADD_MANY: { >+ Collection<?> newValues = (Collection<?>) notification >+ .getNewValue(); >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[newValues >+ .size()]; >+ int position = notification.getPosition(); >+ int index = 0; >+ for (Object newValue : newValues) { >+ listDiffEntries[index++] = Diffs >+ .createListDiffEntry(position++, true, >+ newValue); >+ } >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.REMOVE: { >+ diff = Diffs.createListDiff(Diffs.createListDiffEntry( >+ notification.getPosition(), false, notification >+ .getOldValue())); >+ break; >+ } >+ case Notification.REMOVE_MANY: { >+ Collection<?> oldValues = (Collection<?>) notification >+ .getOldValue(); >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[oldValues >+ .size()]; >+ int position = notification.getPosition(); >+ int index = 0; >+ for (Object oldValue : oldValues) { >+ listDiffEntries[index++] = Diffs >+ .createListDiffEntry(position++, false, >+ oldValue); >+ } >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.SET: >+ case Notification.RESOLVE: { >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[2]; >+ listDiffEntries[0] = Diffs.createListDiffEntry( >+ notification.getPosition(), false, notification >+ .getOldValue()); >+ listDiffEntries[1] = Diffs.createListDiffEntry( >+ notification.getPosition(), true, notification >+ .getNewValue()); >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.MOVE: { >+ Object movedValue = notification.getNewValue(); >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[2]; >+ listDiffEntries[0] = Diffs.createListDiffEntry( >+ (Integer) notification.getOldValue(), false, >+ movedValue); >+ listDiffEntries[1] = Diffs.createListDiffEntry( >+ notification.getPosition(), true, movedValue); >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.UNSET: { >+ // This just represents going back to the unset state, >+ // but that doesn't affect the contents of the list. >+ // >+ return; >+ } >+ default: { >+ throw new RuntimeException("unhandled case"); >+ } >+ } >+ getRealm().exec(new Runnable() { >+ public void run() { >+ fireListChange(diff); >+ } >+ }); >+ } >+ } >+ }; >+ eObject.eAdapters().add(listener); >+ } >+ >+ @Override >+ protected void lastListenerRemoved() { >+ eObject.eAdapters().remove(listener); >+ listener = null; >+ } >+ >+ @Override >+ public synchronized void dispose() { >+ if (listener != null) { >+ eObject.eAdapters().remove(listener); >+ listener = null; >+ } >+ eObject = null; >+ eStructuralFeature = null; >+ super.dispose(); >+ } >+ >+ @SuppressWarnings("unchecked") >+ protected final List<Object> wrappedList() { >+ return wrappedList; >+ } >+ >+ public Object getObserved() { >+ return eObject; >+ } >+ >+ @Override >+ public boolean add(Object object) { >+ checkRealm(); >+ return wrappedList().add(object); >+ } >+ >+ @Override >+ public void add(int index, Object object) { >+ checkRealm(); >+ wrappedList().add(index, object); >+ } >+ >+ @SuppressWarnings("unchecked") >+ @Override >+ public boolean addAll(Collection collection) { >+ checkRealm(); >+ return wrappedList().addAll(collection); >+ } >+ >+ @SuppressWarnings("unchecked") >+ @Override >+ public boolean addAll(int index, Collection collection) { >+ checkRealm(); >+ return wrappedList().addAll(index, collection); >+ } >+ >+ @Override >+ public Object set(int index, Object element) { >+ checkRealm(); >+ return wrappedList().set(index, element); >+ } >+ >+ @Override >+ public Object remove(int index) { >+ checkRealm(); >+ return wrappedList.remove(index); >+ } >+ >+ @Override >+ public boolean remove(Object element) { >+ checkRealm(); >+ return wrappedList.remove(element); >+ } >+ >+ @SuppressWarnings("unchecked") >+ @Override >+ public boolean removeAll(Collection collection) { >+ checkRealm(); >+ return wrappedList().removeAll(collection); >+ } >+ >+ @SuppressWarnings("unchecked") >+ @Override >+ public boolean retainAll(Collection collection) { >+ checkRealm(); >+ return wrappedList().retainAll(collection); >+ } >+ >+ @Override >+ public void clear() { >+ checkRealm(); >+ wrappedList.clear(); >+ } >+ >+ @Override >+ public Object move(int newPosition, int oldPosition) { >+ checkRealm(); >+ return ((EList<?>) wrappedList).move(newPosition, oldPosition); >+ } >+ >+ public void move(int newPosition, Object object) { >+ move(newPosition, indexOf(object)); >+ } >+ >+ @Override >+ public String toString() { >+ StringBuilder result = new StringBuilder(getClass().getName()); >+ result.append('@'); >+ result.append(Integer.toHexString(hashCode())); >+ >+ result.append(" (eObject:"); >+ result.append(eObject); >+ result.append(")"); >+ >+ result.append(" (eStructuralFeature: "); >+ result.append(eStructuralFeature); >+ result.append(")"); >+ >+ result.append(" (wrappedList: "); >+ result.append(wrappedList); >+ result.append(")"); > >- return result.toString(); >- } >+ return result.toString(); >+ } > } > > @SuppressWarnings("unchecked") >-interface InternalRawEList extends EList >-{ >- // This is only at avoid needing an @SuppressWarnings("unchecked") on the EMFObservableList >+interface InternalRawEList extends EList { >+ // This is only at avoid needing an @SuppressWarnings("unchecked") on the >+ // EMFObservableList > } >\ No newline at end of file >Index: src/org/eclipse/emf/databinding/EObjectObservableMap.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/src/org/eclipse/emf/databinding/EObjectObservableMap.java,v >retrieving revision 1.4 >diff -u -r1.4 EObjectObservableMap.java >--- src/org/eclipse/emf/databinding/EObjectObservableMap.java 21 Oct 2008 11:03:56 -0000 1.4 >+++ src/org/eclipse/emf/databinding/EObjectObservableMap.java 24 Jan 2009 17:10:27 -0000 >@@ -9,7 +9,7 @@ > * > * Contributors: > * IBM - Initial API and implementation >- * >+ * Tom Schindl<tom.schindl@bestsolution.at> > * </copyright> > * > * $Id: EObjectObservableMap.java,v 1.4 2008/10/21 11:03:56 emerks Exp $ >@@ -28,71 +28,64 @@ > import org.eclipse.emf.ecore.util.ExtendedMetaData; > > /** >- * PROVISIONAL >- * This API is subject to arbitrary change, including renaming or removal. >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> > */ >-public class EObjectObservableMap extends ComputedObservableMap >-{ >- protected EStructuralFeature eStructuralFeature; >- >- private Adapter elementListener = >- new AdapterImpl() >- { >- @Override >- public void notifyChanged(Notification notification) >- { >- if (eStructuralFeature == notification.getFeature() && !notification.isTouch()) >- { >- // TODO >- // This assumes we only get a SET notification, which isn't a good assumption. >- // >- final MapDiff diff = Diffs.createMapDiffSingleChange(notification.getNotifier(), notification.getOldValue(), notification.getNewValue()); >- getRealm().exec >- (new Runnable() >- { >- public void run() >- { >- fireMapChange(diff); >- } >- }); >- } >- } >- }; >- >- public EObjectObservableMap(IObservableSet objects, EStructuralFeature feature) >- { >- super(objects); >- this.eStructuralFeature = feature; >- } >- >- @Override >- protected void hookListener(Object domainElement) >- { >- ((EObject)domainElement).eAdapters().add(elementListener); >- } >- >- @Override >- protected void unhookListener(Object domainElement) >- { >- ((EObject)domainElement).eAdapters().remove(elementListener); >- } >- >- @Override >- protected Object doGet(Object key) >- { >- EObject eObject = (EObject)key; >- return >- ExtendedMetaData.INSTANCE.getAffiliation(eObject.eClass(), eStructuralFeature) == null ? >- null : >- eObject.eGet(eStructuralFeature); >- } >- >- @Override >- protected Object doPut(Object key, Object value) >- { >- EObject eObject = (EObject)key; >- Object result = eObject.eGet(eStructuralFeature); >- eObject.eSet(eStructuralFeature, value); >- return result; >- } >+public class EObjectObservableMap extends ComputedObservableMap { >+ protected EStructuralFeature eStructuralFeature; >+ >+ private Adapter elementListener = new AdapterImpl() { >+ @Override >+ public void notifyChanged(Notification notification) { >+ if (eStructuralFeature == notification.getFeature() >+ && !notification.isTouch()) { >+ // TODO >+ // This assumes we only get a SET notification, which isn't a >+ // good assumption. >+ // >+ final MapDiff diff = Diffs.createMapDiffSingleChange( >+ notification.getNotifier(), notification.getOldValue(), >+ notification.getNewValue()); >+ getRealm().exec(new Runnable() { >+ public void run() { >+ fireMapChange(diff); >+ } >+ }); >+ } >+ } >+ }; >+ >+ public EObjectObservableMap(IObservableSet objects, >+ EStructuralFeature feature) { >+ super(objects); >+ this.eStructuralFeature = feature; >+ } >+ >+ @Override >+ protected void hookListener(Object domainElement) { >+ ((EObject) domainElement).eAdapters().add(elementListener); >+ } >+ >+ @Override >+ protected void unhookListener(Object domainElement) { >+ ((EObject) domainElement).eAdapters().remove(elementListener); >+ } >+ >+ @Override >+ protected Object doGet(Object key) { >+ EObject eObject = (EObject) key; >+ return ExtendedMetaData.INSTANCE.getAffiliation(eObject.eClass(), >+ eStructuralFeature) == null ? null : eObject >+ .eGet(eStructuralFeature); >+ } >+ >+ @Override >+ protected Object doPut(Object key, Object value) { >+ EObject eObject = (EObject) key; >+ Object result = eObject.eGet(eStructuralFeature); >+ eObject.eSet(eStructuralFeature, value); >+ return result; >+ } > } >Index: src/org/eclipse/emf/databinding/EMFUpdateValueStrategy.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/src/org/eclipse/emf/databinding/EMFUpdateValueStrategy.java,v >retrieving revision 1.2 >diff -u -r1.2 EMFUpdateValueStrategy.java >--- src/org/eclipse/emf/databinding/EMFUpdateValueStrategy.java 22 Feb 2008 12:10:18 -0000 1.2 >+++ src/org/eclipse/emf/databinding/EMFUpdateValueStrategy.java 24 Jan 2009 17:10:27 -0000 >@@ -9,7 +9,7 @@ > * > * Contributors: > * IBM - Initial API and implementation >- * >+ * Tom Schindl<tom.schindl@bestsolution.at> > * </copyright> > * > * $Id: EMFUpdateValueStrategy.java,v 1.2 2008/02/22 12:10:18 emerks Exp $ >@@ -19,103 +19,164 @@ > import java.util.ArrayList; > import java.util.List; > >+import org.eclipse.core.databinding.Binding; >+import org.eclipse.core.databinding.DataBindingContext; > import org.eclipse.core.databinding.UpdateValueStrategy; > import org.eclipse.core.databinding.conversion.Converter; > import org.eclipse.core.databinding.conversion.IConverter; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.validation.IValidator; > import org.eclipse.emf.ecore.EAttribute; > import org.eclipse.emf.ecore.EDataType; > import org.eclipse.emf.ecore.EFactory; > > /** >- * PROVISIONAL >- * This API is subject to arbitrary change, including renaming or removal. >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * Customizes a {@link Binding} between two {@link IObservableValue observable >+ * values}. The following behaviors can be customized via the strategy: >+ * <ul> >+ * <li>Validation</li> >+ * <li>Conversion</li> >+ * <li>Automatic processing</li> >+ * </ul> >+ * <p> >+ * The update phases are: >+ * <ol> >+ * <li>Validate after get - {@link #validateAfterGet(Object)}</li> >+ * <li>Conversion - {@link #convert(Object)}</li> >+ * <li>Validate after conversion - {@link #validateAfterConvert(Object)}</li> >+ * <li>Validate before set - {@link #validateBeforeSet(Object)}</li> >+ * <li>Value set - {@link #doSet(IObservableValue, Object)}</li> >+ * </ol> >+ * </p> >+ * <p> >+ * Validation:<br/> >+ * {@link IValidator Validators} validate the value at multiple phases in the >+ * update process. Statuses returned from validators are aggregated into a >+ * <code>MultiStatus</code> until a status of <code>ERROR</code> or >+ * <code>CANCEL</code> is encountered. Either of these statuses will abort the >+ * update process. These statuses are available as the >+ * {@link Binding#getValidationStatus() binding validation status}. >+ * </p> >+ * <p> >+ * Conversion:<br/> >+ * A {@link IConverter converter} will convert the value from the type of the >+ * source observable into the type of the destination. The strategy has the >+ * ability to default converters for common scenarios. >+ * </p> >+ * <p> >+ * Automatic processing:<br/> >+ * The processing to perform when the source observable changes. This behavior >+ * is configured via policies provided on construction of the strategy (e.g. >+ * {@link #POLICY_NEVER}, {@link #POLICY_CONVERT}, {@link #POLICY_ON_REQUEST}, >+ * {@link #POLICY_UPDATE}). >+ * </p> >+ * >+ * @see DataBindingContext#bindValue(IObservableValue, IObservableValue, >+ * UpdateValueStrategy, UpdateValueStrategy) >+ * @see Binding#getValidationStatus() >+ * @see IValidator >+ * @see IConverter >+ * @since 1.0 > */ >-public class EMFUpdateValueStrategy extends UpdateValueStrategy >-{ >- public EMFUpdateValueStrategy() >- { >- this(true, POLICY_UPDATE); >- } >+public class EMFUpdateValueStrategy extends UpdateValueStrategy { >+ /** >+ * Creates a new update value strategy for automatically updating the >+ * destination observable value whenever the source observable value >+ * changes. Default validators and a default converter will be provided. The >+ * defaults can be changed by calling one of the setter methods. >+ */ >+ public EMFUpdateValueStrategy() { >+ this(true, POLICY_UPDATE); >+ } >+ >+ /** >+ * Creates a new update value strategy with a configurable update policy. >+ * Default validators and a default converter will be provided. The defaults >+ * can be changed by calling one of the setter methods. >+ * >+ * @param updatePolicy >+ * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, >+ * {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE} >+ */ >+ public EMFUpdateValueStrategy(int updatePolicy) { >+ this(true, updatePolicy); >+ } > >- public EMFUpdateValueStrategy(int updatePolicy) >- { >- this(true, updatePolicy); >- } >+ /** >+ * Creates a new update value strategy with a configurable update policy. >+ * Default validators and a default converter will be provided if >+ * <code>provideDefaults</code> is <code>true</code>. The defaults can >+ * be changed by calling one of the setter methods. >+ * >+ * @param provideDefaults >+ * if <code>true</code>, default validators and a default >+ * converter will be provided based on the observable value's >+ * type. >+ * @param updatePolicy >+ * one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, >+ * {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE} >+ */ >+ public EMFUpdateValueStrategy(boolean provideDefaults, int updatePolicy) { >+ super(provideDefaults, updatePolicy); >+ } > >- public EMFUpdateValueStrategy(boolean provideDefaults, int updatePolicy) >- { >- super(provideDefaults, updatePolicy); >- } >- >- @Override >- protected IConverter createConverter(Object fromType, Object toType) >- { >- if (fromType == String.class) >- { >- if (toType instanceof EAttribute) >- { >- final EAttribute eAttribute = (EAttribute)toType; >- final EDataType eDataType = eAttribute.getEAttributeType(); >- final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance(); >- return >- new Converter(fromType, toType) >- { >- public Object convert(Object fromObject) >- { >- String value = fromObject == null ? null : fromObject.toString(); >- if (eAttribute.isMany()) >- { >- List<Object> result = new ArrayList<Object>(); >- if (value != null) >- { >- for (String element : value.split(" ")) >- { >- result.add(eFactory.createFromString(eDataType, element)); >- } >- } >- return result; >- } >- else >- { >- return eFactory.createFromString(eDataType, value); >- } >- } >- }; >- } >- } >- else if (toType == String.class) >- { >- if (fromType instanceof EAttribute) >- { >- final EAttribute eAttribute = (EAttribute)fromType; >- final EDataType eDataType = eAttribute.getEAttributeType(); >- final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance(); >- return >- new Converter(fromType, toType) >- { >- public Object convert(Object fromObject) >- { >- if (eAttribute.isMany()) >- { >- StringBuilder result = new StringBuilder(); >- for (Object value : (List<?>)fromObject) >- { >- if (result.length() == 0) >- { >- result.append(' '); >- } >- result.append(eFactory.convertToString(eDataType, value)); >- } >- return result.toString(); >- } >- else >- { >- return eFactory.convertToString(eDataType, fromObject); >- } >- } >- }; >- } >- } >- return super.createConverter(fromType, toType); >- } >+ @Override >+ protected IConverter createConverter(Object fromType, Object toType) { >+ if (fromType == String.class) { >+ if (toType instanceof EAttribute) { >+ final EAttribute eAttribute = (EAttribute) toType; >+ final EDataType eDataType = eAttribute.getEAttributeType(); >+ final EFactory eFactory = eDataType.getEPackage() >+ .getEFactoryInstance(); >+ return new Converter(fromType, toType) { >+ public Object convert(Object fromObject) { >+ String value = fromObject == null ? null : fromObject >+ .toString(); >+ if (eAttribute.isMany()) { >+ List<Object> result = new ArrayList<Object>(); >+ if (value != null) { >+ for (String element : value.split(" ")) { >+ result.add(eFactory.createFromString( >+ eDataType, element)); >+ } >+ } >+ return result; >+ } else { >+ return eFactory.createFromString(eDataType, value); >+ } >+ } >+ }; >+ } >+ } else if (toType == String.class) { >+ if (fromType instanceof EAttribute) { >+ final EAttribute eAttribute = (EAttribute) fromType; >+ final EDataType eDataType = eAttribute.getEAttributeType(); >+ final EFactory eFactory = eDataType.getEPackage() >+ .getEFactoryInstance(); >+ return new Converter(fromType, toType) { >+ public Object convert(Object fromObject) { >+ if (eAttribute.isMany()) { >+ StringBuilder result = new StringBuilder(); >+ for (Object value : (List<?>) fromObject) { >+ if (result.length() == 0) { >+ result.append(' '); >+ } >+ result.append(eFactory.convertToString( >+ eDataType, value)); >+ } >+ return result.toString(); >+ } else { >+ return eFactory.convertToString(eDataType, >+ fromObject); >+ } >+ } >+ }; >+ } >+ } >+ return super.createConverter(fromType, toType); >+ } > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/org.eclipse.emf.databinding/META-INF/MANIFEST.MF,v >retrieving revision 1.5 >diff -u -r1.5 MANIFEST.MF >--- META-INF/MANIFEST.MF 21 Oct 2008 11:03:56 -0000 1.5 >+++ META-INF/MANIFEST.MF 24 Jan 2009 17:10:26 -0000 >@@ -2,7 +2,7 @@ > Bundle-ManifestVersion: 2 > Bundle-Name: %pluginName > Bundle-SymbolicName: org.eclipse.emf.databinding; singleton:=true >-Bundle-Version: 1.1.0.qualifier >+Bundle-Version: 1.2.0.qualifier > Bundle-ClassPath: . > Bundle-Activator: org.eclipse.emf.databinding.DataBindingPlugin$Implementation > Bundle-Vendor: %providerName >Index: src/org/eclipse/emf/databinding/properties/IEMFValueProperty.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/IEMFValueProperty.java >diff -N src/org/eclipse/emf/databinding/properties/IEMFValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/IEMFValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,184 @@ >+/******************************************************************************* >+ * 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 195222) >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+ >+package org.eclipse.emf.databinding.properties; >+ >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * An {@link IValueProperty} extension interface with convenience methods for >+ * creating nested bean properties. >+ * >+ * @since 1.1 >+ * @noextend This interface is not intended to be extended by clients. >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IEMFValueProperty extends IEMFProperty, IValueProperty { >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * value property. >+ * >+ * @param featurePath >+ * the value property to observe. May be nested e.g. >+ * >+ * <code>property.values(MyPackage.Literals.OBJ_PARENT, MyPackage.Literals.PARENT_NAME)</code> >+ * @return a master-detail combination of this property and the specified >+ * value property. >+ * @see #value(IEMFValueProperty) >+ */ >+ public IEMFValueProperty value(EStructuralFeature... featurePath); >+ >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * value property. The returned property will observe the specified detail >+ * value property for the value of the master value property. >+ * <p> >+ * Example: >+ * >+ * <pre> >+ * // Observes the Node-typed "parent" property of a Node object >+ * IBeanValueProperty parent = BeanProperties.value(Node.class, "parent"); >+ * // Observes the string-typed "name" property of a Node object >+ * IBeanValueProperty name = BeanProperties.value(Node.class, "name"); >+ * // Observes the name of the parent of a Node object. >+ * IBeanValueProperty parentName = parent.value(name); >+ * </pre> >+ * >+ * @param property >+ * the detail property to observe >+ * @return a master-detail combination of this property and the specified >+ * value property. >+ */ >+ public IEMFValueProperty value(IEMFValueProperty property); >+ >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * list property. >+ * >+ * @param feature >+ * the list property to observe >+ * @return a master-detail combination of this property and the specified >+ * list property. >+ * @see #list(IEMFListProperty) >+ */ >+ public IEMFListProperty list(EStructuralFeature feature); >+ >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * list property. The returned property will observe the specified list >+ * property for the value of the master property. >+ * <p> >+ * Example: >+ * >+ * <pre> >+ * // Observes the Node-typed "parent" property of a Node object. >+ * IBeanValueProperty parent = BeanProperties.value(Node.class, "parent"); >+ * // Observes the List-typed "children" property of a Node object >+ * // where the elements are Node objects >+ * IBeanListProperty children = BeanProperties.list(Node.class, "children", >+ * Node.class); >+ * // Observes the children of the parent (siblings) of a Node object. >+ * IBeanListProperty siblings = parent.list(children); >+ * </pre> >+ * >+ * @param property >+ * the detail property to observe >+ * @return a master-detail combination of this property and the specified >+ * list property. >+ */ >+ public IEMFListProperty list(IEMFListProperty property); >+ >+ // /** >+ // * Returns a master-detail combination of this property and the specified >+ // * set property. >+ // * >+ // * @param propertyName >+ // * the set property to observe >+ // * @return a master-detail combination of this property and the specified >+ // * set property. >+ // * @see #set(IEMFSetProperty) >+ // */ >+ // public IEMFSetProperty set(EStructuralFeature featurePath); >+ // >+ // /** >+ // * Returns a master-detail combination of this property and the specified >+ // * set property. The returned property will observe the specified set >+ // * property for the value of the master property. >+ // * <p> >+ // * Example: >+ // * >+ // * <pre> >+ // * // Observes the Node-typed "parent" property of a Node >+ // object. >+ // * IBeanValueProperty parent = BeanProperties.value(Node.class, >+ // "parent"); >+ // * // Observes the Set-typed "children" property of a Node >+ // object >+ // * // where the elements are Node objects >+ // * IBeanSetProperty children = BeanProperties.set(Node.class, >+ // "children", >+ // * Node.class); >+ // * // Observes the children of the parent (siblings) of a Node object. >+ // * IBeanSetProperty siblings = parent.set(children); >+ // * </pre> >+ // * >+ // * @param property >+ // * the detail property to observe >+ // * @return a master-detail combination of this property and the specified >+ // * set property. >+ // */ >+ // public IEMFSetProperty set(IEMFSetProperty property); >+ >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * map property. >+ * >+ * @param feature >+ * the map property to observe >+ * @return a master-detail combination of this property and the specified >+ * map property. >+ * @see #map(IEMFMapProperty) >+ */ >+ public IEMFMapProperty map(EStructuralFeature feature); >+ >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * map property. The returned property will observe the specified map >+ * property for the value of the master property. >+ * <p> >+ * Example: >+ * >+ * <pre> >+ * // Observes the Contact-typed "supervisor" property of a >+ * // Contact class >+ * IBeanValueProperty supervisor = BeanProperties.value(Contact.class, >+ * "supervisor"); >+ * // Observes the property "phoneNumbers" of a Contact object--a property mapping >+ * // from PhoneNumberType to PhoneNumber "set-typed "children", >+ * IBeanMapProperty phoneNumbers = BeanProperties.map(Contact.class, >+ * "phoneNumbers", PhoneNumberType.class, PhoneNumber.class); >+ * // Observes the phone numbers of a contact's supervisor: >+ * IBeanMapProperty supervisorPhoneNumbers = supervisor.map(phoneNumbers); >+ * </pre> >+ * >+ * @param property >+ * the detail property to observe >+ * @return a master-detail combination of this property and the specified >+ * map property. >+ */ >+ public IEMFMapProperty map(IEMFMapProperty property); >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFMapProperty.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFMapProperty.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFMapProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFMapProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,117 @@ >+/******************************************************************************* >+ * 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) >+ * Matthew Hall - bug 195222 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+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.INativePropertyListener; >+import org.eclipse.core.databinding.property.ISimplePropertyListener; >+import org.eclipse.core.databinding.property.SimplePropertyEvent; >+import org.eclipse.core.databinding.property.map.SimpleMapProperty; >+import org.eclipse.emf.common.notify.Adapter; >+import org.eclipse.emf.common.notify.Notification; >+import org.eclipse.emf.common.notify.impl.AdapterImpl; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * @since 1.1 >+ */ >+public class EMFMapProperty extends SimpleMapProperty { >+ >+ private final EStructuralFeature feature; >+ private final Class<?> keyType; >+ private final Class<?> valueType; >+ >+ /** >+ * @param feature >+ * @param keyType >+ * @param valueType >+ */ >+ public EMFMapProperty(EStructuralFeature feature, Class<?> keyType, Class<?> valueType) { >+ this.feature = feature; >+ this.keyType = keyType; >+ this.valueType = valueType; >+ } >+ >+ public Object getKeyType() { >+ return keyType; >+ } >+ >+ public Object getValueType() { >+ return valueType; >+ } >+ >+ @Override >+ protected Map<?,?> doGetMap(Object source) { >+ EObject eObj = (EObject) source; >+ return (Map<?,?>) eObj.eGet(feature); >+ } >+ >+ @SuppressWarnings("unchecked") >+ @Override >+ protected void doSetMap(Object source, Map map, MapDiff diff) { >+ diff.applyTo(doGetMap(source)); >+ } >+ >+ @Override >+ public INativePropertyListener adaptListener( >+ ISimplePropertyListener listener) { >+ return new Listener(listener); >+ } >+ >+ private class Listener extends AdapterImpl implements INativePropertyListener { >+ private final ISimplePropertyListener listener; >+ >+ private Listener(ISimplePropertyListener listener) { >+ this.listener = listener; >+ } >+ >+ @Override >+ public void notifyChanged(Notification msg) { >+ if (feature == msg.getFeature() && !msg.isTouch()) >+ { >+ // TODO >+ // This assumes we only get a SET notification, which isn't a good assumption. >+ // >+ final MapDiff diff = Diffs.createMapDiffSingleChange(msg.getNotifier(), msg.getOldValue(), msg.getNewValue()); >+ listener.handlePropertyChange(new SimplePropertyEvent(msg >+ .getNotifier(), EMFMapProperty.this, diff)); >+ } >+ } >+ } >+ >+ @Override >+ protected void doAddListener(Object source, INativePropertyListener listener) { >+ EObject eObj = (EObject) source; >+ eObj.eAdapters().add((Adapter) listener); >+ } >+ >+ @Override >+ protected void doRemoveListener(Object source, >+ INativePropertyListener listener) { >+ EObject eObj = (EObject) source; >+ eObj.eAdapters().remove((Adapter) listener); >+ } >+ >+ >+ >+ >+ >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFMapPropertyDecorator.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFMapPropertyDecorator.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFMapPropertyDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFMapPropertyDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,88 @@ >+/******************************************************************************* >+ * 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 195222) >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.core.databinding.property.map.MapProperty; >+import org.eclipse.emf.databinding.properties.EMFProperties; >+import org.eclipse.emf.databinding.properties.IEMFMapProperty; >+import org.eclipse.emf.databinding.properties.IEMFValueProperty; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * @since 1.1 >+ */ >+public class EMFMapPropertyDecorator extends MapProperty implements >+ IEMFMapProperty { >+ private final IMapProperty delegate; >+ private final EStructuralFeature feature; >+ >+ /** >+ * @param delegate >+ * @param feature >+ */ >+ public EMFMapPropertyDecorator(IMapProperty delegate, EStructuralFeature feature) { >+ this.delegate = delegate; >+ this.feature = feature; >+ } >+ >+ public EStructuralFeature getFeature() { >+ return feature; >+ } >+ >+ public Object getKeyType() { >+ return delegate.getKeyType(); >+ } >+ >+ public Object getValueType() { >+ return delegate.getValueType(); >+ } >+ >+ public IEMFMapProperty values(EStructuralFeature... featurePath) { >+ return values(EMFProperties.value(featurePath)); >+ } >+ >+ public IEMFMapProperty values(IEMFValueProperty property) { >+ return new EMFMapPropertyDecorator(super.values(property),property.getFeature()); >+ } >+ >+ public IObservableMap observe(Object source) { >+ return new EMFObservableMapDecorator(delegate.observe(source), >+ feature); >+ } >+ >+ public IObservableMap observe(Realm realm, Object source) { >+ return new EMFObservableMapDecorator(delegate.observe(realm, source), >+ feature); >+ } >+ >+ public IObservableFactory mapFactory() { >+ return delegate.mapFactory(); >+ } >+ >+ public IObservableFactory mapFactory(Realm realm) { >+ return delegate.mapFactory(realm); >+ } >+ >+ public IObservableMap observeDetail(IObservableValue master) { >+ return new EMFObservableMapDecorator(delegate.observeDetail(master), >+ feature); >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFObservableListDecorator.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFObservableListDecorator.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFObservableListDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFObservableListDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,59 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 Brad Reynolds and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Brad Reynolds - initial API and implementation >+ * Matthew Hall - bugs 208858, 246625 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import org.eclipse.core.databinding.observable.IObservable; >+import org.eclipse.core.databinding.observable.IObserving; >+import org.eclipse.core.databinding.observable.list.DecoratingObservableList; >+import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.emf.databinding.properties.IEMFObservable; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * {@link IEMFObservable} decorator for an {@link IObservableList}. >+ * >+ * @since 1.1 >+ */ >+public class EMFObservableListDecorator extends DecoratingObservableList >+ implements IEMFObservable { >+ private EStructuralFeature feature; >+ >+ /** >+ * @param decorated >+ * @param feature >+ */ >+ public EMFObservableListDecorator(IObservableList decorated, EStructuralFeature feature) { >+ super(decorated, true); >+ this.feature = feature; >+ } >+ >+ public synchronized void dispose() { >+ this.feature = null; >+ super.dispose(); >+ } >+ >+ public EStructuralFeature getFeature() { >+ return feature; >+ } >+ >+ public Object getObserved() { >+ IObservable decorated = getDecorated(); >+ if (decorated instanceof IObserving) >+ return ((IObserving) decorated).getObserved(); >+ return null; >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFListProperty.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFListProperty.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFListProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,168 @@ >+/******************************************************************************* >+ * 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) >+ * Matthew Hall - bug 195222 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import java.util.Collection; >+import java.util.List; >+ >+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.INativePropertyListener; >+import org.eclipse.core.databinding.property.ISimplePropertyListener; >+import org.eclipse.core.databinding.property.SimplePropertyEvent; >+import org.eclipse.core.databinding.property.list.SimpleListProperty; >+import org.eclipse.emf.common.notify.Adapter; >+import org.eclipse.emf.common.notify.Notification; >+import org.eclipse.emf.common.notify.impl.AdapterImpl; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * @since 1.1 >+ */ >+public class EMFListProperty extends SimpleListProperty { >+ private final EStructuralFeature feature; >+ >+ /** >+ * @param feature >+ */ >+ public EMFListProperty(EStructuralFeature feature) { >+ this.feature = feature; >+ } >+ >+ public Object getElementType() { >+ return feature; >+ } >+ >+ @Override >+ protected List<?> doGetList(Object source) { >+ EObject eObj = (EObject) source; >+ return (List<?>) eObj.eGet(feature); >+ } >+ >+ @SuppressWarnings("unchecked") >+ @Override >+ protected void doSetList(Object source, List list, ListDiff diff) { >+ List<?> currentList = doGetList(source); >+ diff.applyTo(currentList); >+ } >+ >+ @Override >+ public INativePropertyListener adaptListener( >+ ISimplePropertyListener listener) { >+ return new Listener(listener); >+ } >+ >+ private class Listener extends AdapterImpl implements >+ INativePropertyListener { >+ private final ISimplePropertyListener listener; >+ >+ private Listener(ISimplePropertyListener listener) { >+ this.listener = listener; >+ } >+ >+ @Override >+ public void notifyChanged(Notification msg) { >+ if (feature == msg.getFeature() && !msg.isTouch()) { >+ final ListDiff diff; >+ switch (msg.getEventType()) { >+ case Notification.ADD: { >+ diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg >+ .getPosition(), true, msg.getNewValue())); >+ break; >+ } >+ case Notification.ADD_MANY: { >+ Collection<?> newValues = (Collection<?>) msg.getNewValue(); >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[newValues >+ .size()]; >+ int position = msg.getPosition(); >+ int index = 0; >+ for (Object newValue : newValues) { >+ listDiffEntries[index++] = Diffs.createListDiffEntry( >+ position++, true, newValue); >+ } >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.REMOVE: { >+ diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg >+ .getPosition(), false, msg.getOldValue())); >+ break; >+ } >+ case Notification.REMOVE_MANY: { >+ Collection<?> oldValues = (Collection<?>) msg.getOldValue(); >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[oldValues >+ .size()]; >+ int position = msg.getPosition(); >+ int index = 0; >+ for (Object oldValue : oldValues) { >+ listDiffEntries[index++] = Diffs.createListDiffEntry( >+ position++, false, oldValue); >+ } >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.SET: >+ case Notification.RESOLVE: { >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[2]; >+ listDiffEntries[0] = Diffs.createListDiffEntry(msg >+ .getPosition(), false, msg.getOldValue()); >+ listDiffEntries[1] = Diffs.createListDiffEntry(msg >+ .getPosition(), true, msg.getNewValue()); >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.MOVE: { >+ Object movedValue = msg.getNewValue(); >+ ListDiffEntry[] listDiffEntries = new ListDiffEntry[2]; >+ listDiffEntries[0] = Diffs.createListDiffEntry( >+ (Integer) msg.getOldValue(), false, movedValue); >+ listDiffEntries[1] = Diffs.createListDiffEntry(msg >+ .getPosition(), true, movedValue); >+ diff = Diffs.createListDiff(listDiffEntries); >+ break; >+ } >+ case Notification.UNSET: { >+ // This just represents going back to the unset state, but >+ // that doesn't affect the contents of the list. >+ // >+ return; >+ } >+ default: { >+ throw new RuntimeException("unhandled case"); >+ } >+ } >+ listener.handlePropertyChange(new SimplePropertyEvent(msg >+ .getNotifier(), EMFListProperty.this, diff)); >+ } >+ } >+ } >+ >+ @Override >+ protected void doAddListener(Object source, INativePropertyListener listener) { >+ EObject eObj = (EObject) source; >+ eObj.eAdapters().add((Adapter) listener); >+ } >+ >+ @Override >+ protected void doRemoveListener(Object source, >+ INativePropertyListener listener) { >+ EObject eObj = (EObject) source; >+ eObj.eAdapters().remove((Adapter) listener); >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/EMFProperties.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/EMFProperties.java >diff -N src/org/eclipse/emf/databinding/properties/EMFProperties.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/EMFProperties.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,116 @@ >+/******************************************************************************* >+ * 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) >+ * Matthew Hall - bug 195222, 247997, 261843 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties; >+ >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.emf.databinding.properties.internal.EMFListProperty; >+import org.eclipse.emf.databinding.properties.internal.EMFListPropertyDecorator; >+import org.eclipse.emf.databinding.properties.internal.EMFMapProperty; >+import org.eclipse.emf.databinding.properties.internal.EMFMapPropertyDecorator; >+import org.eclipse.emf.databinding.properties.internal.EMFValueProperty; >+import org.eclipse.emf.databinding.properties.internal.EMFValuePropertyDecorator; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * A factory for creating properties for {@link EObject} objects >+ * >+ * @since 1.1 >+ */ >+public class EMFProperties { >+ /** >+ * Returns a value property for the given property name of an arbitrary bean >+ * class. Objects lacking the named property are treated the same as if the >+ * property always contains null. >+ * >+ * @param featurePath >+ * the property name. May be nested e.g. >+ * <code>property.values(MyPackage.Literals.OBJ_PARENT, MyPackage.Literals.PARENT_NAME)</code> >+ * @return a value property for the given property name of an arbitrary bean >+ * class. >+ */ >+ public static IEMFValueProperty value(EStructuralFeature... featurePath) { >+ IValueProperty property = new EMFValueProperty(featurePath[0]); >+ >+ IEMFValueProperty emfProperty = new EMFValuePropertyDecorator(property, >+ featurePath[0]); >+ for (int i = 1; i < featurePath.length; i++) { >+ emfProperty = emfProperty.value(featurePath[i]); >+ } >+ return emfProperty; >+ } >+ >+ // public static IEMFValueProperty[] values(EStructuralFeature[]... >+ // features) { >+ // return null; >+ // } >+ >+ // public static IEMFSetProperty set(EStructuralFeature feature) { >+ // ISetProperty property = new EMFSetProperty(feature, elementType); >+ // return new EMFSetPropertyDecorator(property, feature); >+ // } >+ >+ /** >+ * Returns a list property for the given property name of an arbitrary bean >+ * class. Objects lacking the named property are treated the same as if the >+ * property always contains an empty list. >+ * >+ * @param feature >+ * the property name >+ * @return a list property for the given property name of an arbitrary bean >+ * class. >+ */ >+ public static IEMFListProperty list(EStructuralFeature feature) { >+ IListProperty property = new EMFListProperty(feature); >+ return new EMFListPropertyDecorator(property, feature); >+ } >+ >+ /** >+ * Returns a map property for the given property name of an arbitrary bean >+ * class. Objects lacking the named property are treated the same as if the >+ * property always contains an empty map. >+ * >+ * @param feature >+ * the property name >+ * @return a map property for the given property name of an arbitrary bean >+ * class. >+ */ >+ public static IEMFMapProperty map(EStructuralFeature feature) { >+ return map(feature, null, null); >+ } >+ >+ /** >+ * Returns a map property for the given property name of the given bean >+ * class. >+ * >+ * @param feature >+ * 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 IEMFMapProperty map(EStructuralFeature feature, >+ Class<?> keyType, Class<?> valueType) { >+ IMapProperty property = new EMFMapProperty(feature, keyType, valueType); >+ return new EMFMapPropertyDecorator(property, feature); >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/IEMFMapProperty.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/IEMFMapProperty.java >diff -N src/org/eclipse/emf/databinding/properties/IEMFMapProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/IEMFMapProperty.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 195222) >+ * Tom Schindl<tom.schindl@bestsolution.at> - port to EMF >+ ******************************************************************************/ >+ >+package org.eclipse.emf.databinding.properties; >+ >+import java.util.Map; >+ >+import org.eclipse.core.databinding.property.map.IMapProperty; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * An {@link IMapProperty} extension interface with convenience methods for >+ * creating nested bean properties. >+ * >+ * @since 1.1 >+ * @noextend This interface is not intended to be extended by clients. >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IEMFMapProperty extends IEMFProperty, IMapProperty { >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * value property. >+ * >+ * @param featurePath >+ * the value property to observe. May be nested e.g. >+ * <code>property.values(MyPackage.Literals.OBJ_PARENT, MyPackage.Literals.PARENT_NAME)</code> >+ * @return a master-detail combination of this property and the specified >+ * value property. >+ * @see #values(IEMFValueProperty) >+ */ >+ public IEMFMapProperty values(EStructuralFeature... featurePath); >+ >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * value property. The returned property will observe the specified value >+ * property for all {@link Map#values() values} observed by this map >+ * property, mapping from this map property's {@link Map#keySet() key set} >+ * to the specified value property's value for each element in the master >+ * property's {@link Map#values() values} collection. >+ * >+ * @param property >+ * the detail property to observe >+ * @return a master-detail combination of this property and the specified >+ * value property. >+ */ >+ public IEMFMapProperty values(IEMFValueProperty property); >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFListPropertyDecorator.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFListPropertyDecorator.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFListPropertyDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFListPropertyDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,81 @@ >+/******************************************************************************* >+ * 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 195222) >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.core.databinding.property.list.ListProperty; >+import org.eclipse.emf.databinding.properties.EMFProperties; >+import org.eclipse.emf.databinding.properties.IEMFListProperty; >+import org.eclipse.emf.databinding.properties.IEMFValueProperty; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * @since 1.1 >+ */ >+public class EMFListPropertyDecorator extends ListProperty implements IEMFListProperty { >+ private final IListProperty delegate; >+ private final EStructuralFeature feature; >+ >+ /** >+ * @param delegate >+ * @param feature >+ */ >+ public EMFListPropertyDecorator(IListProperty delegate, EStructuralFeature feature) { >+ this.delegate = delegate; >+ this.feature = feature; >+ } >+ >+ public Object getElementType() { >+ return feature.getEType().getInstanceClass(); >+ } >+ >+ public IEMFListProperty values(EStructuralFeature... feature) { >+ return values(EMFProperties.value(feature)); >+ } >+ public IEMFListProperty values(IEMFValueProperty property) { >+ return new EMFListPropertyDecorator(super.values(property),property.getFeature()); >+ } >+ public EStructuralFeature getFeature() { >+ return feature; >+ } >+ >+ public IObservableList observe(Object source) { >+ return new EMFObservableListDecorator(delegate.observe(source), >+ feature); >+ } >+ >+ public IObservableList observe(Realm realm, Object source) { >+ return new EMFObservableListDecorator(delegate.observe(realm, source), >+ feature); >+ } >+ >+ public IObservableFactory listFactory() { >+ return delegate.listFactory(); >+ } >+ >+ public IObservableFactory listFactory(Realm realm) { >+ return delegate.listFactory(realm); >+ } >+ >+ public IObservableList observeDetail(IObservableValue master) { >+ return new EMFObservableListDecorator(delegate.observeDetail(master), >+ feature); >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFValuePropertyDecorator.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFValuePropertyDecorator.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFValuePropertyDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFValuePropertyDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,127 @@ >+/******************************************************************************* >+ * 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 195222) >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.property.value.IValueProperty; >+import org.eclipse.core.databinding.property.value.ValueProperty; >+import org.eclipse.emf.databinding.properties.EMFProperties; >+import org.eclipse.emf.databinding.properties.IEMFListProperty; >+import org.eclipse.emf.databinding.properties.IEMFMapProperty; >+import org.eclipse.emf.databinding.properties.IEMFValueProperty; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * @since 1.1 >+ */ >+public class EMFValuePropertyDecorator extends ValueProperty implements IEMFValueProperty { >+ private final IValueProperty delegate; >+ private final EStructuralFeature feature; >+ >+ /** >+ * @param delegate >+ * @param feature >+ */ >+ public EMFValuePropertyDecorator(IValueProperty delegate, EStructuralFeature feature) { >+ this.delegate = delegate; >+ this.feature = feature; >+ } >+ >+ public Object getValueType() { >+ return delegate.getValueType(); >+ } >+ >+ public EStructuralFeature getFeature() { >+ return feature; >+ } >+ >+ public IEMFValueProperty value(EStructuralFeature... featurePath) { >+ return value(EMFProperties.value(featurePath)); >+ } >+ >+ public IEMFValueProperty value(IEMFValueProperty property) { >+ return new EMFValuePropertyDecorator(super.value(property),property.getFeature()); >+ } >+ >+ public IEMFListProperty list(EStructuralFeature featurePath) { >+ return list(EMFProperties.list(featurePath)); >+ } >+ >+ public IEMFListProperty list(IEMFListProperty property) { >+ return new EMFListPropertyDecorator(super.list(property),property.getFeature()); >+ } >+ >+// public IEMFSetProperty set(EStructuralFeature featurePath) { >+// // TODO Auto-generated method stub >+// return null; >+// } >+// >+// public IEMFSetProperty set(IEMFSetProperty property) { >+// // TODO Auto-generated method stub >+// return null; >+// } >+ >+ public IEMFMapProperty map(EStructuralFeature featurePath) { >+ return map(EMFProperties.map(featurePath)); >+ } >+ >+ public IEMFMapProperty map(IEMFMapProperty property) { >+ return new EMFMapPropertyDecorator(super.map(property),property.getFeature()); >+ } >+ >+ public IObservableValue observe(Object source) { >+ return new EMFObservableValueDecorator(delegate.observe(source), >+ feature); >+ } >+ >+ public IObservableValue observe(Realm realm, Object source) { >+ return new EMFObservableValueDecorator( >+ delegate.observe(realm, source), feature); >+ } >+ >+ public IObservableFactory valueFactory() { >+ return delegate.valueFactory(); >+ } >+ >+ public IObservableFactory valueFactory(Realm realm) { >+ return delegate.valueFactory(realm); >+ } >+ >+ public IObservableValue observeDetail(IObservableValue master) { >+ return new EMFObservableValueDecorator(delegate.observeDetail(master), >+ feature); >+ } >+ >+ public IObservableList observeDetail(IObservableList master) { >+ return new EMFObservableListDecorator(delegate.observeDetail(master), >+ feature); >+ } >+ >+ public IObservableMap observeDetail(IObservableSet master) { >+ return new EMFObservableMapDecorator(delegate.observeDetail(master), >+ feature); >+ } >+ >+ public IObservableMap observeDetail(IObservableMap master) { >+ return new EMFObservableMapDecorator(delegate.observeDetail(master), >+ feature); >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFObservableValueDecorator.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFObservableValueDecorator.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFObservableValueDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFObservableValueDecorator.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,59 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 Brad Reynolds and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Brad Reynolds - initial API and implementation >+ * Matthew Hall - bug 246625 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import org.eclipse.core.databinding.observable.IObservable; >+import org.eclipse.core.databinding.observable.IObserving; >+import org.eclipse.core.databinding.observable.value.DecoratingObservableValue; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.emf.databinding.properties.IEMFObservable; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * {@link IEMFObservable} decorator for an {@link IObservableValue}. >+ * >+ * @since 1.1 >+ */ >+public class EMFObservableValueDecorator extends DecoratingObservableValue >+ implements IEMFObservable { >+ private EStructuralFeature feature; >+ >+ /** >+ * @param decorated >+ * @param feature >+ */ >+ public EMFObservableValueDecorator(IObservableValue decorated, EStructuralFeature feature) { >+ super(decorated, true); >+ this.feature = feature; >+ } >+ >+ public synchronized void dispose() { >+ this.feature = null; >+ super.dispose(); >+ } >+ >+ public EStructuralFeature getFeature() { >+ return feature; >+ } >+ >+ public Object getObserved() { >+ IObservable decorated = getDecorated(); >+ if (decorated instanceof IObserving) >+ return ((IObserving) decorated).getObserved(); >+ return null; >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/IEMFListProperty.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/IEMFListProperty.java >diff -N src/org/eclipse/emf/databinding/properties/IEMFListProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/IEMFListProperty.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 195222) >+ * Tom Schindl<tom.schindl@bestsolution.at> - port to EMF >+ ******************************************************************************/ >+ >+package org.eclipse.emf.databinding.properties; >+ >+import org.eclipse.core.databinding.property.list.IListProperty; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * An {@link IListProperty} extension interface with convenience methods for >+ * creating nested bean properties. >+ * >+ * @since 1.1 >+ * @noextend This interface is not intended to be extended by clients. >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IEMFListProperty extends IEMFProperty, IListProperty { >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * value property. >+ * >+ * @param featurePath >+ * the value property to observe. May be nested e.g. >+ * >+ * <code>property.values(MyPackage.Literals.OBJ_PARENT, MyPackage.Literals.PARENT_NAME)</code> >+ * @return a nested combination of this property and the specified value >+ * property. >+ * @see #values(IEMFValueProperty) >+ */ >+ public IEMFListProperty values(EStructuralFeature... featurePath); >+ >+ /** >+ * Returns a master-detail combination of this property and the specified >+ * value property. The returned property will observe the specified value >+ * property for all elements observed by this list property. >+ * <p> >+ * Example: >+ * >+ * <pre> >+ * // Observes the list-typed "children" property of a Person object, >+ * // where the elements are Person objects >+ * IBeanListProperty children = BeanProperties.list(Person.class, "children", >+ * Person.class); >+ * // Observes the string-typed "name" property of a Person object >+ * IBeanValueProperty name = BeanProperties.value(Person.class, "name"); >+ * // Observes the names of children of a Person object. >+ * IBeanListProperty childrenNames = children.values(name); >+ * </pre> >+ * >+ * @param property >+ * the detail property to observe >+ * @return a master-detail combination of this property and the specified >+ * value property. >+ */ >+ public IEMFListProperty values(IEMFValueProperty property); >+} >Index: src/org/eclipse/emf/databinding/properties/internal/EMFObservableMapDecorator.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFObservableMapDecorator.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFObservableMapDecorator.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFObservableMapDecorator.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 221704) >+ * Matthew Hall - bug 246625 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import org.eclipse.core.databinding.observable.IObservable; >+import org.eclipse.core.databinding.observable.IObserving; >+import org.eclipse.core.databinding.observable.map.DecoratingObservableMap; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.emf.databinding.properties.IEMFObservable; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * {@link IEMFObservable} decorator for an {@link IObservableMap}. >+ * >+ * @since 1.1 >+ */ >+public class EMFObservableMapDecorator extends DecoratingObservableMap >+ implements IEMFObservable { >+ private EStructuralFeature feature; >+ >+ /** >+ * @param decorated >+ * @param feature >+ */ >+ public EMFObservableMapDecorator(IObservableMap decorated, EStructuralFeature feature) { >+ super(decorated, true); >+ this.feature = feature; >+ } >+ >+ public synchronized void dispose() { >+ this.feature = null; >+ super.dispose(); >+ } >+ >+ public EStructuralFeature getFeature() { >+ return feature; >+ } >+ >+ public Object getObserved() { >+ IObservable decorated = getDecorated(); >+ if (decorated instanceof IObserving) >+ return ((IObserving) decorated).getObserved(); >+ return null; >+ } >+} >Index: .settings/org.eclipse.jdt.core.prefs >=================================================================== >RCS file: .settings/org.eclipse.jdt.core.prefs >diff -N .settings/org.eclipse.jdt.core.prefs >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .settings/org.eclipse.jdt.core.prefs 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,15 @@ >+#Sat Jan 24 17:20:53 CET 2009 >+eclipse.preferences.version=1 >+org.eclipse.jdt.core.compiler.doc.comment.support=enabled >+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled >+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected >+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning >+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled >+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected >+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag >+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning >+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled >+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected >Index: src/org/eclipse/emf/databinding/properties/internal/EMFValueProperty.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/internal/EMFValueProperty.java >diff -N src/org/eclipse/emf/databinding/properties/internal/EMFValueProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/internal/EMFValueProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,103 @@ >+/******************************************************************************* >+ * 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) >+ * Matthew Hall - bug 195222 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties.internal; >+ >+import org.eclipse.core.databinding.observable.Diffs; >+import org.eclipse.core.databinding.observable.value.ValueDiff; >+import org.eclipse.core.databinding.property.INativePropertyListener; >+import org.eclipse.core.databinding.property.ISimplePropertyListener; >+import org.eclipse.core.databinding.property.SimplePropertyEvent; >+import org.eclipse.core.databinding.property.value.SimpleValueProperty; >+import org.eclipse.emf.common.notify.Adapter; >+import org.eclipse.emf.common.notify.Notification; >+import org.eclipse.emf.common.notify.impl.AdapterImpl; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * @since 1.1 >+ */ >+public class EMFValueProperty extends SimpleValueProperty { >+ private EStructuralFeature feature; >+ >+ /** >+ * @param feature >+ */ >+ public EMFValueProperty(EStructuralFeature feature) { >+ this.feature = feature; >+ } >+ >+ public Object getValueType() { >+ return feature.getEType().getInstanceClass(); >+ } >+ >+ @Override >+ protected Object doGetValue(Object source) { >+ EObject eObj = (EObject) source; >+ return eObj.eGet(feature); >+ } >+ >+ >+ @Override >+ protected void doSetValue(Object source, Object value) { >+ EObject eObj = (EObject) source; >+ eObj.eSet(feature, value); >+ } >+ >+ @Override >+ public INativePropertyListener adaptListener( >+ ISimplePropertyListener listener) { >+ return new Listener(listener); >+ } >+ >+ private class Listener extends AdapterImpl implements INativePropertyListener { >+ private final ISimplePropertyListener listener; >+ >+ private Listener(ISimplePropertyListener listener) { >+ this.listener = listener; >+ } >+ >+ @Override >+ public void notifyChanged(Notification msg) { >+ if( feature == msg.getFeature() && !msg.isTouch() ) { >+ ValueDiff diff; >+ Object oldValue = msg.getOldValue(); >+ Object newValue = msg.getNewValue(); >+ if (oldValue != null && newValue != null) { >+ diff = Diffs.createValueDiff(oldValue, newValue); >+ } else { >+ diff = null; >+ } >+ listener.handlePropertyChange(new SimplePropertyEvent(msg.getNotifier(), EMFValueProperty.this, diff)); >+ } >+ } >+ } >+ >+ @Override >+ protected void doAddListener(Object source, INativePropertyListener listener) { >+ EObject eObj = (EObject) source; >+ eObj.eAdapters().add((Adapter) listener); >+ } >+ >+ >+ @Override >+ protected void doRemoveListener(Object source, >+ INativePropertyListener listener) { >+ EObject eObj = (EObject) source; >+ eObj.eAdapters().remove((Adapter) listener); >+ } >+} >Index: src/org/eclipse/emf/databinding/properties/IEMFProperty.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/IEMFProperty.java >diff -N src/org/eclipse/emf/databinding/properties/IEMFProperty.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/IEMFProperty.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,35 @@ >+/******************************************************************************* >+ * 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) >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+ >+package org.eclipse.emf.databinding.properties; >+ >+import org.eclipse.core.databinding.property.IProperty; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * An IProperty extension interface providing access to details of bean >+ * properties. >+ * >+ * @since 1.1 >+ * @noextend This interface is not intended to be extended by clients. >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IEMFProperty extends IProperty { >+ /** >+ * @return the feature observed >+ */ >+ public EStructuralFeature getFeature(); >+} >Index: src/org/eclipse/emf/databinding/properties/IEMFObservable.java >=================================================================== >RCS file: src/org/eclipse/emf/databinding/properties/IEMFObservable.java >diff -N src/org/eclipse/emf/databinding/properties/IEMFObservable.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/emf/databinding/properties/IEMFObservable.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 Brad Reynolds and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Brad Reynolds - initial API and implementation >+ * Brad Reynolds - bug 147515 >+ * Tom Schindl<tom.schindl@bestsolution.at> - Port to EMF >+ ******************************************************************************/ >+package org.eclipse.emf.databinding.properties; >+ >+import org.eclipse.core.databinding.observable.IObserving; >+import org.eclipse.emf.ecore.EStructuralFeature; >+ >+/** >+ * <p> >+ * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or >+ * removal.</b> >+ * </p> >+ * Provides access to details of EMF observables. >+ * <p> >+ * This interface is not meant to be implemented by clients. >+ * </p> >+ * >+ * @since 1.1 >+ * @noimplement This interface is not intended to be implemented by clients. >+ */ >+public interface IEMFObservable extends IObserving { >+ /** >+ * @return the feature observed >+ */ >+ public EStructuralFeature getFeature(); >+}
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 Raw
Actions:
View
Attachments on
bug 262160
:
123633
|
124701
|
125052
|
125836
|
125841
|
132310
|
132579
|
132670
|
134185
|
134272
|
134465
|
134529
|
134710
|
136365
|
136370