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 (-2 / +4 lines)
Lines 8-16 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.internal;x-friends:="org.eclipse.emf.databinding.edit"
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,
16
 org.eclipse.core.databinding.property;bundle-version="1.2.0"
15
Eclipse-LazyStart: true
17
Eclipse-LazyStart: true
16
Bundle-ActivationPolicy: lazy
18
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/emf/databinding/EMFObservables.java (-161 / +214 lines)
Lines 17-23 Link Here
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
 * PROVISIONAL This API is subject to arbitrary change, including renaming or
34
 * This API is subject to arbitrary change, including renaming or removal.
36
 * removal.
35
 */
37
 */
36
public class EMFObservables
38
public class EMFObservables {
37
{
39
	/**
38
  /**
40
	 * Returns an observable value for the given feature of the object.
39
   * Returns an observable value for the given feature of the object.
41
	 * 
40
   * @param eObject the object to observe.
42
	 * @param eObject
41
   * @param eStructuralFeature the feature of the object to observe.
43
	 *            the object to observe.
42
   * @return an observable value for the given feature of the object.
44
	 * @param eStructuralFeature
43
   */
45
	 *            the feature of the object to observe.
44
  public static IObservableValue observeValue(EObject eObject, EStructuralFeature eStructuralFeature)
46
	 * @return an observable value for the given feature of the object.
45
  {
47
	 */
46
    return new EObjectObservableValue(eObject, eStructuralFeature);
48
	public static IObservableValue observeValue(EObject eObject,
47
  }
49
			EStructuralFeature eStructuralFeature) {
48
50
		return new EObjectObservableValue(eObject, eStructuralFeature);
49
  /**
51
	}
50
   * Returns an observable value for the given feature of the object.
52
51
   * @param realm the realm in which to observe.
53
	/**
52
   * @param eObject the object to observe.
54
	 * Returns an observable value for the given feature of the object.
53
   * @param eStructuralFeature the feature of the object to observe.
55
	 * 
54
   * @return an observable value for the given feature of the object.
56
	 * @param realm
55
   */
57
	 *            the realm in which to observe.
56
  public static IObservableValue observeValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
58
	 * @param eObject
57
  {
59
	 *            the object to observe.
58
    return new EObjectObservableValue(realm, eObject, eStructuralFeature);
60
	 * @param eStructuralFeature
59
  }
61
	 *            the feature of the object to observe.
60
62
	 * @return an observable value for the given feature of the object.
61
  /**
63
	 */
62
   * Returns an observable list for the given multi-valued feature of the object.
64
	public static IObservableValue observeValue(Realm realm, EObject eObject,
63
   * @param eObject the object to observe.
65
			EStructuralFeature eStructuralFeature) {
64
   * @param eStructuralFeature the feature of the object to observe.
66
		return new EObjectObservableValue(realm, eObject, eStructuralFeature);
65
   * @return an observable list for the given multi-valued feature of the object.
67
	}
66
   */
68
67
  public static IObservableList observeList(EObject eObject, EStructuralFeature eStructuralFeature)
69
	/**
68
  {
70
	 * Returns an observable list for the given multi-valued feature of the
69
    return new EObjectObservableList(eObject, eStructuralFeature);
71
	 * object.
70
  }
72
	 * 
71
73
	 * @param eObject
72
  /**
74
	 *            the object to observe.
73
   * Returns an observable list for the given multi-valued feature of the object.
75
	 * @param eStructuralFeature
74
   * @param realm the realm in which to observe.
76
	 *            the feature of the object to observe.
75
   * @param eObject the object to observe.
77
	 * @return an observable list for the given multi-valued feature of the
76
   * @param eStructuralFeature the feature of the object to observe.
78
	 *         object.
77
   * @return an observable list for the given multi-valued feature of the object.
79
	 */
78
   */
80
	public static IObservableList observeList(EObject eObject,
79
  public static IObservableList observeList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
81
			EStructuralFeature eStructuralFeature) {
80
  {
82
		return new EObjectObservableList(eObject, eStructuralFeature);
81
    return new EObjectObservableList(realm, eObject, eStructuralFeature);
83
	}
82
  }
84
83
85
	/**
84
  /**
86
	 * Returns an observable list for the given multi-valued feature of the
85
   * Returns an observable map in the default realm 
87
	 * object.
86
   * tracking the current value of the given feature for each object in the given set.
88
	 * 
87
   * @param objects the objects to track.
89
	 * @param realm
88
   * @param eStructuralFeature the feature for which to track the value.
90
	 *            the realm in which to observe.
89
   * @return an observable map tracking the current value of the given feature for each object in the given set.
91
	 * @param eObject
90
   */
92
	 *            the object to observe.
91
  public static IObservableMap observeMap(IObservableSet objects, EStructuralFeature eStructuralFeature)
93
	 * @param eStructuralFeature
92
  {
94
	 *            the feature of the object to observe.
93
    return new EObjectObservableMap(objects, eStructuralFeature);
95
	 * @return an observable list for the given multi-valued feature of the
94
  }
96
	 *         object.
95
97
	 */
96
  /**
98
	public static IObservableList observeList(Realm realm, EObject eObject,
97
   * Returns an array of observable maps in the default realm 
99
			EStructuralFeature eStructuralFeature) {
98
   * tracking the current value of the given features for each object in the given set.
100
		return new EObjectObservableList(realm, eObject, eStructuralFeature);
99
   * @param objects the objects to track.
101
	}
100
   * @param eStructuralFeatures the features for which to track the value.
102
101
   * @return an array of observable maps tracking the current value of the given features for each object in the given set.
103
	/**
102
   */
104
	 * Returns an observable map in the default realm tracking the current value
103
  public static IObservableMap[] observeMaps(IObservableSet objects, EStructuralFeature[] eStructuralFeatures)
105
	 * of the given feature for each object in the given set.
104
  {
106
	 * 
105
    IObservableMap[] result = new IObservableMap [eStructuralFeatures.length];
107
	 * @param objects
106
    for (int i = 0; i < eStructuralFeatures.length; i++)
108
	 *            the objects to track.
107
    {
109
	 * @param eStructuralFeature
108
      result[i] = observeMap(objects, eStructuralFeatures[i]);
110
	 *            the feature for which to track the value.
109
    }
111
	 * @return an observable map tracking the current value of the given feature
110
    return result;
112
	 *         for each object in the given set.
111
  }
113
	 */
112
114
	public static IObservableMap observeMap(IObservableSet objects,
113
  /**
115
			EStructuralFeature eStructuralFeature) {
114
   * Returns an observable value that tracks the current value of the feature of the current value of the master observable value.
116
		return new EObjectObservableMap(objects, eStructuralFeature);
115
   * @param realm the realm in which to observe.
117
	}
116
   * @param value the master observable value.
118
117
   * @param eStructuralFeature the feature for which to track the value.
119
	/**
118
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
120
	 * Returns an array of observable maps in the default realm tracking the
119
   * @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object)
121
	 * current value of the given features for each object in the given set.
120
   */
122
	 * 
121
  public static IObservableValue observeDetailValue(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
123
	 * @param objects
122
  {
124
	 *            the objects to track.
123
    return MasterDetailObservables.detailValue(value, valueFactory(realm, eStructuralFeature), eStructuralFeature);
125
	 * @param eStructuralFeatures
124
  }
126
	 *            the features for which to track the value.
125
127
	 * @return an array of observable maps tracking the current value of the
126
  /**
128
	 *         given features for each object in the given set.
127
   * Returns a factory for creating observable values
129
	 */
128
   * tracking the value of the given feature of a particular {@link EObject object}.
130
	public static IObservableMap[] observeMaps(IObservableSet objects,
129
   * @param realm the realm in which to observe.
131
			EStructuralFeature[] eStructuralFeatures) {
130
   * @param eStructuralFeature the feature for which to track the value.
132
		IObservableMap[] result = new IObservableMap[eStructuralFeatures.length];
131
   * @return an observable factory.
133
		for (int i = 0; i < eStructuralFeatures.length; i++) {
132
   */
134
			result[i] = observeMap(objects, eStructuralFeatures[i]);
133
  public static IObservableFactory valueFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
135
		}
134
  {
136
		return result;
135
    return 
137
	}
136
      new IObservableFactory()
138
137
      {
139
	/**
138
        public IObservable createObservable(Object target)
140
	 * Returns an observable value that tracks the current value of the feature
139
        {
141
	 * of the current value of the master observable value.
140
          return observeValue(realm, (EObject)target, eStructuralFeature);
142
	 * 
141
        }
143
	 * @param realm
142
      };
144
	 *            the realm in which to observe.
143
  }
145
	 * @param value
144
146
	 *            the master observable value.
145
  /**
147
	 * @param eStructuralFeature
146
   * Returns an observable list that tracks the current value of the feature of the current value of the master observable value.
148
	 *            the feature for which to track the value.
147
   * @param realm the realm in which to observe.
149
	 * @return an observable value that tracks the current value of the named
148
   * @param value the master observable value.
150
	 *         property for the current value of the master observable value
149
   * @param eStructuralFeature the feature for which to track the value.
151
	 * @see MasterDetailObservables#detailValue(IObservableValue,
150
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
152
	 *      IObservableFactory, Object)
151
   * @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object)
153
	 */
152
   */
154
	public static IObservableValue observeDetailValue(Realm realm,
153
  public static IObservableList observeDetailList(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
155
			IObservableValue value, EStructuralFeature eStructuralFeature) {
154
  {
156
		return MasterDetailObservables.detailValue(value, valueFactory(realm,
155
    return MasterDetailObservables.detailList(value, listFactory(realm, eStructuralFeature), eStructuralFeature);
157
				eStructuralFeature), eStructuralFeature);
156
  }
158
	}
157
159
158
  /**
160
	/**
159
   * Returns a factory for creating observable lists
161
	 * Returns a factory for creating observable values tracking the value of
160
   * tracking the value of the given feature of a particular {@link EObject object}.
162
	 * the given feature of a particular {@link EObject object}.
161
   * @param realm the realm in which to observe.
163
	 * 
162
   * @param eStructuralFeature the feature for which to track the value.
164
	 * @param realm
163
   * @return an observable factory.
165
	 *            the realm in which to observe.
164
   */
166
	 * @param eStructuralFeature
165
  public static IObservableFactory listFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
167
	 *            the feature for which to track the value.
166
  {
168
	 * @return an observable factory.
167
    return 
169
	 */
168
      new IObservableFactory()
170
	public static IObservableFactory valueFactory(final Realm realm,
169
      {
171
			final EStructuralFeature eStructuralFeature) {
170
        public IObservable createObservable(Object target)
172
		return new IObservableFactory() {
171
        {
173
			public IObservable createObservable(Object target) {
172
          return observeList(realm, (EObject)target, eStructuralFeature);
174
				return observeValue(realm, (EObject) target, eStructuralFeature);
173
        }
175
			}
174
      };
176
		};
175
  }
177
	}
176
  
178
177
  /**
179
	/**
178
   * Returns a factory for creating observable maps
180
	 * Returns an observable list that tracks the current value of the feature
179
   * tracking the value of the given feature of a particular {@link EObject object}.
181
	 * of the current value of the master observable value.
180
   * @param eStructuralFeature the feature for which to track the value.
182
	 * 
181
   * @return an observable factory.
183
	 * @param realm
182
   */
184
	 *            the realm in which to observe.
183
  public static IObservableFactory mapFactory(final EStructuralFeature eStructuralFeature)
185
	 * @param value
184
  {
186
	 *            the master observable value.
185
    return
187
	 * @param eStructuralFeature
186
      new IObservableFactory()
188
	 *            the feature for which to track the value.
187
      {
189
	 * @return an observable value that tracks the current value of the named
188
        public IObservable createObservable(Object target)
190
	 *         property for the current value of the master observable value
189
        {
191
	 * @see MasterDetailObservables#detailList(IObservableValue,
190
          return observeMap((IObservableSet)target, eStructuralFeature);
192
	 *      IObservableFactory, Object)
191
        }
193
	 */
192
      };
194
	public static IObservableList observeDetailList(Realm realm,
193
   }
195
			IObservableValue value, EStructuralFeature eStructuralFeature) {
196
		return MasterDetailObservables.detailList(value, listFactory(realm,
197
				eStructuralFeature), eStructuralFeature);
198
	}
199
200
	/**
201
	 * Returns a factory for creating observable lists tracking the value of the
202
	 * given feature of a particular {@link EObject object}.
203
	 * 
204
	 * @param realm
205
	 *            the realm in which to observe.
206
	 * @param eStructuralFeature
207
	 *            the feature for which to track the value.
208
	 * @return an observable factory.
209
	 */
210
	public static IObservableFactory listFactory(final Realm realm,
211
			final EStructuralFeature eStructuralFeature) {
212
		return new IObservableFactory() {
213
			public IObservable createObservable(Object target) {
214
				return observeList(realm, (EObject) target, eStructuralFeature);
215
			}
216
		};
217
	}
218
219
	/**
220
	 * Returns a factory for creating observable maps tracking the value of the
221
	 * given feature of a particular {@link EObject object}.
222
	 * 
223
	 * @param eStructuralFeature
224
	 *            the feature for which to track the value.
225
	 * @return an observable factory.
226
	 */
227
	public static IObservableFactory mapFactory(
228
			final EStructuralFeature eStructuralFeature) {
229
		return new IObservableFactory() {
230
			public IObservable createObservable(Object target) {
231
				return observeMap((IObservableSet) target, eStructuralFeature);
232
			}
233
		};
234
	}
235
236
	/**
237
	 * Returns an observable for the resource contents (
238
	 * {@link Resource#getContents()})
239
	 * 
240
	 * @param resource
241
	 *            the resources the content should be observed
242
	 * @return an observable list
243
	 */
244
	public static IObservableList observeResourceContents(Resource resource) {
245
		return new EWritableList<EObject>((NotifyingList<EObject>) resource.getContents());
246
	}
194
}
247
}
(-)src/org/eclipse/emf/databinding/internal/EMFPropertyHelper.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Martin Frey <martin.frey@logica.com> - bug 256150
11
 *     Matthew Hall - bug 264307
12
 ******************************************************************************/
13
14
package org.eclipse.emf.databinding.internal;
15
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
18
/**
19
 * @since 1.2
20
 * 
21
 */
22
public class EMFPropertyHelper {
23
24
	/**
25
	 * Returns the element type of the given collection-typed property for the
26
	 * given bean.
27
	 * 
28
	 * @param descriptor
29
	 *            the property being inspected
30
	 * @return the element type of the given collection-typed property if it is
31
	 *         an array property, or Object.class otherwise.
32
	 */
33
	public static Class<?> getCollectionPropertyElementType(
34
			EStructuralFeature eStructuralFeature) {
35
		return Object.class;
36
	}
37
38
39
	/**
40
	 * @param propertyDescriptor
41
	 * @return String description of property descriptor
42
	 */
43
	public static String propertyName(EStructuralFeature eStructuralFeature) {
44
		return eStructuralFeature.getEContainingClass().getName()
45
				+ "." + eStructuralFeature.getName() + ""; //$NON-NLS-1$ //$NON-NLS-2$
46
	}
47
48
	/**
49
	 * @param beanClass
50
	 * @return class name excluding package
51
	 */
52
	public static String shortClassName(EStructuralFeature eStructuralFeature) {
53
		return eStructuralFeature.getEType().getName();
54
	}
55
	
56
	/**
57
	 * @param beanClass
58
	 * @return class name excluding package
59
	 */
60
	public static String shortClassName(Class<?> beanClass) {
61
		if (beanClass == null)
62
			return "?"; //$NON-NLS-1$
63
		String className = beanClass.getName();
64
		int lastDot = className.lastIndexOf('.');
65
		if (lastDot != -1)
66
			className = className.substring(lastDot + 1);
67
		return className;
68
	}
69
}
(-)src/org/eclipse/emf/databinding/internal/EWritableList.java (+354 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2007 BestSolution.at and others.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 * Tom Schindl<tom.schindl@bestsolution.at> - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Id: $
16
 */
17
package org.eclipse.emf.databinding.internal;
18
19
import java.util.Collection;
20
import java.util.Iterator;
21
import java.util.List;
22
import java.util.ListIterator;
23
24
import org.eclipse.core.databinding.observable.Diffs;
25
import org.eclipse.core.databinding.observable.ObservableTracker;
26
import org.eclipse.core.databinding.observable.Realm;
27
import org.eclipse.core.databinding.observable.list.AbstractObservableList;
28
import org.eclipse.core.databinding.observable.list.IObservableList;
29
import org.eclipse.core.databinding.observable.list.ListDiff;
30
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
31
import org.eclipse.emf.common.notify.Adapter;
32
import org.eclipse.emf.common.notify.Notification;
33
import org.eclipse.emf.common.notify.Notifier;
34
import org.eclipse.emf.common.notify.NotifyingList;
35
import org.eclipse.emf.common.notify.impl.AdapterImpl;
36
import org.eclipse.emf.ecore.resource.Resource;
37
38
/**
39
 * Writable list which can be used to observe an {@link NotifyingList}
40
 * 
41
 * @param <Type>
42
 */
43
public class EWritableList<Type> extends AbstractObservableList implements
44
		IObservableList {
45
	private NotifyingList<Type> wrappedList;
46
	private Object elementType;
47
	private boolean stale = false;
48
49
	private class Listener extends AdapterImpl {
50
		private Object feature;
51
52
		public Listener(Object feature) {
53
			this.feature = feature;
54
		}
55
56
		@Override
57
		public void notifyChanged(Notification msg) {
58
59
			if (feature == null
60
					&& msg.getFeature() == null
61
					&& msg.getFeatureID(Resource.class) != Resource.RESOURCE__CONTENTS) {
62
				return;
63
			}
64
65
			if (feature == msg.getFeature() && !msg.isTouch()) {
66
				final ListDiff diff;
67
				switch (msg.getEventType()) {
68
				case Notification.ADD: {
69
					diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg
70
							.getPosition(), true, msg.getNewValue()));
71
					// fireListChange(diff);
72
					break;
73
				}
74
				case Notification.ADD_MANY: {
75
					Collection<?> newValues = (Collection<?>) msg.getNewValue();
76
					ListDiffEntry[] listDiffEntries = new ListDiffEntry[newValues
77
							.size()];
78
					int position = msg.getPosition();
79
					int index = 0;
80
					for (Object newValue : newValues) {
81
						listDiffEntries[index++] = Diffs.createListDiffEntry(
82
								position++, true, newValue);
83
					}
84
					diff = Diffs.createListDiff(listDiffEntries);
85
					// fireListChange(diff);
86
					break;
87
				}
88
				case Notification.REMOVE: {
89
					diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg
90
							.getPosition(), false, msg.getOldValue()));
91
					// fireListChange(diff);
92
					break;
93
				}
94
				case Notification.REMOVE_MANY: {
95
					Collection<?> oldValues = (Collection<?>) msg.getOldValue();
96
					ListDiffEntry[] listDiffEntries = new ListDiffEntry[oldValues
97
							.size()];
98
					int position = msg.getPosition();
99
					int index = 0;
100
					for (Object oldValue : oldValues) {
101
						listDiffEntries[index++] = Diffs.createListDiffEntry(
102
								position++, false, oldValue);
103
					}
104
					diff = Diffs.createListDiff(listDiffEntries);
105
					// fireListChange(diff);
106
					break;
107
				}
108
				case Notification.MOVE: {
109
					Object movedValue = msg.getNewValue();
110
					ListDiffEntry[] listDiffEntries = new ListDiffEntry[2];
111
					listDiffEntries[0] = Diffs.createListDiffEntry(
112
							(Integer) msg.getOldValue(), false, movedValue);
113
					listDiffEntries[1] = Diffs.createListDiffEntry(msg
114
							.getPosition(), true, movedValue);
115
					diff = Diffs.createListDiff(listDiffEntries);
116
					// fireListChange(diff);
117
					break;
118
				}
119
				case Notification.UNSET: {
120
					// This just represents going back to the unset state, but
121
					// that doesn't affect the contents of the list.
122
					//
123
					return;
124
				}
125
				default: {
126
					throw new RuntimeException("unhandled case");
127
				}
128
				}
129
130
				getRealm().exec(new Runnable() {
131
					public void run() {
132
						fireListChange(diff);
133
					}
134
				});
135
136
				// System.err.println("CHANGE: " +
137
				// diff.getDifferences()[0].getElement());
138
139
				// fireListChange(diff);
140
				// listener.handlePropertyChange(new SimplePropertyEvent(msg
141
				// .getNotifier(), EMFListProperty.this, diff));
142
			}
143
		}
144
145
	}
146
147
	private Adapter listener;
148
149
	/**
150
	 * New writable list wrapping the {@link NotifyingList}
151
	 * 
152
	 * @param wrappedList
153
	 *            the wrapped list
154
	 */
155
	public EWritableList(NotifyingList<Type> wrappedList) {
156
		this(Realm.getDefault(), wrappedList);
157
	}
158
159
	/**
160
	 * New writable list wrapping the {@link NotifyingList} and using the
161
	 * {@link Realm}
162
	 * 
163
	 * @param realm
164
	 *            the realm
165
	 * @param wrappedList
166
	 *            the wrapped list
167
	 */
168
	public EWritableList(Realm realm, NotifyingList<Type> wrappedList) {
169
		this(realm, wrappedList, null);
170
	}
171
172
	/**
173
	 * New writable list wrapping the {@link NotifyingList}
174
	 * 
175
	 * @param realm
176
	 *            the realm
177
	 * @param wrappedList
178
	 *            the wrapped list
179
	 * @param elementType
180
	 *            the element type
181
	 */
182
	public EWritableList(Realm realm, NotifyingList<Type> wrappedList,
183
			Class<Type> elementType) {
184
		super(realm);
185
		this.wrappedList = wrappedList;
186
		this.elementType = elementType;
187
		if (wrappedList.getNotifier() instanceof Notifier) {
188
			Notifier notifier = (Notifier) wrappedList.getNotifier();
189
			listener = new Listener(wrappedList.getFeature());
190
			notifier.eAdapters().add(listener);
191
		} else {
192
			throw new IllegalArgumentException(
193
					"Wrapped list must have a notifier attached!");
194
		}
195
	}
196
197
	@Override
198
	public synchronized void dispose() {
199
		((Notifier) wrappedList.getNotifier()).eAdapters().remove(listener);
200
		super.dispose();
201
	}
202
203
	private void getterCalled() {
204
		ObservableTracker.getterCalled(this);
205
	}
206
207
	@SuppressWarnings("unchecked")
208
	public boolean add(Object o) {
209
		checkRealm();
210
		return wrappedList.add((Type) o);
211
	}
212
213
	@SuppressWarnings("unchecked")
214
	public boolean addAll(Collection c) {
215
		checkRealm();
216
		return wrappedList.addAll(c);
217
	}
218
219
	@SuppressWarnings("unchecked")
220
	public boolean addAll(int index, Collection c) {
221
		checkRealm();
222
		return wrappedList.addAll(index, c);
223
	}
224
225
	public boolean contains(Object o) {
226
		getterCalled();
227
		return wrappedList.contains(o);
228
	}
229
230
	@SuppressWarnings("unchecked")
231
	public boolean containsAll(Collection c) {
232
		getterCalled();
233
		return wrappedList.containsAll(c);
234
	}
235
236
	public Object get(int index) {
237
		getterCalled();
238
		return wrappedList.get(index);
239
	}
240
241
	public Object getElementType() {
242
		checkRealm();
243
		return elementType;
244
	}
245
246
	public int indexOf(Object o) {
247
		getterCalled();
248
		return wrappedList.indexOf(o);
249
	}
250
251
	public boolean isEmpty() {
252
		getterCalled();
253
		return wrappedList.isEmpty();
254
	}
255
256
	public Iterator<Type> iterator() {
257
		getterCalled();
258
		return wrappedList.iterator();
259
	}
260
261
	public int lastIndexOf(Object o) {
262
		getterCalled();
263
		return wrappedList.lastIndexOf(o);
264
	}
265
266
	public ListIterator<Type> listIterator() {
267
		getterCalled();
268
		return wrappedList.listIterator();
269
	}
270
271
	public ListIterator<Type> listIterator(int index) {
272
		getterCalled();
273
		return wrappedList.listIterator(index);
274
	}
275
276
	public Object move(int oldIndex, int newIndex) {
277
		checkRealm();
278
		return wrappedList.move(oldIndex, newIndex);
279
	}
280
281
	public boolean remove(Object o) {
282
		checkRealm();
283
		return wrappedList.remove(o);
284
	}
285
286
	public Object remove(int index) {
287
		checkRealm();
288
		return wrappedList.remove(index);
289
	}
290
291
	@SuppressWarnings("unchecked")
292
	public boolean removeAll(Collection c) {
293
		checkRealm();
294
		return wrappedList.removeAll(c);
295
	}
296
297
	@SuppressWarnings("unchecked")
298
	public boolean retainAll(Collection c) {
299
		checkRealm();
300
		return wrappedList.retainAll(c);
301
	}
302
303
	@SuppressWarnings("unchecked")
304
	public Object set(int index, Object element) {
305
		checkRealm();
306
		return wrappedList.set(index, (Type) element);
307
	}
308
309
	public int doGetSize() {
310
		getterCalled();
311
		return wrappedList.size();
312
	}
313
314
	public List<Type> subList(int fromIndex, int toIndex) {
315
		getterCalled();
316
		return wrappedList.subList(fromIndex, toIndex);
317
	}
318
319
	public Object[] toArray() {
320
		getterCalled();
321
		return wrappedList.toArray();
322
	}
323
324
	public Object[] toArray(Object[] a) {
325
		getterCalled();
326
		return wrappedList.toArray();
327
	}
328
329
	@SuppressWarnings("unchecked")
330
	public void add(int index, Object element) {
331
		checkRealm();
332
		wrappedList.add(index, (Type) element);
333
	}
334
335
	public void clear() {
336
		checkRealm();
337
		wrappedList.clear();
338
	}
339
340
	public boolean isStale() {
341
		getterCalled();
342
		return stale;
343
	}
344
345
	// public void setStale(boolean stale) {
346
	// checkRealm();
347
	//
348
	// boolean wasStale = this.stale;
349
	// this.stale = stale;
350
	// if (!wasStale && stale) {
351
	// fireStale();
352
	// }
353
	// }
354
}
(-)src/org/eclipse/emf/databinding/IEMFListValueProperty.java (+192 lines)
Added Link Here
1
package org.eclipse.emf.databinding;
2
3
import org.eclipse.core.databinding.property.value.IValueProperty;
4
import org.eclipse.emf.ecore.EStructuralFeature;
5
6
public interface IEMFListValueProperty extends IEMFProperty, IValueProperty {
7
	public interface Condition {
8
		public boolean match(int index, Object object);
9
	}
10
	
11
	/**
12
	 * Returns a master-detail combination of this property and the specified
13
	 * value property.
14
	 * 
15
	 * @param propertyName
16
	 *            the value property to observe. May be nested e.g.
17
	 *            "parent.name"
18
	 * @return a master-detail combination of this property and the specified
19
	 *         value property.
20
	 * @see #value(IEMFValueProperty)
21
	 */
22
	public IEMFValueProperty value(FeaturePath featurePath);
23
24
	public IEMFValueProperty value(EStructuralFeature feature);
25
	
26
	/**
27
	 * Returns a master-detail combination of this property and the specified
28
	 * value property. The returned property will observe the specified detail
29
	 * value property for the value of the master value property.
30
	 * <p>
31
	 * Example:
32
	 * 
33
	 * <pre>
34
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object
35
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
36
	 * // Observes the string-typed &quot;name&quot; property of a Node object
37
	 * IBeanValueProperty name = BeanProperties.value(Node.class, &quot;name&quot;);
38
	 * // Observes the name of the parent of a Node object.
39
	 * IBeanValueProperty parentName = parent.value(name);
40
	 * </pre>
41
	 * 
42
	 * @param property
43
	 *            the detail property to observe
44
	 * @return a master-detail combination of this property and the specified
45
	 *         value property.
46
	 */
47
	public IEMFValueProperty value(IEMFValueProperty property);
48
49
	/**
50
	 * Returns a master-detail combination of this property and the specified
51
	 * list property.
52
	 * 
53
	 * @param propertyName
54
	 *            the list property to observe
55
	 * @return a master-detail combination of this property and the specified
56
	 *         list property.
57
	 * @see #list(IEMFListProperty)
58
	 */
59
	public IEMFListProperty list(EStructuralFeature feature);
60
61
	/**
62
	 * Returns a master-detail combination of this property and the specified
63
	 * list property. The returned property will observe the specified list
64
	 * property for the value of the master property.
65
	 * <p>
66
	 * Example:
67
	 * 
68
	 * <pre>
69
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object.
70
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
71
	 * // Observes the List-typed &quot;children&quot; property of a Node object
72
	 * // where the elements are Node objects
73
	 * IBeanListProperty children = BeanProperties.list(Node.class, &quot;children&quot;,
74
	 * 		Node.class);
75
	 * // Observes the children of the parent (siblings) of a Node object.
76
	 * IBeanListProperty siblings = parent.list(children);
77
	 * </pre>
78
	 * 
79
	 * @param property
80
	 *            the detail property to observe
81
	 * @return a master-detail combination of this property and the specified
82
	 *         list property.
83
	 */
84
	public IEMFListProperty list(IEMFListProperty property);
85
86
	/**
87
	 * Returns a master-detail combination of this property and the specified
88
	 * set property.
89
	 * 
90
	 * @param propertyName
91
	 *            the set property to observe
92
	 * @return a master-detail combination of this property and the specified
93
	 *         set property.
94
	 * @see #set(IEMFSetProperty)
95
	 */
96
	public IEMFSetProperty set(EStructuralFeature feature);
97
98
	/**
99
	 * Returns a master-detail combination of this property and the specified
100
	 * set property.
101
	 * 
102
	 * @param propertyName
103
	 *            the set property to observe
104
	 * @param elementType
105
	 *            the element type of the named property
106
	 * @return a master-detail combination of this property and the specified
107
	 *         set property.
108
	 * @see #set(IEMFSetProperty)
109
	 */
110
	public IEMFSetProperty set(EStructuralFeature feature, Class<?> elementType);
111
112
	/**
113
	 * Returns a master-detail combination of this property and the specified
114
	 * set property. The returned property will observe the specified set
115
	 * property for the value of the master property.
116
	 * <p>
117
	 * Example:
118
	 * 
119
	 * <pre>
120
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object.
121
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
122
	 * // Observes the Set-typed &quot;children&quot; property of a Node object
123
	 * // where the elements are Node objects
124
	 * IBeanSetProperty children = BeanProperties.set(Node.class, &quot;children&quot;,
125
	 * 		Node.class);
126
	 * // Observes the children of the parent (siblings) of a Node object.
127
	 * IBeanSetProperty siblings = parent.set(children);
128
	 * </pre>
129
	 * 
130
	 * @param property
131
	 *            the detail property to observe
132
	 * @return a master-detail combination of this property and the specified
133
	 *         set property.
134
	 */
135
	public IEMFSetProperty set(IEMFSetProperty property);
136
137
	/**
138
	 * Returns a master-detail combination of this property and the specified
139
	 * map property.
140
	 * 
141
	 * @param propertyName
142
	 *            the map property to observe
143
	 * @return a master-detail combination of this property and the specified
144
	 *         map property.
145
	 * @see #map(IEMFMapProperty)
146
	 */
147
	public IEMFMapProperty map(EStructuralFeature feature);
148
149
	/**
150
	 * Returns a master-detail combination of this property and the specified
151
	 * map property.
152
	 * 
153
	 * @param propertyName
154
	 *            the map property to observe
155
	 * @param keyType
156
	 *            the key type of the named property
157
	 * @param valueType
158
	 *            the value type of the named property
159
	 * @return a master-detail combination of this property and the specified
160
	 *         map property.
161
	 * @see #map(IEMFMapProperty)
162
	 */
163
	public IEMFMapProperty map(EStructuralFeature feature, Class<?> keyType,
164
			Class<?> valueType);
165
166
	/**
167
	 * Returns a master-detail combination of this property and the specified
168
	 * map property. The returned property will observe the specified map
169
	 * property for the value of the master property.
170
	 * <p>
171
	 * Example:
172
	 * 
173
	 * <pre>
174
	 * // Observes the Contact-typed &quot;supervisor&quot; property of a
175
	 * // Contact class 
176
	 * IBeanValueProperty supervisor = BeanProperties.value(Contact.class,
177
	 * 		&quot;supervisor&quot;);
178
	 * // Observes the property &quot;phoneNumbers&quot; of a Contact object--a property mapping
179
	 * // from PhoneNumberType to PhoneNumber &quot;set-typed &quot;children&quot;,
180
	 * IBeanMapProperty phoneNumbers = BeanProperties.map(Contact.class,
181
	 * 		&quot;phoneNumbers&quot;, PhoneNumberType.class, PhoneNumber.class);
182
	 * // Observes the phone numbers of a contact's supervisor:
183
	 * IBeanMapProperty supervisorPhoneNumbers = supervisor.map(phoneNumbers);
184
	 * </pre>
185
	 * 
186
	 * @param property
187
	 *            the detail property to observe
188
	 * @return a master-detail combination of this property and the specified
189
	 *         map property.
190
	 */
191
	public IEMFMapProperty map(IEMFMapProperty property);
192
}
(-)src/org/eclipse/emf/databinding/internal/EMFValuePropertyDecorator.java (+165 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.list.IObservableList;
17
import org.eclipse.core.databinding.observable.map.IObservableMap;
18
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
19
import org.eclipse.core.databinding.observable.set.IObservableSet;
20
import org.eclipse.core.databinding.observable.value.IObservableValue;
21
import org.eclipse.core.databinding.property.value.IValueProperty;
22
import org.eclipse.core.databinding.property.value.ValueProperty;
23
import org.eclipse.emf.databinding.EMFProperties;
24
import org.eclipse.emf.databinding.FeaturePath;
25
import org.eclipse.emf.databinding.IEMFListProperty;
26
import org.eclipse.emf.databinding.IEMFListValueProperty;
27
import org.eclipse.emf.databinding.IEMFMapProperty;
28
import org.eclipse.emf.databinding.IEMFSetProperty;
29
import org.eclipse.emf.databinding.IEMFValueProperty;
30
import org.eclipse.emf.databinding.IEMFListValueProperty.Condition;
31
import org.eclipse.emf.ecore.EStructuralFeature;
32
33
/**
34
 * @since 3.3
35
 * 
36
 */
37
public class EMFValuePropertyDecorator extends ValueProperty implements
38
		IEMFValueProperty {
39
	private final IValueProperty delegate;
40
	private final EStructuralFeature eStructuralFeature;
41
42
	/**
43
	 * @param delegate
44
	 * @param propertyDescriptor
45
	 */
46
	public EMFValuePropertyDecorator(IValueProperty delegate,
47
			EStructuralFeature eStructuralFeature) {
48
		this.delegate = delegate;
49
		this.eStructuralFeature = eStructuralFeature;
50
	}
51
52
	public EStructuralFeature getStructuralFeature() {
53
		return eStructuralFeature;
54
	}
55
56
	public Object getValueType() {
57
		return delegate.getValueType();
58
	}
59
60
	public IEMFValueProperty value(EStructuralFeature feature) {
61
		return value(FeaturePath.fromList(feature));
62
	}
63
	
64
	public IEMFValueProperty value(FeaturePath featurePath) {
65
		return value(EMFProperties.value(featurePath));
66
	}
67
	
68
	public IEMFValueProperty value(IEMFValueProperty property) {
69
		return new EMFValuePropertyDecorator(super.value(property), property
70
				.getStructuralFeature());
71
	}
72
	
73
	public IEMFListValueProperty listValue(EStructuralFeature feature, Condition condition) {
74
		return listValue(FeaturePath.fromList(feature),condition);
75
	}
76
	
77
	public IEMFListValueProperty listValue(FeaturePath featurePath, Condition condition) {
78
//		return listValue(EMFProperties.listValue(featurePath,condition));
79
		return null;
80
	}
81
	
82
//	public IEMFValueProperty listValue(IEMFListValueProperty property) {
83
//		return new EMFListValuePropertyDecorator(super.value(property), property
84
//				.getStructuralFeature());
85
//	}
86
87
	public IEMFListProperty list(EStructuralFeature feature) {
88
		return list(EMFProperties.list(feature));
89
	}
90
91
	public IEMFListProperty list(IEMFListProperty property) {
92
		return new EMFListPropertyDecorator(super.list(property), property
93
				.getStructuralFeature());
94
	}
95
96
	public IEMFSetProperty set(EStructuralFeature feature) {
97
		return set(feature, null);
98
	}
99
100
	public IEMFSetProperty set(EStructuralFeature feature, Class<?> elementType) {
101
		return set(EMFProperties.set(feature, elementType));
102
	}
103
104
	public IEMFSetProperty set(IEMFSetProperty property) {
105
		return new EMFSetPropertyDecorator(super.set(property), property
106
				.getStructuralFeature());
107
	}
108
109
	public IEMFMapProperty map(EStructuralFeature feature) {
110
		return map(feature, null, null);
111
	}
112
113
	public IEMFMapProperty map(EStructuralFeature feature, Class<?> keyType,
114
			Class<?> valueType) {
115
		return map(EMFProperties.map(feature, keyType,
116
				valueType));
117
	}
118
119
	public IEMFMapProperty map(IEMFMapProperty property) {
120
		return new EMFMapPropertyDecorator(super.map(property), property
121
				.getStructuralFeature());
122
	}
123
124
	public IObservableValue observe(Object source) {
125
		return new EMFObservableValueDecorator(delegate.observe(source),
126
				eStructuralFeature);
127
	}
128
129
	public IObservableValue observe(Realm realm, Object source) {
130
		return new EMFObservableValueDecorator(delegate.observe(realm, source),
131
				eStructuralFeature);
132
	}
133
134
	public IObservableFactory valueFactory() {
135
		return delegate.valueFactory();
136
	}
137
138
	public IObservableFactory valueFactory(Realm realm) {
139
		return delegate.valueFactory(realm);
140
	}
141
142
	public IObservableValue observeDetail(IObservableValue master) {
143
		return new EMFObservableValueDecorator(delegate.observeDetail(master),
144
				eStructuralFeature);
145
	}
146
147
	public IObservableList observeDetail(IObservableList master) {
148
		return new EMFObservableListDecorator(delegate.observeDetail(master),
149
				eStructuralFeature);
150
	}
151
152
	public IObservableMap observeDetail(IObservableSet master) {
153
		return new EMFObservableMapDecorator(delegate.observeDetail(master),
154
				eStructuralFeature);
155
	}
156
157
	public IObservableMap observeDetail(IObservableMap master) {
158
		return new EMFObservableMapDecorator(delegate.observeDetail(master),
159
				eStructuralFeature);
160
	}
161
162
	public String toString() {
163
		return delegate.toString();
164
	}
165
}
(-)src/org/eclipse/emf/databinding/internal/EMFObservableMapDecorator.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 221704)
10
 *     Matthew Hall - bug 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObserving;
17
import org.eclipse.core.databinding.observable.map.DecoratingObservableMap;
18
import org.eclipse.core.databinding.observable.map.IObservableMap;
19
import org.eclipse.emf.databinding.IEMFObservable;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
22
/**
23
 * {@link IEMFObservable} decorator for an {@link IObservableMap}.
24
 * 
25
 * @since 3.3
26
 */
27
public class EMFObservableMapDecorator extends DecoratingObservableMap
28
		implements IEMFObservable {
29
	private EStructuralFeature eStructuralFeature;
30
31
	/**
32
	 * @param decorated
33
	 * @param propertyDescriptor
34
	 */
35
	public EMFObservableMapDecorator(IObservableMap decorated,
36
			EStructuralFeature eStructuralFeature) {
37
		super(decorated, true);
38
		this.eStructuralFeature = eStructuralFeature;
39
	}
40
41
	public synchronized void dispose() {
42
		this.eStructuralFeature = null;
43
		super.dispose();
44
	}
45
46
	public Object getObserved() {
47
		IObservable decorated = getDecorated();
48
		if (decorated instanceof IObserving)
49
			return ((IObserving) decorated).getObserved();
50
		return null;
51
	}
52
53
	public EStructuralFeature getStructuralFeature() {
54
		return eStructuralFeature;
55
	}
56
}
(-)src/org/eclipse/emf/databinding/internal/EMFListProperty.java (+86 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bugs 195222, 264307, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import java.util.List;
16
17
import org.eclipse.core.databinding.observable.list.ListDiff;
18
import org.eclipse.core.databinding.property.INativePropertyListener;
19
import org.eclipse.core.databinding.property.IProperty;
20
import org.eclipse.core.databinding.property.ISimplePropertyListener;
21
import org.eclipse.core.databinding.property.list.SimpleListProperty;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.ecore.EStructuralFeature;
24
25
/**
26
 * @since 3.3
27
 * 
28
 */
29
public class EMFListProperty extends SimpleListProperty {
30
	private EStructuralFeature eStructuralFeature;
31
32
	/**
33
	 * @param propertyDescriptor
34
	 * @param elementType
35
	 */
36
	public EMFListProperty(EStructuralFeature eStructuralFeature) {
37
		this.eStructuralFeature = eStructuralFeature;
38
	}
39
	
40
	protected EStructuralFeature getFeature() {
41
		return eStructuralFeature;
42
	}
43
44
	public Object getElementType() {
45
		return eStructuralFeature;
46
	}
47
48
	protected List<?> doGetList(Object source) {
49
		EObject eObj = (EObject) source;
50
		return (List<?>) eObj.eGet(eStructuralFeature);
51
	}
52
53
	@SuppressWarnings("unchecked")
54
	protected void doSetList(Object source, List list, ListDiff diff) {
55
		List<?> currentList = doGetList(source);
56
		diff.applyTo(currentList);
57
	}
58
59
	public INativePropertyListener adaptListener(
60
			final ISimplePropertyListener listener) {
61
		return new EMFPropertyListener.EMFListPropertyListener() {
62
63
			@Override
64
			protected EStructuralFeature getFeature() {
65
				return eStructuralFeature;
66
			}
67
68
			@Override
69
			protected ISimplePropertyListener getListener() {
70
				return listener;
71
			}
72
73
			@Override
74
			protected IProperty getOwner() {
75
				return EMFListProperty.this;
76
			}
77
		};
78
	}
79
80
	public String toString() {
81
		String s = EMFPropertyHelper.propertyName(eStructuralFeature) + "[]"; //$NON-NLS-1$
82
		s += "<" + EMFPropertyHelper.shortClassName(eStructuralFeature) + ">"; //$NON-NLS-1$//$NON-NLS-2$
83
		return s;
84
	}
85
86
}
(-)src/org/eclipse/emf/databinding/internal/EMFPropertyListenerSupport.java (+51 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Matthew Hall - bug 118516
11
 *******************************************************************************/
12
package org.eclipse.emf.databinding.internal;
13
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.emf.common.notify.Adapter;
16
import org.eclipse.emf.ecore.EObject;
17
18
/**
19
 * This is a helper that will hook up and listen for
20
 * <code>PropertyChangeEvent</code> events for a set of target JavaBeans
21
 * 
22
 * @since 1.0
23
 */
24
public class EMFPropertyListenerSupport {
25
	/**
26
	 * Start listen to target (if it supports the JavaBean property change
27
	 * listener pattern)
28
	 * 
29
	 * @param bean
30
	 * @param propertyName
31
	 * @param listener
32
	 */
33
	public static void hookListener(EObject bean, Adapter listener) {
34
		Assert.isNotNull(bean, "Bean cannot be null"); //$NON-NLS-1$
35
		Assert.isNotNull(listener, "Listener cannot be null"); //$NON-NLS-1$
36
		bean.eAdapters().add(listener);
37
	}
38
39
	/**
40
	 * Stop listen to target
41
	 * 
42
	 * @param bean
43
	 * @param propertyName
44
	 * @param listener
45
	 */
46
	public static void unhookListener(EObject bean, Adapter listener) {
47
		Assert.isNotNull(bean, "Bean cannot be null"); //$NON-NLS-1$
48
		Assert.isNotNull(listener, "Listener cannot be null"); //$NON-NLS-1$
49
		bean.eAdapters().remove(listener);
50
	}
51
}
(-)src/org/eclipse/emf/databinding/internal/EMFListValueProperty.java (+147 lines)
Added Link Here
1
package org.eclipse.emf.databinding.internal;
2
3
import java.util.Collection;
4
5
import org.eclipse.core.databinding.observable.Diffs;
6
import org.eclipse.core.databinding.observable.value.ValueDiff;
7
import org.eclipse.core.databinding.property.INativePropertyListener;
8
import org.eclipse.core.databinding.property.IProperty;
9
import org.eclipse.core.databinding.property.ISimplePropertyListener;
10
import org.eclipse.core.databinding.property.SimplePropertyEvent;
11
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
12
import org.eclipse.emf.common.notify.Notification;
13
import org.eclipse.emf.databinding.IEMFListValueProperty.Condition;
14
import org.eclipse.emf.ecore.EStructuralFeature;
15
16
public class EMFListValueProperty extends SimpleValueProperty {
17
	private EStructuralFeature eStructuralFeature;
18
	private Condition condition;
19
20
	public EMFListValueProperty(EStructuralFeature eStructuralFeature,
21
			Condition condition) {
22
		this.eStructuralFeature = eStructuralFeature;
23
		this.condition = condition;
24
	}
25
26
	@Override
27
	public INativePropertyListener adaptListener(
28
			final ISimplePropertyListener listener) {
29
		return new EMFPropertyListenerImpl() {
30
31
			@Override
32
			protected ISimplePropertyListener getListener() {
33
				return listener;
34
			}
35
36
			@Override
37
			protected EStructuralFeature getFeature() {
38
				return eStructuralFeature;
39
			}
40
41
			@Override
42
			protected IProperty getOwner() {
43
				return EMFListValueProperty.this;
44
			}
45
46
			protected Condition getCondition() {
47
				return condition;
48
			}
49
		};
50
	}
51
52
	@Override
53
	protected Object doGetValue(Object source) {
54
		// TODO Auto-generated method stub
55
		return null;
56
	}
57
58
	@Override
59
	protected void doSetValue(Object source, Object value) {
60
		// TODO Auto-generated method stub
61
62
	}
63
64
	public Object getValueType() {
65
		return eStructuralFeature;
66
	}
67
68
	private abstract class EMFPropertyListenerImpl extends EMFPropertyListener {
69
70
		@Override
71
		public void notifyChanged(Notification msg) {
72
			if (getFeature() == msg.getFeature() && !msg.isTouch()) {
73
				Condition condition = getCondition();
74
				ValueDiff diff = null;
75
76
				switch (msg.getEventType()) {
77
				case Notification.ADD: {
78
					if (condition.match(msg.getPosition(), msg.getNewValue())) {
79
						diff = Diffs.createValueDiff(null, msg.getNewValue());
80
					}
81
					break;
82
				}
83
				case Notification.ADD_MANY: {
84
					for (Object o : (Collection<?>) msg.getNewValue()) {
85
						if (condition.match(msg.getPosition(), o)) {
86
							diff = Diffs.createValueDiff(null, o);
87
							break;
88
						}
89
					}
90
					break;
91
				}
92
				case Notification.REMOVE: {
93
					if (condition.match(msg.getPosition(), msg.getNewValue())) {
94
						diff = Diffs.createValueDiff(msg.getOldValue(), null);
95
					}
96
					break;
97
				}
98
				case Notification.REMOVE_MANY: {
99
					for (Object o : (Collection<?>) msg.getOldValue()) {
100
						if (condition.match(msg.getPosition(), o)) {
101
							diff = Diffs.createValueDiff(null, o);
102
							break;
103
						}
104
					}
105
					break;
106
				}
107
					// case Notification.SET:
108
					// case Notification.RESOLVE: {
109
					// ListDiffEntry[] listDiffEntries = new ListDiffEntry[2];
110
					// listDiffEntries[0] = Diffs.createListDiffEntry(msg
111
					// .getPosition(), false, msg.getOldValue());
112
					// listDiffEntries[1] = Diffs.createListDiffEntry(msg
113
					// .getPosition(), true, msg.getNewValue());
114
					// diff = Diffs.createListDiff(listDiffEntries);
115
					// break;
116
					// }
117
				case Notification.MOVE: {
118
					if (condition.match(msg.getPosition(), msg.getNewValue())) {
119
						diff = Diffs.createValueDiff(msg.getOldValue(), null);
120
					}
121
					break;
122
				}
123
				case Notification.UNSET: {
124
					// This just represents going back to the unset state, but
125
					// that doesn't affect the contents of the list.
126
					//
127
					return;
128
				}
129
				default: {
130
					throw new RuntimeException("unhandled case");
131
				}
132
				}
133
134
				if (diff != null) {
135
					getListener().handleEvent(
136
							(new SimplePropertyEvent(
137
									SimplePropertyEvent.CHANGE, msg
138
											.getNotifier(), getOwner(), diff)));
139
				}
140
			}
141
142
		}
143
144
		protected abstract Condition getCondition();
145
146
	}
147
}
(-)src/org/eclipse/emf/databinding/IEMFObservable.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Brad Reynolds - bug 147515
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding;
14
15
import org.eclipse.core.databinding.observable.IObserving;
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
18
/**
19
 * Provides access to details of bean observables.
20
 * <p>
21
 * This interface is not meant to be implemented by clients.
22
 * </p>
23
 * 
24
 * @since 3.3
25
 */
26
public interface IEMFObservable extends IObserving {
27
	/**
28
	 * @return property descriptor of the property being observed,
29
	 *         <code>null</code> if the runtime time information was not
30
	 *         provided on construction of the observable
31
	 */
32
	public EStructuralFeature getStructuralFeature();
33
}
(-)src/org/eclipse/emf/databinding/internal/EMFValueProperty.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bug 195222, 264307, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.property.INativePropertyListener;
16
import org.eclipse.core.databinding.property.IProperty;
17
import org.eclipse.core.databinding.property.ISimplePropertyListener;
18
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
import org.eclipse.emf.ecore.util.ExtendedMetaData;
22
23
/**
24
 * @since 3.3
25
 * 
26
 */
27
public class EMFValueProperty extends SimpleValueProperty {
28
	private final EStructuralFeature eStructuralFeature;
29
30
	/**
31
	 * @param propertyDescriptor
32
	 * @param valueType
33
	 */
34
	public EMFValueProperty(EStructuralFeature eStructuralFeature) {
35
		this.eStructuralFeature = eStructuralFeature;
36
	}
37
38
	public Object getValueType() {
39
		return eStructuralFeature;
40
	}
41
	
42
	protected EStructuralFeature getFeature() {
43
		return eStructuralFeature;
44
	}
45
46
	protected Object doGetValue(Object source) {
47
		EObject eObj = (EObject) source;
48
		return ExtendedMetaData.INSTANCE.getAffiliation(eObj.eClass(), eStructuralFeature) == null ?
49
				        null : eObj.eGet(eStructuralFeature);
50
	}
51
52
	protected void doSetValue(Object source, Object value) {
53
		EObject eObject = (EObject) source;
54
		eObject.eSet(eStructuralFeature, value);
55
	}
56
57
	public INativePropertyListener adaptListener(
58
			final ISimplePropertyListener listener) {
59
		return new EMFPropertyListener.EMFValuePropertyListener(){
60
		
61
			@Override
62
			protected IProperty getOwner() {
63
				return EMFValueProperty.this;
64
			}
65
		
66
			@Override
67
			protected ISimplePropertyListener getListener() {
68
				return listener;
69
			}
70
		
71
			@Override
72
			protected EStructuralFeature getFeature() {
73
				return eStructuralFeature;
74
			}
75
		};
76
	}
77
78
	public String toString() {
79
		String s = EMFPropertyHelper.propertyName(eStructuralFeature);
80
		s += "<" + EMFPropertyHelper.shortClassName(eStructuralFeature) + ">"; //$NON-NLS-1$//$NON-NLS-2$
81
		return s;
82
	}
83
}
(-)src/org/eclipse/emf/databinding/IEMFValueProperty.java (+212 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding;
13
14
import org.eclipse.core.databinding.property.value.IValueProperty;
15
import org.eclipse.emf.databinding.IEMFListValueProperty.Condition;
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
18
/**
19
 * An {@link IValueProperty} extension interface with convenience methods for
20
 * creating nested bean properties.
21
 * 
22
 * @since 1.2
23
 * @noextend This interface is not intended to be extended by clients.
24
 * @noimplement This interface is not intended to be implemented by clients.
25
 */
26
public interface IEMFValueProperty extends IEMFProperty, IValueProperty {
27
	/**
28
	 * Returns a master-detail combination of this property and the specified
29
	 * value property.
30
	 * 
31
	 * @param propertyName
32
	 *            the value property to observe. May be nested e.g.
33
	 *            "parent.name"
34
	 * @return a master-detail combination of this property and the specified
35
	 *         value property.
36
	 * @see #value(IEMFValueProperty)
37
	 */
38
	public IEMFValueProperty value(FeaturePath featurePath);
39
40
	public IEMFValueProperty value(EStructuralFeature feature);
41
	
42
	/**
43
	 * Returns a master-detail combination of this property and the specified
44
	 * value property. The returned property will observe the specified detail
45
	 * value property for the value of the master value property.
46
	 * <p>
47
	 * Example:
48
	 * 
49
	 * <pre>
50
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object
51
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
52
	 * // Observes the string-typed &quot;name&quot; property of a Node object
53
	 * IBeanValueProperty name = BeanProperties.value(Node.class, &quot;name&quot;);
54
	 * // Observes the name of the parent of a Node object.
55
	 * IBeanValueProperty parentName = parent.value(name);
56
	 * </pre>
57
	 * 
58
	 * @param property
59
	 *            the detail property to observe
60
	 * @return a master-detail combination of this property and the specified
61
	 *         value property.
62
	 */
63
	public IEMFValueProperty value(IEMFValueProperty property);
64
	
65
	public IEMFListValueProperty listValue(FeaturePath featurePath, Condition condition);
66
67
	public IEMFListValueProperty listValue(EStructuralFeature feature, Condition condition);
68
69
	/**
70
	 * Returns a master-detail combination of this property and the specified
71
	 * list property.
72
	 * 
73
	 * @param propertyName
74
	 *            the list property to observe
75
	 * @return a master-detail combination of this property and the specified
76
	 *         list property.
77
	 * @see #list(IEMFListProperty)
78
	 */
79
	public IEMFListProperty list(EStructuralFeature feature);
80
81
	/**
82
	 * Returns a master-detail combination of this property and the specified
83
	 * list property. The returned property will observe the specified list
84
	 * property for the value of the master property.
85
	 * <p>
86
	 * Example:
87
	 * 
88
	 * <pre>
89
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object.
90
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
91
	 * // Observes the List-typed &quot;children&quot; property of a Node object
92
	 * // where the elements are Node objects
93
	 * IBeanListProperty children = BeanProperties.list(Node.class, &quot;children&quot;,
94
	 * 		Node.class);
95
	 * // Observes the children of the parent (siblings) of a Node object.
96
	 * IBeanListProperty siblings = parent.list(children);
97
	 * </pre>
98
	 * 
99
	 * @param property
100
	 *            the detail property to observe
101
	 * @return a master-detail combination of this property and the specified
102
	 *         list property.
103
	 */
104
	public IEMFListProperty list(IEMFListProperty property);
105
106
	/**
107
	 * Returns a master-detail combination of this property and the specified
108
	 * set property.
109
	 * 
110
	 * @param propertyName
111
	 *            the set property to observe
112
	 * @return a master-detail combination of this property and the specified
113
	 *         set property.
114
	 * @see #set(IEMFSetProperty)
115
	 */
116
	public IEMFSetProperty set(EStructuralFeature feature);
117
118
	/**
119
	 * Returns a master-detail combination of this property and the specified
120
	 * set property.
121
	 * 
122
	 * @param propertyName
123
	 *            the set property to observe
124
	 * @param elementType
125
	 *            the element type of the named property
126
	 * @return a master-detail combination of this property and the specified
127
	 *         set property.
128
	 * @see #set(IEMFSetProperty)
129
	 */
130
	public IEMFSetProperty set(EStructuralFeature feature, Class<?> elementType);
131
132
	/**
133
	 * Returns a master-detail combination of this property and the specified
134
	 * set property. The returned property will observe the specified set
135
	 * property for the value of the master property.
136
	 * <p>
137
	 * Example:
138
	 * 
139
	 * <pre>
140
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object.
141
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
142
	 * // Observes the Set-typed &quot;children&quot; property of a Node object
143
	 * // where the elements are Node objects
144
	 * IBeanSetProperty children = BeanProperties.set(Node.class, &quot;children&quot;,
145
	 * 		Node.class);
146
	 * // Observes the children of the parent (siblings) of a Node object.
147
	 * IBeanSetProperty siblings = parent.set(children);
148
	 * </pre>
149
	 * 
150
	 * @param property
151
	 *            the detail property to observe
152
	 * @return a master-detail combination of this property and the specified
153
	 *         set property.
154
	 */
155
	public IEMFSetProperty set(IEMFSetProperty property);
156
157
	/**
158
	 * Returns a master-detail combination of this property and the specified
159
	 * map property.
160
	 * 
161
	 * @param propertyName
162
	 *            the map property to observe
163
	 * @return a master-detail combination of this property and the specified
164
	 *         map property.
165
	 * @see #map(IEMFMapProperty)
166
	 */
167
	public IEMFMapProperty map(EStructuralFeature feature);
168
169
	/**
170
	 * Returns a master-detail combination of this property and the specified
171
	 * map property.
172
	 * 
173
	 * @param propertyName
174
	 *            the map property to observe
175
	 * @param keyType
176
	 *            the key type of the named property
177
	 * @param valueType
178
	 *            the value type of the named property
179
	 * @return a master-detail combination of this property and the specified
180
	 *         map property.
181
	 * @see #map(IEMFMapProperty)
182
	 */
183
	public IEMFMapProperty map(EStructuralFeature feature, Class<?> keyType,
184
			Class<?> valueType);
185
186
	/**
187
	 * Returns a master-detail combination of this property and the specified
188
	 * map property. The returned property will observe the specified map
189
	 * property for the value of the master property.
190
	 * <p>
191
	 * Example:
192
	 * 
193
	 * <pre>
194
	 * // Observes the Contact-typed &quot;supervisor&quot; property of a
195
	 * // Contact class 
196
	 * IBeanValueProperty supervisor = BeanProperties.value(Contact.class,
197
	 * 		&quot;supervisor&quot;);
198
	 * // Observes the property &quot;phoneNumbers&quot; of a Contact object--a property mapping
199
	 * // from PhoneNumberType to PhoneNumber &quot;set-typed &quot;children&quot;,
200
	 * IBeanMapProperty phoneNumbers = BeanProperties.map(Contact.class,
201
	 * 		&quot;phoneNumbers&quot;, PhoneNumberType.class, PhoneNumber.class);
202
	 * // Observes the phone numbers of a contact's supervisor:
203
	 * IBeanMapProperty supervisorPhoneNumbers = supervisor.map(phoneNumbers);
204
	 * </pre>
205
	 * 
206
	 * @param property
207
	 *            the detail property to observe
208
	 * @return a master-detail combination of this property and the specified
209
	 *         map property.
210
	 */
211
	public IEMFMapProperty map(IEMFMapProperty property);
212
}
(-)src/org/eclipse/emf/databinding/internal/EMFPropertyListener.java (+160 lines)
Added Link Here
1
package org.eclipse.emf.databinding.internal;
2
3
import java.util.Collection;
4
import java.util.Map;
5
import java.util.Set;
6
7
import org.eclipse.core.databinding.observable.Diffs;
8
import org.eclipse.core.databinding.observable.list.ListDiff;
9
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
10
import org.eclipse.core.databinding.property.INativePropertyListener;
11
import org.eclipse.core.databinding.property.IProperty;
12
import org.eclipse.core.databinding.property.ISimplePropertyListener;
13
import org.eclipse.core.databinding.property.SimplePropertyEvent;
14
import org.eclipse.emf.common.notify.Notification;
15
import org.eclipse.emf.common.notify.impl.AdapterImpl;
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
19
public abstract class EMFPropertyListener extends AdapterImpl implements
20
		INativePropertyListener {
21
22
	public void addTo(Object source) {
23
		EMFPropertyListenerSupport.hookListener((EObject) source, this);
24
	}
25
26
	public void removeFrom(Object source) {
27
		EMFPropertyListenerSupport.unhookListener((EObject) source, this);
28
	}
29
30
	@Override
31
	public abstract void notifyChanged(Notification msg);
32
33
	protected abstract ISimplePropertyListener getListener();
34
35
	protected abstract EStructuralFeature getFeature();
36
37
	protected abstract IProperty getOwner();
38
39
	public abstract static class EMFListPropertyListener extends
40
			EMFPropertyListener {
41
		@Override
42
		public void notifyChanged(Notification msg) {
43
			if (getFeature() == msg.getFeature() && !msg.isTouch()) {
44
				final ListDiff diff;
45
				switch (msg.getEventType()) {
46
				case Notification.ADD: {
47
					diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg
48
							.getPosition(), true, msg.getNewValue()));
49
					break;
50
				}
51
				case Notification.ADD_MANY: {
52
					Collection<?> newValues = (Collection<?>) msg.getNewValue();
53
					ListDiffEntry[] listDiffEntries = new ListDiffEntry[newValues
54
							.size()];
55
					int position = msg.getPosition();
56
					int index = 0;
57
					for (Object newValue : newValues) {
58
						listDiffEntries[index++] = Diffs.createListDiffEntry(
59
								position++, true, newValue);
60
					}
61
					diff = Diffs.createListDiff(listDiffEntries);
62
					break;
63
				}
64
				case Notification.REMOVE: {
65
					diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg
66
							.getPosition(), false, msg.getOldValue()));
67
					break;
68
				}
69
				case Notification.REMOVE_MANY: {
70
					Collection<?> oldValues = (Collection<?>) msg.getOldValue();
71
					ListDiffEntry[] listDiffEntries = new ListDiffEntry[oldValues
72
							.size()];
73
					int position = msg.getPosition();
74
					int index = 0;
75
					for (Object oldValue : oldValues) {
76
						listDiffEntries[index++] = Diffs.createListDiffEntry(
77
								position++, false, oldValue);
78
					}
79
					diff = Diffs.createListDiff(listDiffEntries);
80
					break;
81
				}
82
				case Notification.SET:
83
				case Notification.RESOLVE: {
84
					ListDiffEntry[] listDiffEntries = new ListDiffEntry[2];
85
					listDiffEntries[0] = Diffs.createListDiffEntry(msg
86
							.getPosition(), false, msg.getOldValue());
87
					listDiffEntries[1] = Diffs.createListDiffEntry(msg
88
							.getPosition(), true, msg.getNewValue());
89
					diff = Diffs.createListDiff(listDiffEntries);
90
					break;
91
				}
92
				case Notification.MOVE: {
93
					Object movedValue = msg.getNewValue();
94
					ListDiffEntry[] listDiffEntries = new ListDiffEntry[2];
95
					listDiffEntries[0] = Diffs.createListDiffEntry(
96
							(Integer) msg.getOldValue(), false, movedValue);
97
					listDiffEntries[1] = Diffs.createListDiffEntry(msg
98
							.getPosition(), true, movedValue);
99
					diff = Diffs.createListDiff(listDiffEntries);
100
					break;
101
				}
102
				case Notification.UNSET: {
103
					// This just represents going back to the unset state, but
104
					// that doesn't affect the contents of the list.
105
					//
106
					return;
107
				}
108
				default: {
109
					throw new RuntimeException("unhandled case");
110
				}
111
				}
112
				getListener().handleEvent(
113
						(new SimplePropertyEvent(SimplePropertyEvent.CHANGE,
114
								msg.getNotifier(), getOwner(), diff)));
115
			}
116
		}
117
	}
118
119
	public abstract static class EMFMapPropertyListener extends
120
			EMFPropertyListener {
121
		@Override
122
		public void notifyChanged(Notification msg) {
123
			if (getFeature() == msg.getFeature() && !msg.isTouch()) {
124
				getListener().handleEvent(
125
						new SimplePropertyEvent(SimplePropertyEvent.CHANGE, msg
126
								.getNotifier(), getOwner(), Diffs
127
								.computeMapDiff((Map<?, ?>) msg.getOldValue(),
128
										(Map<?, ?>) msg.getNewValue())));
129
			}
130
		}
131
	}
132
133
	public abstract static class EMFSetPropertyListener extends
134
			EMFPropertyListener {
135
		@Override
136
		public void notifyChanged(Notification msg) {
137
			if (getFeature() == msg.getFeature() && !msg.isTouch()) {
138
				getListener().handleEvent(
139
						new SimplePropertyEvent(SimplePropertyEvent.CHANGE, msg
140
								.getNotifier(), getOwner(), Diffs
141
								.computeSetDiff((Set<?>) msg.getOldValue(),
142
										(Set<?>) msg.getNewValue())));
143
			}
144
		}
145
	}
146
147
	public abstract static class EMFValuePropertyListener extends
148
			EMFPropertyListener {
149
		@Override
150
		public void notifyChanged(Notification msg) {
151
			if (getFeature() == msg.getFeature() && !msg.isTouch()) {
152
				getListener().handleEvent(
153
						new SimplePropertyEvent(SimplePropertyEvent.CHANGE, msg
154
								.getNotifier(), getOwner(), Diffs
155
								.createValueDiff(msg.getOldValue(), msg
156
										.getNewValue())));
157
			}
158
		}
159
	}
160
}
(-)src/org/eclipse/emf/databinding/IEMFListProperty.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding;
13
14
import org.eclipse.core.databinding.property.list.IListProperty;
15
import org.eclipse.emf.ecore.EStructuralFeature;
16
17
/**
18
 * An {@link IListProperty} extension interface with convenience methods for
19
 * creating nested bean properties.
20
 * 
21
 * @since 1.2
22
 */
23
public interface IEMFListProperty extends IEMFProperty, IListProperty {
24
	/**
25
	 * Returns a master-detail combination of this property and the specified
26
	 * value property.
27
	 * 
28
	 * @param propertyName
29
	 *            the value property to observe. May be nested e.g.
30
	 *            "parent.name"
31
	 * @return a nested combination of this property and the specified value
32
	 *         property.
33
	 * @see #values(IEMFValueProperty)
34
	 */
35
	public IEMFListProperty values(FeaturePath featurePath);
36
	
37
	public IEMFListProperty values(EStructuralFeature feature);
38
39
	/**
40
	 * Returns a master-detail combination of this property and the specified
41
	 * value property. The returned property will observe the specified value
42
	 * property for all elements observed by this list property.
43
	 * <p>
44
	 * Example:
45
	 * 
46
	 * <pre>
47
	 * // Observes the list-typed &quot;children&quot; property of a Person object,
48
	 * // where the elements are Person objects
49
	 * IBeanListProperty children = BeanProperties.list(Person.class, &quot;children&quot;,
50
	 * 		Person.class);
51
	 * // Observes the string-typed &quot;name&quot; property of a Person object
52
	 * IBeanValueProperty name = BeanProperties.value(Person.class, &quot;name&quot;);
53
	 * // Observes the names of children of a Person object.
54
	 * IBeanListProperty childrenNames = children.values(name);
55
	 * </pre>
56
	 * 
57
	 * @param property
58
	 *            the detail property to observe
59
	 * @return a master-detail combination of this property and the specified
60
	 *         value property.
61
	 */
62
	public IEMFListProperty values(IEMFValueProperty property);
63
}
(-)src/org/eclipse/emf/databinding/IEMFProperty.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding;
13
14
import org.eclipse.core.databinding.property.IProperty;
15
import org.eclipse.emf.ecore.EStructuralFeature;
16
17
/**
18
 * An IProperty extension interface providing access to details of bean
19
 * properties.
20
 * 
21
 * @since 1.2
22
 * @noextend This interface is not intended to be extended by clients.
23
 * @noimplement This interface is not intended to be implemented by clients.
24
 */
25
public interface IEMFProperty extends IProperty {
26
	/**
27
	 * Returns the property descriptor of the bean property being observed. This
28
	 * method returns null in the case of anonymous properties.
29
	 * 
30
	 * @return the property descriptor of the bean property being observed
31
	 */
32
	public EStructuralFeature getStructuralFeature();
33
}
(-)src/org/eclipse/emf/databinding/IEMFMapProperty.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding;
13
14
import java.util.Map;
15
16
import org.eclipse.core.databinding.property.map.IMapProperty;
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
19
/**
20
 * An {@link IMapProperty} extension interface with convenience methods for
21
 * creating nested bean properties.
22
 * 
23
 * @since 1.2
24
 * @noextend This interface is not intended to be extended by clients.
25
 * @noimplement This interface is not intended to be implemented by clients.
26
 */
27
public interface IEMFMapProperty extends IEMFProperty, IMapProperty {
28
29
	/**
30
	 * Returns a master-detail combination of this property and the specified
31
	 * value property.
32
	 * 
33
	 * @param propertyName
34
	 *            the value property to observe. May be nested e.g.
35
	 *            "parent.name"
36
	 * @return a master-detail combination of this property and the specified
37
	 *         value property.
38
	 * @see #values(IEMFValueProperty)
39
	 */
40
	public IEMFMapProperty values(FeaturePath featurePath);
41
	
42
	public IEMFMapProperty values(EStructuralFeature feature);
43
44
	/**
45
	 * Returns a master-detail combination of this property and the specified
46
	 * value property. The returned property will observe the specified value
47
	 * property for all {@link Map#values() values} observed by this map
48
	 * property, mapping from this map property's {@link Map#keySet() key set}
49
	 * to the specified value property's value for each element in the master
50
	 * property's {@link Map#values() values} collection.
51
	 * 
52
	 * @param property
53
	 *            the detail property to observe
54
	 * @return a master-detail combination of this property and the specified
55
	 *         value property.
56
	 */
57
	public IEMFMapProperty values(IEMFValueProperty property);
58
}
(-)src/org/eclipse/emf/databinding/internal/EMFObservableListDecorator.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Matthew Hall - bugs 208858, 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObserving;
17
import org.eclipse.core.databinding.observable.list.DecoratingObservableList;
18
import org.eclipse.core.databinding.observable.list.IObservableList;
19
import org.eclipse.emf.databinding.IEMFObservable;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
22
/**
23
 * {@link IEMFObservable} decorator for an {@link IObservableList}.
24
 * 
25
 * @since 3.3
26
 */
27
public class EMFObservableListDecorator extends DecoratingObservableList
28
		implements IEMFObservable {
29
	private EStructuralFeature eStructuralFeature;
30
31
	/**
32
	 * @param decorated
33
	 * @param propertyDescriptor
34
	 */
35
	public EMFObservableListDecorator(IObservableList decorated,
36
			EStructuralFeature eStructuralFeature) {
37
		super(decorated, true);
38
		this.eStructuralFeature = eStructuralFeature;
39
	}
40
41
	public synchronized void dispose() {
42
		this.eStructuralFeature = null;
43
		super.dispose();
44
	}
45
46
	public Object getObserved() {
47
		IObservable decorated = getDecorated();
48
		if (decorated instanceof IObserving)
49
			return ((IObserving) decorated).getObserved();
50
		return null;
51
	}
52
53
	public EStructuralFeature getStructuralFeature() {
54
		return eStructuralFeature;
55
	}
56
}
(-)src/org/eclipse/emf/databinding/internal/EMFListPropertyDecorator.java (+93 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.list.IObservableList;
17
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.property.list.IListProperty;
20
import org.eclipse.core.databinding.property.list.ListProperty;
21
import org.eclipse.emf.databinding.EMFProperties;
22
import org.eclipse.emf.databinding.FeaturePath;
23
import org.eclipse.emf.databinding.IEMFListProperty;
24
import org.eclipse.emf.databinding.IEMFValueProperty;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
27
/**
28
 * @since 3.3
29
 * 
30
 */
31
public class EMFListPropertyDecorator extends ListProperty implements
32
		IEMFListProperty {
33
	private final IListProperty delegate;
34
	private final EStructuralFeature eStructuralFeature;
35
	
36
	/**
37
	 * @param delegate
38
	 * @param propertyDescriptor
39
	 */
40
	public EMFListPropertyDecorator(IListProperty delegate,
41
			EStructuralFeature eStructuralFeature) {
42
		this.delegate = delegate;
43
		this.eStructuralFeature = eStructuralFeature;
44
	}
45
46
	public Object getElementType() {
47
		return delegate.getElementType();
48
	}
49
	
50
	public IEMFListProperty values(EStructuralFeature feature) {
51
		return values(FeaturePath.fromList(feature));
52
	}
53
54
	public IEMFListProperty values(FeaturePath featurePath) {
55
		return values(EMFProperties.value(featurePath));
56
	}
57
58
	public IEMFListProperty values(IEMFValueProperty property) {
59
		return new EMFListPropertyDecorator(super.values(property), property
60
				.getStructuralFeature());
61
	}
62
63
	public EStructuralFeature getStructuralFeature() {
64
		return eStructuralFeature;
65
	}
66
67
	public IObservableList observe(Object source) {
68
		return new EMFObservableListDecorator(delegate.observe(source),
69
				eStructuralFeature);
70
	}
71
72
	public IObservableList observe(Realm realm, Object source) {
73
		return new EMFObservableListDecorator(delegate.observe(realm, source),
74
				eStructuralFeature);
75
	}
76
77
	public IObservableFactory listFactory() {
78
		return delegate.listFactory();
79
	}
80
81
	public IObservableFactory listFactory(Realm realm) {
82
		return delegate.listFactory(realm);
83
	}
84
85
	public IObservableList observeDetail(IObservableValue master) {
86
		return new EMFObservableListDecorator(delegate.observeDetail(master),
87
				eStructuralFeature);
88
	}
89
90
	public String toString() {
91
		return delegate.toString();
92
	}
93
}
(-)src/org/eclipse/emf/databinding/internal/Util.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding.internal;
13
14
/**
15
 * @since 3.3
16
 * 
17
 */
18
public class Util {
19
20
	/**
21
	 * Checks whether the two objects are <code>null</code> -- allowing for
22
	 * <code>null</code>.
23
	 * 
24
	 * @param left
25
	 *            The left object to compare; may be <code>null</code>.
26
	 * @param right
27
	 *            The right object to compare; may be <code>null</code>.
28
	 * @return <code>true</code> if the two objects are equivalent;
29
	 *         <code>false</code> otherwise.
30
	 */
31
	public static final boolean equals(final Object left, final Object right) {
32
		return left == null ? right == null : ((right != null) && left
33
				.equals(right));
34
	}
35
}
(-)src/org/eclipse/emf/databinding/internal/EMFSetProperty.java (+91 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bugs 195222, 264307, 265064, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import java.util.Set;
16
17
import org.eclipse.core.databinding.observable.set.SetDiff;
18
import org.eclipse.core.databinding.property.INativePropertyListener;
19
import org.eclipse.core.databinding.property.IProperty;
20
import org.eclipse.core.databinding.property.ISimplePropertyListener;
21
import org.eclipse.core.databinding.property.set.SimpleSetProperty;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.ecore.EStructuralFeature;
24
25
/**
26
 * @since 3.3
27
 * 
28
 */
29
public class EMFSetProperty extends SimpleSetProperty {
30
	private final EStructuralFeature eStructuralFeature;
31
	private final Class<?> elementType;
32
33
	/**
34
	 * @param propertyDescriptor
35
	 * @param elementType
36
	 */
37
	public EMFSetProperty(EStructuralFeature eStructuralFeature,
38
			Class<?> elementType) { 
39
		this.eStructuralFeature = eStructuralFeature;
40
		this.elementType = elementType == null ? EMFPropertyHelper
41
				.getCollectionPropertyElementType(eStructuralFeature)
42
				: elementType;
43
	}
44
	
45
	protected EStructuralFeature getFeature() {
46
		return eStructuralFeature;
47
	}
48
49
	public Object getElementType() {
50
		return elementType;
51
	}
52
53
	protected Set<?> doGetSet(Object source) {
54
		EObject eObj = (EObject) source;
55
	    return (Set<?>) eObj.eGet(eStructuralFeature);
56
	}
57
58
	@SuppressWarnings("unchecked")
59
	protected void doSetSet(Object source, Set set, SetDiff diff) {
60
		EObject eObject = (EObject) source;
61
	    eObject.eSet(eStructuralFeature, set);
62
	}
63
64
	public INativePropertyListener adaptListener(
65
			final ISimplePropertyListener listener) {
66
		return new EMFPropertyListener.EMFSetPropertyListener(){
67
		
68
			@Override
69
			protected IProperty getOwner() {
70
				return EMFSetProperty.this;
71
			}
72
		
73
			@Override
74
			protected ISimplePropertyListener getListener() {
75
				return listener;
76
			}
77
		
78
			@Override
79
			protected EStructuralFeature getFeature() {
80
				return eStructuralFeature;
81
			}
82
		};
83
	}
84
85
	public String toString() {
86
		String s = EMFPropertyHelper.propertyName(eStructuralFeature) + "{}"; //$NON-NLS-1$
87
		if (elementType != null)
88
			s += "<" + EMFPropertyHelper.shortClassName(elementType) + ">"; //$NON-NLS-1$//$NON-NLS-2$
89
		return s;
90
	}
91
}
(-)src/org/eclipse/emf/databinding/internal/EMFObservableSetDecorator.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Matthew Hall - bug 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObserving;
17
import org.eclipse.core.databinding.observable.set.DecoratingObservableSet;
18
import org.eclipse.core.databinding.observable.set.IObservableSet;
19
import org.eclipse.emf.databinding.IEMFObservable;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
22
/**
23
 * {@link IEMFObservable} decorator for an {@link IObservableSet}.
24
 * 
25
 * @since 3.3
26
 */
27
public class EMFObservableSetDecorator extends DecoratingObservableSet
28
		implements IEMFObservable {
29
	private EStructuralFeature eStructuralFeature;
30
31
	/**
32
	 * @param decorated
33
	 * @param propertyDescriptor
34
	 */
35
	public EMFObservableSetDecorator(IObservableSet decorated,
36
			EStructuralFeature eStructuralFeature) {
37
		super(decorated, true);
38
		this.eStructuralFeature = eStructuralFeature;
39
	}
40
41
	public synchronized void dispose() {
42
		this.eStructuralFeature = null;
43
		super.dispose();
44
	}
45
46
	public Object getObserved() {
47
		IObservable decorated = getDecorated();
48
		if (decorated instanceof IObserving)
49
			return ((IObserving) decorated).getObserved();
50
		return null;
51
	}
52
53
	public EStructuralFeature getStructuralFeature() {
54
		return eStructuralFeature;
55
	}
56
}
(-)src/org/eclipse/emf/databinding/internal/EMFObservableValueDecorator.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Matthew Hall - bug 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObserving;
17
import org.eclipse.core.databinding.observable.value.DecoratingObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.emf.databinding.IEMFObservable;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
22
/**
23
 * {@link IEMFObservable} decorator for an {@link IObservableValue}.
24
 * 
25
 * @since 3.3
26
 */
27
public class EMFObservableValueDecorator extends DecoratingObservableValue
28
		implements IEMFObservable {
29
	private EStructuralFeature eStructuralFeature;
30
31
	/**
32
	 * @param decorated
33
	 * @param propertyDescriptor
34
	 */
35
	public EMFObservableValueDecorator(IObservableValue decorated,
36
			EStructuralFeature eStructuralFeature) {
37
		super(decorated, true);
38
		this.eStructuralFeature = eStructuralFeature;
39
	}
40
41
	public synchronized void dispose() {
42
		this.eStructuralFeature = null;
43
		super.dispose();
44
	}
45
46
	public Object getObserved() {
47
		IObservable decorated = getDecorated();
48
		if (decorated instanceof IObserving)
49
			return ((IObserving) decorated).getObserved();
50
		return null;
51
	}
52
53
	public EStructuralFeature getStructuralFeature() {
54
		return eStructuralFeature;
55
	}
56
}
(-)src/org/eclipse/emf/databinding/IEMFSetProperty.java (+67 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding;
13
14
import org.eclipse.core.databinding.property.set.ISetProperty;
15
import org.eclipse.emf.ecore.EStructuralFeature;
16
17
/**
18
 * An {@link ISetProperty} extension interface with convenience methods for
19
 * creating nested bean properties.
20
 * 
21
 * @since 1.2
22
 * @noextend This interface is not intended to be extended by clients.
23
 * @noimplement This interface is not intended to be implemented by clients.
24
 */
25
public interface IEMFSetProperty extends IEMFProperty, ISetProperty {
26
	/**
27
	 * Returns a master-detail combination of this property and the specified
28
	 * value property.
29
	 * 
30
	 * @param propertyName
31
	 *            the value property to observe. May be nested e.g.
32
	 *            "parent.name"
33
	 * @return a master-detail combination of this property and the specified
34
	 *         value property.
35
	 * @see #values(IEMFValueProperty)
36
	 */
37
	public IEMFMapProperty values(FeaturePath featurePath);
38
	
39
	public IEMFMapProperty values(EStructuralFeature feature);
40
41
	/**
42
	 * Returns a master-detail combination of this property and the specified
43
	 * value property. The returned property will observe the specified value
44
	 * property for all elements observed by this set property, mapping from
45
	 * this set property's elements (keys) to the specified value property's
46
	 * value for each element (values).
47
	 * <p>
48
	 * Example:
49
	 * 
50
	 * <pre>
51
	 * // Observes the set-typed &quot;children&quot; property of a Person object,
52
	 * // where the elements are Person objects
53
	 * IBeanSetProperty children = BeanProperties.set(Person.class, &quot;children&quot;,
54
	 * 		Person.class);
55
	 * // Observes the string-typed &quot;name&quot; property of a Person object
56
	 * IBeanValueProperty name = BeanProperties.value(Person.class, &quot;name&quot;);
57
	 * // Observes a map of children objects to their respective names.
58
	 * IBeanMapProperty childrenNames = children.values(name);
59
	 * </pre>
60
	 * 
61
	 * @param property
62
	 *            the detail property to observe
63
	 * @return a master-detail combination of this property and the specified
64
	 *         value property.
65
	 */
66
	public IEMFMapProperty values(IEMFValueProperty property);
67
}
(-)src/org/eclipse/emf/databinding/EMFProperties.java (+201 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bug 195222, 247997, 261843, 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding;
14
15
import org.eclipse.core.databinding.property.list.IListProperty;
16
import org.eclipse.core.databinding.property.map.IMapProperty;
17
import org.eclipse.core.databinding.property.set.ISetProperty;
18
import org.eclipse.core.databinding.property.value.IValueProperty;
19
import org.eclipse.emf.databinding.IEMFListValueProperty.Condition;
20
import org.eclipse.emf.databinding.internal.EMFListProperty;
21
import org.eclipse.emf.databinding.internal.EMFListPropertyDecorator;
22
import org.eclipse.emf.databinding.internal.EMFListValueProperty;
23
import org.eclipse.emf.databinding.internal.EMFListValuePropertyDecorator;
24
import org.eclipse.emf.databinding.internal.EMFMapProperty;
25
import org.eclipse.emf.databinding.internal.EMFMapPropertyDecorator;
26
import org.eclipse.emf.databinding.internal.EMFSetProperty;
27
import org.eclipse.emf.databinding.internal.EMFSetPropertyDecorator;
28
import org.eclipse.emf.databinding.internal.EMFValueProperty;
29
import org.eclipse.emf.databinding.internal.EMFValuePropertyDecorator;
30
import org.eclipse.emf.ecore.EStructuralFeature;
31
32
/**
33
 * A factory for creating properties for Java objects that conform to the <a
34
 * href="http://java.sun.com/products/javabeans/docs/spec.html">JavaBean
35
 * specification</a> for bound properties.
36
 * 
37
 * @since 1.2
38
 */
39
public class EMFProperties {
40
	public static final boolean DEBUG = false;
41
	
42
	public static IEMFListValueProperty listValue(EStructuralFeature feature, Condition condition) {
43
		return listValue(FeaturePath.fromList(feature),condition);
44
	}
45
	
46
	public static IEMFListValueProperty listValue(FeaturePath featurePath, Condition condition) {
47
		IValueProperty property;
48
		if( featurePath.getFeaturePath().length == 1 ) {
49
			property = new EMFListValueProperty(featurePath.getFeaturePath()[0],condition);
50
			return new EMFListValuePropertyDecorator(property, featurePath.getFeaturePath()[0]);
51
		} else {
52
			property = new EMFValueProperty(featurePath.getFeaturePath()[0]);
53
54
			IEMFValueProperty beanProperty = new EMFValuePropertyDecorator(
55
					property, featurePath.getFeaturePath()[0]);
56
			
57
			int i = 1;
58
			for (i = 1; i < featurePath.getFeaturePath().length; i++) {
59
				beanProperty = beanProperty.value(featurePath.getFeaturePath()[i]);
60
			}
61
			
62
			return beanProperty.listValue(featurePath.getFeaturePath()[i],condition);
63
		}
64
		
65
	}
66
	
67
	public static IEMFValueProperty value(EStructuralFeature feature) {
68
		return value(FeaturePath.fromList(feature));
69
	}
70
	
71
	/**
72
	 * Returns a value property for the given property name of the given bean
73
	 * class.
74
	 * 
75
	 * @param beanClass
76
	 *            the bean class
77
	 * @param propertyName
78
	 *            the property name. May be nested e.g. "parent.name"
79
	 * @param valueType
80
	 *            the value type of the returned value property
81
	 * @return a value property for the given property name of the given bean
82
	 *         class.
83
	 */
84
	public static IEMFValueProperty value(FeaturePath featurePath) {
85
		IValueProperty property;
86
		property = new EMFValueProperty(featurePath.getFeaturePath()[0]);
87
88
		IEMFValueProperty beanProperty = new EMFValuePropertyDecorator(
89
				property, featurePath.getFeaturePath()[0]);
90
		
91
		for (int i = 1; i < featurePath.getFeaturePath().length; i++) {
92
			beanProperty = beanProperty.value(featurePath.getFeaturePath()[i]);
93
		}
94
		
95
		return beanProperty;
96
	}
97
98
	public static IEMFValueProperty[] values(EStructuralFeature... features) {
99
		IEMFValueProperty[] properties = new IEMFValueProperty[features.length];
100
		for (int i = 0; i < properties.length; i++)
101
			properties[i] = value(features[i]);
102
		return properties;
103
	}
104
	
105
	/**
106
	 * Returns a value property array for the given property names of the given
107
	 * bean class.
108
	 * 
109
	 * @param beanClass
110
	 *            the bean class
111
	 * @param propertyNames
112
	 *            array of property names. May be nested e.g. "parent.name"
113
	 * @return a value property array for the given property names of the given
114
	 *         bean class.
115
	 */
116
	public static IEMFValueProperty[] values(FeaturePath... featurePaths) {
117
		IEMFValueProperty[] properties = new IEMFValueProperty[featurePaths.length];
118
		for (int i = 0; i < properties.length; i++)
119
			properties[i] = value(featurePaths[i]);
120
		return properties;
121
	}
122
123
	public static IEMFSetProperty set(EStructuralFeature feature) {
124
		return set(feature,null);
125
	}
126
	
127
	/**
128
	 * Returns a set property for the given property name of the given bean
129
	 * class.
130
	 * 
131
	 * @param beanClass
132
	 *            the bean class
133
	 * @param propertyName
134
	 *            the property name
135
	 * @param elementType
136
	 *            the element type of the returned set property
137
	 * @return a set property for the given property name of the given bean
138
	 *         class.
139
	 */
140
	public static IEMFSetProperty set(EStructuralFeature feature, Class<?> elementType) {
141
		ISetProperty property;
142
		property = new EMFSetProperty(feature, elementType);
143
		return new EMFSetPropertyDecorator(property, feature);
144
	}
145
146
	/**
147
	 * Returns a list property for the given property name of the given bean
148
	 * class.
149
	 * 
150
	 * @param beanClass
151
	 *            the bean class
152
	 * @param propertyName
153
	 *            the property name
154
	 * @param elementType
155
	 *            the element type of the returned list property
156
	 * @return a list property for the given property name of the given bean
157
	 *         class.
158
	 */
159
	public static IEMFListProperty list(EStructuralFeature feature) {
160
		IListProperty property;
161
		property = new EMFListProperty(feature);
162
		return new EMFListPropertyDecorator(property, feature);
163
	}
164
165
	/**
166
	 * Returns a map property for the given property name of an arbitrary bean
167
	 * class. Objects lacking the named property are treated the same as if the
168
	 * property always contains an empty map.
169
	 * 
170
	 * @param propertyName
171
	 *            the property name
172
	 * @return a map property for the given property name of an arbitrary bean
173
	 *         class.
174
	 */
175
	public static IEMFMapProperty map(EStructuralFeature feature) {
176
		return map(feature, null, null);
177
	}
178
179
	/**
180
	 * Returns a map property for the given property name of the given bean
181
	 * class.
182
	 * 
183
	 * @param beanClass
184
	 *            the bean class
185
	 * @param propertyName
186
	 *            the property name
187
	 * @param keyType
188
	 *            the key type for the returned map property
189
	 * @param valueType
190
	 *            the value type for the returned map property
191
	 * @return a map property for the given property name of the given bean
192
	 *         class.
193
	 */
194
	public static IEMFMapProperty map(EStructuralFeature feature,
195
			Class<?> keyType, Class<?> valueType) {
196
		IMapProperty property;
197
		property = new EMFMapProperty(feature, keyType,
198
					valueType);
199
		return new EMFMapPropertyDecorator(property, feature);
200
	}
201
}
(-)src/org/eclipse/emf/databinding/internal/EMFListValuePropertyDecorator.java (+133 lines)
Added Link Here
1
package org.eclipse.emf.databinding.internal;
2
3
import org.eclipse.core.databinding.observable.Realm;
4
import org.eclipse.core.databinding.observable.list.IObservableList;
5
import org.eclipse.core.databinding.observable.map.IObservableMap;
6
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
7
import org.eclipse.core.databinding.observable.set.IObservableSet;
8
import org.eclipse.core.databinding.observable.value.IObservableValue;
9
import org.eclipse.core.databinding.property.value.IValueProperty;
10
import org.eclipse.core.databinding.property.value.ValueProperty;
11
import org.eclipse.emf.databinding.EMFProperties;
12
import org.eclipse.emf.databinding.FeaturePath;
13
import org.eclipse.emf.databinding.IEMFListProperty;
14
import org.eclipse.emf.databinding.IEMFListValueProperty;
15
import org.eclipse.emf.databinding.IEMFMapProperty;
16
import org.eclipse.emf.databinding.IEMFSetProperty;
17
import org.eclipse.emf.databinding.IEMFValueProperty;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
20
public class EMFListValuePropertyDecorator extends ValueProperty implements IEMFListValueProperty {
21
	private final IValueProperty delegate;
22
	private final EStructuralFeature eStructuralFeature;
23
24
	/**
25
	 * @param delegate
26
	 * @param propertyDescriptor
27
	 */
28
	public EMFListValuePropertyDecorator(IValueProperty delegate,
29
			EStructuralFeature eStructuralFeature) {
30
		this.delegate = delegate;
31
		this.eStructuralFeature = eStructuralFeature;
32
	}
33
34
	public EStructuralFeature getStructuralFeature() {
35
		return eStructuralFeature;
36
	}
37
38
	public Object getValueType() {
39
		return delegate.getValueType();
40
	}
41
42
	public IEMFValueProperty value(EStructuralFeature feature) {
43
		return value(FeaturePath.fromList(feature));
44
	}
45
	
46
	public IEMFValueProperty value(FeaturePath featurePath) {
47
		return value(EMFProperties.value(featurePath));
48
	}
49
50
	public IEMFValueProperty value(IEMFValueProperty property) {
51
		return new EMFValuePropertyDecorator(super.value(property), property
52
				.getStructuralFeature());
53
	}
54
55
	public IEMFListProperty list(EStructuralFeature feature) {
56
		return list(EMFProperties.list(feature));
57
	}
58
59
	public IEMFListProperty list(IEMFListProperty property) {
60
		return new EMFListPropertyDecorator(super.list(property), property
61
				.getStructuralFeature());
62
	}
63
64
	public IEMFSetProperty set(EStructuralFeature feature) {
65
		return set(feature, null);
66
	}
67
68
	public IEMFSetProperty set(EStructuralFeature feature, Class<?> elementType) {
69
		return set(EMFProperties.set(feature, elementType));
70
	}
71
72
	public IEMFSetProperty set(IEMFSetProperty property) {
73
		return new EMFSetPropertyDecorator(super.set(property), property
74
				.getStructuralFeature());
75
	}
76
77
	public IEMFMapProperty map(EStructuralFeature feature) {
78
		return map(feature, null, null);
79
	}
80
81
	public IEMFMapProperty map(EStructuralFeature feature, Class<?> keyType,
82
			Class<?> valueType) {
83
		return map(EMFProperties.map(feature, keyType,
84
				valueType));
85
	}
86
87
	public IEMFMapProperty map(IEMFMapProperty property) {
88
		return new EMFMapPropertyDecorator(super.map(property), property
89
				.getStructuralFeature());
90
	}
91
92
	public IObservableValue observe(Object source) {
93
		return new EMFObservableValueDecorator(delegate.observe(source),
94
				eStructuralFeature);
95
	}
96
97
	public IObservableValue observe(Realm realm, Object source) {
98
		return new EMFObservableValueDecorator(delegate.observe(realm, source),
99
				eStructuralFeature);
100
	}
101
102
	public IObservableFactory valueFactory() {
103
		return delegate.valueFactory();
104
	}
105
106
	public IObservableFactory valueFactory(Realm realm) {
107
		return delegate.valueFactory(realm);
108
	}
109
110
	public IObservableValue observeDetail(IObservableValue master) {
111
		return new EMFObservableValueDecorator(delegate.observeDetail(master),
112
				eStructuralFeature);
113
	}
114
115
	public IObservableList observeDetail(IObservableList master) {
116
		return new EMFObservableListDecorator(delegate.observeDetail(master),
117
				eStructuralFeature);
118
	}
119
120
	public IObservableMap observeDetail(IObservableSet master) {
121
		return new EMFObservableMapDecorator(delegate.observeDetail(master),
122
				eStructuralFeature);
123
	}
124
125
	public IObservableMap observeDetail(IObservableMap master) {
126
		return new EMFObservableMapDecorator(delegate.observeDetail(master),
127
				eStructuralFeature);
128
	}
129
130
	public String toString() {
131
		return delegate.toString();
132
	}
133
}
(-)src/org/eclipse/emf/databinding/FeaturePath.java (+19 lines)
Added Link Here
1
package org.eclipse.emf.databinding;
2
3
import org.eclipse.emf.ecore.EStructuralFeature;
4
5
public class FeaturePath {
6
	private EStructuralFeature[] featurePath;
7
	
8
	private FeaturePath(EStructuralFeature[] featurePath) {
9
		this.featurePath = featurePath;
10
	}
11
	
12
	public EStructuralFeature[] getFeaturePath() {
13
		return featurePath;
14
	}
15
	
16
	public static FeaturePath fromList(EStructuralFeature... featurePath) {
17
		return new FeaturePath(featurePath);
18
	}
19
}
(-)src/org/eclipse/emf/databinding/internal/EMFMapPropertyDecorator.java (+97 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.map.IObservableMap;
17
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.property.map.IMapProperty;
20
import org.eclipse.core.databinding.property.map.MapProperty;
21
import org.eclipse.emf.databinding.EMFProperties;
22
import org.eclipse.emf.databinding.FeaturePath;
23
import org.eclipse.emf.databinding.IEMFMapProperty;
24
import org.eclipse.emf.databinding.IEMFValueProperty;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
27
/**
28
 * @since 3.3
29
 * 
30
 */
31
public class EMFMapPropertyDecorator extends MapProperty implements
32
		IEMFMapProperty {
33
	private final IMapProperty delegate;
34
	private final EStructuralFeature eStructuralFeature;
35
36
	/**
37
	 * @param delegate
38
	 * @param propertyDescriptor
39
	 */
40
	public EMFMapPropertyDecorator(IMapProperty delegate,
41
			EStructuralFeature eStructuralFeature) {
42
		this.delegate = delegate;
43
		this.eStructuralFeature = eStructuralFeature;
44
	}
45
46
	public EStructuralFeature getStructuralFeature() {
47
		return eStructuralFeature;
48
	}
49
50
	public Object getKeyType() {
51
		return delegate.getKeyType();
52
	}
53
54
	public Object getValueType() {
55
		return delegate.getValueType();
56
	}
57
	
58
	public IEMFMapProperty values(EStructuralFeature feature) {
59
		return values(FeaturePath.fromList(feature));
60
	}
61
62
	public IEMFMapProperty values(FeaturePath featurePath) {
63
		return values(EMFProperties.value(featurePath));
64
	}
65
66
	public IEMFMapProperty values(IEMFValueProperty property) {
67
		return new EMFMapPropertyDecorator(super.values(property), property
68
				.getStructuralFeature());
69
	}
70
71
	public IObservableMap observe(Object source) {
72
		return new EMFObservableMapDecorator(delegate.observe(source),
73
				eStructuralFeature);
74
	}
75
76
	public IObservableMap observe(Realm realm, Object source) {
77
		return new EMFObservableMapDecorator(delegate.observe(realm, source),
78
				eStructuralFeature);
79
	}
80
81
	public IObservableFactory mapFactory() {
82
		return delegate.mapFactory();
83
	}
84
85
	public IObservableFactory mapFactory(Realm realm) {
86
		return delegate.mapFactory(realm);
87
	}
88
89
	public IObservableMap observeDetail(IObservableValue master) {
90
		return new EMFObservableMapDecorator(delegate.observeDetail(master),
91
				eStructuralFeature);
92
	}
93
94
	public String toString() {
95
		return delegate.toString();
96
	}
97
}
(-)src/org/eclipse/emf/databinding/internal/EMFMapProperty.java (+99 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bugs 195222, 264307, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import java.util.Map;
16
17
import org.eclipse.core.databinding.observable.map.MapDiff;
18
import org.eclipse.core.databinding.property.INativePropertyListener;
19
import org.eclipse.core.databinding.property.IProperty;
20
import org.eclipse.core.databinding.property.ISimplePropertyListener;
21
import org.eclipse.core.databinding.property.map.SimpleMapProperty;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.ecore.EStructuralFeature;
24
25
/**
26
 * @since 3.3
27
 * 
28
 */
29
public class EMFMapProperty extends SimpleMapProperty {
30
	private EStructuralFeature eStructuralFeature;
31
	
32
	private final Class<?> keyType;
33
	private final Class<?> valueType;
34
35
	/**
36
	 * @param propertyDescriptor
37
	 * @param keyType
38
	 * @param valueType
39
	 */
40
	public EMFMapProperty(EStructuralFeature eStructuralFeature,
41
			Class<?> keyType, Class<?> valueType) {
42
		this.eStructuralFeature = eStructuralFeature;
43
		this.keyType = keyType;
44
		this.valueType = valueType;
45
	}
46
47
	protected EStructuralFeature getFeature() {
48
		return eStructuralFeature;
49
	}
50
	
51
	public Object getKeyType() {
52
		return keyType;
53
	}
54
55
	public Object getValueType() {
56
		return valueType;
57
	}
58
59
	protected Map<?,?> doGetMap(Object source) {
60
		EObject eObj = (EObject) source;
61
	    return (Map<?, ?>) eObj.eGet(eStructuralFeature);
62
	}
63
64
	@SuppressWarnings("unchecked")
65
	protected void doSetMap(Object source, Map map, MapDiff diff) {
66
		EObject eObject = (EObject) source;
67
	    eObject.eSet(eStructuralFeature, map);
68
	}
69
70
	public INativePropertyListener adaptListener(
71
			final ISimplePropertyListener listener) {
72
		return new EMFPropertyListener.EMFMapPropertyListener(){
73
		
74
			@Override
75
			protected IProperty getOwner() {
76
				return EMFMapProperty.this;
77
			}
78
		
79
			@Override
80
			protected ISimplePropertyListener getListener() {
81
				return listener;
82
			}
83
		
84
			@Override
85
			protected EStructuralFeature getFeature() {
86
				return eStructuralFeature;
87
			}
88
		};
89
	}
90
91
	public String toString() {
92
		String s = EMFPropertyHelper.propertyName(eStructuralFeature) + "{:}"; //$NON-NLS-1$
93
94
		if (keyType != null || valueType != null)
95
			s += "<" + EMFPropertyHelper.shortClassName(keyType) + ", " //$NON-NLS-1$ //$NON-NLS-2$
96
					+ EMFPropertyHelper.shortClassName(valueType) + ">"; //$NON-NLS-1$
97
		return s;
98
	}
99
}
(-)src/org/eclipse/emf/databinding/internal/EMFSetPropertyDecorator.java (+94 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
17
import org.eclipse.core.databinding.observable.set.IObservableSet;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.property.set.ISetProperty;
20
import org.eclipse.core.databinding.property.set.SetProperty;
21
import org.eclipse.emf.databinding.EMFProperties;
22
import org.eclipse.emf.databinding.FeaturePath;
23
import org.eclipse.emf.databinding.IEMFMapProperty;
24
import org.eclipse.emf.databinding.IEMFSetProperty;
25
import org.eclipse.emf.databinding.IEMFValueProperty;
26
import org.eclipse.emf.ecore.EStructuralFeature;
27
28
/**
29
 * @since 3.3
30
 * 
31
 */
32
public class EMFSetPropertyDecorator extends SetProperty implements
33
		IEMFSetProperty {
34
	private final ISetProperty delegate;
35
	private final EStructuralFeature eStructuralFeature;
36
37
	/**
38
	 * @param delegate
39
	 * @param propertyDescriptor
40
	 */
41
	public EMFSetPropertyDecorator(ISetProperty delegate,
42
			EStructuralFeature eStructuralFeature) {
43
		this.delegate = delegate;
44
		this.eStructuralFeature = eStructuralFeature;
45
	}
46
47
	public EStructuralFeature getStructuralFeature() {
48
		return eStructuralFeature;
49
	}
50
51
	public Object getElementType() {
52
		return delegate.getElementType();
53
	}
54
	
55
	public IEMFMapProperty values(EStructuralFeature feature) {
56
		return values(FeaturePath.fromList(feature));
57
	}
58
	
59
	public IEMFMapProperty values(FeaturePath featurePath) {
60
		return values(EMFProperties.value(featurePath));
61
	}
62
63
	public IEMFMapProperty values(IEMFValueProperty property) {
64
		return new EMFMapPropertyDecorator(super.values(property), property
65
				.getStructuralFeature());
66
	}
67
68
	public IObservableSet observe(Object source) {
69
		return new EMFObservableSetDecorator(delegate.observe(source),
70
				eStructuralFeature);
71
	}
72
73
	public IObservableSet observe(Realm realm, Object source) {
74
		return new EMFObservableSetDecorator(delegate.observe(realm, source),
75
				eStructuralFeature);
76
	}
77
78
	public IObservableFactory setFactory() {
79
		return delegate.setFactory();
80
	}
81
82
	public IObservableFactory setFactory(Realm realm) {
83
		return delegate.setFactory(realm);
84
	}
85
86
	public IObservableSet observeDetail(IObservableValue master) {
87
		return new EMFObservableSetDecorator(delegate.observeDetail(master),
88
				eStructuralFeature);
89
	}
90
91
	public String toString() {
92
		return delegate.toString();
93
	}
94
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 11-16 Link Here
11
Export-Package: org.eclipse.emf.databinding.edit
11
Export-Package: org.eclipse.emf.databinding.edit
12
Require-Bundle: org.eclipse.core.runtime,
12
Require-Bundle: org.eclipse.core.runtime,
13
 org.eclipse.emf.databinding;visibility:=reexport,
13
 org.eclipse.emf.databinding;visibility:=reexport,
14
 org.eclipse.emf.edit;visibility:=reexport
14
 org.eclipse.emf.edit;visibility:=reexport,
15
 org.eclipse.core.databinding.property;bundle-version="1.2.0"
15
Eclipse-LazyStart: true
16
Eclipse-LazyStart: true
16
Bundle-ActivationPolicy: lazy
17
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditMapProperty.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bugs 195222, 264307, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import java.util.Map;
16
17
import org.eclipse.core.databinding.observable.map.MapDiff;
18
import org.eclipse.emf.common.command.Command;
19
import org.eclipse.emf.databinding.internal.EMFMapProperty;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.edit.command.SetCommand;
23
import org.eclipse.emf.edit.domain.EditingDomain;
24
25
/**
26
 * @since 3.3
27
 * 
28
 */
29
public class EMFEditMapProperty extends EMFMapProperty {
30
	private final EditingDomain editingDomain;
31
	
32
	public EMFEditMapProperty(EditingDomain editingDomain, EStructuralFeature eStructuralFeature,
33
			Class<?> keyType, Class<?> valueType) {
34
		super(eStructuralFeature, keyType, valueType);
35
		this.editingDomain = editingDomain;
36
	}
37
38
	@SuppressWarnings("unchecked")
39
	@Override
40
	protected void doSetMap(Object source, Map map, MapDiff diff) {
41
		EObject eObject = (EObject) source;
42
		Command command = SetCommand.create(editingDomain, eObject, getFeature(), map);
43
		editingDomain.getCommandStack().execute(command);
44
	}
45
46
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditListProperty.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding.edit;
13
14
import org.eclipse.core.databinding.property.list.IListProperty;
15
import org.eclipse.emf.databinding.FeaturePath;
16
import org.eclipse.emf.databinding.IEMFProperty;
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
19
/**
20
 * An {@link IListProperty} extension interface with convenience methods for
21
 * creating nested bean properties.
22
 * 
23
 * @since 1.2
24
 */
25
public interface IEMFEditListProperty extends IEMFProperty, IListProperty {
26
	/**
27
	 * Returns a master-detail combination of this property and the specified
28
	 * value property.
29
	 * 
30
	 * @param propertyName
31
	 *            the value property to observe. May be nested e.g.
32
	 *            "parent.name"
33
	 * @return a nested combination of this property and the specified value
34
	 *         property.
35
	 * @see #values(IEMFEditValueProperty)
36
	 */
37
	public IEMFEditListProperty values(FeaturePath featurePath);
38
	
39
	public IEMFEditListProperty values(EStructuralFeature feature);
40
41
	/**
42
	 * Returns a master-detail combination of this property and the specified
43
	 * value property. The returned property will observe the specified value
44
	 * property for all elements observed by this list property.
45
	 * <p>
46
	 * Example:
47
	 * 
48
	 * <pre>
49
	 * // Observes the list-typed &quot;children&quot; property of a Person object,
50
	 * // where the elements are Person objects
51
	 * IBeanListProperty children = BeanProperties.list(Person.class, &quot;children&quot;,
52
	 * 		Person.class);
53
	 * // Observes the string-typed &quot;name&quot; property of a Person object
54
	 * IBeanValueProperty name = BeanProperties.value(Person.class, &quot;name&quot;);
55
	 * // Observes the names of children of a Person object.
56
	 * IBeanListProperty childrenNames = children.values(name);
57
	 * </pre>
58
	 * 
59
	 * @param property
60
	 *            the detail property to observe
61
	 * @return a master-detail combination of this property and the specified
62
	 *         value property.
63
	 */
64
	public IEMFEditListProperty values(IEMFEditValueProperty property);
65
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditSetProperty.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bugs 195222, 264307, 265064, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import java.util.Set;
16
17
import org.eclipse.core.databinding.observable.set.SetDiff;
18
import org.eclipse.emf.common.command.Command;
19
import org.eclipse.emf.databinding.internal.EMFSetProperty;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.edit.command.SetCommand;
23
import org.eclipse.emf.edit.domain.EditingDomain;
24
25
/**
26
 * @since 3.3
27
 * 
28
 */
29
public class EMFEditSetProperty extends EMFSetProperty {
30
	private final EditingDomain editingDomain;
31
	
32
	public EMFEditSetProperty(EditingDomain editingDomain, EStructuralFeature eStructuralFeature,
33
			Class<?> elementType) {
34
		super(eStructuralFeature, elementType);
35
		this.editingDomain = editingDomain;
36
	}
37
	
38
	@SuppressWarnings("unchecked")
39
	@Override
40
	protected void doSetSet(Object source, Set set, SetDiff diff) {
41
		EObject eObject = (EObject) source;
42
		Command command = SetCommand.create(editingDomain, eObject, getFeature(), set);
43
		editingDomain.getCommandStack().execute(command);
44
	}
45
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditMapProperty.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding.edit;
13
14
import java.util.Map;
15
16
import org.eclipse.core.databinding.property.map.IMapProperty;
17
import org.eclipse.emf.databinding.FeaturePath;
18
import org.eclipse.emf.databinding.IEMFProperty;
19
import org.eclipse.emf.ecore.EStructuralFeature;
20
21
/**
22
 * An {@link IMapProperty} extension interface with convenience methods for
23
 * creating nested bean properties.
24
 * 
25
 * @since 1.2
26
 * @noextend This interface is not intended to be extended by clients.
27
 * @noimplement This interface is not intended to be implemented by clients.
28
 */
29
public interface IEMFEditMapProperty extends IEMFProperty, IMapProperty {
30
31
	/**
32
	 * Returns a master-detail combination of this property and the specified
33
	 * value property.
34
	 * 
35
	 * @param propertyName
36
	 *            the value property to observe. May be nested e.g.
37
	 *            "parent.name"
38
	 * @return a master-detail combination of this property and the specified
39
	 *         value property.
40
	 * @see #values(IEMFEditValueProperty)
41
	 */
42
	public IEMFEditMapProperty values(FeaturePath featurePath);
43
	
44
	public IEMFEditMapProperty values(EStructuralFeature feature);
45
46
	/**
47
	 * Returns a master-detail combination of this property and the specified
48
	 * value property. The returned property will observe the specified value
49
	 * property for all {@link Map#values() values} observed by this map
50
	 * property, mapping from this map property's {@link Map#keySet() key set}
51
	 * to the specified value property's value for each element in the master
52
	 * property's {@link Map#values() values} collection.
53
	 * 
54
	 * @param property
55
	 *            the detail property to observe
56
	 * @return a master-detail combination of this property and the specified
57
	 *         value property.
58
	 */
59
	public IEMFEditMapProperty values(IEMFEditValueProperty property);
60
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditObservableMapDecorator.java (+43 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 221704)
10
 *     Matthew Hall - bug 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.map.IObservableMap;
16
import org.eclipse.emf.databinding.edit.IEMFEditObservable;
17
import org.eclipse.emf.databinding.internal.EMFObservableMapDecorator;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.edit.domain.EditingDomain;
20
21
/**
22
 * {@link IEMFObservable} decorator for an {@link IObservableMap}.
23
 * 
24
 * @since 3.3
25
 */
26
public class EMFEditObservableMapDecorator extends EMFObservableMapDecorator
27
		implements IEMFEditObservable {
28
	private final EditingDomain editingDomain;
29
	
30
	/**
31
	 * @param decorated
32
	 * @param propertyDescriptor
33
	 */
34
	public EMFEditObservableMapDecorator(EditingDomain editingDomain, IObservableMap decorated,
35
			EStructuralFeature eStructuralFeature) {
36
		super(decorated, eStructuralFeature);
37
		this.editingDomain = editingDomain;
38
	}
39
40
	public EditingDomain getEditingDomain() {
41
		return editingDomain;
42
	}
43
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditObservable.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Brad Reynolds - bug 147515
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit;
14
15
import org.eclipse.core.databinding.observable.IObserving;
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
import org.eclipse.emf.edit.domain.EditingDomain;
18
19
/**
20
 * Provides access to details of bean observables.
21
 * <p>
22
 * This interface is not meant to be implemented by clients.
23
 * </p>
24
 * 
25
 * @since 3.3
26
 */
27
public interface IEMFEditObservable extends IObserving {
28
	/**
29
	 * @return property descriptor of the property being observed,
30
	 *         <code>null</code> if the runtime time information was not
31
	 *         provided on construction of the observable
32
	 */
33
	public EStructuralFeature getStructuralFeature();
34
	
35
	public EditingDomain getEditingDomain();
36
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditSetPropertyDecorator.java (+97 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
17
import org.eclipse.core.databinding.observable.set.IObservableSet;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.property.set.ISetProperty;
20
import org.eclipse.core.databinding.property.set.SetProperty;
21
import org.eclipse.emf.databinding.FeaturePath;
22
import org.eclipse.emf.databinding.edit.EMFEditProperties;
23
import org.eclipse.emf.databinding.edit.IEMFEditMapProperty;
24
import org.eclipse.emf.databinding.edit.IEMFEditSetProperty;
25
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
26
import org.eclipse.emf.ecore.EStructuralFeature;
27
import org.eclipse.emf.edit.domain.EditingDomain;
28
29
/**
30
 * @since 3.3
31
 * 
32
 */
33
public class EMFEditSetPropertyDecorator extends SetProperty implements
34
		IEMFEditSetProperty {
35
	private final ISetProperty delegate;
36
	private final EStructuralFeature eStructuralFeature;
37
	private final EditingDomain editingDomain;
38
39
	/**
40
	 * @param delegate
41
	 * @param propertyDescriptor
42
	 */
43
	public EMFEditSetPropertyDecorator(EditingDomain editingDomain,ISetProperty delegate,
44
			EStructuralFeature eStructuralFeature) {
45
		this.delegate = delegate;
46
		this.eStructuralFeature = eStructuralFeature;
47
		this.editingDomain = editingDomain;
48
	}
49
50
	public EStructuralFeature getStructuralFeature() {
51
		return eStructuralFeature;
52
	}
53
54
	public Object getElementType() {
55
		return delegate.getElementType();
56
	}
57
	
58
	public IEMFEditMapProperty values(EStructuralFeature feature) {
59
		return values(FeaturePath.fromList(feature));
60
	}
61
	
62
	public IEMFEditMapProperty values(FeaturePath featurePath) {
63
		return values(EMFEditProperties.value(editingDomain,featurePath));
64
	}
65
66
	public IEMFEditMapProperty values(IEMFEditValueProperty property) {
67
		return new EMFEditMapPropertyDecorator(editingDomain,super.values(property), property
68
				.getStructuralFeature());
69
	}
70
71
	public IObservableSet observe(Object source) {
72
		return new EMFEditObservableSetDecorator(editingDomain,delegate.observe(source),
73
				eStructuralFeature);
74
	}
75
76
	public IObservableSet observe(Realm realm, Object source) {
77
		return new EMFEditObservableSetDecorator(editingDomain,delegate.observe(realm, source),
78
				eStructuralFeature);
79
	}
80
81
	public IObservableFactory setFactory() {
82
		return delegate.setFactory();
83
	}
84
85
	public IObservableFactory setFactory(Realm realm) {
86
		return delegate.setFactory(realm);
87
	}
88
89
	public IObservableSet observeDetail(IObservableValue master) {
90
		return new EMFEditObservableSetDecorator(editingDomain,delegate.observeDetail(master),
91
				eStructuralFeature);
92
	}
93
94
	public String toString() {
95
		return delegate.toString();
96
	}
97
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditListPropertyDecorator.java (+96 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.list.IObservableList;
17
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.property.list.IListProperty;
20
import org.eclipse.core.databinding.property.list.ListProperty;
21
import org.eclipse.emf.databinding.FeaturePath;
22
import org.eclipse.emf.databinding.edit.EMFEditProperties;
23
import org.eclipse.emf.databinding.edit.IEMFEditListProperty;
24
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.edit.domain.EditingDomain;
27
28
/**
29
 * @since 3.3
30
 * 
31
 */
32
public class EMFEditListPropertyDecorator extends ListProperty implements
33
		IEMFEditListProperty {
34
	private final IListProperty delegate;
35
	private final EStructuralFeature eStructuralFeature;
36
	private final EditingDomain editingDomain;
37
	
38
	/**
39
	 * @param delegate
40
	 * @param propertyDescriptor
41
	 */
42
	public EMFEditListPropertyDecorator(EditingDomain editingDomain,IListProperty delegate,
43
			EStructuralFeature eStructuralFeature) {
44
		this.delegate = delegate;
45
		this.eStructuralFeature = eStructuralFeature;
46
		this.editingDomain = editingDomain;
47
	}
48
49
	public Object getElementType() {
50
		return delegate.getElementType();
51
	}
52
	
53
	public IEMFEditListProperty values(EStructuralFeature feature) {
54
		return values(FeaturePath.fromList(feature));
55
	}
56
57
	public IEMFEditListProperty values(FeaturePath featurePath) {
58
		return values(EMFEditProperties.value(editingDomain,featurePath));
59
	}
60
61
	public IEMFEditListProperty values(IEMFEditValueProperty property) {
62
		return new EMFEditListPropertyDecorator(editingDomain,super.values(property), property
63
				.getStructuralFeature());
64
	}
65
66
	public EStructuralFeature getStructuralFeature() {
67
		return eStructuralFeature;
68
	}
69
70
	public IObservableList observe(Object source) {
71
		return new EMFEditObservableListDecorator(editingDomain,delegate.observe(source),
72
				eStructuralFeature);
73
	}
74
75
	public IObservableList observe(Realm realm, Object source) {
76
		return new EMFEditObservableListDecorator(editingDomain,delegate.observe(realm, source),
77
				eStructuralFeature);
78
	}
79
80
	public IObservableFactory listFactory() {
81
		return delegate.listFactory();
82
	}
83
84
	public IObservableFactory listFactory(Realm realm) {
85
		return delegate.listFactory(realm);
86
	}
87
88
	public IObservableList observeDetail(IObservableValue master) {
89
		return new EMFEditObservableListDecorator(editingDomain,delegate.observeDetail(master),
90
				eStructuralFeature);
91
	}
92
93
	public String toString() {
94
		return delegate.toString();
95
	}
96
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditValuePropertyDecorator.java (+152 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.list.IObservableList;
17
import org.eclipse.core.databinding.observable.map.IObservableMap;
18
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
19
import org.eclipse.core.databinding.observable.set.IObservableSet;
20
import org.eclipse.core.databinding.observable.value.IObservableValue;
21
import org.eclipse.core.databinding.property.value.IValueProperty;
22
import org.eclipse.core.databinding.property.value.ValueProperty;
23
import org.eclipse.emf.databinding.FeaturePath;
24
import org.eclipse.emf.databinding.edit.EMFEditProperties;
25
import org.eclipse.emf.databinding.edit.IEMFEditListProperty;
26
import org.eclipse.emf.databinding.edit.IEMFEditMapProperty;
27
import org.eclipse.emf.databinding.edit.IEMFEditSetProperty;
28
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
29
import org.eclipse.emf.ecore.EStructuralFeature;
30
import org.eclipse.emf.edit.domain.EditingDomain;
31
32
/**
33
 * @since 3.3
34
 * 
35
 */
36
public class EMFEditValuePropertyDecorator extends ValueProperty implements
37
		IEMFEditValueProperty {
38
	private final IValueProperty delegate;
39
	private final EStructuralFeature eStructuralFeature;
40
	private final EditingDomain editingDomain;
41
42
	/**
43
	 * @param delegate
44
	 * @param propertyDescriptor
45
	 */
46
	public EMFEditValuePropertyDecorator(EditingDomain editingDomain,IValueProperty delegate,
47
			EStructuralFeature eStructuralFeature) {
48
		this.delegate = delegate;
49
		this.eStructuralFeature = eStructuralFeature;
50
		this.editingDomain = editingDomain;
51
	}
52
53
	public EStructuralFeature getStructuralFeature() {
54
		return eStructuralFeature;
55
	}
56
57
	public Object getValueType() {
58
		return delegate.getValueType();
59
	}
60
61
	public IEMFEditValueProperty value(EStructuralFeature feature) {
62
		return value(FeaturePath.fromList(feature));
63
	}
64
	
65
	public IEMFEditValueProperty value(FeaturePath featurePath) {
66
		return value(EMFEditProperties.value(editingDomain,featurePath));
67
	}
68
69
	public IEMFEditValueProperty value(IEMFEditValueProperty property) {
70
		return new EMFEditValuePropertyDecorator(editingDomain,super.value(property), property
71
				.getStructuralFeature());
72
	}
73
74
	public IEMFEditListProperty list(EStructuralFeature feature) {
75
		return list(EMFEditProperties.list(editingDomain,feature));
76
	}
77
78
	public IEMFEditListProperty list(IEMFEditListProperty property) {
79
		return new EMFEditListPropertyDecorator(editingDomain,super.list(property), property
80
				.getStructuralFeature());
81
	}
82
83
	public IEMFEditSetProperty set(EStructuralFeature feature) {
84
		return set(feature, null);
85
	}
86
87
	public IEMFEditSetProperty set(EStructuralFeature feature, Class<?> elementType) {
88
		return set(EMFEditProperties.set(editingDomain,feature, elementType));
89
	}
90
91
	public IEMFEditSetProperty set(IEMFEditSetProperty property) {
92
		return new EMFEditSetPropertyDecorator(editingDomain,super.set(property), property
93
				.getStructuralFeature());
94
	}
95
96
	public IEMFEditMapProperty map(EStructuralFeature feature) {
97
		return map(feature, null, null);
98
	}
99
100
	public IEMFEditMapProperty map(EStructuralFeature feature, Class<?> keyType,
101
			Class<?> valueType) {
102
		return map(EMFEditProperties.map(editingDomain,feature, keyType,
103
				valueType));
104
	}
105
106
	public IEMFEditMapProperty map(IEMFEditMapProperty property) {
107
		return new EMFEditMapPropertyDecorator(editingDomain,super.map(property), property
108
				.getStructuralFeature());
109
	}
110
111
	public IObservableValue observe(Object source) {
112
		return new EMFEditObservableValueDecorator(editingDomain,delegate.observe(source),
113
				eStructuralFeature);
114
	}
115
116
	public IObservableValue observe(Realm realm, Object source) {
117
		return new EMFEditObservableValueDecorator(editingDomain,delegate.observe(realm, source),
118
				eStructuralFeature);
119
	}
120
121
	public IObservableFactory valueFactory() {
122
		return delegate.valueFactory();
123
	}
124
125
	public IObservableFactory valueFactory(Realm realm) {
126
		return delegate.valueFactory(realm);
127
	}
128
129
	public IObservableValue observeDetail(IObservableValue master) {
130
		return new EMFEditObservableValueDecorator(editingDomain,delegate.observeDetail(master),
131
				eStructuralFeature);
132
	}
133
134
	public IObservableList observeDetail(IObservableList master) {
135
		return new EMFEditObservableListDecorator(editingDomain,delegate.observeDetail(master),
136
				eStructuralFeature);
137
	}
138
139
	public IObservableMap observeDetail(IObservableSet master) {
140
		return new EMFEditObservableMapDecorator(editingDomain,delegate.observeDetail(master),
141
				eStructuralFeature);
142
	}
143
144
	public IObservableMap observeDetail(IObservableMap master) {
145
		return new EMFEditObservableMapDecorator(editingDomain,delegate.observeDetail(master),
146
				eStructuralFeature);
147
	}
148
149
	public String toString() {
150
		return delegate.toString();
151
	}
152
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditObservableValueDecorator.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Matthew Hall - bug 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.value.IObservableValue;
16
import org.eclipse.emf.databinding.edit.IEMFEditObservable;
17
import org.eclipse.emf.databinding.internal.EMFObservableValueDecorator;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.edit.domain.EditingDomain;
20
21
/**
22
 * {@link IEMFObservable} decorator for an {@link IObservableValue}.
23
 * 
24
 * @since 3.3
25
 */
26
public class EMFEditObservableValueDecorator extends EMFObservableValueDecorator
27
		implements IEMFEditObservable {
28
	private final EditingDomain editingDomain;
29
	
30
	/**
31
	 * @param decorated
32
	 * @param propertyDescriptor
33
	 */
34
	public EMFEditObservableValueDecorator(EditingDomain editingDomain,IObservableValue decorated,
35
			EStructuralFeature eStructuralFeature) {
36
		super(decorated, eStructuralFeature);
37
		this.editingDomain = editingDomain;
38
	}
39
40
	public EditingDomain getEditingDomain() {
41
		return editingDomain;
42
	}
43
44
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditProperty.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding.edit;
13
14
import org.eclipse.core.databinding.property.IProperty;
15
import org.eclipse.emf.ecore.EStructuralFeature;
16
import org.eclipse.emf.edit.domain.EditingDomain;
17
18
/**
19
 * An IProperty extension interface providing access to details of bean
20
 * properties.
21
 * 
22
 * @since 1.2
23
 * @noextend This interface is not intended to be extended by clients.
24
 * @noimplement This interface is not intended to be implemented by clients.
25
 */
26
public interface IEMFEditProperty extends IProperty {
27
	/**
28
	 * Returns the property descriptor of the bean property being observed. This
29
	 * method returns null in the case of anonymous properties.
30
	 * 
31
	 * @return the property descriptor of the bean property being observed
32
	 */
33
	public EStructuralFeature getStructuralFeature();
34
	
35
	public EditingDomain getEditingDomain();
36
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditObservableListDecorator.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Matthew Hall - bugs 208858, 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.list.IObservableList;
16
import org.eclipse.emf.databinding.edit.IEMFEditObservable;
17
import org.eclipse.emf.databinding.internal.EMFObservableListDecorator;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.edit.domain.EditingDomain;
20
21
/**
22
 * {@link IEMFObservable} decorator for an {@link IObservableList}.
23
 * 
24
 * @since 3.3
25
 */
26
public class EMFEditObservableListDecorator extends EMFObservableListDecorator
27
		implements IEMFEditObservable {
28
	
29
	private final EditingDomain editingDomain;
30
31
	public EMFEditObservableListDecorator(EditingDomain editingDomain, IObservableList decorated,
32
			EStructuralFeature eStructuralFeature) {
33
		super(decorated, eStructuralFeature);
34
		this.editingDomain = editingDomain;
35
	}
36
37
	public EditingDomain getEditingDomain() {
38
		return editingDomain;
39
	}
40
	
41
	
42
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditMapPropertyDecorator.java (+100 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 *     Matthew Hall - bug 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.map.IObservableMap;
17
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.property.map.IMapProperty;
20
import org.eclipse.core.databinding.property.map.MapProperty;
21
import org.eclipse.emf.databinding.FeaturePath;
22
import org.eclipse.emf.databinding.edit.EMFEditProperties;
23
import org.eclipse.emf.databinding.edit.IEMFEditMapProperty;
24
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.edit.domain.EditingDomain;
27
28
/**
29
 * @since 3.3
30
 * 
31
 */
32
public class EMFEditMapPropertyDecorator extends MapProperty implements
33
		IEMFEditMapProperty {
34
	private final IMapProperty delegate;
35
	private final EStructuralFeature eStructuralFeature;
36
	private final EditingDomain editingDomain;
37
38
	/**
39
	 * @param delegate
40
	 * @param propertyDescriptor
41
	 */
42
	public EMFEditMapPropertyDecorator(EditingDomain editingDomain,IMapProperty delegate,
43
			EStructuralFeature eStructuralFeature) {
44
		this.delegate = delegate;
45
		this.eStructuralFeature = eStructuralFeature;
46
		this.editingDomain = editingDomain;
47
	}
48
49
	public EStructuralFeature getStructuralFeature() {
50
		return eStructuralFeature;
51
	}
52
53
	public Object getKeyType() {
54
		return delegate.getKeyType();
55
	}
56
57
	public Object getValueType() {
58
		return delegate.getValueType();
59
	}
60
	
61
	public IEMFEditMapProperty values(EStructuralFeature feature) {
62
		return values(FeaturePath.fromList(feature));
63
	}
64
65
	public IEMFEditMapProperty values(FeaturePath featurePath) {
66
		return values(EMFEditProperties.value(editingDomain,featurePath));
67
	}
68
69
	public IEMFEditMapProperty values(IEMFEditValueProperty property) {
70
		return new EMFEditMapPropertyDecorator(editingDomain,super.values(property), property
71
				.getStructuralFeature());
72
	}
73
74
	public IObservableMap observe(Object source) {
75
		return new EMFEditObservableMapDecorator(editingDomain,delegate.observe(source),
76
				eStructuralFeature);
77
	}
78
79
	public IObservableMap observe(Realm realm, Object source) {
80
		return new EMFEditObservableMapDecorator(editingDomain,delegate.observe(realm, source),
81
				eStructuralFeature);
82
	}
83
84
	public IObservableFactory mapFactory() {
85
		return delegate.mapFactory();
86
	}
87
88
	public IObservableFactory mapFactory(Realm realm) {
89
		return delegate.mapFactory(realm);
90
	}
91
92
	public IObservableMap observeDetail(IObservableValue master) {
93
		return new EMFEditObservableMapDecorator(editingDomain,delegate.observeDetail(master),
94
				eStructuralFeature);
95
	}
96
97
	public String toString() {
98
		return delegate.toString();
99
	}
100
}
(-)src/org/eclipse/emf/databinding/edit/EMFEditProperties.java (+185 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bug 195222, 247997, 261843, 264307
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit;
14
15
import org.eclipse.core.databinding.property.list.IListProperty;
16
import org.eclipse.core.databinding.property.map.IMapProperty;
17
import org.eclipse.core.databinding.property.set.ISetProperty;
18
import org.eclipse.core.databinding.property.value.IValueProperty;
19
import org.eclipse.emf.databinding.FeaturePath;
20
import org.eclipse.emf.databinding.edit.internal.EMFEditListProperty;
21
import org.eclipse.emf.databinding.edit.internal.EMFEditListPropertyDecorator;
22
import org.eclipse.emf.databinding.edit.internal.EMFEditMapProperty;
23
import org.eclipse.emf.databinding.edit.internal.EMFEditMapPropertyDecorator;
24
import org.eclipse.emf.databinding.edit.internal.EMFEditSetProperty;
25
import org.eclipse.emf.databinding.edit.internal.EMFEditSetPropertyDecorator;
26
import org.eclipse.emf.databinding.edit.internal.EMFEditValueProperty;
27
import org.eclipse.emf.databinding.edit.internal.EMFEditValuePropertyDecorator;
28
import org.eclipse.emf.ecore.EStructuralFeature;
29
import org.eclipse.emf.edit.domain.EditingDomain;
30
31
/**
32
 * A factory for creating properties for Java objects that conform to the <a
33
 * href="http://java.sun.com/products/javabeans/docs/spec.html">JavaBean
34
 * specification</a> for bound properties.
35
 * 
36
 * @since 1.2
37
 */
38
public class EMFEditProperties {
39
	public static final boolean DEBUG = false;
40
41
	public static IEMFEditValueProperty value(EditingDomain editingDomain,
42
			EStructuralFeature feature) {
43
		return value(editingDomain, FeaturePath.fromList(feature));
44
	}
45
46
	/**
47
	 * Returns a value property for the given property name of the given bean
48
	 * class.
49
	 * 
50
	 * @param beanClass
51
	 *            the bean class
52
	 * @param propertyName
53
	 *            the property name. May be nested e.g. "parent.name"
54
	 * @param valueType
55
	 *            the value type of the returned value property
56
	 * @return a value property for the given property name of the given bean
57
	 *         class.
58
	 */
59
	public static IEMFEditValueProperty value(EditingDomain editingDomain,
60
			FeaturePath featurePath) {
61
		IValueProperty property;
62
		property = new EMFEditValueProperty(editingDomain, featurePath
63
				.getFeaturePath()[0]);
64
65
		IEMFEditValueProperty beanProperty = new EMFEditValuePropertyDecorator(
66
				editingDomain, property, featurePath.getFeaturePath()[0]);
67
68
		for (int i = 1; i < featurePath.getFeaturePath().length; i++) {
69
			beanProperty = beanProperty.value(featurePath.getFeaturePath()[i]);
70
		}
71
72
		return beanProperty;
73
	}
74
75
	public static IEMFEditValueProperty[] values(EditingDomain editingDomain,
76
			EStructuralFeature... features) {
77
		IEMFEditValueProperty[] properties = new IEMFEditValueProperty[features.length];
78
		for (int i = 0; i < properties.length; i++)
79
			properties[i] = value(editingDomain, features[i]);
80
		return properties;
81
	}
82
83
	/**
84
	 * Returns a value property array for the given property names of the given
85
	 * bean class.
86
	 * 
87
	 * @param beanClass
88
	 *            the bean class
89
	 * @param propertyNames
90
	 *            array of property names. May be nested e.g. "parent.name"
91
	 * @return a value property array for the given property names of the given
92
	 *         bean class.
93
	 */
94
	public static IEMFEditValueProperty[] values(EditingDomain editingDomain,
95
			FeaturePath... featurePaths) {
96
		IEMFEditValueProperty[] properties = new IEMFEditValueProperty[featurePaths.length];
97
		for (int i = 0; i < properties.length; i++)
98
			properties[i] = value(editingDomain, featurePaths[i]);
99
		return properties;
100
	}
101
102
	public static IEMFEditSetProperty set(EditingDomain editingDomain,
103
			EStructuralFeature feature) {
104
		return set(editingDomain, feature, null);
105
	}
106
107
	/**
108
	 * Returns a set property for the given property name of the given bean
109
	 * class.
110
	 * 
111
	 * @param beanClass
112
	 *            the bean class
113
	 * @param propertyName
114
	 *            the property name
115
	 * @param elementType
116
	 *            the element type of the returned set property
117
	 * @return a set property for the given property name of the given bean
118
	 *         class.
119
	 */
120
	public static IEMFEditSetProperty set(EditingDomain editingDomain,
121
			EStructuralFeature feature, Class<?> elementType) {
122
		ISetProperty property;
123
		property = new EMFEditSetProperty(editingDomain, feature, elementType);
124
		return new EMFEditSetPropertyDecorator(editingDomain, property, feature);
125
	}
126
127
	/**
128
	 * Returns a list property for the given property name of the given bean
129
	 * class.
130
	 * 
131
	 * @param beanClass
132
	 *            the bean class
133
	 * @param propertyName
134
	 *            the property name
135
	 * @param elementType
136
	 *            the element type of the returned list property
137
	 * @return a list property for the given property name of the given bean
138
	 *         class.
139
	 */
140
	public static IEMFEditListProperty list(EditingDomain editingDomain,
141
			EStructuralFeature feature) {
142
		IListProperty property;
143
		property = new EMFEditListProperty(editingDomain, feature);
144
		return new EMFEditListPropertyDecorator(editingDomain, property,
145
				feature);
146
	}
147
148
	/**
149
	 * Returns a map property for the given property name of an arbitrary bean
150
	 * class. Objects lacking the named property are treated the same as if the
151
	 * property always contains an empty map.
152
	 * 
153
	 * @param propertyName
154
	 *            the property name
155
	 * @return a map property for the given property name of an arbitrary bean
156
	 *         class.
157
	 */
158
	public static IEMFEditMapProperty map(EditingDomain editingDomain,
159
			EStructuralFeature feature) {
160
		return map(editingDomain, feature, null, null);
161
	}
162
163
	/**
164
	 * Returns a map property for the given property name of the given bean
165
	 * class.
166
	 * 
167
	 * @param beanClass
168
	 *            the bean class
169
	 * @param propertyName
170
	 *            the property name
171
	 * @param keyType
172
	 *            the key type for the returned map property
173
	 * @param valueType
174
	 *            the value type for the returned map property
175
	 * @return a map property for the given property name of the given bean
176
	 *         class.
177
	 */
178
	public static IEMFEditMapProperty map(EditingDomain editingDomain,
179
			EStructuralFeature feature, Class<?> keyType, Class<?> valueType) {
180
		IMapProperty property;
181
		property = new EMFEditMapProperty(editingDomain, feature, keyType,
182
				valueType);
183
		return new EMFEditMapPropertyDecorator(editingDomain, property, feature);
184
	}
185
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditSetProperty.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding.edit;
13
14
import org.eclipse.core.databinding.property.set.ISetProperty;
15
import org.eclipse.emf.databinding.FeaturePath;
16
import org.eclipse.emf.databinding.IEMFProperty;
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
19
/**
20
 * An {@link ISetProperty} extension interface with convenience methods for
21
 * creating nested bean properties.
22
 * 
23
 * @since 1.2
24
 * @noextend This interface is not intended to be extended by clients.
25
 * @noimplement This interface is not intended to be implemented by clients.
26
 */
27
public interface IEMFEditSetProperty extends IEMFProperty, ISetProperty {
28
	/**
29
	 * Returns a master-detail combination of this property and the specified
30
	 * value property.
31
	 * 
32
	 * @param propertyName
33
	 *            the value property to observe. May be nested e.g.
34
	 *            "parent.name"
35
	 * @return a master-detail combination of this property and the specified
36
	 *         value property.
37
	 * @see #values(IEMFEditValueProperty)
38
	 */
39
	public IEMFEditMapProperty values(FeaturePath featurePath);
40
	
41
	public IEMFEditMapProperty values(EStructuralFeature feature);
42
43
	/**
44
	 * Returns a master-detail combination of this property and the specified
45
	 * value property. The returned property will observe the specified value
46
	 * property for all elements observed by this set property, mapping from
47
	 * this set property's elements (keys) to the specified value property's
48
	 * value for each element (values).
49
	 * <p>
50
	 * Example:
51
	 * 
52
	 * <pre>
53
	 * // Observes the set-typed &quot;children&quot; property of a Person object,
54
	 * // where the elements are Person objects
55
	 * IBeanSetProperty children = BeanProperties.set(Person.class, &quot;children&quot;,
56
	 * 		Person.class);
57
	 * // Observes the string-typed &quot;name&quot; property of a Person object
58
	 * IBeanValueProperty name = BeanProperties.value(Person.class, &quot;name&quot;);
59
	 * // Observes a map of children objects to their respective names.
60
	 * IBeanMapProperty childrenNames = children.values(name);
61
	 * </pre>
62
	 * 
63
	 * @param property
64
	 *            the detail property to observe
65
	 * @return a master-detail combination of this property and the specified
66
	 *         value property.
67
	 */
68
	public IEMFEditMapProperty values(IEMFEditValueProperty property);
69
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditValueProperty.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bug 195222, 264307, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.emf.common.command.Command;
16
import org.eclipse.emf.databinding.internal.EMFValueProperty;
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.edit.command.SetCommand;
20
import org.eclipse.emf.edit.domain.EditingDomain;
21
22
/**
23
 * @since 3.3
24
 * 
25
 */
26
public class EMFEditValueProperty extends EMFValueProperty {
27
	private final EditingDomain editingDomain;
28
29
	public EMFEditValueProperty(EditingDomain editingDomain, EStructuralFeature eStructuralFeature) {
30
		super(eStructuralFeature);
31
		this.editingDomain = editingDomain;
32
	}
33
	
34
	
35
	
36
	@Override
37
	protected void doSetValue(Object source, Object value) {
38
		EObject eObject = (EObject) source;
39
		Command command = SetCommand.create(editingDomain, eObject, getFeature(), value);
40
		editingDomain.getCommandStack().execute(command);
41
	}
42
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditValueProperty.java (+209 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 195222)
10
 ******************************************************************************/
11
12
package org.eclipse.emf.databinding.edit;
13
14
import org.eclipse.core.databinding.property.value.IValueProperty;
15
import org.eclipse.emf.databinding.FeaturePath;
16
import org.eclipse.emf.databinding.IEMFProperty;
17
import org.eclipse.emf.ecore.EStructuralFeature;
18
19
/**
20
 * An {@link IValueProperty} extension interface with convenience methods for
21
 * creating nested bean properties.
22
 * 
23
 * @since 1.2
24
 * @noextend This interface is not intended to be extended by clients.
25
 * @noimplement This interface is not intended to be implemented by clients.
26
 */
27
public interface IEMFEditValueProperty extends IEMFProperty, IValueProperty {
28
	/**
29
	 * Returns a master-detail combination of this property and the specified
30
	 * value property.
31
	 * 
32
	 * @param propertyName
33
	 *            the value property to observe. May be nested e.g.
34
	 *            "parent.name"
35
	 * @return a master-detail combination of this property and the specified
36
	 *         value property.
37
	 * @see #value(IEMFEditValueProperty)
38
	 */
39
	public IEMFEditValueProperty value(FeaturePath featurePath);
40
41
	public IEMFEditValueProperty value(EStructuralFeature feature);
42
	
43
	/**
44
	 * Returns a master-detail combination of this property and the specified
45
	 * value property. The returned property will observe the specified detail
46
	 * value property for the value of the master value property.
47
	 * <p>
48
	 * Example:
49
	 * 
50
	 * <pre>
51
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object
52
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
53
	 * // Observes the string-typed &quot;name&quot; property of a Node object
54
	 * IBeanValueProperty name = BeanProperties.value(Node.class, &quot;name&quot;);
55
	 * // Observes the name of the parent of a Node object.
56
	 * IBeanValueProperty parentName = parent.value(name);
57
	 * </pre>
58
	 * 
59
	 * @param property
60
	 *            the detail property to observe
61
	 * @return a master-detail combination of this property and the specified
62
	 *         value property.
63
	 */
64
	public IEMFEditValueProperty value(IEMFEditValueProperty property);
65
66
	/**
67
	 * Returns a master-detail combination of this property and the specified
68
	 * list property.
69
	 * 
70
	 * @param propertyName
71
	 *            the list property to observe
72
	 * @return a master-detail combination of this property and the specified
73
	 *         list property.
74
	 * @see #list(IEMFEditListProperty)
75
	 */
76
	public IEMFEditListProperty list(EStructuralFeature feature);
77
78
	/**
79
	 * Returns a master-detail combination of this property and the specified
80
	 * list property. The returned property will observe the specified list
81
	 * property for the value of the master property.
82
	 * <p>
83
	 * Example:
84
	 * 
85
	 * <pre>
86
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object.
87
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
88
	 * // Observes the List-typed &quot;children&quot; property of a Node object
89
	 * // where the elements are Node objects
90
	 * IBeanListProperty children = BeanProperties.list(Node.class, &quot;children&quot;,
91
	 * 		Node.class);
92
	 * // Observes the children of the parent (siblings) of a Node object.
93
	 * IBeanListProperty siblings = parent.list(children);
94
	 * </pre>
95
	 * 
96
	 * @param property
97
	 *            the detail property to observe
98
	 * @return a master-detail combination of this property and the specified
99
	 *         list property.
100
	 */
101
	public IEMFEditListProperty list(IEMFEditListProperty property);
102
103
	/**
104
	 * Returns a master-detail combination of this property and the specified
105
	 * set property.
106
	 * 
107
	 * @param propertyName
108
	 *            the set property to observe
109
	 * @return a master-detail combination of this property and the specified
110
	 *         set property.
111
	 * @see #set(IEMFEditSetProperty)
112
	 */
113
	public IEMFEditSetProperty set(EStructuralFeature feature);
114
115
	/**
116
	 * Returns a master-detail combination of this property and the specified
117
	 * set property.
118
	 * 
119
	 * @param propertyName
120
	 *            the set property to observe
121
	 * @param elementType
122
	 *            the element type of the named property
123
	 * @return a master-detail combination of this property and the specified
124
	 *         set property.
125
	 * @see #set(IEMFEditSetProperty)
126
	 */
127
	public IEMFEditSetProperty set(EStructuralFeature feature, Class<?> elementType);
128
129
	/**
130
	 * Returns a master-detail combination of this property and the specified
131
	 * set property. The returned property will observe the specified set
132
	 * property for the value of the master property.
133
	 * <p>
134
	 * Example:
135
	 * 
136
	 * <pre>
137
	 * // Observes the Node-typed &quot;parent&quot; property of a Node object.
138
	 * IBeanValueProperty parent = BeanProperties.value(Node.class, &quot;parent&quot;);
139
	 * // Observes the Set-typed &quot;children&quot; property of a Node object
140
	 * // where the elements are Node objects
141
	 * IBeanSetProperty children = BeanProperties.set(Node.class, &quot;children&quot;,
142
	 * 		Node.class);
143
	 * // Observes the children of the parent (siblings) of a Node object.
144
	 * IBeanSetProperty siblings = parent.set(children);
145
	 * </pre>
146
	 * 
147
	 * @param property
148
	 *            the detail property to observe
149
	 * @return a master-detail combination of this property and the specified
150
	 *         set property.
151
	 */
152
	public IEMFEditSetProperty set(IEMFEditSetProperty property);
153
154
	/**
155
	 * Returns a master-detail combination of this property and the specified
156
	 * map property.
157
	 * 
158
	 * @param propertyName
159
	 *            the map property to observe
160
	 * @return a master-detail combination of this property and the specified
161
	 *         map property.
162
	 * @see #map(IEMFEditMapProperty)
163
	 */
164
	public IEMFEditMapProperty map(EStructuralFeature feature);
165
166
	/**
167
	 * Returns a master-detail combination of this property and the specified
168
	 * map property.
169
	 * 
170
	 * @param propertyName
171
	 *            the map property to observe
172
	 * @param keyType
173
	 *            the key type of the named property
174
	 * @param valueType
175
	 *            the value type of the named property
176
	 * @return a master-detail combination of this property and the specified
177
	 *         map property.
178
	 * @see #map(IEMFEditMapProperty)
179
	 */
180
	public IEMFEditMapProperty map(EStructuralFeature feature, Class<?> keyType,
181
			Class<?> valueType);
182
183
	/**
184
	 * Returns a master-detail combination of this property and the specified
185
	 * map property. The returned property will observe the specified map
186
	 * property for the value of the master property.
187
	 * <p>
188
	 * Example:
189
	 * 
190
	 * <pre>
191
	 * // Observes the Contact-typed &quot;supervisor&quot; property of a
192
	 * // Contact class 
193
	 * IBeanValueProperty supervisor = BeanProperties.value(Contact.class,
194
	 * 		&quot;supervisor&quot;);
195
	 * // Observes the property &quot;phoneNumbers&quot; of a Contact object--a property mapping
196
	 * // from PhoneNumberType to PhoneNumber &quot;set-typed &quot;children&quot;,
197
	 * IBeanMapProperty phoneNumbers = BeanProperties.map(Contact.class,
198
	 * 		&quot;phoneNumbers&quot;, PhoneNumberType.class, PhoneNumber.class);
199
	 * // Observes the phone numbers of a contact's supervisor:
200
	 * IBeanMapProperty supervisorPhoneNumbers = supervisor.map(phoneNumbers);
201
	 * </pre>
202
	 * 
203
	 * @param property
204
	 *            the detail property to observe
205
	 * @return a master-detail combination of this property and the specified
206
	 *         map property.
207
	 */
208
	public IEMFEditMapProperty map(IEMFEditMapProperty property);
209
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditListProperty.java (+75 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Matthew Hall and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Matthew Hall - initial API and implementation (bug 194734)
10
 *     Matthew Hall - bugs 195222, 264307, 265561
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import java.util.List;
16
17
import org.eclipse.core.databinding.observable.list.ListDiff;
18
import org.eclipse.core.databinding.observable.list.ListDiffVisitor;
19
import org.eclipse.emf.common.command.Command;
20
import org.eclipse.emf.databinding.internal.EMFListProperty;
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.emf.ecore.EStructuralFeature;
23
import org.eclipse.emf.edit.command.AddCommand;
24
import org.eclipse.emf.edit.command.RemoveCommand;
25
import org.eclipse.emf.edit.domain.EditingDomain;
26
27
/**
28
 * @since 3.3
29
 * 
30
 */
31
public class EMFEditListProperty extends EMFListProperty {
32
	private final EditingDomain editingDomain;
33
34
	public EMFEditListProperty(EditingDomain editingDomain,
35
			EStructuralFeature eStructuralFeature) {
36
		super(eStructuralFeature);
37
		this.editingDomain = editingDomain;
38
	}
39
40
	@SuppressWarnings("unchecked")
41
	@Override
42
	protected void doSetList(Object source, List list, ListDiff diff) {
43
		diff.accept(new ListVisitorImpl((EObject) source, getFeature()));
44
	}
45
46
	private class ListVisitorImpl extends ListDiffVisitor {
47
		private EObject eObj;
48
		private EStructuralFeature feature;
49
50
		private ListVisitorImpl(EObject eObj, EStructuralFeature feature) {
51
			this.eObj = eObj;
52
			this.feature = feature;
53
		}
54
55
		@Override
56
		public void handleAdd(int index, Object element) {
57
			execute(AddCommand.create(editingDomain, eObj, feature, element,
58
					index));
59
		}
60
61
		@Override
62
		public void handleRemove(int index, Object element) {
63
			execute(RemoveCommand.create(editingDomain, eObj, feature, element));
64
		}
65
66
		private boolean execute(Command command) {
67
			if (command.canExecute()) {
68
				editingDomain.getCommandStack().execute(command);
69
				return true;
70
			} else {
71
				return false;
72
			}
73
		}
74
	}
75
}
(-)src/org/eclipse/emf/databinding/edit/internal/EMFEditObservableSetDecorator.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 *     Matthew Hall - bug 246625
11
 ******************************************************************************/
12
13
package org.eclipse.emf.databinding.edit.internal;
14
15
import org.eclipse.core.databinding.observable.set.IObservableSet;
16
import org.eclipse.emf.databinding.edit.IEMFEditObservable;
17
import org.eclipse.emf.databinding.internal.EMFObservableSetDecorator;
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
import org.eclipse.emf.edit.domain.EditingDomain;
20
21
/**
22
 * {@link IEMFObservable} decorator for an {@link IObservableSet}.
23
 * 
24
 * @since 3.3
25
 */
26
public class EMFEditObservableSetDecorator extends EMFObservableSetDecorator
27
		implements IEMFEditObservable {
28
	private final EditingDomain editingDomain;
29
	
30
	/**
31
	 * @param decorated
32
	 * @param propertyDescriptor
33
	 */
34
	public EMFEditObservableSetDecorator(EditingDomain editingDomain,IObservableSet decorated,
35
			EStructuralFeature eStructuralFeature) {
36
		super(decorated, eStructuralFeature);
37
		this.editingDomain = editingDomain;
38
	}
39
40
	public EditingDomain getEditingDomain() {
41
		return editingDomain;
42
	}
43
44
}

Return to bug 262160