Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 262160 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 8-14 Link Here
8
Bundle-Vendor: %providerName
8
Bundle-Vendor: %providerName
9
Bundle-Localization: plugin
9
Bundle-Localization: plugin
10
Bundle-RequiredExecutionEnvironment: J2SE-1.5
10
Bundle-RequiredExecutionEnvironment: J2SE-1.5
11
Export-Package: org.eclipse.emf.databinding
11
Export-Package: org.eclipse.emf.databinding,
12
 org.eclipse.emf.databinding.properties
12
Require-Bundle: org.eclipse.core.runtime,
13
Require-Bundle: org.eclipse.core.runtime,
13
 org.eclipse.emf.ecore;visibility:=reexport,
14
 org.eclipse.emf.ecore;visibility:=reexport,
14
 org.eclipse.core.databinding;visibility:=reexport
15
 org.eclipse.core.databinding;visibility:=reexport
(-)src/org/eclipse/emf/databinding/EMFDataBindingContext.java (-24 / +65 lines)
Lines 9-51 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
11
 *   IBM - Initial API and implementation
12
 *
12
 *   Tom Schindl<tom.schindl@bestsolution.at>
13
 * </copyright>
13
 * </copyright>
14
 *
14
 *
15
 * $Id: EMFDataBindingContext.java,v 1.1 2007/11/16 21:25:21 emerks Exp $
15
 * $Id: EMFDataBindingContext.java,v 1.1 2007/11/16 21:25:21 emerks Exp $
16
 */
16
 */
17
package org.eclipse.emf.databinding;
17
package org.eclipse.emf.databinding;
18
18
19
import org.eclipse.core.databinding.Binding;
19
import org.eclipse.core.databinding.DataBindingContext;
20
import org.eclipse.core.databinding.DataBindingContext;
20
import org.eclipse.core.databinding.UpdateValueStrategy;
21
import org.eclipse.core.databinding.UpdateValueStrategy;
21
import org.eclipse.core.databinding.observable.Realm;
22
import org.eclipse.core.databinding.observable.Realm;
23
import org.eclipse.core.databinding.observable.list.IObservableList;
22
import org.eclipse.core.databinding.observable.value.IObservableValue;
24
import org.eclipse.core.databinding.observable.value.IObservableValue;
23
25
24
/**
26
/**
25
 * PROVISIONAL
27
 * <p>
26
 * This API is subject to arbitrary change, including renaming or removal.
28
 * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or
29
 * removal.</b>
30
 * </p>
31
 * 
32
 * A DataBindingContext is the point of contact for the creation and management
33
 * of {@link Binding bindings}, and aggregates validation statuses of its
34
 * bindings, or more generally, its validation status providers.
35
 * <p>
36
 * A DataBindingContext provides the following abilities:
37
 * <ul>
38
 * <li>Ability to create bindings between {@link IObservableValue observable
39
 * values}.</li>
40
 * <li>Ability to create bindings between {@link IObservableList observable
41
 * lists}.</li>
42
 * <li>Access to the bindings created by the instance.</li>
43
 * <li>Access to the list of validation status providers (this includes all
44
 * bindings).</li>
45
 * </ul>
46
 * </p>
47
 * <p>
48
 * Multiple contexts can be used at any point in time. One strategy for the
49
 * management of contexts is the aggregation of validation statuses. For example
50
 * an <code>IWizardPage</code> could use a single context and the statuses could
51
 * be aggregated to set the page status and fulfillment. Each page in the
52
 * <code>IWizard</code> would have its own context instance.
53
 * </p>
54
 * 
55
 * @since 1.0
27
 */
56
 */
28
public class EMFDataBindingContext extends DataBindingContext
57
public class EMFDataBindingContext extends DataBindingContext {
29
{
58
	/**
30
  public EMFDataBindingContext()
59
	 * Creates a data binding context, using the current default realm for the
31
  {
60
	 * validation observables.
32
    this(Realm.getDefault());
61
	 * 
33
  }
62
	 * @see Realm
63
	 */
64
	public EMFDataBindingContext() {
65
		this(Realm.getDefault());
66
	}
67
68
	/**
69
	 * Creates a data binding context using the given realm for the validation
70
	 * observables.
71
	 * 
72
	 * @param validationRealm
73
	 *            the realm to be used for the validation observables
74
	 * 
75
	 * @see Realm
76
	 */
77
	public EMFDataBindingContext(Realm validationRealm) {
78
		super(validationRealm);
79
	}
34
80
35
  public EMFDataBindingContext(Realm validationRealm)
81
	@Override
36
  {
82
	protected UpdateValueStrategy createModelToTargetUpdateValueStrategy(
37
    super(validationRealm);
83
			IObservableValue fromValue, IObservableValue toValue) {
38
  }
84
		return new EMFUpdateValueStrategy();
85
	}
39
86
40
  @Override
87
	@Override
41
  protected UpdateValueStrategy createModelToTargetUpdateValueStrategy(IObservableValue fromValue, IObservableValue toValue)
88
	protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(
42
  {
89
			IObservableValue fromValue, IObservableValue toValue) {
43
    return new EMFUpdateValueStrategy();
90
		return new EMFUpdateValueStrategy();
44
  }
91
	}
45
  
46
  @Override
47
  protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(IObservableValue fromValue, IObservableValue toValue)
48
  {
49
    return new EMFUpdateValueStrategy();
50
  }
51
}
92
}
(-)src/org/eclipse/emf/databinding/EMFObservables.java (-162 / +219 lines)
Lines 10-23 Link Here
10
 * Contributors: 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
11
 *   IBM - Initial API and implementation
12
 *   Trevor S. Kaufman - Bug 215131 - added mapFactory
12
 *   Trevor S. Kaufman - Bug 215131 - added mapFactory
13
 *
13
 *   Tom Schindl<tom.schindl@bestsolution.at>
14
 * </copyright>
14
 * </copyright>
15
 *
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
17
 */
18
package org.eclipse.emf.databinding;
18
package org.eclipse.emf.databinding;
19
19
20
21
import org.eclipse.core.databinding.observable.IObservable;
20
import org.eclipse.core.databinding.observable.IObservable;
22
import org.eclipse.core.databinding.observable.Realm;
21
import org.eclipse.core.databinding.observable.Realm;
23
import org.eclipse.core.databinding.observable.list.IObservableList;
22
import org.eclipse.core.databinding.observable.list.IObservableList;
Lines 26-194 Link Here
26
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables;
25
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables;
27
import org.eclipse.core.databinding.observable.set.IObservableSet;
26
import org.eclipse.core.databinding.observable.set.IObservableSet;
28
import org.eclipse.core.databinding.observable.value.IObservableValue;
27
import org.eclipse.core.databinding.observable.value.IObservableValue;
28
import org.eclipse.emf.common.notify.NotifyingList;
29
import org.eclipse.emf.databinding.internal.EWritableList;
29
import org.eclipse.emf.ecore.EObject;
30
import org.eclipse.emf.ecore.EObject;
30
import org.eclipse.emf.ecore.EStructuralFeature;
31
import org.eclipse.emf.ecore.EStructuralFeature;
32
import org.eclipse.emf.ecore.resource.Resource;
31
33
32
/**
34
/**
33
 * PROVISIONAL
35
 * <p>
34
 * This API is subject to arbitrary change, including renaming or removal.
36
 * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or
37
 * removal.</b>
38
 * </p>
39
 * A factory for creating observable objects of Java objects that conform to the
40
 * <a href="http://java.sun.com/products/javabeans/docs/spec.html">JavaBean
41
 * specification</a> for bound properties.
42
 * 
43
 * @since 1.0
35
 */
44
 */
36
public class EMFObservables
45
public class EMFObservables {
37
{
46
	/**
38
  /**
47
	 * 
39
   * Returns an observable value for the given feature of the object.
48
	 */
40
   * @param eObject the object to observe.
49
	public static final boolean DEBUG = false;
41
   * @param eStructuralFeature the feature of the object to observe.
50
42
   * @return an observable value for the given feature of the object.
51
	/**
43
   */
52
	 * Returns an observable value for the given feature of the object.
44
  public static IObservableValue observeValue(EObject eObject, EStructuralFeature eStructuralFeature)
53
	 * 
45
  {
54
	 * @param eObject
46
    return new EObjectObservableValue(eObject, eStructuralFeature);
55
	 *            the object to observe.
47
  }
56
	 * @param eStructuralFeature
48
57
	 *            the feature of the object to observe.
49
  /**
58
	 * @return an observable value for the given feature of the object.
50
   * Returns an observable value for the given feature of the object.
59
	 */
51
   * @param realm the realm in which to observe.
60
	public static IObservableValue observeValue(EObject eObject,
52
   * @param eObject the object to observe.
61
			EStructuralFeature eStructuralFeature) {
53
   * @param eStructuralFeature the feature of the object to observe.
62
		return new EObjectObservableValue(eObject, eStructuralFeature);
54
   * @return an observable value for the given feature of the object.
63
	}
55
   */
64
56
  public static IObservableValue observeValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
65
	/**
57
  {
66
	 * Returns an observable value for the given feature of the object.
58
    return new EObjectObservableValue(realm, eObject, eStructuralFeature);
67
	 * 
59
  }
68
	 * @param realm
60
69
	 *            the realm in which to observe.
61
  /**
70
	 * @param eObject
62
   * Returns an observable list for the given multi-valued feature of the object.
71
	 *            the object to observe.
63
   * @param eObject the object to observe.
72
	 * @param eStructuralFeature
64
   * @param eStructuralFeature the feature of the object to observe.
73
	 *            the feature of the object to observe.
65
   * @return an observable list for the given multi-valued feature of the object.
74
	 * @return an observable value for the given feature of the object.
66
   */
75
	 */
67
  public static IObservableList observeList(EObject eObject, EStructuralFeature eStructuralFeature)
76
	public static IObservableValue observeValue(Realm realm, EObject eObject,
68
  {
77
			EStructuralFeature eStructuralFeature) {
69
    return new EObjectObservableList(eObject, eStructuralFeature);
78
		return new EObjectObservableValue(realm, eObject, eStructuralFeature);
70
  }
79
	}
71
80
72
  /**
81
	/**
73
   * Returns an observable list for the given multi-valued feature of the object.
82
	 * Returns an observable list for the given multi-valued feature of the
74
   * @param realm the realm in which to observe.
83
	 * object.
75
   * @param eObject the object to observe.
84
	 * 
76
   * @param eStructuralFeature the feature of the object to observe.
85
	 * @param eObject
77
   * @return an observable list for the given multi-valued feature of the object.
86
	 *            the object to observe.
78
   */
87
	 * @param eStructuralFeature
79
  public static IObservableList observeList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
88
	 *            the feature of the object to observe.
80
  {
89
	 * @return an observable list for the given multi-valued feature of the
81
    return new EObjectObservableList(realm, eObject, eStructuralFeature);
90
	 *         object.
82
  }
91
	 */
83
92
	public static IObservableList observeList(EObject eObject,
84
  /**
93
			EStructuralFeature eStructuralFeature) {
85
   * Returns an observable map in the default realm 
94
		return new EObjectObservableList(eObject, eStructuralFeature);
86
   * tracking the current value of the given feature for each object in the given set.
95
	}
87
   * @param objects the objects to track.
96
88
   * @param eStructuralFeature the feature for which to track the value.
97
	/**
89
   * @return an observable map tracking the current value of the given feature for each object in the given set.
98
	 * Returns an observable list for the given multi-valued feature of the
90
   */
99
	 * object.
91
  public static IObservableMap observeMap(IObservableSet objects, EStructuralFeature eStructuralFeature)
100
	 * 
92
  {
101
	 * @param realm
93
    return new EObjectObservableMap(objects, eStructuralFeature);
102
	 *            the realm in which to observe.
94
  }
103
	 * @param eObject
95
104
	 *            the object to observe.
96
  /**
105
	 * @param eStructuralFeature
97
   * Returns an array of observable maps in the default realm 
106
	 *            the feature of the object to observe.
98
   * tracking the current value of the given features for each object in the given set.
107
	 * @return an observable list for the given multi-valued feature of the
99
   * @param objects the objects to track.
108
	 *         object.
100
   * @param eStructuralFeatures the features for which to track the value.
109
	 */
101
   * @return an array of observable maps tracking the current value of the given features for each object in the given set.
110
	public static IObservableList observeList(Realm realm, EObject eObject,
102
   */
111
			EStructuralFeature eStructuralFeature) {
103
  public static IObservableMap[] observeMaps(IObservableSet objects, EStructuralFeature[] eStructuralFeatures)
112
		return new EObjectObservableList(realm, eObject, eStructuralFeature);
104
  {
113
	}
105
    IObservableMap[] result = new IObservableMap [eStructuralFeatures.length];
114
106
    for (int i = 0; i < eStructuralFeatures.length; i++)
115
	/**
107
    {
116
	 * Returns an observable map in the default realm tracking the current value
108
      result[i] = observeMap(objects, eStructuralFeatures[i]);
117
	 * of the given feature for each object in the given set.
109
    }
118
	 * 
110
    return result;
119
	 * @param objects
111
  }
120
	 *            the objects to track.
112
121
	 * @param eStructuralFeature
113
  /**
122
	 *            the feature for which to track the value.
114
   * Returns an observable value that tracks the current value of the feature of the current value of the master observable value.
123
	 * @return an observable map tracking the current value of the given feature
115
   * @param realm the realm in which to observe.
124
	 *         for each object in the given set.
116
   * @param value the master observable value.
125
	 */
117
   * @param eStructuralFeature the feature for which to track the value.
126
	public static IObservableMap observeMap(IObservableSet objects,
118
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
127
			EStructuralFeature eStructuralFeature) {
119
   * @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object)
128
		return new EObjectObservableMap(objects, eStructuralFeature);
120
   */
129
	}
121
  public static IObservableValue observeDetailValue(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
130
122
  {
131
	/**
123
    return MasterDetailObservables.detailValue(value, valueFactory(realm, eStructuralFeature), eStructuralFeature);
132
	 * Returns an array of observable maps in the default realm tracking the
124
  }
133
	 * current value of the given features for each object in the given set.
125
134
	 * 
126
  /**
135
	 * @param objects
127
   * Returns a factory for creating observable values
136
	 *            the objects to track.
128
   * tracking the value of the given feature of a particular {@link EObject object}.
137
	 * @param eStructuralFeatures
129
   * @param realm the realm in which to observe.
138
	 *            the features for which to track the value.
130
   * @param eStructuralFeature the feature for which to track the value.
139
	 * @return an array of observable maps tracking the current value of the
131
   * @return an observable factory.
140
	 *         given features for each object in the given set.
132
   */
141
	 */
133
  public static IObservableFactory valueFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
142
	public static IObservableMap[] observeMaps(IObservableSet objects,
134
  {
143
			EStructuralFeature[] eStructuralFeatures) {
135
    return 
144
		IObservableMap[] result = new IObservableMap[eStructuralFeatures.length];
136
      new IObservableFactory()
145
		for (int i = 0; i < eStructuralFeatures.length; i++) {
137
      {
146
			result[i] = observeMap(objects, eStructuralFeatures[i]);
138
        public IObservable createObservable(Object target)
147
		}
139
        {
148
		return result;
140
          return observeValue(realm, (EObject)target, eStructuralFeature);
149
	}
141
        }
150
142
      };
151
	/**
143
  }
152
	 * Returns an observable value that tracks the current value of the feature
144
153
	 * of the current value of the master observable value.
145
  /**
154
	 * 
146
   * Returns an observable list that tracks the current value of the feature of the current value of the master observable value.
155
	 * @param realm
147
   * @param realm the realm in which to observe.
156
	 *            the realm in which to observe.
148
   * @param value the master observable value.
157
	 * @param value
149
   * @param eStructuralFeature the feature for which to track the value.
158
	 *            the master observable value.
150
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
159
	 * @param eStructuralFeature
151
   * @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object)
160
	 *            the feature for which to track the value.
152
   */
161
	 * @return an observable value that tracks the current value of the named
153
  public static IObservableList observeDetailList(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
162
	 *         property for the current value of the master observable value
154
  {
163
	 * @see MasterDetailObservables#detailValue(IObservableValue,
155
    return MasterDetailObservables.detailList(value, listFactory(realm, eStructuralFeature), eStructuralFeature);
164
	 *      IObservableFactory, Object)
156
  }
165
	 */
157
166
	public static IObservableValue observeDetailValue(Realm realm,
158
  /**
167
			IObservableValue value, EStructuralFeature eStructuralFeature) {
159
   * Returns a factory for creating observable lists
168
		return MasterDetailObservables.detailValue(value, valueFactory(realm,
160
   * tracking the value of the given feature of a particular {@link EObject object}.
169
				eStructuralFeature), eStructuralFeature);
161
   * @param realm the realm in which to observe.
170
	}
162
   * @param eStructuralFeature the feature for which to track the value.
171
163
   * @return an observable factory.
172
	/**
164
   */
173
	 * Returns a factory for creating observable values tracking the value of
165
  public static IObservableFactory listFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
174
	 * the given feature of a particular {@link EObject object}.
166
  {
175
	 * 
167
    return 
176
	 * @param realm
168
      new IObservableFactory()
177
	 *            the realm in which to observe.
169
      {
178
	 * @param eStructuralFeature
170
        public IObservable createObservable(Object target)
179
	 *            the feature for which to track the value.
171
        {
180
	 * @return an observable factory.
172
          return observeList(realm, (EObject)target, eStructuralFeature);
181
	 */
173
        }
182
	public static IObservableFactory valueFactory(final Realm realm,
174
      };
183
			final EStructuralFeature eStructuralFeature) {
175
  }
184
		return new IObservableFactory() {
176
  
185
			public IObservable createObservable(Object target) {
177
  /**
186
				return observeValue(realm, (EObject) target, eStructuralFeature);
178
   * Returns a factory for creating observable maps
187
			}
179
   * tracking the value of the given feature of a particular {@link EObject object}.
188
		};
180
   * @param eStructuralFeature the feature for which to track the value.
189
	}
181
   * @return an observable factory.
190
182
   */
191
	/**
183
  public static IObservableFactory mapFactory(final EStructuralFeature eStructuralFeature)
192
	 * Returns an observable list that tracks the current value of the feature
184
  {
193
	 * of the current value of the master observable value.
185
    return
194
	 * 
186
      new IObservableFactory()
195
	 * @param realm
187
      {
196
	 *            the realm in which to observe.
188
        public IObservable createObservable(Object target)
197
	 * @param value
189
        {
198
	 *            the master observable value.
190
          return observeMap((IObservableSet)target, eStructuralFeature);
199
	 * @param eStructuralFeature
191
        }
200
	 *            the feature for which to track the value.
192
      };
201
	 * @return an observable value that tracks the current value of the named
193
   }
202
	 *         property for the current value of the master observable value
203
	 * @see MasterDetailObservables#detailList(IObservableValue,
204
	 *      IObservableFactory, Object)
205
	 */
206
	public static IObservableList observeDetailList(Realm realm,
207
			IObservableValue value, EStructuralFeature eStructuralFeature) {
208
		return MasterDetailObservables.detailList(value, listFactory(realm,
209
				eStructuralFeature), eStructuralFeature);
210
	}
211
212
	/**
213
	 * Returns a factory for creating observable lists tracking the value of the
214
	 * given feature of a particular {@link EObject object}.
215
	 * 
216
	 * @param realm
217
	 *            the realm in which to observe.
218
	 * @param eStructuralFeature
219
	 *            the feature for which to track the value.
220
	 * @return an observable factory.
221
	 */
222
	public static IObservableFactory listFactory(final Realm realm,
223
			final EStructuralFeature eStructuralFeature) {
224
		return new IObservableFactory() {
225
			public IObservable createObservable(Object target) {
226
				return observeList(realm, (EObject) target, eStructuralFeature);
227
			}
228
		};
229
	}
230
231
	/**
232
	 * Returns a factory for creating observable maps tracking the value of the
233
	 * given feature of a particular {@link EObject object}.
234
	 * 
235
	 * @param eStructuralFeature
236
	 *            the feature for which to track the value.
237
	 * @return an observable factory.
238
	 */
239
	public static IObservableFactory mapFactory(
240
			final EStructuralFeature eStructuralFeature) {
241
		return new IObservableFactory() {
242
			public IObservable createObservable(Object target) {
243
				return observeMap((IObservableSet) target, eStructuralFeature);
244
			}
245
		};
246
	}
247
	
248
	public static IObservableList observeResourceContents(Resource resource) {
249
		return new EWritableList<EObject>((NotifyingList<EObject>) resource.getContents());
250
	}
194
}
251
}
(-)src/org/eclipse/emf/databinding/EMFUpdateListStrategy.java (-57 / +101 lines)
Lines 9-86 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
11
 *   IBM - Initial API and implementation
12
 *
12
 *   Tom Schindl<tom.schindl@bestsolution.at>
13
 * </copyright>
13
 * </copyright>
14
 *
14
 *
15
 * $Id: EMFUpdateListStrategy.java,v 1.1 2007/11/16 21:25:21 emerks Exp $
15
 * $Id: EMFUpdateListStrategy.java,v 1.1 2007/11/16 21:25:21 emerks Exp $
16
 */
16
 */
17
package org.eclipse.emf.databinding;
17
package org.eclipse.emf.databinding;
18
18
19
import org.eclipse.core.databinding.Binding;
20
import org.eclipse.core.databinding.DataBindingContext;
19
import org.eclipse.core.databinding.UpdateListStrategy;
21
import org.eclipse.core.databinding.UpdateListStrategy;
20
import org.eclipse.core.databinding.conversion.Converter;
22
import org.eclipse.core.databinding.conversion.Converter;
21
import org.eclipse.core.databinding.conversion.IConverter;
23
import org.eclipse.core.databinding.conversion.IConverter;
24
import org.eclipse.core.databinding.observable.list.IObservableList;
22
import org.eclipse.emf.ecore.EAttribute;
25
import org.eclipse.emf.ecore.EAttribute;
23
import org.eclipse.emf.ecore.EDataType;
26
import org.eclipse.emf.ecore.EDataType;
24
import org.eclipse.emf.ecore.EFactory;
27
import org.eclipse.emf.ecore.EFactory;
25
28
26
/**
29
/**
27
 * PROVISIONAL
30
 * <p>
28
 * This API is subject to arbitrary change, including renaming or removal.
31
 * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or
32
 * removal.</b>
33
 * </p>
34
 * Customizes a {@link Binding} between two {@link IObservableList observable
35
 * lists}. The following behaviors can be customized via the strategy:
36
 * <ul>
37
 * <li>Conversion</li>
38
 * <li>Automatic processing</li>
39
 * </ul>
40
 * <p>
41
 * Conversion:<br/>
42
 * When elements are added they can be {@link #convert(Object) converted} to the
43
 * destination element type.
44
 * </p>
45
 * <p>
46
 * Automatic processing:<br/>
47
 * The processing to perform when the source observable changes. This behavior
48
 * is configured via policies provided on construction of the strategy (e.g.
49
 * {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, {@link #POLICY_UPDATE}).
50
 * </p>
51
 * 
52
 * 
53
 * @see DataBindingContext#bindList(IObservableList, IObservableList,
54
 *      UpdateListStrategy, UpdateListStrategy)
55
 * @see IConverter
56
 * @since 1.0
29
 */
57
 */
30
public class EMFUpdateListStrategy extends UpdateListStrategy
58
public class EMFUpdateListStrategy extends UpdateListStrategy {
31
{
59
	/**
32
  public EMFUpdateListStrategy()
60
	 * Creates a new update list strategy for automatically updating the
33
  {
61
	 * destination observable list whenever the source observable list changes.
34
    this(true, POLICY_UPDATE);
62
	 * A default converter will be provided. The defaults can be changed by
35
  }
63
	 * calling one of the setter methods.
64
	 */
65
	public EMFUpdateListStrategy() {
66
		this(true, POLICY_UPDATE);
67
	}
68
	
69
	/**
70
	 * Creates a new update list strategy with a configurable update policy. A
71
	 * default converter will be provided. The defaults can be changed by
72
	 * calling one of the setter methods.
73
	 *
74
	 * @param updatePolicy
75
	 *            one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or
76
	 *            {@link #POLICY_UPDATE}
77
	 */
78
	public EMFUpdateListStrategy(int updatePolicy) {
79
		this(true, updatePolicy);
80
	}
36
81
37
  public EMFUpdateListStrategy(int updatePolicy)
82
	/**
38
  {
83
	 * Creates a new update list strategy with a configurable update policy. A
39
    this(true, updatePolicy);
84
	 * default converter will be provided if <code>provideDefaults</code> is
40
  }
85
	 * <code>true</code>. The defaults can be changed by calling one of the
86
	 * setter methods.
87
	 *
88
	 * @param provideDefaults
89
	 *            if <code>true</code>, default validators and a default
90
	 *            converter will be provided based on the observable list's
91
	 *            type.
92
	 * @param updatePolicy
93
	 *            one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, or
94
	 *            {@link #POLICY_UPDATE}
95
	 */
96
	public EMFUpdateListStrategy(boolean provideDefaults, int updatePolicy) {
97
		super(provideDefaults, updatePolicy);
98
	}
41
99
42
  public EMFUpdateListStrategy(boolean provideDefaults, int updatePolicy)
100
	@Override
43
  {
101
	protected IConverter createConverter(Object fromType, Object toType) {
44
    super(provideDefaults, updatePolicy);
102
		if (fromType == String.class) {
45
  }
103
			if (toType instanceof EAttribute) {
46
  
104
				final EAttribute eAttribute = (EAttribute) toType;
47
  @Override
105
				final EDataType eDataType = eAttribute.getEAttributeType();
48
  protected IConverter createConverter(Object fromType, Object toType)
106
				final EFactory eFactory = eDataType.getEPackage()
49
  {
107
						.getEFactoryInstance();
50
    if (fromType == String.class)
108
				return new Converter(fromType, toType) {
51
    {
109
					public Object convert(Object fromObject) {
52
      if (toType instanceof EAttribute)
110
						return eFactory.createFromString(eDataType,
53
      {
111
								(String) fromObject);
54
        final EAttribute eAttribute = (EAttribute)toType;
112
					}
55
        final EDataType eDataType = eAttribute.getEAttributeType();
113
				};
56
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
114
			}
57
        return
115
		} else if (toType == String.class) {
58
          new Converter(fromType, toType)
116
			if (fromType instanceof EAttribute) {
59
          {
117
				final EAttribute eAttribute = (EAttribute) fromType;
60
            public Object convert(Object fromObject)
118
				final EDataType eDataType = eAttribute.getEAttributeType();
61
            {
119
				final EFactory eFactory = eDataType.getEPackage()
62
              return eFactory.createFromString(eDataType, (String)fromObject);
120
						.getEFactoryInstance();
63
            }
121
				return new Converter(fromType, toType) {
64
          };
122
					public Object convert(Object fromObject) {
65
      }
123
						return eFactory.convertToString(eDataType, fromObject);
66
    }
124
					}
67
    else if (toType == String.class)
125
				};
68
    {
126
			}
69
      if (fromType instanceof EAttribute)
127
		}
70
      {
128
		return super.createConverter(fromType, toType);
71
        final EAttribute eAttribute = (EAttribute)fromType;
129
	}
72
        final EDataType eDataType = eAttribute.getEAttributeType();
73
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
74
        return
75
          new Converter(fromType, toType)
76
          {
77
            public Object convert(Object fromObject)
78
            {
79
              return eFactory.convertToString(eDataType, fromObject);
80
            }
81
          };
82
      }
83
    }
84
    return super.createConverter(fromType, toType);
85
  }
86
}
130
}
(-)src/org/eclipse/emf/databinding/EMFUpdateValueStrategy.java (-89 / +150 lines)
Lines 9-15 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
11
 *   IBM - Initial API and implementation
12
 *
12
 *   Tom Schindl<tom.schindl@bestsolution.at>
13
 * </copyright>
13
 * </copyright>
14
 *
14
 *
15
 * $Id: EMFUpdateValueStrategy.java,v 1.2 2008/02/22 12:10:18 emerks Exp $
15
 * $Id: EMFUpdateValueStrategy.java,v 1.2 2008/02/22 12:10:18 emerks Exp $
Lines 19-121 Link Here
19
import java.util.ArrayList;
19
import java.util.ArrayList;
20
import java.util.List;
20
import java.util.List;
21
21
22
import org.eclipse.core.databinding.Binding;
23
import org.eclipse.core.databinding.DataBindingContext;
22
import org.eclipse.core.databinding.UpdateValueStrategy;
24
import org.eclipse.core.databinding.UpdateValueStrategy;
23
import org.eclipse.core.databinding.conversion.Converter;
25
import org.eclipse.core.databinding.conversion.Converter;
24
import org.eclipse.core.databinding.conversion.IConverter;
26
import org.eclipse.core.databinding.conversion.IConverter;
27
import org.eclipse.core.databinding.observable.value.IObservableValue;
28
import org.eclipse.core.databinding.validation.IValidator;
25
import org.eclipse.emf.ecore.EAttribute;
29
import org.eclipse.emf.ecore.EAttribute;
26
import org.eclipse.emf.ecore.EDataType;
30
import org.eclipse.emf.ecore.EDataType;
27
import org.eclipse.emf.ecore.EFactory;
31
import org.eclipse.emf.ecore.EFactory;
28
32
29
/**
33
/**
30
 * PROVISIONAL
34
 * <p>
31
 * This API is subject to arbitrary change, including renaming or removal.
35
 * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or
36
 * removal.</b>
37
 * </p>
38
 * Customizes a {@link Binding} between two {@link IObservableValue observable
39
 * values}. The following behaviors can be customized via the strategy:
40
 * <ul>
41
 * <li>Validation</li>
42
 * <li>Conversion</li>
43
 * <li>Automatic processing</li>
44
 * </ul>
45
 * <p>
46
 * The update phases are:
47
 * <ol>
48
 * <li>Validate after get - {@link #validateAfterGet(Object)}</li>
49
 * <li>Conversion - {@link #convert(Object)}</li>
50
 * <li>Validate after conversion - {@link #validateAfterConvert(Object)}</li>
51
 * <li>Validate before set - {@link #validateBeforeSet(Object)}</li>
52
 * <li>Value set - {@link #doSet(IObservableValue, Object)}</li>
53
 * </ol>
54
 * </p>
55
 * <p>
56
 * Validation:<br/>
57
 * {@link IValidator Validators} validate the value at multiple phases in the
58
 * update process. Statuses returned from validators are aggregated into a
59
 * <code>MultiStatus</code> until a status of <code>ERROR</code> or
60
 * <code>CANCEL</code> is encountered. Either of these statuses will abort the
61
 * update process. These statuses are available as the
62
 * {@link Binding#getValidationStatus() binding validation status}.
63
 * </p>
64
 * <p>
65
 * Conversion:<br/>
66
 * A {@link IConverter converter} will convert the value from the type of the
67
 * source observable into the type of the destination. The strategy has the
68
 * ability to default converters for common scenarios.
69
 * </p>
70
 * <p>
71
 * Automatic processing:<br/>
72
 * The processing to perform when the source observable changes. This behavior
73
 * is configured via policies provided on construction of the strategy (e.g.
74
 * {@link #POLICY_NEVER}, {@link #POLICY_CONVERT}, {@link #POLICY_ON_REQUEST},
75
 * {@link #POLICY_UPDATE}).
76
 * </p>
77
 * 
78
 * @see DataBindingContext#bindValue(IObservableValue, IObservableValue,
79
 *      UpdateValueStrategy, UpdateValueStrategy)
80
 * @see Binding#getValidationStatus()
81
 * @see IValidator
82
 * @see IConverter
83
 * @since 1.0
32
 */
84
 */
33
public class EMFUpdateValueStrategy extends UpdateValueStrategy
85
public class EMFUpdateValueStrategy extends UpdateValueStrategy {
34
{
86
	/**
35
  public EMFUpdateValueStrategy()
87
	 * Creates a new update value strategy for automatically updating the
36
  {
88
	 * destination observable value whenever the source observable value
37
    this(true, POLICY_UPDATE);
89
	 * changes. Default validators and a default converter will be provided. The
38
  }
90
	 * defaults can be changed by calling one of the setter methods.
91
	 */
92
	public EMFUpdateValueStrategy() {
93
		this(true, POLICY_UPDATE);
94
	}
95
	
96
	/**
97
	 * Creates a new update value strategy with a configurable update policy.
98
	 * Default validators and a default converter will be provided. The defaults
99
	 * can be changed by calling one of the setter methods.
100
	 *
101
	 * @param updatePolicy
102
	 *            one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST},
103
	 *            {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE}
104
	 */
105
	public EMFUpdateValueStrategy(int updatePolicy) {
106
		this(true, updatePolicy);
107
	}
39
108
40
  public EMFUpdateValueStrategy(int updatePolicy)
109
	/**
41
  {
110
	 * Creates a new update value strategy with a configurable update policy.
42
    this(true, updatePolicy);
111
	 * Default validators and a default converter will be provided if
43
  }
112
	 * <code>provideDefaults</code> is <code>true</code>. The defaults can
113
	 * be changed by calling one of the setter methods.
114
	 *
115
	 * @param provideDefaults
116
	 *            if <code>true</code>, default validators and a default
117
	 *            converter will be provided based on the observable value's
118
	 *            type.
119
	 * @param updatePolicy
120
	 *            one of {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST},
121
	 *            {@link #POLICY_CONVERT}, or {@link #POLICY_UPDATE}
122
	 */
123
	public EMFUpdateValueStrategy(boolean provideDefaults, int updatePolicy) {
124
		super(provideDefaults, updatePolicy);
125
	}
44
126
45
  public EMFUpdateValueStrategy(boolean provideDefaults, int updatePolicy)
127
	@Override
46
  {
128
	protected IConverter createConverter(Object fromType, Object toType) {
47
    super(provideDefaults, updatePolicy);
129
		if (fromType == String.class) {
48
  }
130
			if (toType instanceof EAttribute) {
49
  
131
				final EAttribute eAttribute = (EAttribute) toType;
50
  @Override
132
				final EDataType eDataType = eAttribute.getEAttributeType();
51
  protected IConverter createConverter(Object fromType, Object toType)
133
				final EFactory eFactory = eDataType.getEPackage()
52
  {
134
						.getEFactoryInstance();
53
    if (fromType == String.class)
135
				return new Converter(fromType, toType) {
54
    {
136
					public Object convert(Object fromObject) {
55
      if (toType instanceof EAttribute)
137
						String value = fromObject == null ? null : fromObject
56
      {
138
								.toString();
57
        final EAttribute eAttribute = (EAttribute)toType;
139
						if (eAttribute.isMany()) {
58
        final EDataType eDataType = eAttribute.getEAttributeType();
140
							List<Object> result = new ArrayList<Object>();
59
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
141
							if (value != null) {
60
        return
142
								for (String element : value.split(" ")) {
61
          new Converter(fromType, toType)
143
									result.add(eFactory.createFromString(
62
          {
144
											eDataType, element));
63
            public Object convert(Object fromObject)
145
								}
64
            {
146
							}
65
              String value = fromObject == null ? null : fromObject.toString();
147
							return result;
66
              if (eAttribute.isMany())
148
						} else {
67
              {
149
							return eFactory.createFromString(eDataType, value);
68
                List<Object> result = new ArrayList<Object>();
150
						}
69
                if (value != null)
151
					}
70
                {
152
				};
71
                  for (String element : value.split(" "))
153
			}
72
                  {
154
		} else if (toType == String.class) {
73
                    result.add(eFactory.createFromString(eDataType, element));
155
			if (fromType instanceof EAttribute) {
74
                  }
156
				final EAttribute eAttribute = (EAttribute) fromType;
75
                }
157
				final EDataType eDataType = eAttribute.getEAttributeType();
76
                return result;
158
				final EFactory eFactory = eDataType.getEPackage()
77
              }
159
						.getEFactoryInstance();
78
              else
160
				return new Converter(fromType, toType) {
79
              {
161
					public Object convert(Object fromObject) {
80
                return eFactory.createFromString(eDataType, value);
162
						if (eAttribute.isMany()) {
81
              }
163
							StringBuilder result = new StringBuilder();
82
            }
164
							for (Object value : (List<?>) fromObject) {
83
          };
165
								if (result.length() == 0) {
84
      }
166
									result.append(' ');
85
    }
167
								}
86
    else if (toType == String.class)
168
								result.append(eFactory.convertToString(
87
    {
169
										eDataType, value));
88
      if (fromType instanceof EAttribute)
170
							}
89
      {
171
							return result.toString();
90
        final EAttribute eAttribute = (EAttribute)fromType;
172
						} else {
91
        final EDataType eDataType = eAttribute.getEAttributeType();
173
							return eFactory.convertToString(eDataType,
92
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
174
									fromObject);
93
        return
175
						}
94
          new Converter(fromType, toType)
176
					}
95
          {
177
				};
96
            public Object convert(Object fromObject)
178
			}
97
            {
179
		}
98
              if (eAttribute.isMany())
180
		return super.createConverter(fromType, toType);
99
              {
181
	}
100
                StringBuilder result = new StringBuilder();
101
                for (Object value : (List<?>)fromObject)
102
                {
103
                  if (result.length() == 0)
104
                  {
105
                    result.append(' ');
106
                  }
107
                  result.append(eFactory.convertToString(eDataType, value));
108
                }
109
                return result.toString();
110
              }
111
              else
112
              {
113
                return eFactory.convertToString(eDataType, fromObject);
114
              }
115
            }
116
          };
117
      }
118
    }
119
    return super.createConverter(fromType, toType);
120
  }
121
}
182
}
(-)src/org/eclipse/emf/databinding/EObjectObservableList.java (-254 / +241 lines)
Lines 9-15 Link Here
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
11
 *   IBM - Initial API and implementation
11
 *   IBM - Initial API and implementation
12
 *
12
 *   Tom Schindl<tom.schindl@bestsolution.at>
13
 * </copyright>
13
 * </copyright>
14
 *
14
 *
15
 * $Id: EObjectObservableList.java,v 1.4 2008/02/21 15:26:16 emerks Exp $
15
 * $Id: EObjectObservableList.java,v 1.4 2008/02/21 15:26:16 emerks Exp $
Lines 33-294 Link Here
33
import org.eclipse.emf.ecore.EStructuralFeature;
33
import org.eclipse.emf.ecore.EStructuralFeature;
34
34
35
/**
35
/**
36
 * PROVISIONAL
36
 * <p>
37
 * This API is subject to arbitrary change, including renaming or removal.
37
 * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or
38
 * removal.</b>
39
 * </p>
38
 */
40
 */
39
public class EObjectObservableList extends ObservableList implements IObserving, InternalRawEList
41
public class EObjectObservableList extends ObservableList implements
40
{
42
		IObserving, InternalRawEList {
41
  protected EObject eObject;
43
	protected EObject eObject;
42
  protected EStructuralFeature eStructuralFeature;
44
	protected EStructuralFeature eStructuralFeature;
43
  protected Adapter listener;
45
	protected Adapter listener;
44
46
45
  public EObjectObservableList(EObject eObject, EStructuralFeature eStructuralFeature)
47
	public EObjectObservableList(EObject eObject,
46
  {
48
			EStructuralFeature eStructuralFeature) {
47
    this(Realm.getDefault(), eObject, eStructuralFeature);
49
		this(Realm.getDefault(), eObject, eStructuralFeature);
48
  }
50
	}
49
51
50
  public EObjectObservableList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
52
	public EObjectObservableList(Realm realm, EObject eObject,
51
  {
53
			EStructuralFeature eStructuralFeature) {
52
    super(realm, (EList<?>)eObject.eGet(eStructuralFeature), eStructuralFeature);
54
		super(realm, (EList<?>) eObject.eGet(eStructuralFeature),
53
    this.eObject = eObject;
55
				eStructuralFeature);
54
    this.eStructuralFeature = eStructuralFeature;
56
		this.eObject = eObject;
55
  }
57
		this.eStructuralFeature = eStructuralFeature;
56
58
	}
57
  @Override
59
58
  protected void firstListenerAdded()
60
	@Override
59
  {
61
	protected void firstListenerAdded() {
60
    listener =
62
		listener = new AdapterImpl() {
61
      new AdapterImpl()
63
			@Override
62
      {
64
			public void notifyChanged(Notification notification) {
63
        @Override
65
				if (eStructuralFeature == notification.getFeature()
64
        public void notifyChanged(Notification notification)
66
						&& !notification.isTouch()) {
65
        {
67
					final ListDiff diff;
66
          if (eStructuralFeature == notification.getFeature() && !notification.isTouch())
68
					switch (notification.getEventType()) {
67
          {
69
					case Notification.ADD: {
68
            final ListDiff diff;
70
						diff = Diffs.createListDiff(Diffs.createListDiffEntry(
69
            switch (notification.getEventType())
71
								notification.getPosition(), true, notification
70
            {
72
										.getNewValue()));
71
              case Notification.ADD:
73
						break;
72
              {
74
					}
73
                diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue()));
75
					case Notification.ADD_MANY: {
74
                break;
76
						Collection<?> newValues = (Collection<?>) notification
75
              }
77
								.getNewValue();
76
              case Notification.ADD_MANY:
78
						ListDiffEntry[] listDiffEntries = new ListDiffEntry[newValues
77
              {
79
								.size()];
78
                Collection<?> newValues = (Collection<?>)notification.getNewValue();
80
						int position = notification.getPosition();
79
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [newValues.size()];
81
						int index = 0;
80
                int position = notification.getPosition();
82
						for (Object newValue : newValues) {
81
                int index = 0;
83
							listDiffEntries[index++] = Diffs
82
                for (Object newValue : newValues)
84
									.createListDiffEntry(position++, true,
83
                {
85
											newValue);
84
                  listDiffEntries[index++] = Diffs.createListDiffEntry(position++, true, newValue);
86
						}
85
                }
87
						diff = Diffs.createListDiff(listDiffEntries);
86
                diff = Diffs.createListDiff(listDiffEntries);
88
						break;
87
                break;
89
					}
88
              }
90
					case Notification.REMOVE: {
89
              case Notification.REMOVE:
91
						diff = Diffs.createListDiff(Diffs.createListDiffEntry(
90
              {
92
								notification.getPosition(), false, notification
91
                diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue()));
93
										.getOldValue()));
92
                break;
94
						break;
93
              }
95
					}
94
              case Notification.REMOVE_MANY:
96
					case Notification.REMOVE_MANY: {
95
              {
97
						Collection<?> oldValues = (Collection<?>) notification
96
                Collection<?> oldValues = (Collection<?>)notification.getOldValue();
98
								.getOldValue();
97
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [oldValues.size()];
99
						ListDiffEntry[] listDiffEntries = new ListDiffEntry[oldValues
98
                int position = notification.getPosition();
100
								.size()];
99
                int index = 0;
101
						int position = notification.getPosition();
100
                for (Object oldValue : oldValues)
102
						int index = 0;
101
                {
103
						for (Object oldValue : oldValues) {
102
                  listDiffEntries[index++] = Diffs.createListDiffEntry(position++, false, oldValue);
104
							listDiffEntries[index++] = Diffs
103
                }
105
									.createListDiffEntry(position++, false,
104
                diff = Diffs.createListDiff(listDiffEntries);
106
											oldValue);
105
                break;
107
						}
106
              }
108
						diff = Diffs.createListDiff(listDiffEntries);
107
              case Notification.SET:
109
						break;
108
              case Notification.RESOLVE:
110
					}
109
              {
111
					case Notification.SET:
110
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [2];
112
					case Notification.RESOLVE: {
111
                listDiffEntries[0] = Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue());
113
						ListDiffEntry[] listDiffEntries = new ListDiffEntry[2];
112
                listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue());
114
						listDiffEntries[0] = Diffs.createListDiffEntry(
113
                diff = Diffs.createListDiff(listDiffEntries);
115
								notification.getPosition(), false, notification
114
                break;
116
										.getOldValue());
115
              }
117
						listDiffEntries[1] = Diffs.createListDiffEntry(
116
              case Notification.MOVE:
118
								notification.getPosition(), true, notification
117
              {
119
										.getNewValue());
118
                Object movedValue = notification.getNewValue();
120
						diff = Diffs.createListDiff(listDiffEntries);
119
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [2];
121
						break;
120
                listDiffEntries[0] = Diffs.createListDiffEntry((Integer)notification.getOldValue(), false, movedValue);
122
					}
121
                listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, movedValue);
123
					case Notification.MOVE: {
122
                diff = Diffs.createListDiff(listDiffEntries);
124
						Object movedValue = notification.getNewValue();
123
                break;
125
						ListDiffEntry[] listDiffEntries = new ListDiffEntry[2];
124
              }
126
						listDiffEntries[0] = Diffs.createListDiffEntry(
125
              case Notification.UNSET:
127
								(Integer) notification.getOldValue(), false,
126
              {
128
								movedValue);
127
                // This just represents going back to the unset state, but that doesn't affect the contents of the list.
129
						listDiffEntries[1] = Diffs.createListDiffEntry(
128
                //
130
								notification.getPosition(), true, movedValue);
129
                return;
131
						diff = Diffs.createListDiff(listDiffEntries);
130
              }
132
						break;
131
              default:
133
					}
132
              {
134
					case Notification.UNSET: {
133
                throw new RuntimeException("unhandled case");
135
						// This just represents going back to the unset state,
134
              }
136
						// but that doesn't affect the contents of the list.
135
            }
137
						//
136
            getRealm().exec
138
						return;
137
             (new Runnable()
139
					}
138
              {
140
					default: {
139
                public void run()
141
						throw new RuntimeException("unhandled case");
140
                {
142
					}
141
                  fireListChange(diff);
143
					}
142
                }
144
					getRealm().exec(new Runnable() {
143
              });
145
						public void run() {
144
          }
146
							fireListChange(diff);
145
        }
147
						}
146
      };
148
					});
147
    eObject.eAdapters().add(listener);
149
				}
148
  }
150
			}
149
  
151
		};
150
  @Override
152
		eObject.eAdapters().add(listener);
151
  protected void lastListenerRemoved()
153
	}
152
  {
154
153
    eObject.eAdapters().remove(listener);
155
	@Override
154
    listener = null;
156
	protected void lastListenerRemoved() {
155
  }
157
		eObject.eAdapters().remove(listener);
156
158
		listener = null;
157
  @Override
159
	}
158
  public synchronized void dispose()
160
159
  {
161
	@Override
160
    if (listener != null)
162
	public synchronized void dispose() {
161
    {
163
		if (listener != null) {
162
      eObject.eAdapters().remove(listener);
164
			eObject.eAdapters().remove(listener);
163
      listener = null;
165
			listener = null;
164
    }
166
		}
165
    eObject = null;
167
		eObject = null;
166
    eStructuralFeature = null;
168
		eStructuralFeature = null;
167
    super.dispose();
169
		super.dispose();
168
  }
170
	}
169
171
170
  @SuppressWarnings("unchecked")
172
	@SuppressWarnings("unchecked")
171
  protected final List<Object> wrappedList()
173
	protected final List<Object> wrappedList() {
172
  {
174
		return wrappedList;
173
    return wrappedList;
175
	}
174
  }
176
175
177
	public Object getObserved() {
176
  public Object getObserved()
178
		return eObject;
177
  {
179
	}
178
    return eObject;
180
179
  }
181
	@Override
180
182
	public boolean add(Object object) {
181
  @Override
183
		checkRealm();
182
  public boolean add(Object object)
184
		return wrappedList().add(object);
183
  {
185
	}
184
    checkRealm();
186
185
    return wrappedList().add(object);
187
	@Override
186
  }
188
	public void add(int index, Object object) {
187
189
		checkRealm();
188
  @Override
190
		wrappedList().add(index, object);
189
  public void add(int index, Object object)
191
	}
190
  {
192
191
    checkRealm();
193
	@SuppressWarnings("unchecked")
192
    wrappedList().add(index, object);
194
	@Override
193
  }
195
	public boolean addAll(Collection collection) {
194
196
		checkRealm();
195
  @SuppressWarnings("unchecked")
197
		return wrappedList().addAll(collection);
196
  @Override
198
	}
197
  public boolean addAll(Collection collection)
199
198
  {
200
	@SuppressWarnings("unchecked")
199
    checkRealm();
201
	@Override
200
    return wrappedList().addAll(collection);
202
	public boolean addAll(int index, Collection collection) {
201
  }
203
		checkRealm();
202
204
		return wrappedList().addAll(index, collection);
203
  @SuppressWarnings("unchecked")
205
	}
204
  @Override
206
205
  public boolean addAll(int index, Collection collection)
207
	@Override
206
  {
208
	public Object set(int index, Object element) {
207
    checkRealm();
209
		checkRealm();
208
    return wrappedList().addAll(index, collection);
210
		return wrappedList().set(index, element);
209
  }
211
	}
210
212
211
  @Override
213
	@Override
212
  public Object set(int index, Object element)
214
	public Object remove(int index) {
213
  {
215
		checkRealm();
214
    checkRealm();
216
		return wrappedList.remove(index);
215
    return wrappedList().set(index, element);
217
	}
216
  }
218
217
219
	@Override
218
  @Override
220
	public boolean remove(Object element) {
219
  public Object remove(int index)
221
		checkRealm();
220
  {
222
		return wrappedList.remove(element);
221
    checkRealm();
223
	}
222
    return wrappedList.remove(index);
224
223
  }
225
	@SuppressWarnings("unchecked")
224
226
	@Override
225
  @Override
227
	public boolean removeAll(Collection collection) {
226
  public boolean remove(Object element)
228
		checkRealm();
227
  {
229
		return wrappedList().removeAll(collection);
228
    checkRealm();
230
	}
229
    return wrappedList.remove(element);
231
230
  }
232
	@SuppressWarnings("unchecked")
231
233
	@Override
232
  @SuppressWarnings("unchecked")
234
	public boolean retainAll(Collection collection) {
233
  @Override
235
		checkRealm();
234
  public boolean removeAll(Collection collection)
236
		return wrappedList().retainAll(collection);
235
  {
237
	}
236
    checkRealm();
238
237
    return wrappedList().removeAll(collection);
239
	@Override
238
  }
240
	public void clear() {
239
241
		checkRealm();
240
  @SuppressWarnings("unchecked")
242
		wrappedList.clear();
241
  @Override
243
	}
242
  public boolean retainAll(Collection collection)
244
243
  {
245
	@Override
244
    checkRealm();
246
	public Object move(int newPosition, int oldPosition) {
245
    return wrappedList().retainAll(collection);
247
		checkRealm();
246
  }
248
		return ((EList<?>) wrappedList).move(newPosition, oldPosition);
247
249
	}
248
  @Override
250
249
  public void clear()
251
	public void move(int newPosition, Object object) {
250
  {
252
		move(newPosition, indexOf(object));
251
    checkRealm();
253
	}
252
    wrappedList.clear();
254
253
  }
255
	@Override
254
256
	public String toString() {
255
  @Override
257
		StringBuilder result = new StringBuilder(getClass().getName());
256
  public Object move(int newPosition, int oldPosition)
258
		result.append('@');
257
  {
259
		result.append(Integer.toHexString(hashCode()));
258
    checkRealm();
260
259
    return ((EList<?>)wrappedList).move(newPosition, oldPosition);
261
		result.append(" (eObject:");
260
  }
262
		result.append(eObject);
261
263
		result.append(")");
262
  public void move(int newPosition, Object object)
264
263
  {
265
		result.append(" (eStructuralFeature: ");
264
    move(newPosition, indexOf(object));
266
		result.append(eStructuralFeature);
265
  }
267
		result.append(")");
266
268
267
  @Override
269
		result.append(" (wrappedList: ");
268
  public String toString()
270
		result.append(wrappedList);
269
  {
271
		result.append(")");
270
    StringBuilder result = new StringBuilder(getClass().getName());
271
    result.append('@');
272
    result.append(Integer.toHexString(hashCode()));
273
274
    result.append(" (eObject:");
275
    result.append(eObject);
276
    result.append(")");
277
278
    result.append(" (eStructuralFeature: ");
279
    result.append(eStructuralFeature);
280
    result.append(")");
281
282
    result.append(" (wrappedList: ");
283
    result.append(wrappedList);
284
    result.append(")");
285
272
286
    return result.toString();
273
		return result.toString();
287
  }
274
	}
288
}
275
}
289
276
290
@SuppressWarnings("unchecked")
277
@SuppressWarnings("unchecked")
291
interface InternalRawEList extends EList
278
interface InternalRawEList extends EList {
292
{
279
	// This is only at avoid needing an @SuppressWarnings("unchecked") on the
293
  // This is only at avoid needing an @SuppressWarnings("unchecked") on the EMFObservableList
280
	// EMFObservableList
294
}
281
}
(-)src/org/eclipse/emf/databinding/EObjectObservableMap.java (-67 / +60 lines)
Lines 9-15 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *   IBM - Initial API and implementation
11
 *   IBM - Initial API and implementation
12
 *
12
 *   Tom Schindl<tom.schindl@bestsolution.at>
13
 * </copyright>
13
 * </copyright>
14
 *
14
 *
15
 * $Id: EObjectObservableMap.java,v 1.4 2008/10/21 11:03:56 emerks Exp $
15
 * $Id: EObjectObservableMap.java,v 1.4 2008/10/21 11:03:56 emerks Exp $
Lines 28-98 Link Here
28
import org.eclipse.emf.ecore.util.ExtendedMetaData;
28
import org.eclipse.emf.ecore.util.ExtendedMetaData;
29
29
30
/**
30
/**
31
 * PROVISIONAL
31
 * <p>
32
 * This API is subject to arbitrary change, including renaming or removal.
32
 * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or
33
 * removal.</b>
34
 * </p>
33
 */
35
 */
34
public class EObjectObservableMap extends ComputedObservableMap
36
public class EObjectObservableMap extends ComputedObservableMap {
35
{
37
	protected EStructuralFeature eStructuralFeature;
36
  protected EStructuralFeature eStructuralFeature;
38
37
39
	private Adapter elementListener = new AdapterImpl() {
38
  private Adapter elementListener = 
40
		@Override
39
    new AdapterImpl()
41
		public void notifyChanged(Notification notification) {
40
    {
42
			if (eStructuralFeature == notification.getFeature()
41
      @Override
43
					&& !notification.isTouch()) {
42
      public void notifyChanged(Notification notification)
44
				// TODO
43
      {
45
				// This assumes we only get a SET notification, which isn't a
44
        if (eStructuralFeature == notification.getFeature() && !notification.isTouch())
46
				// good assumption.
45
        {
47
				//
46
          // TODO
48
				final MapDiff diff = Diffs.createMapDiffSingleChange(
47
          // This assumes we only get a SET notification, which isn't a good assumption.
49
						notification.getNotifier(), notification.getOldValue(),
48
          //
50
						notification.getNewValue());
49
          final MapDiff diff = Diffs.createMapDiffSingleChange(notification.getNotifier(), notification.getOldValue(), notification.getNewValue());
51
				getRealm().exec(new Runnable() {
50
          getRealm().exec
52
					public void run() {
51
            (new Runnable()
53
						fireMapChange(diff);
52
             {
54
					}
53
               public void run()
55
				});
54
               {
56
			}
55
                 fireMapChange(diff);
57
		}
56
               }
58
	};
57
             });
59
58
        }
60
	public EObjectObservableMap(IObservableSet objects,
59
      }
61
			EStructuralFeature feature) {
60
    };
62
		super(objects);
61
63
		this.eStructuralFeature = feature;
62
  public EObjectObservableMap(IObservableSet objects, EStructuralFeature feature)
64
	}
63
  {
65
64
    super(objects);
66
	@Override
65
    this.eStructuralFeature = feature;
67
	protected void hookListener(Object domainElement) {
66
  }
68
		((EObject) domainElement).eAdapters().add(elementListener);
67
69
	}
68
  @Override
70
69
  protected void hookListener(Object domainElement)
71
	@Override
70
  {
72
	protected void unhookListener(Object domainElement) {
71
    ((EObject)domainElement).eAdapters().add(elementListener);
73
		((EObject) domainElement).eAdapters().remove(elementListener);
72
  }
74
	}
73
75
74
  @Override
76
	@Override
75
  protected void unhookListener(Object domainElement)
77
	protected Object doGet(Object key) {
76
  {
78
		EObject eObject = (EObject) key;
77
    ((EObject)domainElement).eAdapters().remove(elementListener);
79
		return ExtendedMetaData.INSTANCE.getAffiliation(eObject.eClass(),
78
  }
80
				eStructuralFeature) == null ? null : eObject
79
81
				.eGet(eStructuralFeature);
80
  @Override
82
	}
81
  protected Object doGet(Object key)
83
82
  {
84
	@Override
83
    EObject eObject = (EObject)key;
85
	protected Object doPut(Object key, Object value) {
84
    return  
86
		EObject eObject = (EObject) key;
85
      ExtendedMetaData.INSTANCE.getAffiliation(eObject.eClass(), eStructuralFeature) == null ?
87
		Object result = eObject.eGet(eStructuralFeature);
86
        null :
88
		eObject.eSet(eStructuralFeature, value);
87
        eObject.eGet(eStructuralFeature);
89
		return result;
88
  }
90
	}
89
90
  @Override
91
  protected Object doPut(Object key, Object value)
92
  {
93
    EObject eObject = (EObject)key;
94
    Object result = eObject.eGet(eStructuralFeature);
95
    eObject.eSet(eStructuralFeature, value);
96
    return result;
97
  }
98
}
91
}
(-)src/org/eclipse/emf/databinding/EObjectObservableValue.java (-117 / +102 lines)
Lines 9-15 Link Here
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
11
 *   IBM - Initial API and implementation
11
 *   IBM - Initial API and implementation
12
 *
12
 *   Tom Schindl<tom.schindl@bestsolution.at>
13
 * </copyright>
13
 * </copyright>
14
 *
14
 *
15
 * $Id: EObjectObservableValue.java,v 1.2 2008/01/26 21:01:07 emerks Exp $
15
 * $Id: EObjectObservableValue.java,v 1.2 2008/01/26 21:01:07 emerks Exp $
Lines 28-149 Link Here
28
import org.eclipse.emf.ecore.EStructuralFeature;
28
import org.eclipse.emf.ecore.EStructuralFeature;
29
29
30
/**
30
/**
31
 * PROVISIONAL
31
 * <p>
32
 * This API is subject to arbitrary change, including renaming or removal.
32
 * <b>PROVISIONAL This API is subject to arbitrary change, including renaming or
33
 * removal.</b>
34
 * </p>
33
 */
35
 */
34
public class EObjectObservableValue extends AbstractObservableValue implements IObserving
36
public class EObjectObservableValue extends AbstractObservableValue implements
35
{
37
		IObserving {
36
  protected EObject eObject;
38
	protected EObject eObject;
37
  protected EStructuralFeature eStructuralFeature;
39
	protected EStructuralFeature eStructuralFeature;
38
  protected Adapter listener;
40
	protected Adapter listener;
39
41
40
  public EObjectObservableValue(EObject eObject, EStructuralFeature eStructuralFeature)
42
	public EObjectObservableValue(EObject eObject,
41
  {
43
			EStructuralFeature eStructuralFeature) {
42
    this(Realm.getDefault(), eObject, eStructuralFeature);
44
		this(Realm.getDefault(), eObject, eStructuralFeature);
43
  }
45
	}
44
46
45
  public EObjectObservableValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
47
	public EObjectObservableValue(Realm realm, EObject eObject,
46
  {
48
			EStructuralFeature eStructuralFeature) {
47
    super(realm);
49
		super(realm);
48
    this.eObject = eObject;
50
		this.eObject = eObject;
49
    this.eStructuralFeature = eStructuralFeature;
51
		this.eStructuralFeature = eStructuralFeature;
50
  }
52
	}
51
53
52
  @Override
54
	@Override
53
  public synchronized void dispose()
55
	public synchronized void dispose() {
54
  {
56
		if (listener != null) {
55
    if (listener != null)
57
			eObject.eAdapters().remove(listener);
56
    {
58
			listener = null;
57
      eObject.eAdapters().remove(listener);
59
		}
58
      listener = null;
60
		eObject = null;
59
    }
61
		eStructuralFeature = null;
60
    eObject = null;
62
		super.dispose();
61
    eStructuralFeature = null;
63
	}
62
    super.dispose();
64
63
  }
65
	public Object getObserved() {
64
66
		return eObject;
65
  public Object getObserved()
67
	}
66
  {
68
67
    return eObject;
69
	@Override
68
  }
70
	protected void firstListenerAdded() {
69
71
		listener = new AdapterImpl() {
70
  @Override
72
			@Override
71
  protected void firstListenerAdded()
73
			public void notifyChanged(Notification notification) {
72
  {
74
				if (eStructuralFeature == notification.getFeature()
73
    listener =
75
						&& !notification.isTouch()) {
74
      new AdapterImpl()
76
					final ValueDiff diff = Diffs.createValueDiff(notification
75
      {
77
							.getOldValue(), notification.getNewValue());
76
        @Override
78
					getRealm().exec(new Runnable() {
77
        public void notifyChanged(Notification notification)
79
						public void run() {
78
        {
80
							fireValueChange(diff);
79
          if (eStructuralFeature == notification.getFeature() && !notification.isTouch())
81
						}
80
          {
82
					});
81
            final ValueDiff diff = Diffs.createValueDiff(notification.getOldValue(), notification.getNewValue());
83
				}
82
            getRealm().exec
84
			}
83
              (new Runnable()
85
		};
84
               {
86
		eObject.eAdapters().add(listener);
85
                 public void run()
87
	}
86
                 {
88
87
                   fireValueChange(diff);
89
	@Override
88
                 }
90
	protected void lastListenerRemoved() {
89
               });
91
		eObject.eAdapters().remove(listener);
90
          }
92
		listener = null;
91
        }
93
	}
92
      };
94
93
    eObject.eAdapters().add(listener);
95
	@Override
94
  }
96
	protected Object doGetValue() {
95
97
		return eObject.eGet(eStructuralFeature);
96
  @Override
98
	}
97
  protected void lastListenerRemoved()
99
98
  {
100
	@Override
99
    eObject.eAdapters().remove(listener);
101
	protected void doSetValue(Object value) {
100
    listener = null;
102
		eObject.eSet(eStructuralFeature, value);
101
  }
103
	}
102
104
103
  @Override
105
	public Object getValueType() {
104
  protected Object doGetValue()
106
		return eStructuralFeature;
105
  {
107
	}
106
    return eObject.eGet(eStructuralFeature);
108
107
  }
109
	@Override
108
110
	public String toString() {
109
  @Override
111
		StringBuilder result = new StringBuilder(getClass().getName());
110
  protected void doSetValue(Object value)
112
		result.append('@');
111
  {
113
		result.append(Integer.toHexString(hashCode()));
112
    eObject.eSet(eStructuralFeature, value);
114
113
  }
115
		result.append(" (eObject:");
114
116
		result.append(eObject);
115
  public Object getValueType()
117
		result.append(")");
116
  {
118
117
    return eStructuralFeature;
119
		result.append(" (eStructuralFeature: ");
118
  }
120
		result.append(eStructuralFeature);
119
121
		result.append(")");
120
  @Override
122
121
  public String toString()
123
		try {
122
  {
124
			Object value = eObject.eGet(eStructuralFeature, false);
123
    StringBuilder result = new StringBuilder(getClass().getName());
125
			result.append(" (value: ");
124
    result.append('@');
126
			result.append(value);
125
    result.append(Integer.toHexString(hashCode()));
127
			result.append(")");
126
128
		} catch (Exception exception) {
127
    result.append(" (eObject:");
129
			// Ignore.
128
    result.append(eObject);
130
		}
129
    result.append(")");
130
131
    result.append(" (eStructuralFeature: ");
132
    result.append(eStructuralFeature);
133
    result.append(")");
134
135
    try
136
    {
137
      Object value = eObject.eGet(eStructuralFeature, false);
138
      result.append(" (value: ");
139
      result.append(value);
140
      result.append(")");
141
    }
142
    catch (Exception exception)
143
    {
144
      // Ignore.
145
    }
146
131
147
    return result.toString();
132
		return result.toString();
148
  }
133
	}
149
}
134
}

Return to bug 262160