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

(-)src/org/eclipse/emf/databinding/EMFUpdateListStrategy.java (-7 / +27 lines)
Lines 23-49 Link Here
23
import org.eclipse.emf.ecore.EDataType;
23
import org.eclipse.emf.ecore.EDataType;
24
import org.eclipse.emf.ecore.EFactory;
24
import org.eclipse.emf.ecore.EFactory;
25
25
26
26
/**
27
/**
27
 * PROVISIONAL
28
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
28
 * This API is subject to arbitrary change, including renaming or removal.
29
 */
29
 */
30
public class EMFUpdateListStrategy extends UpdateListStrategy
30
public class EMFUpdateListStrategy extends UpdateListStrategy
31
{
31
{
32
  /**
33
   * A list update strategy with default update policy
34
   * {@link UpdateListStrategy#POLICY_UPDATE} and default converters and
35
   * validators
36
   */
32
  public EMFUpdateListStrategy()
37
  public EMFUpdateListStrategy()
33
  {
38
  {
34
    this(true, POLICY_UPDATE);
39
    this(true, POLICY_UPDATE);
35
  }
40
  }
36
41
42
  /**
43
   * A list update strategy with a specific update policy but with default
44
   * converters and validators
45
   * 
46
   * @param updatePolicy
47
   *            the policy
48
   */
37
  public EMFUpdateListStrategy(int updatePolicy)
49
  public EMFUpdateListStrategy(int updatePolicy)
38
  {
50
  {
39
    this(true, updatePolicy);
51
    this(true, updatePolicy);
40
  }
52
  }
41
53
54
  /**
55
   * A list update strategy with a specific update policy and with the
56
   * possibility to turn of default converters and validators
57
   * 
58
   * @param provideDefaults
59
   *            <code>false</code> to turn of default converters and
60
   *            validators
61
   * @param updatePolicy
62
   *            the policy
63
   */
42
  public EMFUpdateListStrategy(boolean provideDefaults, int updatePolicy)
64
  public EMFUpdateListStrategy(boolean provideDefaults, int updatePolicy)
43
  {
65
  {
44
    super(provideDefaults, updatePolicy);
66
    super(provideDefaults, updatePolicy);
45
  }
67
  }
46
  
68
47
  @Override
69
  @Override
48
  protected IConverter createConverter(Object fromType, Object toType)
70
  protected IConverter createConverter(Object fromType, Object toType)
49
  {
71
  {
Lines 54-61 Link Here
54
        final EAttribute eAttribute = (EAttribute)toType;
76
        final EAttribute eAttribute = (EAttribute)toType;
55
        final EDataType eDataType = eAttribute.getEAttributeType();
77
        final EDataType eDataType = eAttribute.getEAttributeType();
56
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
78
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
57
        return
79
        return new Converter(fromType, toType)
58
          new Converter(fromType, toType)
59
          {
80
          {
60
            public Object convert(Object fromObject)
81
            public Object convert(Object fromObject)
61
            {
82
            {
Lines 71-78 Link Here
71
        final EAttribute eAttribute = (EAttribute)fromType;
92
        final EAttribute eAttribute = (EAttribute)fromType;
72
        final EDataType eDataType = eAttribute.getEAttributeType();
93
        final EDataType eDataType = eAttribute.getEAttributeType();
73
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
94
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
74
        return
95
        return new Converter(fromType, toType)
75
          new Converter(fromType, toType)
76
          {
96
          {
77
            public Object convert(Object fromObject)
97
            public Object convert(Object fromObject)
78
            {
98
            {
(-)src/org/eclipse/emf/databinding/DataBindingPlugin.java (-1 / +3 lines)
Lines 20-26 Link Here
20
20
21
import org.eclipse.emf.common.util.ResourceLocator;
21
import org.eclipse.emf.common.util.ResourceLocator;
22
22
23
23
/**
24
/**
25
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
24
 * This is the central singleton for the Data Binding plugin.
26
 * This is the central singleton for the Data Binding plugin.
25
 */
27
 */
26
public final class DataBindingPlugin extends EMFPlugin
28
public final class DataBindingPlugin extends EMFPlugin
Lines 40-46 Link Here
40
   */
42
   */
41
  public DataBindingPlugin()
43
  public DataBindingPlugin()
42
  {
44
  {
43
    super(new ResourceLocator [] {});
45
    super(new ResourceLocator []{});
44
  }
46
  }
45
47
46
  /**
48
  /**
(-)src/org/eclipse/emf/databinding/EObjectObservableValue.java (-13 / +40 lines)
Lines 26-47 Link Here
26
import org.eclipse.emf.common.notify.impl.AdapterImpl;
26
import org.eclipse.emf.common.notify.impl.AdapterImpl;
27
import org.eclipse.emf.ecore.EObject;
27
import org.eclipse.emf.ecore.EObject;
28
import org.eclipse.emf.ecore.EStructuralFeature;
28
import org.eclipse.emf.ecore.EStructuralFeature;
29
import org.eclipse.emf.ecore.util.ExtendedMetaData;
30
29
31
30
/**
32
/**
31
 * PROVISIONAL
33
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
32
 * This API is subject to arbitrary change, including renaming or removal.
34
 * @deprecated do not use this value it will be removed in 2.6
33
 */
35
 */
34
public class EObjectObservableValue extends AbstractObservableValue implements IObserving
36
public class EObjectObservableValue extends AbstractObservableValue implements IObserving
35
{
37
{
38
  /**
39
   * The object instance
40
   */
36
  protected EObject eObject;
41
  protected EObject eObject;
42
  /**
43
   * The feature
44
   */
37
  protected EStructuralFeature eStructuralFeature;
45
  protected EStructuralFeature eStructuralFeature;
46
  /**
47
   * The listener
48
   */
38
  protected Adapter listener;
49
  protected Adapter listener;
39
50
51
  /**
52
   * Observe a feature of the instance using the default realm
53
   * 
54
   * @param eObject
55
   *            the object
56
   * @param eStructuralFeature
57
   *            the feature
58
   */
40
  public EObjectObservableValue(EObject eObject, EStructuralFeature eStructuralFeature)
59
  public EObjectObservableValue(EObject eObject, EStructuralFeature eStructuralFeature)
41
  {
60
  {
42
    this(Realm.getDefault(), eObject, eStructuralFeature);
61
    this(Realm.getDefault(), eObject, eStructuralFeature);
43
  }
62
  }
44
63
64
  /**
65
   * Observe a feature of the instance using the realm
66
   * 
67
   * @param realm
68
   * 
69
   * @param eObject
70
   *            the object
71
   * @param eStructuralFeature
72
   *            the feature
73
   */
45
  public EObjectObservableValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
74
  public EObjectObservableValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
46
  {
75
  {
47
    super(realm);
76
    super(realm);
Lines 70-77 Link Here
70
  @Override
99
  @Override
71
  protected void firstListenerAdded()
100
  protected void firstListenerAdded()
72
  {
101
  {
73
    listener =
102
    listener = new AdapterImpl()
74
      new AdapterImpl()
75
      {
103
      {
76
        @Override
104
        @Override
77
        public void notifyChanged(Notification notification)
105
        public void notifyChanged(Notification notification)
Lines 79-92 Link Here
79
          if (eStructuralFeature == notification.getFeature() && !notification.isTouch())
107
          if (eStructuralFeature == notification.getFeature() && !notification.isTouch())
80
          {
108
          {
81
            final ValueDiff diff = Diffs.createValueDiff(notification.getOldValue(), notification.getNewValue());
109
            final ValueDiff diff = Diffs.createValueDiff(notification.getOldValue(), notification.getNewValue());
82
            getRealm().exec
110
            getRealm().exec(new Runnable()
83
              (new Runnable()
111
              {
84
               {
112
                public void run()
85
                 public void run()
113
                {
86
                 {
114
                  fireValueChange(diff);
87
                   fireValueChange(diff);
115
                }
88
                 }
116
              });
89
               });
90
          }
117
          }
91
        }
118
        }
92
      };
119
      };
Lines 103-109 Link Here
103
  @Override
130
  @Override
104
  protected Object doGetValue()
131
  protected Object doGetValue()
105
  {
132
  {
106
    return eObject.eGet(eStructuralFeature);
133
    return ExtendedMetaData.INSTANCE.getAffiliation(eObject.eClass(), eStructuralFeature) == null ? null : eObject.eGet(eStructuralFeature);
107
  }
134
  }
108
135
109
  @Override
136
  @Override
(-)src/org/eclipse/emf/databinding/EMFDataBindingContext.java (-3 / +14 lines)
Lines 21-37 Link Here
21
import org.eclipse.core.databinding.observable.Realm;
21
import org.eclipse.core.databinding.observable.Realm;
22
import org.eclipse.core.databinding.observable.value.IObservableValue;
22
import org.eclipse.core.databinding.observable.value.IObservableValue;
23
23
24
24
/**
25
/**
25
 * PROVISIONAL
26
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
26
 * This API is subject to arbitrary change, including renaming or removal.
27
 */
27
 */
28
public class EMFDataBindingContext extends DataBindingContext
28
public class EMFDataBindingContext extends DataBindingContext
29
{
29
{
30
  /**
31
   * Create a new databinding context which uses the default realm for
32
   * validation
33
   */
30
  public EMFDataBindingContext()
34
  public EMFDataBindingContext()
31
  {
35
  {
32
    this(Realm.getDefault());
36
    this(Realm.getDefault());
33
  }
37
  }
34
38
39
  /**
40
   * Create a databinding context which uses an explicit realm for
41
   * validation
42
   * 
43
   * @param validationRealm
44
   *            the realm to use
45
   */
35
  public EMFDataBindingContext(Realm validationRealm)
46
  public EMFDataBindingContext(Realm validationRealm)
36
  {
47
  {
37
    super(validationRealm);
48
    super(validationRealm);
Lines 42-48 Link Here
42
  {
53
  {
43
    return new EMFUpdateValueStrategy();
54
    return new EMFUpdateValueStrategy();
44
  }
55
  }
45
  
56
46
  @Override
57
  @Override
47
  protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(IObservableValue fromValue, IObservableValue toValue)
58
  protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(IObservableValue fromValue, IObservableValue toValue)
48
  {
59
  {
(-)src/org/eclipse/emf/databinding/EMFObservables.java (-11 / +32 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-37 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;
33
31
34
32
/**
35
/**
33
 * PROVISIONAL
36
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
34
 * This API is subject to arbitrary change, including renaming or removal.
35
 */
37
 */
36
public class EMFObservables
38
public class EMFObservables
37
{
39
{
Lines 40-45 Link Here
40
   * @param eObject the object to observe.
42
   * @param eObject the object to observe.
41
   * @param eStructuralFeature the feature of the object to observe.
43
   * @param eStructuralFeature the feature of the object to observe.
42
   * @return an observable value for the given feature of the object.
44
   * @return an observable value for the given feature of the object.
45
   * @deprecated you should use {@link EMFProperties#value(FeaturePath)} and {@link IEMFValueProperty#observe(Object)}
43
   */
46
   */
44
  public static IObservableValue observeValue(EObject eObject, EStructuralFeature eStructuralFeature)
47
  public static IObservableValue observeValue(EObject eObject, EStructuralFeature eStructuralFeature)
45
  {
48
  {
Lines 52-57 Link Here
52
   * @param eObject the object to observe.
55
   * @param eObject the object to observe.
53
   * @param eStructuralFeature the feature of the object to observe.
56
   * @param eStructuralFeature the feature of the object to observe.
54
   * @return an observable value for the given feature of the object.
57
   * @return an observable value for the given feature of the object.
58
   * @deprecated you should use {@link EMFProperties#value(EStructuralFeature)} and {@link IEMFValueProperty#observe(Realm, Object)}
55
   */
59
   */
56
  public static IObservableValue observeValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
60
  public static IObservableValue observeValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
57
  {
61
  {
Lines 63-68 Link Here
63
   * @param eObject the object to observe.
67
   * @param eObject the object to observe.
64
   * @param eStructuralFeature the feature of the object to observe.
68
   * @param eStructuralFeature the feature of the object to observe.
65
   * @return an observable list for the given multi-valued feature of the object.
69
   * @return an observable list for the given multi-valued feature of the object.
70
   * @deprecated you should use {@link EMFProperties#list(EStructuralFeature)} and {@link IEMFListProperty#observe(Object)}
66
   */
71
   */
67
  public static IObservableList observeList(EObject eObject, EStructuralFeature eStructuralFeature)
72
  public static IObservableList observeList(EObject eObject, EStructuralFeature eStructuralFeature)
68
  {
73
  {
Lines 75-80 Link Here
75
   * @param eObject the object to observe.
80
   * @param eObject the object to observe.
76
   * @param eStructuralFeature the feature of the object to observe.
81
   * @param eStructuralFeature the feature of the object to observe.
77
   * @return an observable list for the given multi-valued feature of the object.
82
   * @return an observable list for the given multi-valued feature of the object.
83
   * @deprecated you should use {@link EMFProperties#list(EStructuralFeature)} and {@link IEMFListProperty#observe(Realm,Object)}
78
   */
84
   */
79
  public static IObservableList observeList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
85
  public static IObservableList observeList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
80
  {
86
  {
Lines 87-92 Link Here
87
   * @param objects the objects to track.
93
   * @param objects the objects to track.
88
   * @param eStructuralFeature the feature for which to track the value.
94
   * @param eStructuralFeature the feature for which to track the value.
89
   * @return an observable map tracking the current value of the given feature for each object in the given set.
95
   * @return an observable map tracking the current value of the given feature for each object in the given set.
96
   * @deprecated you should use {@link EMFProperties#value(EStructuralFeature)} and {@link IEMFValueProperty#observeDetail(IObservableSet)}
90
   */
97
   */
91
  public static IObservableMap observeMap(IObservableSet objects, EStructuralFeature eStructuralFeature)
98
  public static IObservableMap observeMap(IObservableSet objects, EStructuralFeature eStructuralFeature)
92
  {
99
  {
Lines 99-104 Link Here
99
   * @param objects the objects to track.
106
   * @param objects the objects to track.
100
   * @param eStructuralFeatures the features for which to track the value.
107
   * @param eStructuralFeatures the features for which to track the value.
101
   * @return an array of observable maps tracking the current value of the given features for each object in the given set.
108
   * @return an array of observable maps tracking the current value of the given features for each object in the given set.
109
   * @deprecated you should use {@link EMFProperties#values(EStructuralFeature...)} and {@link IEMFValueProperty#observeDetail(IObservableSet)}
102
   */
110
   */
103
  public static IObservableMap[] observeMaps(IObservableSet objects, EStructuralFeature[] eStructuralFeatures)
111
  public static IObservableMap[] observeMaps(IObservableSet objects, EStructuralFeature[] eStructuralFeatures)
104
  {
112
  {
Lines 117-122 Link Here
117
   * @param eStructuralFeature the feature for which to track the value.
125
   * @param eStructuralFeature the feature for which to track the value.
118
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
126
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
119
   * @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object)
127
   * @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object)
128
   * @deprecated you should use {@link EMFProperties#value(EStructuralFeature)} and {@link IEMFValueProperty#observeDetail(IObservableValue)}
120
   */
129
   */
121
  public static IObservableValue observeDetailValue(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
130
  public static IObservableValue observeDetailValue(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
122
  {
131
  {
Lines 132-139 Link Here
132
   */
141
   */
133
  public static IObservableFactory valueFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
142
  public static IObservableFactory valueFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
134
  {
143
  {
135
    return 
144
    return new IObservableFactory()
136
      new IObservableFactory()
137
      {
145
      {
138
        public IObservable createObservable(Object target)
146
        public IObservable createObservable(Object target)
139
        {
147
        {
Lines 149-154 Link Here
149
   * @param eStructuralFeature the feature for which to track the value.
157
   * @param eStructuralFeature the feature for which to track the value.
150
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
158
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
151
   * @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object)
159
   * @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object)
160
   * @deprecated you should use {@link EMFProperties#value(EStructuralFeature)} and {@link IEMFValueProperty#observeDetail(IObservableList)}
152
   */
161
   */
153
  public static IObservableList observeDetailList(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
162
  public static IObservableList observeDetailList(Realm realm, IObservableValue value, EStructuralFeature eStructuralFeature)
154
  {
163
  {
Lines 164-171 Link Here
164
   */
173
   */
165
  public static IObservableFactory listFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
174
  public static IObservableFactory listFactory(final Realm realm, final EStructuralFeature eStructuralFeature)
166
  {
175
  {
167
    return 
176
    return new IObservableFactory()
168
      new IObservableFactory()
169
      {
177
      {
170
        public IObservable createObservable(Object target)
178
        public IObservable createObservable(Object target)
171
        {
179
        {
Lines 173-179 Link Here
173
        }
181
        }
174
      };
182
      };
175
  }
183
  }
176
  
184
177
  /**
185
  /**
178
   * Returns a factory for creating observable maps
186
   * Returns a factory for creating observable maps
179
   * tracking the value of the given feature of a particular {@link EObject object}.
187
   * tracking the value of the given feature of a particular {@link EObject object}.
Lines 182-194 Link Here
182
   */
190
   */
183
  public static IObservableFactory mapFactory(final EStructuralFeature eStructuralFeature)
191
  public static IObservableFactory mapFactory(final EStructuralFeature eStructuralFeature)
184
  {
192
  {
185
    return
193
    return new IObservableFactory()
186
      new IObservableFactory()
187
      {
194
      {
188
        public IObservable createObservable(Object target)
195
        public IObservable createObservable(Object target)
189
        {
196
        {
190
          return observeMap((IObservableSet)target, eStructuralFeature);
197
          return observeMap((IObservableSet)target, eStructuralFeature);
191
        }
198
        }
192
      };
199
      };
193
   }
200
  }
201
202
  /**
203
  	 * Returns an observable for the resource contents (
204
  	 * {@link Resource#getContents()})
205
  	 * 
206
  	 * @param resource
207
  	 *            the resources the content should be observed
208
  	 * @return an observable list
209
  	 */
210
  public static IObservableList observeResourceContents(Resource resource)
211
  {
212
    return new EWritableList<EObject>((NotifyingList<EObject>)resource.getContents());
213
  }
214
194
}
215
}
(-)src/org/eclipse/emf/databinding/EObjectObservableList.java (-33 / +57 lines)
Lines 32-55 Link Here
32
import org.eclipse.emf.ecore.EObject;
32
import org.eclipse.emf.ecore.EObject;
33
import org.eclipse.emf.ecore.EStructuralFeature;
33
import org.eclipse.emf.ecore.EStructuralFeature;
34
34
35
35
/**
36
/**
36
 * PROVISIONAL
37
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
37
 * This API is subject to arbitrary change, including renaming or removal.
38
 * @deprecated do not use this list it will be removed in 2.6
38
 */
39
 */
39
public class EObjectObservableList extends ObservableList implements IObserving, InternalRawEList
40
public class EObjectObservableList extends ObservableList implements IObserving, InternalRawEList
40
{
41
{
42
  /**
43
   * The object owning the feature
44
   */
41
  protected EObject eObject;
45
  protected EObject eObject;
46
  /**
47
   * The structural feature
48
   */
42
  protected EStructuralFeature eStructuralFeature;
49
  protected EStructuralFeature eStructuralFeature;
50
  /**
51
   * The listener attached
52
   */
43
  protected Adapter listener;
53
  protected Adapter listener;
44
54
55
  /**
56
   * Observe a list feature using a default realm
57
   * 
58
   * @param eObject
59
   *            the object instance
60
   * @param eStructuralFeature
61
   *            the feature
62
   */
45
  public EObjectObservableList(EObject eObject, EStructuralFeature eStructuralFeature)
63
  public EObjectObservableList(EObject eObject, EStructuralFeature eStructuralFeature)
46
  {
64
  {
47
    this(Realm.getDefault(), eObject, eStructuralFeature);
65
    this(Realm.getDefault(), eObject, eStructuralFeature);
48
  }
66
  }
49
67
68
  /**
69
   * Observe a list feature using a custom realm
70
   * 
71
   * @param realm
72
   *            the realm
73
   * 
74
   * @param eObject
75
   *            the object instance
76
   * @param eStructuralFeature
77
   *            the feature
78
   */
50
  public EObjectObservableList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
79
  public EObjectObservableList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature)
51
  {
80
  {
52
    super(realm, (EList<?>)eObject.eGet(eStructuralFeature), eStructuralFeature);
81
    super(realm, (EList< ? >)eObject.eGet(eStructuralFeature), eStructuralFeature);
53
    this.eObject = eObject;
82
    this.eObject = eObject;
54
    this.eStructuralFeature = eStructuralFeature;
83
    this.eStructuralFeature = eStructuralFeature;
55
  }
84
  }
Lines 57-64 Link Here
57
  @Override
86
  @Override
58
  protected void firstListenerAdded()
87
  protected void firstListenerAdded()
59
  {
88
  {
60
    listener =
89
    listener = new AdapterImpl()
61
      new AdapterImpl()
62
      {
90
      {
63
        @Override
91
        @Override
64
        public void notifyChanged(Notification notification)
92
        public void notifyChanged(Notification notification)
Lines 68-82 Link Here
68
            final ListDiff diff;
96
            final ListDiff diff;
69
            switch (notification.getEventType())
97
            switch (notification.getEventType())
70
            {
98
            {
71
              case Notification.ADD:
99
              case Notification.ADD: {
72
              {
73
                diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue()));
100
                diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue()));
74
                break;
101
                break;
75
              }
102
              }
76
              case Notification.ADD_MANY:
103
              case Notification.ADD_MANY: {
77
              {
104
                Collection< ? > newValues = (Collection< ? >)notification.getNewValue();
78
                Collection<?> newValues = (Collection<?>)notification.getNewValue();
105
                ListDiffEntry[] listDiffEntries = new ListDiffEntry [newValues.size()];
79
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [newValues.size()];
80
                int position = notification.getPosition();
106
                int position = notification.getPosition();
81
                int index = 0;
107
                int index = 0;
82
                for (Object newValue : newValues)
108
                for (Object newValue : newValues)
Lines 86-100 Link Here
86
                diff = Diffs.createListDiff(listDiffEntries);
112
                diff = Diffs.createListDiff(listDiffEntries);
87
                break;
113
                break;
88
              }
114
              }
89
              case Notification.REMOVE:
115
              case Notification.REMOVE: {
90
              {
91
                diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue()));
116
                diff = Diffs.createListDiff(Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue()));
92
                break;
117
                break;
93
              }
118
              }
94
              case Notification.REMOVE_MANY:
119
              case Notification.REMOVE_MANY: {
95
              {
120
                Collection< ? > oldValues = (Collection< ? >)notification.getOldValue();
96
                Collection<?> oldValues = (Collection<?>)notification.getOldValue();
121
                ListDiffEntry[] listDiffEntries = new ListDiffEntry [oldValues.size()];
97
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [oldValues.size()];
98
                int position = notification.getPosition();
122
                int position = notification.getPosition();
99
                int index = 0;
123
                int index = 0;
100
                for (Object oldValue : oldValues)
124
                for (Object oldValue : oldValues)
Lines 105-140 Link Here
105
                break;
129
                break;
106
              }
130
              }
107
              case Notification.SET:
131
              case Notification.SET:
108
              case Notification.RESOLVE:
132
              case Notification.RESOLVE: {
109
              {
133
                ListDiffEntry[] listDiffEntries = new ListDiffEntry [2];
110
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [2];
111
                listDiffEntries[0] = Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue());
134
                listDiffEntries[0] = Diffs.createListDiffEntry(notification.getPosition(), false, notification.getOldValue());
112
                listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue());
135
                listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, notification.getNewValue());
113
                diff = Diffs.createListDiff(listDiffEntries);
136
                diff = Diffs.createListDiff(listDiffEntries);
114
                break;
137
                break;
115
              }
138
              }
116
              case Notification.MOVE:
139
              case Notification.MOVE: {
117
              {
118
                Object movedValue = notification.getNewValue();
140
                Object movedValue = notification.getNewValue();
119
                ListDiffEntry [] listDiffEntries = new ListDiffEntry [2];
141
                ListDiffEntry[] listDiffEntries = new ListDiffEntry [2];
120
                listDiffEntries[0] = Diffs.createListDiffEntry((Integer)notification.getOldValue(), false, movedValue);
142
                listDiffEntries[0] = Diffs.createListDiffEntry((Integer)notification.getOldValue(), false, movedValue);
121
                listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, movedValue);
143
                listDiffEntries[1] = Diffs.createListDiffEntry(notification.getPosition(), true, movedValue);
122
                diff = Diffs.createListDiff(listDiffEntries);
144
                diff = Diffs.createListDiff(listDiffEntries);
123
                break;
145
                break;
124
              }
146
              }
125
              case Notification.UNSET:
147
              case Notification.UNSET: {
126
              {
148
                // This just represents going back to the unset state,
127
                // This just represents going back to the unset state, but that doesn't affect the contents of the list.
149
                // but that doesn't affect the contents of the list.
128
                //
150
                //
129
                return;
151
                return;
130
              }
152
              }
131
              default:
153
              default: {
132
              {
133
                throw new RuntimeException("unhandled case");
154
                throw new RuntimeException("unhandled case");
134
              }
155
              }
135
            }
156
            }
136
            getRealm().exec
157
            getRealm().exec(new Runnable()
137
             (new Runnable()
138
              {
158
              {
139
                public void run()
159
                public void run()
140
                {
160
                {
Lines 146-152 Link Here
146
      };
166
      };
147
    eObject.eAdapters().add(listener);
167
    eObject.eAdapters().add(listener);
148
  }
168
  }
149
  
169
150
  @Override
170
  @Override
151
  protected void lastListenerRemoved()
171
  protected void lastListenerRemoved()
152
  {
172
  {
Lines 167-172 Link Here
167
    super.dispose();
187
    super.dispose();
168
  }
188
  }
169
189
190
  /**
191
   * @return the wrapped list
192
   */
170
  @SuppressWarnings("unchecked")
193
  @SuppressWarnings("unchecked")
171
  protected final List<Object> wrappedList()
194
  protected final List<Object> wrappedList()
172
  {
195
  {
Lines 256-262 Link Here
256
  public Object move(int newPosition, int oldPosition)
279
  public Object move(int newPosition, int oldPosition)
257
  {
280
  {
258
    checkRealm();
281
    checkRealm();
259
    return ((EList<?>)wrappedList).move(newPosition, oldPosition);
282
    return ((EList< ? >)wrappedList).move(newPosition, oldPosition);
260
  }
283
  }
261
284
262
  public void move(int newPosition, Object object)
285
  public void move(int newPosition, Object object)
Lines 290-294 Link Here
290
@SuppressWarnings("unchecked")
313
@SuppressWarnings("unchecked")
291
interface InternalRawEList extends EList
314
interface InternalRawEList extends EList
292
{
315
{
293
  // This is only at avoid needing an @SuppressWarnings("unchecked") on the EMFObservableList
316
  // This is only at avoid needing an @SuppressWarnings("unchecked") on the
317
  // EMFObservableList
294
}
318
}
(-)src/org/eclipse/emf/databinding/EObjectObservableMap.java (-18 / +29 lines)
Lines 27-42 Link Here
27
import org.eclipse.emf.ecore.EStructuralFeature;
27
import org.eclipse.emf.ecore.EStructuralFeature;
28
import org.eclipse.emf.ecore.util.ExtendedMetaData;
28
import org.eclipse.emf.ecore.util.ExtendedMetaData;
29
29
30
30
/**
31
/**
31
 * PROVISIONAL
32
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
32
 * This API is subject to arbitrary change, including renaming or removal.
33
 * @deprecated do not use this map it will be removed in 2.6
33
 */
34
 */
34
public class EObjectObservableMap extends ComputedObservableMap
35
public class EObjectObservableMap extends ComputedObservableMap
35
{
36
{
37
  /**
38
   * The feature to observe
39
   */
36
  protected EStructuralFeature eStructuralFeature;
40
  protected EStructuralFeature eStructuralFeature;
37
41
38
  private Adapter elementListener = 
42
  private Adapter elementListener = new AdapterImpl()
39
    new AdapterImpl()
40
    {
43
    {
41
      @Override
44
      @Override
42
      public void notifyChanged(Notification notification)
45
      public void notifyChanged(Notification notification)
Lines 44-64 Link Here
44
        if (eStructuralFeature == notification.getFeature() && !notification.isTouch())
47
        if (eStructuralFeature == notification.getFeature() && !notification.isTouch())
45
        {
48
        {
46
          // TODO
49
          // TODO
47
          // This assumes we only get a SET notification, which isn't a good assumption.
50
          // This assumes we only get a SET notification, which isn't a
51
          // good assumption.
48
          //
52
          //
49
          final MapDiff diff = Diffs.createMapDiffSingleChange(notification.getNotifier(), notification.getOldValue(), notification.getNewValue());
53
          final MapDiff diff = Diffs.createMapDiffSingleChange(
50
          getRealm().exec
54
            notification.getNotifier(),
51
            (new Runnable()
55
            notification.getOldValue(),
52
             {
56
            notification.getNewValue());
53
               public void run()
57
          getRealm().exec(new Runnable()
54
               {
58
            {
55
                 fireMapChange(diff);
59
              public void run()
56
               }
60
              {
57
             });
61
                fireMapChange(diff);
62
              }
63
            });
58
        }
64
        }
59
      }
65
      }
60
    };
66
    };
61
67
68
  /**
69
   * Create a new observable for the set of features
70
   * 
71
   * @param objects
72
   *            the objects to observe
73
   * @param feature
74
   *            the feature
75
   */
62
  public EObjectObservableMap(IObservableSet objects, EStructuralFeature feature)
76
  public EObjectObservableMap(IObservableSet objects, EStructuralFeature feature)
63
  {
77
  {
64
    super(objects);
78
    super(objects);
Lines 81-90 Link Here
81
  protected Object doGet(Object key)
95
  protected Object doGet(Object key)
82
  {
96
  {
83
    EObject eObject = (EObject)key;
97
    EObject eObject = (EObject)key;
84
    return  
98
    return ExtendedMetaData.INSTANCE.getAffiliation(eObject.eClass(), eStructuralFeature) == null ? null : eObject.eGet(eStructuralFeature);
85
      ExtendedMetaData.INSTANCE.getAffiliation(eObject.eClass(), eStructuralFeature) == null ?
86
        null :
87
        eObject.eGet(eStructuralFeature);
88
  }
99
  }
89
100
90
  @Override
101
  @Override
(-)src/org/eclipse/emf/databinding/EMFUpdateValueStrategy.java (-9 / +30 lines)
Lines 19-24 Link Here
19
import java.util.ArrayList;
19
import java.util.ArrayList;
20
import java.util.List;
20
import java.util.List;
21
21
22
import org.eclipse.core.databinding.UpdateListStrategy;
22
import org.eclipse.core.databinding.UpdateValueStrategy;
23
import org.eclipse.core.databinding.UpdateValueStrategy;
23
import org.eclipse.core.databinding.conversion.Converter;
24
import org.eclipse.core.databinding.conversion.Converter;
24
import org.eclipse.core.databinding.conversion.IConverter;
25
import org.eclipse.core.databinding.conversion.IConverter;
Lines 26-52 Link Here
26
import org.eclipse.emf.ecore.EDataType;
27
import org.eclipse.emf.ecore.EDataType;
27
import org.eclipse.emf.ecore.EFactory;
28
import org.eclipse.emf.ecore.EFactory;
28
29
30
29
/**
31
/**
30
 * PROVISIONAL
32
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
31
 * This API is subject to arbitrary change, including renaming or removal.
32
 */
33
 */
33
public class EMFUpdateValueStrategy extends UpdateValueStrategy
34
public class EMFUpdateValueStrategy extends UpdateValueStrategy
34
{
35
{
36
  /**
37
   * A value update strategy with default update policy
38
   * {@link UpdateListStrategy#POLICY_UPDATE} and default converters and
39
   * validators
40
   */
35
  public EMFUpdateValueStrategy()
41
  public EMFUpdateValueStrategy()
36
  {
42
  {
37
    this(true, POLICY_UPDATE);
43
    this(true, POLICY_UPDATE);
38
  }
44
  }
39
45
46
  /**
47
   * A value strategy with a specific update policy but with default
48
   * converters and validators
49
   * 
50
   * @param updatePolicy
51
   *            the policy
52
   */
40
  public EMFUpdateValueStrategy(int updatePolicy)
53
  public EMFUpdateValueStrategy(int updatePolicy)
41
  {
54
  {
42
    this(true, updatePolicy);
55
    this(true, updatePolicy);
43
  }
56
  }
44
57
58
  /**
59
   * A value strategy with a specific update policy and with the
60
   * possibility to turn of default converters and validators
61
   * 
62
   * @param provideDefaults
63
   *            <code>false</code> to turn of default converters and
64
   *            validators
65
   * @param updatePolicy
66
   *            the policy
67
   */
45
  public EMFUpdateValueStrategy(boolean provideDefaults, int updatePolicy)
68
  public EMFUpdateValueStrategy(boolean provideDefaults, int updatePolicy)
46
  {
69
  {
47
    super(provideDefaults, updatePolicy);
70
    super(provideDefaults, updatePolicy);
48
  }
71
  }
49
  
72
50
  @Override
73
  @Override
51
  protected IConverter createConverter(Object fromType, Object toType)
74
  protected IConverter createConverter(Object fromType, Object toType)
52
  {
75
  {
Lines 57-64 Link Here
57
        final EAttribute eAttribute = (EAttribute)toType;
80
        final EAttribute eAttribute = (EAttribute)toType;
58
        final EDataType eDataType = eAttribute.getEAttributeType();
81
        final EDataType eDataType = eAttribute.getEAttributeType();
59
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
82
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
60
        return
83
        return new Converter(fromType, toType)
61
          new Converter(fromType, toType)
62
          {
84
          {
63
            public Object convert(Object fromObject)
85
            public Object convert(Object fromObject)
64
            {
86
            {
Lines 90-104 Link Here
90
        final EAttribute eAttribute = (EAttribute)fromType;
112
        final EAttribute eAttribute = (EAttribute)fromType;
91
        final EDataType eDataType = eAttribute.getEAttributeType();
113
        final EDataType eDataType = eAttribute.getEAttributeType();
92
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
114
        final EFactory eFactory = eDataType.getEPackage().getEFactoryInstance();
93
        return
115
        return new Converter(fromType, toType)
94
          new Converter(fromType, toType)
95
          {
116
          {
96
            public Object convert(Object fromObject)
117
            public Object convert(Object fromObject)
97
            {
118
            {
98
              if (eAttribute.isMany())
119
              if (eAttribute.isMany())
99
              {
120
              {
100
                StringBuilder result = new StringBuilder();
121
                StringBuilder result = new StringBuilder();
101
                for (Object value : (List<?>)fromObject)
122
                for (Object value : (List< ? >)fromObject)
102
                {
123
                {
103
                  if (result.length() == 0)
124
                  if (result.length() == 0)
104
                  {
125
                  {
Lines 118-121 Link Here
118
    }
139
    }
119
    return super.createConverter(fromType, toType);
140
    return super.createConverter(fromType, toType);
120
  }
141
  }
121
}
142
}
(-)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
(-).settings/org.eclipse.jdt.core.prefs (-1 / +18 lines)
Lines 1-8 Link Here
1
#Thu Mar 19 06:34:41 EDT 2009
1
#Mon May 04 17:54:25 CEST 2009
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5
org.eclipse.jdt.core.compiler.compliance=1.5
6
org.eclipse.jdt.core.compiler.compliance=1.5
7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
7
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
14
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
15
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
16
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
17
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected
18
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning
19
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
20
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
21
org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
22
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
23
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
24
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected
8
org.eclipse.jdt.core.compiler.source=1.5
25
org.eclipse.jdt.core.compiler.source=1.5
(-)src/org/eclipse/emf/databinding/IEMFMapProperty.java (+529 lines)
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *    Matthew Hall - initial API and implementation (bug 195222)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding;
18
19
import java.util.Map;
20
21
import org.eclipse.core.databinding.property.map.IMapProperty;
22
import org.eclipse.emf.ecore.EStructuralFeature;
23
24
25
/**
26
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
27
 * 
28
 * An {@link IMapProperty} extension interface with convenience methods for
29
 * creating nested {@link EStructuralFeature}s
30
 * 
31
 * @since 2.5
32
 * @noextend This interface is not intended to be extended by clients.
33
 * @noimplement This interface is not intended to be implemented by clients.
34
 */
35
public interface IEMFMapProperty extends IEMFProperty, IMapProperty
36
{
37
38
  /**
39
   * Returns a master-detail combination of this property and the specified
40
   * nested value feature.
41
   * 
42
   * @param featurePath
43
   *            the nested value feature to observe
44
   * @return a master-detail combination of this property and the specified
45
   *         nested value feature.
46
   * @see #values(IEMFValueProperty)
47
   */
48
  public IEMFMapProperty values(FeaturePath featurePath);
49
50
  /**
51
   * Returns a master-detail combination of this property and the specified
52
   * value feature.
53
   * 
54
   * @param feature
55
   *            the value feature to observe
56
   * @return a master-detail combination of this property and the specified
57
   *         nested value feature.
58
   * @see #values(IEMFValueProperty)
59
   */
60
  public IEMFMapProperty values(EStructuralFeature feature);
61
62
  /**
63
   * Returns a master-detail combination of this property and the specified
64
   * value property. The returned property will observe the specified value
65
   * property for all {@link Map#values() values} observed by this map
66
   * property, mapping from this map property's {@link Map#keySet() key set}
67
   * to the specified value property's value for each element in the master
68
   * property's {@link Map#values() values} collection.
69
   * 
70
   * @param property
71
   *            the detail property to observe
72
   * @return a master-detail combination of this property and the specified
73
   *         value property.
74
   */
75
  public IEMFMapProperty values(IEMFValueProperty property);
76
}
Index: src/org/eclipse/emf/databinding/internal/EMFPropertyHelper.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Martin Frey <martin.frey@logica.com> - bug 256150
13
 *   Matthew Hall - bug 264307
14
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
15
 * </copyright>
16
 *
17
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
18
 */
19
package org.eclipse.emf.databinding.internal;
20
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
23
24
/**
25
 * @since 2.5
26
 */
27
public class EMFPropertyHelper
28
{
29
30
  /**
31
   * @param eStructuralFeature
32
   * @return String description of property descriptor
33
   */
34
  public static String propertyName(EStructuralFeature eStructuralFeature)
35
  {
36
    return eStructuralFeature.getEContainingClass().getName() + "." + eStructuralFeature.getName() + ""; //$NON-NLS-1$ //$NON-NLS-2$
37
  }
38
39
  /**
40
   * @param eStructuralFeature
41
   * @return class name excluding package
42
   */
43
  public static String shortClassName(EStructuralFeature eStructuralFeature)
44
  {
45
    return eStructuralFeature.getEType().getName();
46
  }
47
}
Index: src/org/eclipse/emf/databinding/internal/EWritableList.java
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2009 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 in 262160
12
 * </copyright>
13
 *
14
 * $Id: $
15
 */
16
package org.eclipse.emf.databinding.internal;
17
18
import java.util.Collection;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.ListIterator;
22
23
import org.eclipse.core.databinding.observable.Diffs;
24
import org.eclipse.core.databinding.observable.ObservableTracker;
25
import org.eclipse.core.databinding.observable.Realm;
26
import org.eclipse.core.databinding.observable.list.AbstractObservableList;
27
import org.eclipse.core.databinding.observable.list.IObservableList;
28
import org.eclipse.core.databinding.observable.list.ListDiff;
29
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
30
import org.eclipse.emf.common.notify.Adapter;
31
import org.eclipse.emf.common.notify.Notification;
32
import org.eclipse.emf.common.notify.Notifier;
33
import org.eclipse.emf.common.notify.NotifyingList;
34
import org.eclipse.emf.common.notify.impl.AdapterImpl;
35
import org.eclipse.emf.ecore.resource.Resource;
36
37
38
/**
39
 * Writable list which can be used to observe an {@link NotifyingList}
40
 * 
41
 * @param <Type> the type
42
 * @since 2.5
43
 */
44
public class EWritableList<Type> extends AbstractObservableList implements IObservableList
45
{
46
  private NotifyingList<Type> wrappedList;
47
  private Object elementType;
48
  private boolean stale = false;
49
50
  private class Listener extends AdapterImpl
51
  {
52
    private Object feature;
53
54
    public Listener(Object feature)
55
    {
56
      this.feature = feature;
57
    }
58
59
    @Override
60
    public void notifyChanged(Notification msg)
61
    {
62
63
      if (feature == null && msg.getFeature() == null && msg.getFeatureID(Resource.class) != Resource.RESOURCE__CONTENTS)
64
      {
65
        return;
66
      }
67
68
      if (feature == msg.getFeature() && !msg.isTouch())
69
      {
70
        final ListDiff diff;
71
        switch (msg.getEventType())
72
        {
73
          case Notification.ADD: {
74
            diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg.getPosition(), true, msg.getNewValue()));
75
            // fireListChange(diff);
76
            break;
77
          }
78
          case Notification.ADD_MANY: {
79
            Collection< ? > newValues = (Collection< ? >)msg.getNewValue();
80
            ListDiffEntry[] listDiffEntries = new ListDiffEntry [newValues.size()];
81
            int position = msg.getPosition();
82
            int index = 0;
83
            for (Object newValue : newValues)
84
            {
85
              listDiffEntries[index++] = Diffs.createListDiffEntry(position++, true, newValue);
86
            }
87
            diff = Diffs.createListDiff(listDiffEntries);
88
            // fireListChange(diff);
89
            break;
90
          }
91
          case Notification.REMOVE: {
92
            diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg.getPosition(), false, msg.getOldValue()));
93
            // fireListChange(diff);
94
            break;
95
          }
96
          case Notification.REMOVE_MANY: {
97
            Collection< ? > oldValues = (Collection< ? >)msg.getOldValue();
98
            ListDiffEntry[] listDiffEntries = new ListDiffEntry [oldValues.size()];
99
            int position = msg.getPosition();
100
            int index = 0;
101
            for (Object oldValue : oldValues)
102
            {
103
              listDiffEntries[index++] = Diffs.createListDiffEntry(position++, false, oldValue);
104
            }
105
            diff = Diffs.createListDiff(listDiffEntries);
106
            // fireListChange(diff);
107
            break;
108
          }
109
          case Notification.MOVE: {
110
            Object movedValue = msg.getNewValue();
111
            ListDiffEntry[] listDiffEntries = new ListDiffEntry [2];
112
            listDiffEntries[0] = Diffs.createListDiffEntry((Integer)msg.getOldValue(), false, movedValue);
113
            listDiffEntries[1] = Diffs.createListDiffEntry(msg.getPosition(), true, movedValue);
114
            diff = Diffs.createListDiff(listDiffEntries);
115
            // fireListChange(diff);
116
            break;
117
          }
118
          case Notification.UNSET: {
119
            // This just represents going back to the unset state, but
120
            // that doesn't affect the contents of the list.
121
            //
122
            return;
123
          }
124
          default: {
125
            throw new RuntimeException("unhandled case");
126
          }
127
        }
128
129
        getRealm().exec(new Runnable()
130
          {
131
            public void run()
132
            {
133
              fireListChange(diff);
134
            }
135
          });
136
137
        // System.err.println("CHANGE: " +
138
        // diff.getDifferences()[0].getElement());
139
140
        // fireListChange(diff);
141
        // listener.handlePropertyChange(new SimplePropertyEvent(msg
142
        // .getNotifier(), EMFListProperty.this, diff));
143
      }
144
    }
145
146
  }
147
148
  private Adapter listener;
149
150
  /**
151
   * New writable list wrapping the {@link NotifyingList}
152
   * 
153
   * @param wrappedList
154
   *            the wrapped list
155
   */
156
  public EWritableList(NotifyingList<Type> wrappedList)
157
  {
158
    this(Realm.getDefault(), wrappedList);
159
  }
160
161
  /**
162
   * New writable list wrapping the {@link NotifyingList} and using the
163
   * {@link Realm}
164
   * 
165
   * @param realm
166
   *            the realm
167
   * @param wrappedList
168
   *            the wrapped list
169
   */
170
  public EWritableList(Realm realm, NotifyingList<Type> wrappedList)
171
  {
172
    this(realm, wrappedList, null);
173
  }
174
175
  /**
176
   * New writable list wrapping the {@link NotifyingList}
177
   * 
178
   * @param realm
179
   *            the realm
180
   * @param wrappedList
181
   *            the wrapped list
182
   * @param elementType
183
   *            the element type
184
   */
185
  public EWritableList(Realm realm, NotifyingList<Type> wrappedList, Class<Type> elementType)
186
  {
187
    super(realm);
188
    this.wrappedList = wrappedList;
189
    this.elementType = elementType;
190
  }
191
192
  @Override
193
  protected void firstListenerAdded()
194
  {
195
    if (wrappedList.getNotifier() instanceof Notifier)
196
    {
197
      Notifier notifier = (Notifier)wrappedList.getNotifier();
198
      listener = new Listener(wrappedList.getFeature());
199
      notifier.eAdapters().add(listener);
200
    }
201
    else
202
    {
203
      throw new IllegalArgumentException("Wrapped list must have a notifier attached!");
204
    }
205
  }
206
207
  @Override
208
  protected void lastListenerRemoved()
209
  {
210
    if (wrappedList.getNotifier() instanceof Notifier)
211
    {
212
      Notifier notifier = (Notifier)wrappedList.getNotifier();
213
      listener = new Listener(wrappedList.getFeature());
214
      notifier.eAdapters().remove(listener);
215
    }
216
    else
217
    {
218
      throw new IllegalArgumentException("Wrapped list must have a notifier attached!");
219
    }
220
  }
221
222
  @Override
223
  public synchronized void dispose()
224
  {
225
    super.dispose();
226
  }
227
228
  private void getterCalled()
229
  {
230
    ObservableTracker.getterCalled(this);
231
  }
232
233
  @SuppressWarnings("unchecked")
234
  public boolean add(Object o)
235
  {
236
    checkRealm();
237
    return wrappedList.add((Type)o);
238
  }
239
240
  @SuppressWarnings("unchecked")
241
  public boolean addAll(Collection c)
242
  {
243
    checkRealm();
244
    return wrappedList.addAll(c);
245
  }
246
247
  @SuppressWarnings("unchecked")
248
  public boolean addAll(int index, Collection c)
249
  {
250
    checkRealm();
251
    return wrappedList.addAll(index, c);
252
  }
253
254
  public boolean contains(Object o)
255
  {
256
    getterCalled();
257
    return wrappedList.contains(o);
258
  }
259
260
  @SuppressWarnings("unchecked")
261
  public boolean containsAll(Collection c)
262
  {
263
    getterCalled();
264
    return wrappedList.containsAll(c);
265
  }
266
267
  public Object get(int index)
268
  {
269
    getterCalled();
270
    return wrappedList.get(index);
271
  }
272
273
  public Object getElementType()
274
  {
275
    checkRealm();
276
    return elementType;
277
  }
278
279
  public int indexOf(Object o)
280
  {
281
    getterCalled();
282
    return wrappedList.indexOf(o);
283
  }
284
285
  public boolean isEmpty()
286
  {
287
    getterCalled();
288
    return wrappedList.isEmpty();
289
  }
290
291
  public Iterator<Type> iterator()
292
  {
293
    getterCalled();
294
    return wrappedList.iterator();
295
  }
296
297
  public int lastIndexOf(Object o)
298
  {
299
    getterCalled();
300
    return wrappedList.lastIndexOf(o);
301
  }
302
303
  public ListIterator<Type> listIterator()
304
  {
305
    getterCalled();
306
    return wrappedList.listIterator();
307
  }
308
309
  public ListIterator<Type> listIterator(int index)
310
  {
311
    getterCalled();
312
    return wrappedList.listIterator(index);
313
  }
314
315
  public Object move(int oldIndex, int newIndex)
316
  {
317
    checkRealm();
318
    return wrappedList.move(oldIndex, newIndex);
319
  }
320
321
  public boolean remove(Object o)
322
  {
323
    checkRealm();
324
    return wrappedList.remove(o);
325
  }
326
327
  public Object remove(int index)
328
  {
329
    checkRealm();
330
    return wrappedList.remove(index);
331
  }
332
333
  @SuppressWarnings("unchecked")
334
  public boolean removeAll(Collection c)
335
  {
336
    checkRealm();
337
    return wrappedList.removeAll(c);
338
  }
339
340
  @SuppressWarnings("unchecked")
341
  public boolean retainAll(Collection c)
342
  {
343
    checkRealm();
344
    return wrappedList.retainAll(c);
345
  }
346
347
  @SuppressWarnings("unchecked")
348
  public Object set(int index, Object element)
349
  {
350
    checkRealm();
351
    return wrappedList.set(index, (Type)element);
352
  }
353
354
  public int doGetSize()
355
  {
356
    getterCalled();
357
    return wrappedList.size();
358
  }
359
360
  public List<Type> subList(int fromIndex, int toIndex)
361
  {
362
    getterCalled();
363
    return wrappedList.subList(fromIndex, toIndex);
364
  }
365
366
  public Object[] toArray()
367
  {
368
    getterCalled();
369
    return wrappedList.toArray();
370
  }
371
372
  public Object[] toArray(Object[] a)
373
  {
374
    getterCalled();
375
    return wrappedList.toArray();
376
  }
377
378
  @SuppressWarnings("unchecked")
379
  public void add(int index, Object element)
380
  {
381
    checkRealm();
382
    wrappedList.add(index, (Type)element);
383
  }
384
385
  public void clear()
386
  {
387
    checkRealm();
388
    wrappedList.clear();
389
  }
390
391
  public boolean isStale()
392
  {
393
    getterCalled();
394
    return stale;
395
  }
396
397
  // public void setStale(boolean stale) {
398
  // checkRealm();
399
  //
400
  // boolean wasStale = this.stale;
401
  // this.stale = stale;
402
  // if (!wasStale && stale) {
403
  // fireStale();
404
  // }
405
  // }
406
}
(-)src/org/eclipse/emf/databinding/internal/EMFListPropertyDecorator.java (+1631 lines)
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 195222)
12
 *   Matthew Hall - bug 264307
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import org.eclipse.core.databinding.observable.Realm;
21
import org.eclipse.core.databinding.observable.list.IObservableList;
22
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
23
import org.eclipse.core.databinding.observable.value.IObservableValue;
24
import org.eclipse.core.databinding.property.list.IListProperty;
25
import org.eclipse.core.databinding.property.list.ListProperty;
26
import org.eclipse.emf.databinding.EMFProperties;
27
import org.eclipse.emf.databinding.FeaturePath;
28
import org.eclipse.emf.databinding.IEMFListProperty;
29
import org.eclipse.emf.databinding.IEMFValueProperty;
30
import org.eclipse.emf.ecore.EStructuralFeature;
31
32
33
/**
34
 * @since 2.5
35
 */
36
public class EMFListPropertyDecorator extends ListProperty implements IEMFListProperty
37
{
38
  private final IListProperty delegate;
39
  private final EStructuralFeature eStructuralFeature;
40
41
  /**
42
   * @param delegate
43
   * @param eStructuralFeature
44
   */
45
  public EMFListPropertyDecorator(IListProperty delegate, EStructuralFeature eStructuralFeature)
46
  {
47
    this.delegate = delegate;
48
    this.eStructuralFeature = eStructuralFeature;
49
  }
50
51
  public Object getElementType()
52
  {
53
    return delegate.getElementType();
54
  }
55
56
  public IEMFListProperty values(EStructuralFeature feature)
57
  {
58
    return values(FeaturePath.fromList(feature));
59
  }
60
61
  public IEMFListProperty values(FeaturePath featurePath)
62
  {
63
    return values(EMFProperties.value(featurePath));
64
  }
65
66
  public IEMFListProperty values(IEMFValueProperty property)
67
  {
68
    return new EMFListPropertyDecorator(super.values(property), property.getStructuralFeature());
69
  }
70
71
  public EStructuralFeature getStructuralFeature()
72
  {
73
    return eStructuralFeature;
74
  }
75
76
  public IObservableList observe(Object source)
77
  {
78
    return new EMFObservableListDecorator(delegate.observe(source), eStructuralFeature);
79
  }
80
81
  public IObservableList observe(Realm realm, Object source)
82
  {
83
    return new EMFObservableListDecorator(delegate.observe(realm, source), eStructuralFeature);
84
  }
85
86
  public IObservableFactory listFactory()
87
  {
88
    return delegate.listFactory();
89
  }
90
91
  public IObservableFactory listFactory(Realm realm)
92
  {
93
    return delegate.listFactory(realm);
94
  }
95
96
  public IObservableList observeDetail(IObservableValue master)
97
  {
98
    return new EMFObservableListDecorator(delegate.observeDetail(master), eStructuralFeature);
99
  }
100
101
  public String toString()
102
  {
103
    return delegate.toString();
104
  }
105
}
Index: src/org/eclipse/emf/databinding/internal/EMFObservableListDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2007 Brad Reynolds 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
 *   Brad Reynolds - initial API and implementation
12
 *   Matthew Hall - bugs 208858, 246625
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import org.eclipse.core.databinding.observable.IObservable;
21
import org.eclipse.core.databinding.observable.IObserving;
22
import org.eclipse.core.databinding.observable.list.DecoratingObservableList;
23
import org.eclipse.core.databinding.observable.list.IObservableList;
24
import org.eclipse.emf.databinding.IEMFObservable;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
27
28
/**
29
 * {@link IEMFObservable} decorator for an {@link IObservableList}.
30
 * @since 2.5
31
 */
32
public class EMFObservableListDecorator extends DecoratingObservableList implements IEMFObservable
33
{
34
  private EStructuralFeature eStructuralFeature;
35
36
  /**
37
   * @param decorated
38
   * @param eStructuralFeature
39
   */
40
  public EMFObservableListDecorator(IObservableList decorated, EStructuralFeature eStructuralFeature)
41
  {
42
    super(decorated, true);
43
    this.eStructuralFeature = eStructuralFeature;
44
  }
45
46
  public synchronized void dispose()
47
  {
48
    this.eStructuralFeature = null;
49
    super.dispose();
50
  }
51
52
  public Object getObserved()
53
  {
54
    IObservable decorated = getDecorated();
55
    if (decorated instanceof IObserving)
56
      return ((IObserving)decorated).getObserved();
57
    return null;
58
  }
59
60
  public EStructuralFeature getStructuralFeature()
61
  {
62
    return eStructuralFeature;
63
  }
64
}
Index: src/org/eclipse/emf/databinding/internal/Util.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2006 IBM Corporation 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
 *   IBM Corporation - initial API and implementation
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.internal;
17
18
/**
19
 * @since 2.5
20
 */
21
public class Util
22
{
23
24
  /**
25
   * Checks whether the two objects are <code>null</code> -- allowing for
26
   * <code>null</code>.
27
   * 
28
   * @param left
29
   *            The left object to compare; may be <code>null</code>.
30
   * @param right
31
   *            The right object to compare; may be <code>null</code>.
32
   * @return <code>true</code> if the two objects are equivalent;
33
   *         <code>false</code> otherwise.
34
   */
35
  public static final boolean equals(final Object left, final Object right)
36
  {
37
    return left == null ? right == null : ((right != null) && left.equals(right));
38
  }
39
}
Index: src/org/eclipse/emf/databinding/internal/EMFValuePropertyDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Matthew Hall - bugs 195222, 264307, 265561
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import org.eclipse.core.databinding.observable.Realm;
21
import org.eclipse.core.databinding.observable.list.IObservableList;
22
import org.eclipse.core.databinding.observable.map.IObservableMap;
23
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
24
import org.eclipse.core.databinding.observable.set.IObservableSet;
25
import org.eclipse.core.databinding.observable.value.IObservableValue;
26
import org.eclipse.core.databinding.property.value.IValueProperty;
27
import org.eclipse.core.databinding.property.value.ValueProperty;
28
import org.eclipse.emf.databinding.EMFProperties;
29
import org.eclipse.emf.databinding.FeaturePath;
30
import org.eclipse.emf.databinding.IEMFListProperty;
31
import org.eclipse.emf.databinding.IEMFMapProperty;
32
import org.eclipse.emf.databinding.IEMFValueProperty;
33
import org.eclipse.emf.ecore.EStructuralFeature;
34
35
36
/**
37
 * @since 2.5
38
 */
39
public class EMFValuePropertyDecorator extends ValueProperty implements IEMFValueProperty
40
{
41
  private final IValueProperty delegate;
42
  private final EStructuralFeature eStructuralFeature;
43
44
  /**
45
   * @param delegate
46
   * @param eStructuralFeature
47
   */
48
  public EMFValuePropertyDecorator(IValueProperty delegate, EStructuralFeature eStructuralFeature)
49
  {
50
    this.delegate = delegate;
51
    this.eStructuralFeature = eStructuralFeature;
52
  }
53
54
  public EStructuralFeature getStructuralFeature()
55
  {
56
    return eStructuralFeature;
57
  }
58
59
  public Object getValueType()
60
  {
61
    return delegate.getValueType();
62
  }
63
64
  public IEMFValueProperty value(EStructuralFeature feature)
65
  {
66
    return value(FeaturePath.fromList(feature));
67
  }
68
69
  public IEMFValueProperty value(FeaturePath featurePath)
70
  {
71
    return value(EMFProperties.value(featurePath));
72
  }
73
74
  public IEMFValueProperty value(IEMFValueProperty property)
75
  {
76
    return new EMFValuePropertyDecorator(super.value(property), property.getStructuralFeature());
77
  }
78
79
  public IEMFListProperty list(EStructuralFeature feature)
80
  {
81
    return list(EMFProperties.list(feature));
82
  }
83
84
  public IEMFListProperty list(IEMFListProperty property)
85
  {
86
    return new EMFListPropertyDecorator(super.list(property), property.getStructuralFeature());
87
  }
88
89
  public IEMFMapProperty map(EStructuralFeature feature)
90
  {
91
    return map(EMFProperties.map(feature));
92
  }
93
94
  public IEMFMapProperty map(IEMFMapProperty property)
95
  {
96
    return new EMFMapPropertyDecorator(super.map(property), property.getStructuralFeature());
97
  }
98
99
  public IObservableValue observe(Object source)
100
  {
101
    return new EMFObservableValueDecorator(delegate.observe(source), eStructuralFeature);
102
  }
103
104
  public IObservableValue observe(Realm realm, Object source)
105
  {
106
    return new EMFObservableValueDecorator(delegate.observe(realm, source), eStructuralFeature);
107
  }
108
109
  public IObservableFactory valueFactory()
110
  {
111
    return delegate.valueFactory();
112
  }
113
114
  public IObservableFactory valueFactory(Realm realm)
115
  {
116
    return delegate.valueFactory(realm);
117
  }
118
119
  public IObservableValue observeDetail(IObservableValue master)
120
  {
121
    return new EMFObservableValueDecorator(delegate.observeDetail(master), eStructuralFeature);
122
  }
123
124
  public IObservableList observeDetail(IObservableList master)
125
  {
126
    return new EMFObservableListDecorator(delegate.observeDetail(master), eStructuralFeature);
127
  }
128
129
  public IObservableMap observeDetail(IObservableSet master)
130
  {
131
    return new EMFObservableMapDecorator(delegate.observeDetail(master), eStructuralFeature);
132
  }
133
134
  public IObservableMap observeDetail(IObservableMap master)
135
  {
136
    return new EMFObservableMapDecorator(delegate.observeDetail(master), eStructuralFeature);
137
  }
138
139
  public String toString()
140
  {
141
    return delegate.toString();
142
  }
143
}
Index: src/org/eclipse/emf/databinding/internal/EMFObservableMapDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *    Matthew Hall - initial API and implementation (bug 221704)
12
 *    Matthew Hall - bug 246625
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import org.eclipse.core.databinding.observable.IObservable;
21
import org.eclipse.core.databinding.observable.IObserving;
22
import org.eclipse.core.databinding.observable.map.DecoratingObservableMap;
23
import org.eclipse.core.databinding.observable.map.IObservableMap;
24
import org.eclipse.emf.databinding.IEMFObservable;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
27
28
/**
29
 * {@link IEMFObservable} decorator for an {@link IObservableMap}.
30
 * 
31
 * @since 2.5
32
 */
33
public class EMFObservableMapDecorator extends DecoratingObservableMap implements IEMFObservable
34
{
35
  private EStructuralFeature eStructuralFeature;
36
37
  /**
38
   * @param decorated
39
   * @param eStructuralFeature
40
   */
41
  public EMFObservableMapDecorator(IObservableMap decorated, EStructuralFeature eStructuralFeature)
42
  {
43
    super(decorated, true);
44
    this.eStructuralFeature = eStructuralFeature;
45
  }
46
47
  public synchronized void dispose()
48
  {
49
    this.eStructuralFeature = null;
50
    super.dispose();
51
  }
52
53
  public Object getObserved()
54
  {
55
    IObservable decorated = getDecorated();
56
    if (decorated instanceof IObserving)
57
      return ((IObserving)decorated).getObserved();
58
    return null;
59
  }
60
61
  public EStructuralFeature getStructuralFeature()
62
  {
63
    return eStructuralFeature;
64
  }
65
}
Index: src/org/eclipse/emf/databinding/internal/EMFListProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Matthew Hall - bugs 195222, 264307, 265561
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import java.util.List;
21
22
import org.eclipse.core.databinding.observable.list.ListDiff;
23
import org.eclipse.core.databinding.property.INativePropertyListener;
24
import org.eclipse.core.databinding.property.IProperty;
25
import org.eclipse.core.databinding.property.ISimplePropertyListener;
26
import org.eclipse.core.databinding.property.list.SimpleListProperty;
27
import org.eclipse.emf.ecore.EObject;
28
import org.eclipse.emf.ecore.EStructuralFeature;
29
30
31
/**
32
 * @since 2.5
33
 */
34
public class EMFListProperty extends SimpleListProperty
35
{
36
  private EStructuralFeature eStructuralFeature;
37
38
  /**
39
   * @param eStructuralFeature
40
   */
41
  public EMFListProperty(EStructuralFeature eStructuralFeature)
42
  {
43
    this.eStructuralFeature = eStructuralFeature;
44
  }
45
46
  /**
47
   * @return the feature
48
   */
49
  protected EStructuralFeature getFeature()
50
  {
51
    return eStructuralFeature;
52
  }
53
54
  public Object getElementType()
55
  {
56
    return eStructuralFeature;
57
  }
58
59
  protected List< ? > doGetList(Object source)
60
  {
61
    EObject eObj = (EObject)source;
62
    return (List< ? >)eObj.eGet(eStructuralFeature);
63
  }
64
65
  @SuppressWarnings("unchecked")
66
  protected void doSetList(Object source, List list, ListDiff diff)
67
  {
68
    List< ? > currentList = doGetList(source);
69
    diff.applyTo(currentList);
70
  }
71
72
  public INativePropertyListener adaptListener(final ISimplePropertyListener listener)
73
  {
74
    return new EMFPropertyListener.EMFListPropertyListener()
75
      {
76
77
        @Override
78
        protected EStructuralFeature getFeature()
79
        {
80
          return eStructuralFeature;
81
        }
82
83
        @Override
84
        protected ISimplePropertyListener getListener()
85
        {
86
          return listener;
87
        }
88
89
        @Override
90
        protected IProperty getOwner()
91
        {
92
          return EMFListProperty.this;
93
        }
94
      };
95
  }
96
97
  public String toString()
98
  {
99
    String s = EMFPropertyHelper.propertyName(eStructuralFeature) + "[]"; //$NON-NLS-1$
100
    s += "<" + EMFPropertyHelper.shortClassName(eStructuralFeature) + ">"; //$NON-NLS-1$//$NON-NLS-2$
101
    return s;
102
  }
103
104
}
Index: src/org/eclipse/emf/databinding/IEMFObservable.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2007 Brad Reynolds 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
 *   Brad Reynolds - initial API and implementation
12
 *   Brad Reynolds - bug 147515
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding;
19
20
import org.eclipse.core.databinding.observable.IObserving;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
23
24
/**
25
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
26
 * 
27
 * Provides access to details of EObject observables.
28
 * <p>
29
 * This interface is not meant to be implemented by clients.
30
 * </p>
31
 * 
32
 * @since 2.5
33
 * @noextend This interface is not intended to be extended by clients.
34
 * @noimplement This interface is not intended to be implemented by clients.
35
 */
36
public interface IEMFObservable extends IObserving
37
{
38
  /**
39
   * @return property descriptor of the property being observed,
40
   *         <code>null</code> if the runtime time information was not
41
   *         provided on construction of the observable
42
   */
43
  public EStructuralFeature getStructuralFeature();
44
}
Index: src/org/eclipse/emf/databinding/IEMFValueProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 195222)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding;
18
19
import org.eclipse.core.databinding.property.value.IValueProperty;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
22
23
/**
24
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
25
 * 
26
 * An {@link IValueProperty} extension interface with convenience methods for
27
 * creating nested {@link EStructuralFeature} properties.
28
 * 
29
 * @since 2.5
30
 * @noextend This interface is not intended to be extended by clients.
31
 * @noimplement This interface is not intended to be implemented by clients.
32
 */
33
public interface IEMFValueProperty extends IEMFProperty, IValueProperty
34
{
35
  /**
36
   * Returns a master-detail combination of this property and the specified
37
   * nested value feature.
38
   * 
39
   * @param featurePath
40
   *            the nested value property to observe.
41
   * @return a master-detail combination of this property and the specified
42
   *         nested value feature.
43
   * @see #value(IEMFValueProperty)
44
   */
45
  public IEMFValueProperty value(FeaturePath featurePath);
46
47
  /**
48
   * Returns a master-detail combination of this property and the specified
49
   * value feature.
50
   * 
51
   * @param feature
52
   *            the nested value property to observe.
53
   * @return a master-detail combination of this property and the specified
54
   *         value feature.
55
   * @see #value(IEMFValueProperty)
56
   */
57
  public IEMFValueProperty value(EStructuralFeature feature);
58
59
  /**
60
   * Returns a master-detail combination of this property and the specified
61
   * value property. The returned property will observe the specified detail
62
   * value property for the value of the master value property.
63
   * <p>
64
   * Example:
65
   * 
66
   * <pre>
67
   * // Observes the Node-typed &quot;parent&quot; property of a Node object
68
   * IEMFValueProperty parent = EMFProperties.value(MyPackage.Literals.NODE_PARENT);
69
   * // Observes the string-typed &quot;name&quot; property of a Node object
70
   * IEMFValueProperty name = EMFProperties.value(MyPackage.Literals.NODE_NAME);
71
   * // Observes the name of the parent of a Node object.
72
   * IEMFValueProperty parentName = parent.value(name);
73
   * </pre>
74
   * 
75
   * @param property
76
   *            the detail property to observe
77
   * @return a master-detail combination of this property and the specified
78
   *         value property.
79
   */
80
  public IEMFValueProperty value(IEMFValueProperty property);
81
82
  /**
83
   * Returns a master-detail combination of this property and the specified
84
   * list feature.
85
   * 
86
   * @param feature
87
   *            the list feature to observe
88
   * @return a master-detail combination of this property and the specified
89
   *         list feature.
90
   * @see #list(IEMFListProperty)
91
   */
92
  public IEMFListProperty list(EStructuralFeature feature);
93
94
  /**
95
   * Returns a master-detail combination of this property and the specified
96
   * list property. The returned property will observe the specified list
97
   * property for the value of the master property.
98
   * <p>
99
   * Example:
100
   * 
101
   * <pre>
102
   * // Observes the Node-typed &quot;parent&quot; property of a Node object.
103
   * IEMFValueProperty parent = EMFProperties.value(MyPackage.Literals.NODE_PARENT);
104
   * // Observes the List-typed &quot;children&quot; property of a Node object
105
   * // where the elements are Node objects
106
   * IEMFListProperty children = EMFProperties.list(MyPackage.Literals.NODE_CHILDREN);
107
   * // Observes the children of the parent (siblings) of a Node object.
108
   * IEMFListProperty siblings = parent.list(children);
109
   * </pre>
110
   * 
111
   * @param property
112
   *            the detail property to observe
113
   * @return a master-detail combination of this property and the specified
114
   *         list property.
115
   */
116
  public IEMFListProperty list(IEMFListProperty property);
117
118
  /**
119
   * Returns a master-detail combination of this property and the specified
120
   * map feature.
121
   * 
122
   * @param feature
123
   *            the map property to observe
124
   * @return a master-detail combination of this property and the specified
125
   *         map feature.
126
   * @see #map(IEMFMapProperty)
127
   */
128
  public IEMFMapProperty map(EStructuralFeature feature);
129
130
  /**
131
   * Returns a master-detail combination of this property and the specified
132
   * map property. The returned property will observe the specified map
133
   * property for the value of the master property.
134
   * <p>
135
   * Example:
136
   * 
137
   * <pre>
138
   * // Observes the Contact-typed &quot;supervisor&quot; property of a
139
   * // Contact class 
140
   * IEMFValueProperty supervisor = EMFProperties.value(MyPackage.Literals.CONTACT_SUPERVISOR);
141
   * // Observes the property &quot;phoneNumbers&quot; of a Contact object--a property mapping
142
   * // from PhoneNumberType to PhoneNumber &quot;set-typed &quot;children&quot;,
143
   * IEMFMapProperty phoneNumbers = EMFProperties.map(MyPackage.Literals.CONTACT_PHONENUMBERS);
144
   * // Observes the phone numbers of a contact's supervisor:
145
   * IEMFMapProperty supervisorPhoneNumbers = supervisor.map(phoneNumbers);
146
   * </pre>
147
   * 
148
   * @param property
149
   *            the detail property to observe
150
   * @return a master-detail combination of this property and the specified
151
   *         map property.
152
   */
153
  public IEMFMapProperty map(IEMFMapProperty property);
154
}
Index: src/org/eclipse/emf/databinding/internal/EMFValueProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Matthew Hall - bug 195222, 264307, 265561
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import org.eclipse.core.databinding.property.INativePropertyListener;
21
import org.eclipse.core.databinding.property.IProperty;
22
import org.eclipse.core.databinding.property.ISimplePropertyListener;
23
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.ecore.util.ExtendedMetaData;
27
28
29
/**
30
 * @since 2.5
31
 */
32
public class EMFValueProperty extends SimpleValueProperty
33
{
34
  private final EStructuralFeature eStructuralFeature;
35
36
  /**
37
   * @param eStructuralFeature
38
   */
39
  public EMFValueProperty(EStructuralFeature eStructuralFeature)
40
  {
41
    this.eStructuralFeature = eStructuralFeature;
42
  }
43
44
  public Object getValueType()
45
  {
46
    return eStructuralFeature;
47
  }
48
49
  /**
50
   * @return the feature
51
   */
52
  protected EStructuralFeature getFeature()
53
  {
54
    return eStructuralFeature;
55
  }
56
57
  protected Object doGetValue(Object source)
58
  {
59
    EObject eObj = (EObject)source;
60
    return ExtendedMetaData.INSTANCE.getAffiliation(eObj.eClass(), eStructuralFeature) == null ? null : eObj.eGet(eStructuralFeature);
61
  }
62
63
  protected void doSetValue(Object source, Object value)
64
  {
65
    EObject eObject = (EObject)source;
66
    eObject.eSet(eStructuralFeature, value);
67
  }
68
69
  public INativePropertyListener adaptListener(final ISimplePropertyListener listener)
70
  {
71
    return new EMFPropertyListener.EMFValuePropertyListener()
72
      {
73
74
        @Override
75
        protected IProperty getOwner()
76
        {
77
          return EMFValueProperty.this;
78
        }
79
80
        @Override
81
        protected ISimplePropertyListener getListener()
82
        {
83
          return listener;
84
        }
85
86
        @Override
87
        protected EStructuralFeature getFeature()
88
        {
89
          return eStructuralFeature;
90
        }
91
      };
92
  }
93
94
  public String toString()
95
  {
96
    String s = EMFPropertyHelper.propertyName(eStructuralFeature);
97
    s += "<" + EMFPropertyHelper.shortClassName(eStructuralFeature) + ">"; //$NON-NLS-1$//$NON-NLS-2$
98
    return s;
99
  }
100
}
Index: src/org/eclipse/emf/databinding/internal/EMFObservableValueDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2007 Brad Reynolds 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
 *   Brad Reynolds - initial API and implementation
12
 *   Matthew Hall - bug 246625
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import org.eclipse.core.databinding.observable.IObservable;
21
import org.eclipse.core.databinding.observable.IObserving;
22
import org.eclipse.core.databinding.observable.value.DecoratingObservableValue;
23
import org.eclipse.core.databinding.observable.value.IObservableValue;
24
import org.eclipse.emf.databinding.IEMFObservable;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
27
28
/**
29
 * {@link IEMFObservable} decorator for an {@link IObservableValue}.
30
 * 
31
 * @since 2.5
32
 */
33
public class EMFObservableValueDecorator extends DecoratingObservableValue implements IEMFObservable
34
{
35
  private EStructuralFeature eStructuralFeature;
36
37
  /**
38
   * @param decorated
39
   * @param eStructuralFeature
40
   */
41
  public EMFObservableValueDecorator(IObservableValue decorated, EStructuralFeature eStructuralFeature)
42
  {
43
    super(decorated, true);
44
    this.eStructuralFeature = eStructuralFeature;
45
  }
46
47
  public synchronized void dispose()
48
  {
49
    this.eStructuralFeature = null;
50
    super.dispose();
51
  }
52
53
  public Object getObserved()
54
  {
55
    IObservable decorated = getDecorated();
56
    if (decorated instanceof IObserving)
57
      return ((IObserving)decorated).getObserved();
58
    return null;
59
  }
60
61
  public EStructuralFeature getStructuralFeature()
62
  {
63
    return eStructuralFeature;
64
  }
65
}
Index: src/org/eclipse/emf/databinding/EMFProperties.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Matthew Hall - bug 195222, 247997, 261843, 264307
13
 *   Hasan Ceylan  - patch in bug 262160
14
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
15
 * </copyright>
16
 *
17
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
18
 */
19
package org.eclipse.emf.databinding;
20
21
import org.eclipse.core.databinding.property.list.IListProperty;
22
import org.eclipse.core.databinding.property.map.IMapProperty;
23
import org.eclipse.core.databinding.property.value.IValueProperty;
24
import org.eclipse.emf.databinding.internal.EMFListProperty;
25
import org.eclipse.emf.databinding.internal.EMFListPropertyDecorator;
26
import org.eclipse.emf.databinding.internal.EMFMapProperty;
27
import org.eclipse.emf.databinding.internal.EMFMapPropertyDecorator;
28
import org.eclipse.emf.databinding.internal.EMFValueProperty;
29
import org.eclipse.emf.databinding.internal.EMFValuePropertyDecorator;
30
import org.eclipse.emf.ecore.EObject;
31
import org.eclipse.emf.ecore.EStructuralFeature;
32
33
34
/**
35
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
36
 * 
37
 * A factory to create property bound attributes for {@link EObject}
38
 * 
39
 * @since 2.5
40
 */
41
public class EMFProperties
42
{
43
  /**
44
   * Debug constant to turn on/off debugging
45
   */
46
  public static final boolean DEBUG = false;
47
48
  /**
49
   * Returns a value property for the given {@link EStructuralFeature}
50
   * 
51
   * @param feature
52
   *            the feature instance the property is created for
53
   * @return a value property for the given {@link EStructuralFeature}
54
   */
55
  public static IEMFValueProperty value(EStructuralFeature feature)
56
  {
57
    return value(FeaturePath.fromList(feature));
58
  }
59
60
  /**
61
   * Returns a value property for the given nested {@link EStructuralFeature}
62
   * feature like the <code>name</code> of a <code>person</code>
63
   * 
64
   * @param featurePath
65
   *            path to the feature
66
   * @return a value property for the given {@link FeaturePath}
67
   */
68
  public static IEMFValueProperty value(FeaturePath featurePath)
69
  {
70
    IValueProperty property;
71
    property = new EMFValueProperty(featurePath.getFeaturePath()[0]);
72
73
    IEMFValueProperty featureProperty = new EMFValuePropertyDecorator(property, featurePath.getFeaturePath()[0]);
74
75
    for (int i = 1; i < featurePath.getFeaturePath().length; i++)
76
    {
77
      featureProperty = featureProperty.value(featurePath.getFeaturePath()[i]);
78
    }
79
80
    return featureProperty;
81
  }
82
83
  /**
84
   * Returns multiple value properties for the given
85
   * {@link EStructuralFeature}s
86
   * 
87
   * @param features
88
   *            the feature instances the properties are created for
89
   * @return an array of properties for the given {@link EStructuralFeature}s
90
   */
91
  public static IEMFValueProperty[] values(EStructuralFeature... features)
92
  {
93
    IEMFValueProperty[] properties = new IEMFValueProperty [features.length];
94
    for (int i = 0; i < properties.length; i++)
95
      properties[i] = value(features[i]);
96
    return properties;
97
  }
98
99
  /**
100
   * Returns multiple value property for the given nested
101
   * {@link EStructuralFeature} features like the <code>name</code> of a
102
   * <code>person</code>
103
   * 
104
   * @param featurePaths
105
   *            path to the feature
106
   * @return an array of properties for the given {@link FeaturePath}s
107
   */
108
  public static IEMFValueProperty[] values(FeaturePath... featurePaths)
109
  {
110
    IEMFValueProperty[] properties = new IEMFValueProperty [featurePaths.length];
111
    for (int i = 0; i < properties.length; i++)
112
      properties[i] = value(featurePaths[i]);
113
    return properties;
114
  }
115
116
  /**
117
   * Returns a list property for the given {@link EStructuralFeature}
118
   * 
119
   * @param feature
120
   *            the feature instance the property is created for
121
   * @return a list property for the given {@link EStructuralFeature}
122
   */
123
  public static IEMFListProperty list(EStructuralFeature feature)
124
  {
125
    IListProperty property;
126
    property = new EMFListProperty(feature);
127
    return new EMFListPropertyDecorator(property, feature);
128
  }
129
130
  /**
131
   * Returns a map property for the given {@link EStructuralFeature}. Objects lacking the named property are treated the same as if the
132
   * property always contains an empty map.
133
   * 
134
   * @param feature
135
   *            the feature the property is created for
136
   * @return a map property for the given {@link EStructuralFeature}
137
   */
138
  public static IEMFMapProperty map(EStructuralFeature feature)
139
  {
140
    IMapProperty property;
141
    property = new EMFMapProperty(feature);
142
    return new EMFMapPropertyDecorator(property, feature);
143
  }
144
}
Index: src/org/eclipse/emf/databinding/FeaturePath.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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> - port to EMF in 262160
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding;
17
18
import org.eclipse.emf.ecore.EStructuralFeature;
19
20
21
/**
22
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
23
 * 
24
 * Encapsulate a path to features also known as nested feature like person.name
25
 * 
26
 * @since 2.5
27
 * @noextend This interface is not intended to be extended by clients.
28
 * @noimplement This interface is not intended to be implemented by clients.
29
 */
30
public class FeaturePath
31
{
32
  private EStructuralFeature[] featurePath;
33
34
  private FeaturePath(EStructuralFeature[] featurePath)
35
  {
36
    this.featurePath = featurePath;
37
  }
38
39
  /**
40
   * @return the path to the feature from the local position
41
   */
42
  public EStructuralFeature[] getFeaturePath()
43
  {
44
    return featurePath;
45
  }
46
47
  /**
48
   * Create a feature path from the list of given features
49
   * 
50
   * @param featurePath
51
   *            the list of feature to go from the local instance to the
52
   *            requested instance
53
   * @return the path constructed
54
   */
55
  public static FeaturePath fromList(EStructuralFeature... featurePath)
56
  {
57
    return new FeaturePath(featurePath);
58
  }
59
}
Index: src/org/eclipse/emf/databinding/IEMFProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding;
18
19
import org.eclipse.core.databinding.property.IProperty;
20
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.emf.ecore.EStructuralFeature;
23
24
25
/**
26
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
27
 * 
28
 * An IProperty extension interface providing access to details of {@link EObject}s
29
 * 
30
 * @since 2.5
31
 * @noextend This interface is not intended to be extended by clients.
32
 * @noimplement This interface is not intended to be implemented by clients.
33
 */
34
public interface IEMFProperty extends IProperty
35
{
36
  /**
37
   * Returns the descriptor of the {@link EStructuralFeature} being observed.
38
   * 
39
   * @return the {@link EStructuralFeature} being observed
40
   */
41
  public EStructuralFeature getStructuralFeature();
42
}
Index: src/org/eclipse/emf/databinding/IEMFListProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 195222)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding;
18
19
import org.eclipse.core.databinding.property.list.IListProperty;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
22
23
/**
24
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
25
 * 
26
 * An {@link IListProperty} extension interface with convenience methods for
27
 * creating nested {@link EStructuralFeature}s
28
 * 
29
 * @since 2.5
30
 * @noextend This interface is not intended to be extended by clients.
31
 * @noimplement This interface is not intended to be implemented by clients.
32
 */
33
public interface IEMFListProperty extends IEMFProperty, IListProperty
34
{
35
  /**
36
   * Returns a master-detail combination of this property and the specified
37
   * value nested feature.
38
   * 
39
   * @param featurePath
40
   *            the nested feature to observe
41
   * @return a nested combination of this property and the specified nested
42
   *         feature.
43
   * @see #values(IEMFValueProperty)
44
   */
45
  public IEMFListProperty values(FeaturePath featurePath);
46
47
  /**
48
   * Returns a master-detail combination of this property and the specified
49
   * value property.
50
   * 
51
   * @param feature
52
   *            the feature
53
   * @return a nested combination of this property and the specified nested
54
   *         feature.
55
   */
56
  public IEMFListProperty values(EStructuralFeature feature);
57
58
  /**
59
   * Returns a master-detail combination of this property and the specified
60
   * value property. The returned property will observe the specified value
61
   * property for all elements observed by this list property.
62
   * <p>
63
   * Example:
64
   * 
65
   * <pre>
66
   * // Observes the list-typed &quot;children&quot; property of a Person object,
67
   * // where the elements are Person objects
68
   * IEMFListProperty children = EMFProperties
69
   * 		.list(MyPackage.Literals.PERSON_CHILDREN);
70
   * // Observes the string-typed &quot;name&quot; property of a Person object
71
   * IEMFValueProperty name = EMFProperties.value(MyPackage.Literals.PERSON_NAME);
72
   * // Observes the names of children of a Person object.
73
   * IEMFListProperty childrenNames = children.values(name);
74
   * </pre>
75
   * 
76
   * @param property
77
   *            the detail property to observe
78
   * @return a master-detail combination of this property and the specified
79
   *         value property.
80
   */
81
  public IEMFListProperty values(IEMFValueProperty property);
82
}
Index: src/org/eclipse/emf/databinding/internal/EMFPropertyListener.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 Tom Schindl 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> - port to EMF in 262160
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.internal;
17
18
import java.util.Collection;
19
import java.util.Map;
20
21
import org.eclipse.core.databinding.observable.Diffs;
22
import org.eclipse.core.databinding.observable.list.ListDiff;
23
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
24
import org.eclipse.core.databinding.property.INativePropertyListener;
25
import org.eclipse.core.databinding.property.IProperty;
26
import org.eclipse.core.databinding.property.ISimplePropertyListener;
27
import org.eclipse.core.databinding.property.SimplePropertyEvent;
28
import org.eclipse.emf.common.notify.Notification;
29
import org.eclipse.emf.common.notify.impl.AdapterImpl;
30
import org.eclipse.emf.ecore.EObject;
31
import org.eclipse.emf.ecore.EStructuralFeature;
32
33
34
/**
35
 * @since 2.5
36
 */
37
public abstract class EMFPropertyListener extends AdapterImpl implements INativePropertyListener
38
{
39
40
  public void addTo(Object source)
41
  {
42
    ((EObject)source).eAdapters().add(this);
43
  }
44
45
  public void removeFrom(Object source)
46
  {
47
    ((EObject)source).eAdapters().remove(this);
48
  }
49
50
  @Override
51
  public abstract void notifyChanged(Notification msg);
52
53
  /**
54
   * @return the listener
55
   */
56
  protected abstract ISimplePropertyListener getListener();
57
58
  /**
59
   * @return the feature
60
   */
61
  protected abstract EStructuralFeature getFeature();
62
63
  /**
64
   * @return the owner property
65
   */
66
  protected abstract IProperty getOwner();
67
68
  /**
69
   * 
70
   */
71
  public abstract static class EMFListPropertyListener extends EMFPropertyListener
72
  {
73
    @Override
74
    public void notifyChanged(Notification msg)
75
    {
76
      if (getFeature() == msg.getFeature() && !msg.isTouch())
77
      {
78
        final ListDiff diff;
79
        switch (msg.getEventType())
80
        {
81
          case Notification.ADD: {
82
            diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg.getPosition(), true, msg.getNewValue()));
83
            break;
84
          }
85
          case Notification.ADD_MANY: {
86
            Collection< ? > newValues = (Collection< ? >)msg.getNewValue();
87
            ListDiffEntry[] listDiffEntries = new ListDiffEntry [newValues.size()];
88
            int position = msg.getPosition();
89
            int index = 0;
90
            for (Object newValue : newValues)
91
            {
92
              listDiffEntries[index++] = Diffs.createListDiffEntry(position++, true, newValue);
93
            }
94
            diff = Diffs.createListDiff(listDiffEntries);
95
            break;
96
          }
97
          case Notification.REMOVE: {
98
            diff = Diffs.createListDiff(Diffs.createListDiffEntry(msg.getPosition(), false, msg.getOldValue()));
99
            break;
100
          }
101
          case Notification.REMOVE_MANY: {
102
            Collection< ? > oldValues = (Collection< ? >)msg.getOldValue();
103
            ListDiffEntry[] listDiffEntries = new ListDiffEntry [oldValues.size()];
104
            int position = msg.getPosition();
105
            int index = 0;
106
            for (Object oldValue : oldValues)
107
            {
108
              listDiffEntries[index++] = Diffs.createListDiffEntry(position++, false, oldValue);
109
            }
110
            diff = Diffs.createListDiff(listDiffEntries);
111
            break;
112
          }
113
          case Notification.SET:
114
          case Notification.RESOLVE: {
115
            ListDiffEntry[] listDiffEntries = new ListDiffEntry [2];
116
            listDiffEntries[0] = Diffs.createListDiffEntry(msg.getPosition(), false, msg.getOldValue());
117
            listDiffEntries[1] = Diffs.createListDiffEntry(msg.getPosition(), true, msg.getNewValue());
118
            diff = Diffs.createListDiff(listDiffEntries);
119
            break;
120
          }
121
          case Notification.MOVE: {
122
            Object movedValue = msg.getNewValue();
123
            ListDiffEntry[] listDiffEntries = new ListDiffEntry [2];
124
            listDiffEntries[0] = Diffs.createListDiffEntry((Integer)msg.getOldValue(), false, movedValue);
125
            listDiffEntries[1] = Diffs.createListDiffEntry(msg.getPosition(), true, movedValue);
126
            diff = Diffs.createListDiff(listDiffEntries);
127
            break;
128
          }
129
          case Notification.UNSET: {
130
            // This just represents going back to the unset state, but
131
            // that doesn't affect the contents of the list.
132
            //
133
            return;
134
          }
135
          default: {
136
            throw new RuntimeException("unhandled case");
137
          }
138
        }
139
        getListener().handleEvent((new SimplePropertyEvent(SimplePropertyEvent.CHANGE, msg.getNotifier(), getOwner(), diff)));
140
      }
141
    }
142
  }
143
144
  /**
145
   * 
146
   */
147
  public abstract static class EMFMapPropertyListener extends EMFPropertyListener
148
  {
149
    @Override
150
    public void notifyChanged(Notification msg)
151
    {
152
      if (getFeature() == msg.getFeature() && !msg.isTouch())
153
      {
154
        getListener().handleEvent(
155
          new SimplePropertyEvent(SimplePropertyEvent.CHANGE, msg.getNotifier(), getOwner(), Diffs.computeMapDiff(
156
            (Map< ? , ? >)msg.getOldValue(),
157
            (Map< ? , ? >)msg.getNewValue())));
158
      }
159
    }
160
  }
161
162
  /**
163
   * 
164
   */
165
  public abstract static class EMFValuePropertyListener extends EMFPropertyListener
166
  {
167
    @Override
168
    public void notifyChanged(Notification msg)
169
    {
170
      if (getFeature() == msg.getFeature() && !msg.isTouch())
171
      {
172
        getListener().handleEvent(
173
          new SimplePropertyEvent(SimplePropertyEvent.CHANGE, msg.getNotifier(), getOwner(), Diffs.createValueDiff(
174
            msg.getOldValue(),
175
            msg.getNewValue())));
176
      }
177
    }
178
  }
179
}
Index: src/org/eclipse/emf/databinding/internal/EMFMapPropertyDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 195222)
12
 *   Matthew Hall - bug 264307
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.internal;
19
20
import org.eclipse.core.databinding.observable.Realm;
21
import org.eclipse.core.databinding.observable.map.IObservableMap;
22
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
23
import org.eclipse.core.databinding.observable.value.IObservableValue;
24
import org.eclipse.core.databinding.property.map.IMapProperty;
25
import org.eclipse.core.databinding.property.map.MapProperty;
26
import org.eclipse.emf.databinding.EMFProperties;
27
import org.eclipse.emf.databinding.FeaturePath;
28
import org.eclipse.emf.databinding.IEMFMapProperty;
29
import org.eclipse.emf.databinding.IEMFValueProperty;
30
import org.eclipse.emf.ecore.EStructuralFeature;
31
32
33
/**
34
 * @since 2.5
35
 */
36
public class EMFMapPropertyDecorator extends MapProperty implements IEMFMapProperty
37
{
38
  private final IMapProperty delegate;
39
  private final EStructuralFeature eStructuralFeature;
40
41
  /**
42
   * @param delegate
43
   * @param eStructuralFeature
44
   */
45
  public EMFMapPropertyDecorator(IMapProperty delegate, EStructuralFeature eStructuralFeature)
46
  {
47
    this.delegate = delegate;
48
    this.eStructuralFeature = eStructuralFeature;
49
  }
50
51
  public EStructuralFeature getStructuralFeature()
52
  {
53
    return eStructuralFeature;
54
  }
55
56
  public Object getKeyType()
57
  {
58
    return delegate.getKeyType();
59
  }
60
61
  public Object getValueType()
62
  {
63
    return delegate.getValueType();
64
  }
65
66
  public IEMFMapProperty values(EStructuralFeature feature)
67
  {
68
    return values(FeaturePath.fromList(feature));
69
  }
70
71
  public IEMFMapProperty values(FeaturePath featurePath)
72
  {
73
    return values(EMFProperties.value(featurePath));
74
  }
75
76
  public IEMFMapProperty values(IEMFValueProperty property)
77
  {
78
    return new EMFMapPropertyDecorator(super.values(property), property.getStructuralFeature());
79
  }
80
81
  public IObservableMap observe(Object source)
82
  {
83
    return new EMFObservableMapDecorator(delegate.observe(source), eStructuralFeature);
84
  }
85
86
  public IObservableMap observe(Realm realm, Object source)
87
  {
88
    return new EMFObservableMapDecorator(delegate.observe(realm, source), eStructuralFeature);
89
  }
90
91
  public IObservableFactory mapFactory()
92
  {
93
    return delegate.mapFactory();
94
  }
95
96
  public IObservableFactory mapFactory(Realm realm)
97
  {
98
    return delegate.mapFactory(realm);
99
  }
100
101
  public IObservableMap observeDetail(IObservableValue master)
102
  {
103
    return new EMFObservableMapDecorator(delegate.observeDetail(master), eStructuralFeature);
104
  }
105
106
  public String toString()
107
  {
108
    return delegate.toString();
109
  }
110
}
Index: src/org/eclipse/emf/databinding/internal/EMFMapProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Matthew Hall - bugs 195222, 264307, 265561
13
 *   Hasan Ceylan  - patch in bug 262160
14
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
15
 * </copyright>
16
 *
17
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
18
 */
19
package org.eclipse.emf.databinding.internal;
20
21
import java.util.Map;
22
23
import org.eclipse.core.databinding.observable.map.MapDiff;
24
import org.eclipse.core.databinding.property.INativePropertyListener;
25
import org.eclipse.core.databinding.property.IProperty;
26
import org.eclipse.core.databinding.property.ISimplePropertyListener;
27
import org.eclipse.core.databinding.property.map.SimpleMapProperty;
28
import org.eclipse.emf.ecore.EClass;
29
import org.eclipse.emf.ecore.EObject;
30
import org.eclipse.emf.ecore.EStructuralFeature;
31
32
33
/**
34
 * @since 2.5
35
 */
36
public class EMFMapProperty extends SimpleMapProperty
37
{
38
  private EStructuralFeature eStructuralFeature;
39
40
  /**
41
   * @param eStructuralFeature
42
   */
43
  public EMFMapProperty(EStructuralFeature eStructuralFeature)
44
  {
45
    this.eStructuralFeature = eStructuralFeature;
46
  }
47
48
  /**
49
   * @return the feature
50
   */
51
  protected EStructuralFeature getFeature()
52
  {
53
    return eStructuralFeature;
54
  }
55
56
  public Object getKeyType()
57
  {
58
    final EClass eType = (EClass)this.eStructuralFeature.getEType();
59
60
    for (final EStructuralFeature feature : eType.getEAllStructuralFeatures())
61
    {
62
      if (feature.getName().equals("key"))
63
      {
64
        return feature;
65
      }
66
    }
67
68
    return null;
69
  }
70
71
  public Object getValueType()
72
  {
73
    final EClass eType = (EClass)this.eStructuralFeature.getEType();
74
75
    for (final EStructuralFeature feature : eType.getEAllStructuralFeatures())
76
    {
77
      if (feature.getName().equals("value"))
78
      {
79
        return feature;
80
      }
81
    }
82
83
    return null;
84
  }
85
86
  protected Map< ? , ? > doGetMap(Object source)
87
  {
88
    EObject eObj = (EObject)source;
89
    return (Map< ? , ? >)eObj.eGet(eStructuralFeature);
90
  }
91
92
  @SuppressWarnings("unchecked")
93
  protected void doSetMap(Object source, Map map, MapDiff diff)
94
  {
95
    EObject eObject = (EObject)source;
96
    eObject.eSet(eStructuralFeature, map);
97
  }
98
99
  public INativePropertyListener adaptListener(final ISimplePropertyListener listener)
100
  {
101
    return new EMFPropertyListener.EMFMapPropertyListener()
102
      {
103
104
        @Override
105
        protected IProperty getOwner()
106
        {
107
          return EMFMapProperty.this;
108
        }
109
110
        @Override
111
        protected ISimplePropertyListener getListener()
112
        {
113
          return listener;
114
        }
115
116
        @Override
117
        protected EStructuralFeature getFeature()
118
        {
119
          return eStructuralFeature;
120
        }
121
      };
122
  }
123
124
  public String toString()
125
  {
126
    String s = EMFPropertyHelper.propertyName(eStructuralFeature) + "{:}"; //$NON-NLS-1$
127
128
    s += "<" + EMFPropertyHelper.shortClassName((EStructuralFeature)getKeyType()) + ", " //$NON-NLS-1$ //$NON-NLS-2$
129
      + EMFPropertyHelper.shortClassName((EStructuralFeature)getValueType()) + ">"; //$NON-NLS-1$
130
    return s;
131
  }
132
}
#P org.eclipse.emf.databinding.edit
(-)src/org/eclipse/emf/databinding/edit/DataBindingEditPlugin.java (-1 / +3 lines)
Lines 20-26 Link Here
20
20
21
import org.eclipse.emf.common.util.ResourceLocator;
21
import org.eclipse.emf.common.util.ResourceLocator;
22
22
23
23
/**
24
/**
25
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
24
 * This is the central singleton for the Data binding Edit plugin.
26
 * This is the central singleton for the Data binding Edit plugin.
25
 */
27
 */
26
public final class DataBindingEditPlugin extends EMFPlugin
28
public final class DataBindingEditPlugin extends EMFPlugin
Lines 40-46 Link Here
40
   */
42
   */
41
  public DataBindingEditPlugin()
43
  public DataBindingEditPlugin()
42
  {
44
  {
43
    super(new ResourceLocator [] {});
45
    super(new ResourceLocator []{});
44
  }
46
  }
45
47
46
  /**
48
  /**
(-)src/org/eclipse/emf/databinding/edit/EMFEditObservables.java (-9 / +26 lines)
Lines 24-36 Link Here
24
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables;
24
import org.eclipse.core.databinding.observable.masterdetail.MasterDetailObservables;
25
import org.eclipse.core.databinding.observable.set.IObservableSet;
25
import org.eclipse.core.databinding.observable.set.IObservableSet;
26
import org.eclipse.core.databinding.observable.value.IObservableValue;
26
import org.eclipse.core.databinding.observable.value.IObservableValue;
27
28
import org.eclipse.emf.databinding.FeaturePath;
29
import org.eclipse.emf.databinding.IEMFValueProperty;
27
import org.eclipse.emf.ecore.EObject;
30
import org.eclipse.emf.ecore.EObject;
28
import org.eclipse.emf.ecore.EStructuralFeature;
31
import org.eclipse.emf.ecore.EStructuralFeature;
29
import org.eclipse.emf.edit.domain.EditingDomain;
32
import org.eclipse.emf.edit.domain.EditingDomain;
30
33
34
31
/**
35
/**
32
 * PROVISIONAL
36
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
33
 * This API is subject to arbitrary change, including renaming or removal.
34
 */
37
 */
35
public class EMFEditObservables
38
public class EMFEditObservables
36
{
39
{
Lines 40-45 Link Here
40
   * @param eObject the object to observe.
43
   * @param eObject the object to observe.
41
   * @param eStructuralFeature the feature of the object to observe.
44
   * @param eStructuralFeature the feature of the object to observe.
42
   * @return an observable value for the given feature of the object.
45
   * @return an observable value for the given feature of the object.
46
   * @deprecated you should use {@link EMFEditProperties#value(EditingDomain,FeaturePath)} and {@link IEMFValueProperty#observe(Object)}
43
   */
47
   */
44
  public static IObservableValue observeValue(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
48
  public static IObservableValue observeValue(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
45
  {
49
  {
Lines 53-58 Link Here
53
   * @param eObject the object to observe.
57
   * @param eObject the object to observe.
54
   * @param eStructuralFeature the feature of the object to observe.
58
   * @param eStructuralFeature the feature of the object to observe.
55
   * @return an observable value for the given feature of the object.
59
   * @return an observable value for the given feature of the object.
60
   * @deprecated you should use {@link EMFEditProperties#value(EditingDomain,EStructuralFeature)} and {@link IEMFEditValueProperty#observe(Realm, Object)}
56
   */
61
   */
57
  public static IObservableValue observeValue(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
62
  public static IObservableValue observeValue(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
58
  {
63
  {
Lines 65-70 Link Here
65
   * @param eObject the object to observe.
70
   * @param eObject the object to observe.
66
   * @param eStructuralFeature the feature of the object to observe.
71
   * @param eStructuralFeature the feature of the object to observe.
67
   * @return an observable list for the given multi-valued feature of the object.
72
   * @return an observable list for the given multi-valued feature of the object.
73
   * @deprecated you should use {@link EMFEditProperties#list(EditingDomain,EStructuralFeature)} and {@link IEMFEditListProperty#observe(Object)}
68
   */
74
   */
69
  public static IObservableList observeList(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
75
  public static IObservableList observeList(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
70
  {
76
  {
Lines 78-83 Link Here
78
   * @param eObject the object to observe.
84
   * @param eObject the object to observe.
79
   * @param eStructuralFeature the feature of the object to observe.
85
   * @param eStructuralFeature the feature of the object to observe.
80
   * @return an observable list for the given multi-valued feature of the object.
86
   * @return an observable list for the given multi-valued feature of the object.
87
   * @deprecated you should use {@link EMFEditProperties#list(EditingDomain,EStructuralFeature)} and {@link IEMFEditListProperty#observe(Realm,Object)}
81
   */
88
   */
82
  public static IObservableList observeList(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
89
  public static IObservableList observeList(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
83
  {
90
  {
Lines 91-96 Link Here
91
   * @param objects the objects to track.
98
   * @param objects the objects to track.
92
   * @param eStructuralFeature the feature for which to track the value.
99
   * @param eStructuralFeature the feature for which to track the value.
93
   * @return an observable map tracking the current value of the given feature for each object in the given set.
100
   * @return an observable map tracking the current value of the given feature for each object in the given set.
101
   * @deprecated you should use {@link EMFEditProperties#value(EditingDomain,EStructuralFeature)} and {@link IEMFEditValueProperty#observeDetail(IObservableSet)}
94
   */
102
   */
95
  public static IObservableMap observeMap(EditingDomain domain, IObservableSet objects, EStructuralFeature eStructuralFeature)
103
  public static IObservableMap observeMap(EditingDomain domain, IObservableSet objects, EStructuralFeature eStructuralFeature)
96
  {
104
  {
Lines 104-109 Link Here
104
   * @param objects the objects to track.
112
   * @param objects the objects to track.
105
   * @param eStructuralFeatures the features for which to track the value.
113
   * @param eStructuralFeatures the features for which to track the value.
106
   * @return an array of observable maps tracking the current value of the given features for each object in the given set.
114
   * @return an array of observable maps tracking the current value of the given features for each object in the given set.
115
   * @deprecated you should use {@link EMFEditProperties#values(EditingDomain,EStructuralFeature...)} and {@link IEMFEditValueProperty#observeDetail(IObservableSet)}
107
   */
116
   */
108
  public static IObservableMap[] observeMaps(EditingDomain domain, IObservableSet objects, EStructuralFeature[] eStructuralFeatures)
117
  public static IObservableMap[] observeMaps(EditingDomain domain, IObservableSet objects, EStructuralFeature[] eStructuralFeatures)
109
  {
118
  {
Lines 123-130 Link Here
123
   * @param eStructuralFeature the feature for which to track the value.
132
   * @param eStructuralFeature the feature for which to track the value.
124
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
133
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
125
   * @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object)
134
   * @see MasterDetailObservables#detailValue(IObservableValue, IObservableFactory, Object)
135
   * @deprecated you should use {@link EMFEditProperties#value(EditingDomain,EStructuralFeature)} and {@link IEMFEditValueProperty#observeDetail(IObservableValue)}
126
   */
136
   */
127
  public static IObservableValue observeDetailValue(Realm realm, EditingDomain domain, IObservableValue value, EStructuralFeature eStructuralFeature)
137
  public static IObservableValue observeDetailValue(
138
    Realm realm,
139
    EditingDomain domain,
140
    IObservableValue value,
141
    EStructuralFeature eStructuralFeature)
128
  {
142
  {
129
    return MasterDetailObservables.detailValue(value, valueFactory(realm, domain, eStructuralFeature), eStructuralFeature);
143
    return MasterDetailObservables.detailValue(value, valueFactory(realm, domain, eStructuralFeature), eStructuralFeature);
130
  }
144
  }
Lines 156-163 Link Here
156
   * @param eStructuralFeature the feature for which to track the value.
170
   * @param eStructuralFeature the feature for which to track the value.
157
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
171
   * @return an observable value that tracks the current value of the named property for the current value of the master observable value
158
   * @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object)
172
   * @see MasterDetailObservables#detailList(IObservableValue, IObservableFactory, Object)
173
   * @deprecated you should use {@link EMFEditProperties#value(EditingDomain,EStructuralFeature)} and {@link IEMFEditValueProperty#observeDetail(IObservableList)}
159
   */
174
   */
160
  public static IObservableList observeDetailList(Realm realm, EditingDomain domain, IObservableValue value, EStructuralFeature eStructuralFeature)
175
  public static IObservableList observeDetailList(
176
    Realm realm,
177
    EditingDomain domain,
178
    IObservableValue value,
179
    EStructuralFeature eStructuralFeature)
161
  {
180
  {
162
    return MasterDetailObservables.detailList(value, listFactory(realm, domain, eStructuralFeature), eStructuralFeature);
181
    return MasterDetailObservables.detailList(value, listFactory(realm, domain, eStructuralFeature), eStructuralFeature);
163
  }
182
  }
Lines 172-179 Link Here
172
   */
191
   */
173
  public static IObservableFactory listFactory(final Realm realm, final EditingDomain domain, final EStructuralFeature eStructuralFeature)
192
  public static IObservableFactory listFactory(final Realm realm, final EditingDomain domain, final EStructuralFeature eStructuralFeature)
174
  {
193
  {
175
    return 
194
    return new IObservableFactory()
176
      new IObservableFactory()
177
      {
195
      {
178
        public IObservable createObservable(Object target)
196
        public IObservable createObservable(Object target)
179
        {
197
        {
Lines 191-203 Link Here
191
   */
209
   */
192
  public static IObservableFactory mapFactory(final EditingDomain domain, final EStructuralFeature eStructuralFeature)
210
  public static IObservableFactory mapFactory(final EditingDomain domain, final EStructuralFeature eStructuralFeature)
193
  {
211
  {
194
    return
212
    return new IObservableFactory()
195
      new IObservableFactory()
196
      {
213
      {
197
        public IObservable createObservable(Object target)
214
        public IObservable createObservable(Object target)
198
        {
215
        {
199
          return observeMap(domain, (IObservableSet)target, eStructuralFeature);
216
          return observeMap(domain, (IObservableSet)target, eStructuralFeature);
200
        }
217
        }
201
      };
218
      };
202
   }
219
  }
203
}
220
}
(-)src/org/eclipse/emf/databinding/edit/EditingDomainEObjectObservableValue.java (-2 / +29 lines)
Lines 24-41 Link Here
24
import org.eclipse.emf.edit.command.SetCommand;
24
import org.eclipse.emf.edit.command.SetCommand;
25
import org.eclipse.emf.edit.domain.EditingDomain;
25
import org.eclipse.emf.edit.domain.EditingDomain;
26
26
27
27
/**
28
/**
28
 * PROVISIONAL
29
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
29
 * This API is subject to arbitrary change, including renaming or removal.
30
 * @deprecated do not use this value it will be removed in 2.6
30
 */
31
 */
31
public class EditingDomainEObjectObservableValue extends EObjectObservableValue
32
public class EditingDomainEObjectObservableValue extends EObjectObservableValue
32
{
33
{
34
  /**
35
   * The editing domain
36
   */
33
  protected EditingDomain domain;
37
  protected EditingDomain domain;
34
38
39
  /**
40
   * Observe a list feature using a default realm
41
   * 
42
   * @param domain 
43
   *            the editing domain
44
   * @param eObject
45
   *            the object instance
46
   * @param eStructuralFeature
47
   *            the feature
48
   */
35
  public EditingDomainEObjectObservableValue(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
49
  public EditingDomainEObjectObservableValue(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
36
  {
50
  {
37
    this(Realm.getDefault(), domain, eObject, eStructuralFeature);
51
    this(Realm.getDefault(), domain, eObject, eStructuralFeature);
38
  }
52
  }
53
54
  /**
55
   * Observe a list feature using a custom realm
56
   * 
57
   * @param realm
58
   *            the realm
59
   * @param domain 
60
   *            the editing domain
61
   * @param eObject
62
   *            the object instance
63
   * @param eStructuralFeature
64
   *            the feature
65
   */
39
  public EditingDomainEObjectObservableValue(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
66
  public EditingDomainEObjectObservableValue(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
40
  {
67
  {
41
    super(realm, eObject, eStructuralFeature);
68
    super(realm, eObject, eStructuralFeature);
(-)src/org/eclipse/emf/databinding/edit/EditingDomainEObjectObservableList.java (-4 / +31 lines)
Lines 30-54 Link Here
30
import org.eclipse.emf.edit.command.SetCommand;
30
import org.eclipse.emf.edit.command.SetCommand;
31
import org.eclipse.emf.edit.domain.EditingDomain;
31
import org.eclipse.emf.edit.domain.EditingDomain;
32
32
33
33
/**
34
/**
34
 * PROVISIONAL
35
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
35
 * This API is subject to arbitrary change, including renaming or removal.
36
 * @deprecated do not use this list it will be removed in 2.6
36
 */
37
 */
37
public class EditingDomainEObjectObservableList extends EObjectObservableList
38
public class EditingDomainEObjectObservableList extends EObjectObservableList
38
{
39
{
40
  /**
41
   * The editing domain
42
   */
39
  protected EditingDomain domain;
43
  protected EditingDomain domain;
40
44
45
  /**
46
   * Observe a feature of the instance using the default realm
47
   * @param domain
48
   *            the editing domain
49
   * @param eObject
50
   *            the object
51
   * @param eStructuralFeature
52
   *            the feature
53
   */
41
  public EditingDomainEObjectObservableList(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
54
  public EditingDomainEObjectObservableList(EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
42
  {
55
  {
43
    this(Realm.getDefault(), domain, eObject, eStructuralFeature);
56
    this(Realm.getDefault(), domain, eObject, eStructuralFeature);
44
  }
57
  }
45
58
59
  /**
60
   * Observe a feature of the instance using the realm
61
   * @param domain
62
   *            the editing domain
63
   * @param realm
64
   * 
65
   * @param eObject
66
   *            the object
67
   * @param eStructuralFeature
68
   *            the feature
69
   */
46
  public EditingDomainEObjectObservableList(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
70
  public EditingDomainEObjectObservableList(Realm realm, EditingDomain domain, EObject eObject, EStructuralFeature eStructuralFeature)
47
  {
71
  {
48
    super(realm, eObject, eStructuralFeature);
72
    super(realm, eObject, eStructuralFeature);
49
    this.domain = domain;
73
    this.domain = domain;
50
  }
74
  }
51
  
52
75
53
  @Override
76
  @Override
54
  public synchronized void dispose()
77
  public synchronized void dispose()
Lines 57-62 Link Here
57
    super.dispose();
80
    super.dispose();
58
  }
81
  }
59
82
83
  /**
84
   * Execute a command
85
   * @param command the command to execute
86
   * @return <code>true</code> if execute else <code>false</code>
87
   */
60
  protected boolean execute(Command command)
88
  protected boolean execute(Command command)
61
  {
89
  {
62
    if (command.canExecute())
90
    if (command.canExecute())
Lines 70-76 Link Here
70
    }
98
    }
71
  }
99
  }
72
100
73
74
  @Override
101
  @Override
75
  public boolean add(Object object)
102
  public boolean add(Object object)
76
  {
103
  {
(-)src/org/eclipse/emf/databinding/edit/EditingDomainEObjectObservableMap.java (-4 / +17 lines)
Lines 24-43 Link Here
24
import org.eclipse.emf.edit.command.SetCommand;
24
import org.eclipse.emf.edit.command.SetCommand;
25
import org.eclipse.emf.edit.domain.EditingDomain;
25
import org.eclipse.emf.edit.domain.EditingDomain;
26
26
27
27
/**
28
/**
28
 * PROVISIONAL
29
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
29
 * This API is subject to arbitrary change, including renaming or removal.
30
 * @deprecated do not use this map it will be removed in 2.6
30
 */
31
 */
31
public class EditingDomainEObjectObservableMap extends EObjectObservableMap
32
public class EditingDomainEObjectObservableMap extends EObjectObservableMap
32
{
33
{
34
  /**
35
   * The editing domain
36
   */
33
  protected EditingDomain domain;
37
  protected EditingDomain domain;
34
38
39
  /**
40
   * Create a new observable for the set of features
41
   * @param domain
42
   *            the editing domain
43
   * @param objects
44
   *            the objects to observe
45
   * @param eStructuralFeature
46
   *            the feature
47
   */
35
  public EditingDomainEObjectObservableMap(EditingDomain domain, IObservableSet objects, EStructuralFeature eStructuralFeature)
48
  public EditingDomainEObjectObservableMap(EditingDomain domain, IObservableSet objects, EStructuralFeature eStructuralFeature)
36
  {
49
  {
37
    super(objects, eStructuralFeature);
50
    super(objects, eStructuralFeature);
38
    this.domain = domain;
51
    this.domain = domain;
39
  }
52
  }
40
  
53
41
  @Override
54
  @Override
42
  protected Object doPut(Object key, Object value)
55
  protected Object doPut(Object key, Object value)
43
  {
56
  {
Lines 45-51 Link Here
45
    Object result = eObject.eGet(eStructuralFeature);
58
    Object result = eObject.eGet(eStructuralFeature);
46
    Command command = SetCommand.create(domain, eObject, eStructuralFeature, value);
59
    Command command = SetCommand.create(domain, eObject, eStructuralFeature, value);
47
    domain.getCommandStack().execute(command);
60
    domain.getCommandStack().execute(command);
48
    
61
49
    eObject.eSet(eStructuralFeature, value);
62
    eObject.eSet(eStructuralFeature, value);
50
    return result;
63
    return result;
51
  }
64
  }
(-)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 (+55 lines)
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import java.util.Map;
19
20
import org.eclipse.core.databinding.observable.map.MapDiff;
21
import org.eclipse.emf.common.command.Command;
22
import org.eclipse.emf.databinding.internal.EMFMapProperty;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EStructuralFeature;
25
import org.eclipse.emf.edit.command.SetCommand;
26
import org.eclipse.emf.edit.domain.EditingDomain;
27
28
29
/**
30
 * @since 2.5
31
 */
32
public class EMFEditMapProperty extends EMFMapProperty
33
{
34
  private final EditingDomain editingDomain;
35
36
  /**
37
   * @param editingDomain
38
   * @param eStructuralFeature
39
   */
40
  public EMFEditMapProperty(EditingDomain editingDomain, EStructuralFeature eStructuralFeature)
41
  {
42
    super(eStructuralFeature);
43
    this.editingDomain = editingDomain;
44
  }
45
46
  @SuppressWarnings("unchecked")
47
  @Override
48
  protected void doSetMap(Object source, Map map, MapDiff diff)
49
  {
50
    EObject eObject = (EObject)source;
51
    Command command = SetCommand.create(editingDomain, eObject, getFeature(), map);
52
    editingDomain.getCommandStack().execute(command);
53
  }
54
55
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditListProperty.java (+978 lines)
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 195222)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding.edit;
18
19
import org.eclipse.core.databinding.property.list.IListProperty;
20
import org.eclipse.emf.databinding.FeaturePath;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
23
24
/**
25
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
26
 * 
27
 * An {@link IListProperty} extension interface with convenience methods for
28
 * creating nested {@link EStructuralFeature}s
29
 * 
30
 * @since 2.5
31
 * @noextend This interface is not intended to be extended by clients.
32
 * @noimplement This interface is not intended to be implemented by clients.
33
 */
34
public interface IEMFEditListProperty extends IEMFEditProperty, IListProperty
35
{
36
  /**
37
   * Returns a master-detail combination of this property and the specified
38
   * value nested feature.
39
   * 
40
   * @param featurePath
41
   *            the nested feature to observe
42
   * @return a nested combination of this property and the specified nested
43
   *         feature.
44
   * @see #values(IEMFEditValueProperty)
45
   */
46
  public IEMFEditListProperty values(FeaturePath featurePath);
47
48
  /**
49
   * Returns a master-detail combination of this property and the specified
50
   * value property.
51
   * 
52
   * @param feature
53
   *            the feature
54
   * @return a nested combination of this property and the specified nested
55
   *         feature.
56
   */
57
  public IEMFEditListProperty values(EStructuralFeature feature);
58
59
  /**
60
   * Returns a master-detail combination of this property and the specified
61
   * value property. The returned property will observe the specified value
62
   * property for all elements observed by this list property.
63
   * <p>
64
   * Example:
65
   * 
66
   * <pre>
67
   * // Observes the list-typed &quot;children&quot; property of a Person object,
68
   * // where the elements are Person objects
69
   * IEMFListProperty children = EMFProperties
70
   *        .list(MyPackage.Literals.PERSON_CHILDREN);
71
   * // Observes the string-typed &quot;name&quot; property of a Person object
72
   * IEMFValueProperty name = EMFProperties.value(MyPackage.Literals.PERSON_NAME);
73
   * // Observes the names of children of a Person object.
74
   * IEMFListProperty childrenNames = children.values(name);
75
   * </pre>
76
   * 
77
   * @param property
78
   *            the detail property to observe
79
   * @return a master-detail combination of this property and the specified
80
   *         value property.
81
   */
82
  public IEMFEditListProperty values(IEMFEditValueProperty property);
83
}
Index: src/org/eclipse/emf/databinding/edit/IEMFEditMapProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 195222)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding.edit;
18
19
import java.util.Map;
20
21
import org.eclipse.core.databinding.property.map.IMapProperty;
22
import org.eclipse.emf.databinding.FeaturePath;
23
import org.eclipse.emf.ecore.EStructuralFeature;
24
25
26
/**
27
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
28
 * 
29
 * An {@link IMapProperty} extension interface with convenience methods for
30
 * creating nested {@link EStructuralFeature} properties.
31
 * 
32
 * @since 2.5
33
 * @noextend This interface is not intended to be extended by clients.
34
 * @noimplement This interface is not intended to be implemented by clients.
35
 */
36
public interface IEMFEditMapProperty extends IEMFEditProperty, IMapProperty
37
{
38
39
  /**
40
   * Returns a master-detail combination of this property and the specified
41
   * nested value feature.
42
   * 
43
   * @param featurePath
44
   *            the nested value feature to observe
45
   * @return a master-detail combination of this property and the specified
46
   *         nested value feature.
47
   * @see #values(IEMFEditValueProperty)
48
   */
49
  public IEMFEditMapProperty values(FeaturePath featurePath);
50
51
  /**
52
   * Returns a master-detail combination of this property and the specified
53
   * value feature.
54
   * 
55
   * @param feature
56
   *            the value feature to observe
57
   * @return a master-detail combination of this property and the specified
58
   *         nested value feature.
59
   * @see #values(IEMFEditValueProperty)
60
   */
61
  public IEMFEditMapProperty values(EStructuralFeature feature);
62
63
  /**
64
   * Returns a master-detail combination of this property and the specified
65
   * value property. The returned property will observe the specified value
66
   * property for all {@link Map#values() values} observed by this map
67
   * property, mapping from this map property's {@link Map#keySet() key set}
68
   * to the specified value property's value for each element in the master
69
   * property's {@link Map#values() values} collection.
70
   * 
71
   * @param property
72
   *            the detail property to observe
73
   * @return a master-detail combination of this property and the specified
74
   *         value property.
75
   */
76
  public IEMFEditMapProperty values(IEMFEditValueProperty property);
77
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditObservableMapDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import org.eclipse.core.databinding.observable.map.IObservableMap;
19
import org.eclipse.emf.databinding.edit.IEMFEditObservable;
20
import org.eclipse.emf.databinding.internal.EMFObservableMapDecorator;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.edit.domain.EditingDomain;
23
24
25
/**
26
 * {@link IEMFEditObservable} decorator for an {@link IObservableMap}.
27
 * 
28
 * @since 2.5
29
 */
30
public class EMFEditObservableMapDecorator extends EMFObservableMapDecorator implements IEMFEditObservable
31
{
32
  private final EditingDomain editingDomain;
33
34
  /**
35
   * @param editingDomain
36
   * @param decorated
37
   * @param eStructuralFeature
38
   */
39
  public EMFEditObservableMapDecorator(EditingDomain editingDomain, IObservableMap decorated, EStructuralFeature eStructuralFeature)
40
  {
41
    super(decorated, eStructuralFeature);
42
    this.editingDomain = editingDomain;
43
  }
44
45
  public EditingDomain getEditingDomain()
46
  {
47
    return editingDomain;
48
  }
49
}
Index: src/org/eclipse/emf/databinding/edit/IEMFEditObservable.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2007 Brad Reynolds 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
 *   Brad Reynolds - initial API and implementation
12
 *   Brad Reynolds - bug 147515
13
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
14
 * </copyright>
15
 *
16
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
17
 */
18
package org.eclipse.emf.databinding.edit;
19
20
21
import org.eclipse.emf.databinding.IEMFObservable;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.edit.domain.EditingDomain;
24
25
26
/**
27
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
28
 * Provides access to details of {@link EObject} observables.
29
 * <p>
30
 * This interface is not meant to be implemented by clients.
31
 * </p>
32
 * 
33
 * @since 2.5
34
 * @noextend This interface is not intended to be extended by clients.
35
 * @noimplement This interface is not intended to be implemented by clients.
36
 */
37
public interface IEMFEditObservable extends IEMFObservable
38
{
39
  /**
40
   * @return the editing domain to execute commands
41
   */
42
  public EditingDomain getEditingDomain();
43
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditListPropertyDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.list.IObservableList;
20
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
21
import org.eclipse.core.databinding.observable.value.IObservableValue;
22
import org.eclipse.core.databinding.property.list.IListProperty;
23
import org.eclipse.core.databinding.property.list.ListProperty;
24
import org.eclipse.emf.databinding.FeaturePath;
25
import org.eclipse.emf.databinding.edit.EMFEditProperties;
26
import org.eclipse.emf.databinding.edit.IEMFEditListProperty;
27
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
28
import org.eclipse.emf.ecore.EStructuralFeature;
29
import org.eclipse.emf.edit.domain.EditingDomain;
30
31
32
/**
33
 * @since 2.5
34
 */
35
public class EMFEditListPropertyDecorator extends ListProperty implements IEMFEditListProperty
36
{
37
  private final IListProperty delegate;
38
  private final EStructuralFeature eStructuralFeature;
39
  private final EditingDomain editingDomain;
40
41
  
42
  /**
43
   * @param editingDomain
44
   * @param delegate
45
   * @param eStructuralFeature
46
   */
47
  public EMFEditListPropertyDecorator(EditingDomain editingDomain, IListProperty delegate, EStructuralFeature eStructuralFeature)
48
  {
49
    this.delegate = delegate;
50
    this.eStructuralFeature = eStructuralFeature;
51
    this.editingDomain = editingDomain;
52
  }
53
54
  public Object getElementType()
55
  {
56
    return delegate.getElementType();
57
  }
58
59
  public IEMFEditListProperty values(EStructuralFeature feature)
60
  {
61
    return values(FeaturePath.fromList(feature));
62
  }
63
64
  public IEMFEditListProperty values(FeaturePath featurePath)
65
  {
66
    return values(EMFEditProperties.value(editingDomain, featurePath));
67
  }
68
69
  public IEMFEditListProperty values(IEMFEditValueProperty property)
70
  {
71
    return new EMFEditListPropertyDecorator(editingDomain, super.values(property), property.getStructuralFeature());
72
  }
73
74
  public EStructuralFeature getStructuralFeature()
75
  {
76
    return eStructuralFeature;
77
  }
78
79
  public IObservableList observe(Object source)
80
  {
81
    return new EMFEditObservableListDecorator(editingDomain, delegate.observe(source), eStructuralFeature);
82
  }
83
84
  public IObservableList observe(Realm realm, Object source)
85
  {
86
    return new EMFEditObservableListDecorator(editingDomain, delegate.observe(realm, source), eStructuralFeature);
87
  }
88
89
  public IObservableFactory listFactory()
90
  {
91
    return delegate.listFactory();
92
  }
93
94
  public IObservableFactory listFactory(Realm realm)
95
  {
96
    return delegate.listFactory(realm);
97
  }
98
99
  public IObservableList observeDetail(IObservableValue master)
100
  {
101
    return new EMFEditObservableListDecorator(editingDomain, delegate.observeDetail(master), eStructuralFeature);
102
  }
103
104
  public String toString()
105
  {
106
    return delegate.toString();
107
  }
108
109
  public EditingDomain getEditingDomain()
110
  {
111
    return editingDomain;
112
  }
113
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditValuePropertyDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.list.IObservableList;
20
import org.eclipse.core.databinding.observable.map.IObservableMap;
21
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
22
import org.eclipse.core.databinding.observable.set.IObservableSet;
23
import org.eclipse.core.databinding.observable.value.IObservableValue;
24
import org.eclipse.core.databinding.property.value.IValueProperty;
25
import org.eclipse.core.databinding.property.value.ValueProperty;
26
import org.eclipse.emf.databinding.FeaturePath;
27
import org.eclipse.emf.databinding.edit.EMFEditProperties;
28
import org.eclipse.emf.databinding.edit.IEMFEditListProperty;
29
import org.eclipse.emf.databinding.edit.IEMFEditMapProperty;
30
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
31
import org.eclipse.emf.ecore.EStructuralFeature;
32
import org.eclipse.emf.edit.domain.EditingDomain;
33
34
35
/**
36
 * @since 2.5
37
 */
38
public class EMFEditValuePropertyDecorator extends ValueProperty implements IEMFEditValueProperty
39
{
40
  private final IValueProperty delegate;
41
  private final EStructuralFeature eStructuralFeature;
42
  private final EditingDomain editingDomain;
43
44
  /**
45
   * @param editingDomain
46
   * @param delegate
47
   * @param eStructuralFeature
48
   */
49
  public EMFEditValuePropertyDecorator(EditingDomain editingDomain, IValueProperty delegate, EStructuralFeature eStructuralFeature)
50
  {
51
    this.delegate = delegate;
52
    this.eStructuralFeature = eStructuralFeature;
53
    this.editingDomain = editingDomain;
54
  }
55
56
  public EStructuralFeature getStructuralFeature()
57
  {
58
    return eStructuralFeature;
59
  }
60
61
  public Object getValueType()
62
  {
63
    return delegate.getValueType();
64
  }
65
66
  public IEMFEditValueProperty value(EStructuralFeature feature)
67
  {
68
    return value(FeaturePath.fromList(feature));
69
  }
70
71
  public IEMFEditValueProperty value(FeaturePath featurePath)
72
  {
73
    return value(EMFEditProperties.value(editingDomain, featurePath));
74
  }
75
76
  public IEMFEditValueProperty value(IEMFEditValueProperty property)
77
  {
78
    return new EMFEditValuePropertyDecorator(editingDomain, super.value(property), property.getStructuralFeature());
79
  }
80
81
  public IEMFEditListProperty list(EStructuralFeature feature)
82
  {
83
    return list(EMFEditProperties.list(editingDomain, feature));
84
  }
85
86
  public IEMFEditListProperty list(IEMFEditListProperty property)
87
  {
88
    return new EMFEditListPropertyDecorator(editingDomain, super.list(property), property.getStructuralFeature());
89
  }
90
91
  public IEMFEditMapProperty map(EStructuralFeature feature)
92
  {
93
    return EMFEditProperties.map(editingDomain, feature);
94
  }
95
96
  public IEMFEditMapProperty map(IEMFEditMapProperty property)
97
  {
98
    return new EMFEditMapPropertyDecorator(editingDomain, super.map(property), property.getStructuralFeature());
99
  }
100
101
  public IObservableValue observe(Object source)
102
  {
103
    return new EMFEditObservableValueDecorator(editingDomain, delegate.observe(source), eStructuralFeature);
104
  }
105
106
  public IObservableValue observe(Realm realm, Object source)
107
  {
108
    return new EMFEditObservableValueDecorator(editingDomain, delegate.observe(realm, source), eStructuralFeature);
109
  }
110
111
  public IObservableFactory valueFactory()
112
  {
113
    return delegate.valueFactory();
114
  }
115
116
  public IObservableFactory valueFactory(Realm realm)
117
  {
118
    return delegate.valueFactory(realm);
119
  }
120
121
  public IObservableValue observeDetail(IObservableValue master)
122
  {
123
    return new EMFEditObservableValueDecorator(editingDomain, delegate.observeDetail(master), eStructuralFeature);
124
  }
125
126
  public IObservableList observeDetail(IObservableList master)
127
  {
128
    return new EMFEditObservableListDecorator(editingDomain, delegate.observeDetail(master), eStructuralFeature);
129
  }
130
131
  public IObservableMap observeDetail(IObservableSet master)
132
  {
133
    return new EMFEditObservableMapDecorator(editingDomain, delegate.observeDetail(master), eStructuralFeature);
134
  }
135
136
  public IObservableMap observeDetail(IObservableMap master)
137
  {
138
    return new EMFEditObservableMapDecorator(editingDomain, delegate.observeDetail(master), eStructuralFeature);
139
  }
140
141
  public String toString()
142
  {
143
    return delegate.toString();
144
  }
145
146
  public EditingDomain getEditingDomain()
147
  {
148
    return editingDomain;
149
  }
150
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditObservableValueDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.emf.databinding.edit.IEMFEditObservable;
20
import org.eclipse.emf.databinding.internal.EMFObservableValueDecorator;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.edit.domain.EditingDomain;
23
24
25
/**
26
 * {@link IEMFEditObservable} decorator for an {@link IObservableValue}.
27
 * 
28
 * @since 2.5
29
 */
30
public class EMFEditObservableValueDecorator extends EMFObservableValueDecorator implements IEMFEditObservable
31
{
32
  private final EditingDomain editingDomain;
33
34
  /**
35
   * @param editingDomain
36
   * @param decorated
37
   * @param eStructuralFeature
38
   */
39
  public EMFEditObservableValueDecorator(EditingDomain editingDomain, IObservableValue decorated, EStructuralFeature eStructuralFeature)
40
  {
41
    super(decorated, eStructuralFeature);
42
    this.editingDomain = editingDomain;
43
  }
44
45
  public EditingDomain getEditingDomain()
46
  {
47
    return editingDomain;
48
  }
49
50
}
Index: src/org/eclipse/emf/databinding/edit/IEMFEditProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding.edit;
18
19
import org.eclipse.emf.databinding.IEMFProperty;
20
import org.eclipse.emf.ecore.EStructuralFeature;
21
import org.eclipse.emf.edit.domain.EditingDomain;
22
23
24
/**
25
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
26
 * An IProperty extension interface providing access to details of {@link EStructuralFeature}
27
 * properties.
28
 * 
29
 * @since 2.5
30
 * @noextend This interface is not intended to be extended by clients.
31
 * @noimplement This interface is not intended to be implemented by clients.
32
 */
33
public interface IEMFEditProperty extends IEMFProperty
34
{
35
  /**
36
   * @return the editing domain to execute commands
37
   */
38
  public EditingDomain getEditingDomain();
39
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditObservableListDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import org.eclipse.core.databinding.observable.list.IObservableList;
19
import org.eclipse.emf.databinding.edit.IEMFEditObservable;
20
import org.eclipse.emf.databinding.internal.EMFObservableListDecorator;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.edit.domain.EditingDomain;
23
24
25
/**
26
 * {@link IEMFEditObservable} decorator for an {@link IObservableList}.
27
 * 
28
 * @since 2.5
29
 */
30
public class EMFEditObservableListDecorator extends EMFObservableListDecorator implements IEMFEditObservable
31
{
32
33
  private final EditingDomain editingDomain;
34
35
  /**
36
   * @param editingDomain
37
   * @param decorated
38
   * @param eStructuralFeature
39
   */
40
  public EMFEditObservableListDecorator(EditingDomain editingDomain, IObservableList decorated, EStructuralFeature eStructuralFeature)
41
  {
42
    super(decorated, eStructuralFeature);
43
    this.editingDomain = editingDomain;
44
  }
45
46
  public EditingDomain getEditingDomain()
47
  {
48
    return editingDomain;
49
  }
50
51
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditMapPropertyDecorator.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.map.IObservableMap;
20
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
21
import org.eclipse.core.databinding.observable.value.IObservableValue;
22
import org.eclipse.core.databinding.property.map.IMapProperty;
23
import org.eclipse.core.databinding.property.map.MapProperty;
24
import org.eclipse.emf.databinding.FeaturePath;
25
import org.eclipse.emf.databinding.edit.EMFEditProperties;
26
import org.eclipse.emf.databinding.edit.IEMFEditMapProperty;
27
import org.eclipse.emf.databinding.edit.IEMFEditValueProperty;
28
import org.eclipse.emf.ecore.EStructuralFeature;
29
import org.eclipse.emf.edit.domain.EditingDomain;
30
31
32
/**
33
 * @since 2.5
34
 */
35
public class EMFEditMapPropertyDecorator extends MapProperty implements IEMFEditMapProperty
36
{
37
  private final IMapProperty delegate;
38
  private final EStructuralFeature eStructuralFeature;
39
  private final EditingDomain editingDomain;
40
41
  /**
42
   * @param editingDomain
43
   * @param delegate
44
   * @param eStructuralFeature
45
   */
46
  public EMFEditMapPropertyDecorator(EditingDomain editingDomain, IMapProperty delegate, EStructuralFeature eStructuralFeature)
47
  {
48
    this.delegate = delegate;
49
    this.eStructuralFeature = eStructuralFeature;
50
    this.editingDomain = editingDomain;
51
  }
52
53
  public EStructuralFeature getStructuralFeature()
54
  {
55
    return eStructuralFeature;
56
  }
57
58
  public Object getKeyType()
59
  {
60
    return delegate.getKeyType();
61
  }
62
63
  public Object getValueType()
64
  {
65
    return delegate.getValueType();
66
  }
67
68
  public IEMFEditMapProperty values(EStructuralFeature feature)
69
  {
70
    return values(FeaturePath.fromList(feature));
71
  }
72
73
  public IEMFEditMapProperty values(FeaturePath featurePath)
74
  {
75
    return values(EMFEditProperties.value(editingDomain, featurePath));
76
  }
77
78
  public IEMFEditMapProperty values(IEMFEditValueProperty property)
79
  {
80
    return new EMFEditMapPropertyDecorator(editingDomain, super.values(property), property.getStructuralFeature());
81
  }
82
83
  public IObservableMap observe(Object source)
84
  {
85
    return new EMFEditObservableMapDecorator(editingDomain, delegate.observe(source), eStructuralFeature);
86
  }
87
88
  public IObservableMap observe(Realm realm, Object source)
89
  {
90
    return new EMFEditObservableMapDecorator(editingDomain, delegate.observe(realm, source), eStructuralFeature);
91
  }
92
93
  public IObservableFactory mapFactory()
94
  {
95
    return delegate.mapFactory();
96
  }
97
98
  public IObservableFactory mapFactory(Realm realm)
99
  {
100
    return delegate.mapFactory(realm);
101
  }
102
103
  public IObservableMap observeDetail(IObservableValue master)
104
  {
105
    return new EMFEditObservableMapDecorator(editingDomain, delegate.observeDetail(master), eStructuralFeature);
106
  }
107
108
  public String toString()
109
  {
110
    return delegate.toString();
111
  }
112
113
  public EditingDomain getEditingDomain()
114
  {
115
    return editingDomain;
116
  }
117
}
Index: src/org/eclipse/emf/databinding/edit/EMFEditProperties.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 194734)
12
 *   Matthew Hall - bug 195222, 247997, 261843, 264307
13
 *   Hasan Ceylan  - patch in bug 262160
14
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
15
 * </copyright>
16
 *
17
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
18
 */
19
package org.eclipse.emf.databinding.edit;
20
21
import org.eclipse.core.databinding.property.list.IListProperty;
22
import org.eclipse.core.databinding.property.map.IMapProperty;
23
import org.eclipse.core.databinding.property.value.IValueProperty;
24
import org.eclipse.emf.databinding.FeaturePath;
25
import org.eclipse.emf.databinding.edit.internal.EMFEditListProperty;
26
import org.eclipse.emf.databinding.edit.internal.EMFEditListPropertyDecorator;
27
import org.eclipse.emf.databinding.edit.internal.EMFEditMapProperty;
28
import org.eclipse.emf.databinding.edit.internal.EMFEditMapPropertyDecorator;
29
import org.eclipse.emf.databinding.edit.internal.EMFEditValueProperty;
30
import org.eclipse.emf.databinding.edit.internal.EMFEditValuePropertyDecorator;
31
import org.eclipse.emf.ecore.EObject;
32
import org.eclipse.emf.ecore.EStructuralFeature;
33
import org.eclipse.emf.edit.domain.EditingDomain;
34
35
36
/**
37
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
38
 * 
39
 * A factory to create property bound attributes for {@link EObject} which use an {@link EditingDomain} to make changes to the {@link EObject}
40
 * 
41
 * @since 2.5
42
 */
43
public class EMFEditProperties
44
{
45
  /**
46
   * Turn on debug logging
47
   */
48
  public static final boolean DEBUG = false;
49
50
  /**
51
   * Returns a value property for the given {@link EStructuralFeature}
52
   * 
53
   * @param editingDomain the editing domain
54
   * @param feature
55
   *            the feature instance the property is created for
56
   * @return a value property for the given {@link EStructuralFeature}
57
   */
58
  public static IEMFEditValueProperty value(EditingDomain editingDomain, EStructuralFeature feature)
59
  {
60
    return value(editingDomain, FeaturePath.fromList(feature));
61
  }
62
63
  /**
64
   * Returns a value property for the given nested {@link EStructuralFeature}
65
   * feature like the <code>name</code> of a <code>person</code>
66
   * 
67
   * @param editingDomain the editing domain
68
   * @param featurePath
69
   *            path to the feature
70
   * @return a value property for the given {@link FeaturePath}
71
   */
72
  public static IEMFEditValueProperty value(EditingDomain editingDomain, FeaturePath featurePath)
73
  {
74
    IValueProperty property;
75
    property = new EMFEditValueProperty(editingDomain, featurePath.getFeaturePath()[0]);
76
77
    IEMFEditValueProperty featureProperty = new EMFEditValuePropertyDecorator(editingDomain, property, featurePath.getFeaturePath()[0]);
78
79
    for (int i = 1; i < featurePath.getFeaturePath().length; i++)
80
    {
81
      featureProperty = featureProperty.value(featurePath.getFeaturePath()[i]);
82
    }
83
84
    return featureProperty;
85
  }
86
87
  /**
88
   * Returns multiple value properties for the given
89
   * {@link EStructuralFeature}s
90
   * 
91
   * @param editingDomain 
92
   *            the editing domain
93
   * @param features
94
   *            the feature instances the properties are created for
95
   * @return an array of properties for the given {@link EStructuralFeature}s
96
   */
97
  public static IEMFEditValueProperty[] values(EditingDomain editingDomain, EStructuralFeature... features)
98
  {
99
    IEMFEditValueProperty[] properties = new IEMFEditValueProperty [features.length];
100
    for (int i = 0; i < properties.length; i++)
101
      properties[i] = value(editingDomain, features[i]);
102
    return properties;
103
  }
104
105
  /**
106
   * Returns multiple value property for the given nested
107
   * {@link EStructuralFeature} features like the <code>name</code> of a
108
   * <code>person</code>
109
   * 
110
   * @param editingDomain 
111
   *            the editing domain
112
   * @param featurePaths
113
   *            path to the feature
114
   * @return an array of properties for the given {@link FeaturePath}s
115
   */
116
  public static IEMFEditValueProperty[] values(EditingDomain editingDomain, FeaturePath... featurePaths)
117
  {
118
    IEMFEditValueProperty[] properties = new IEMFEditValueProperty [featurePaths.length];
119
    for (int i = 0; i < properties.length; i++)
120
      properties[i] = value(editingDomain, featurePaths[i]);
121
    return properties;
122
  }
123
124
  /**
125
   * Returns a list property for the given {@link EStructuralFeature}
126
   * 
127
   * @param editingDomain 
128
   *            the editing domain
129
   * @param feature
130
   *            the feature instance the property is created for
131
   * @return a list property for the given {@link EStructuralFeature}
132
   */
133
  public static IEMFEditListProperty list(EditingDomain editingDomain, EStructuralFeature feature)
134
  {
135
    IListProperty property;
136
    property = new EMFEditListProperty(editingDomain, feature);
137
    return new EMFEditListPropertyDecorator(editingDomain, property, feature);
138
  }
139
140
  /**
141
   * Returns a map property for the given {@link EStructuralFeature}. Objects lacking the named property are treated the same as if the
142
   * property always contains an empty map.
143
   * 
144
   * @param editingDomain 
145
   *            the editing domain
146
   * @param feature
147
   *            the feature the property is created for
148
   * @return a map property for the given {@link EStructuralFeature}
149
   */
150
  public static IEMFEditMapProperty map(EditingDomain editingDomain, EStructuralFeature feature)
151
  {
152
    IMapProperty property;
153
    property = new EMFEditMapProperty(editingDomain, feature);
154
    return new EMFEditMapPropertyDecorator(editingDomain, property, feature);
155
  }
156
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditValueProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import org.eclipse.emf.common.command.Command;
19
import org.eclipse.emf.databinding.internal.EMFValueProperty;
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
/**
27
 * @since 2.5
28
 */
29
public class EMFEditValueProperty extends EMFValueProperty
30
{
31
  private final EditingDomain editingDomain;
32
33
  /**
34
   * @param editingDomain
35
   * @param eStructuralFeature
36
   */
37
  public EMFEditValueProperty(EditingDomain editingDomain, EStructuralFeature eStructuralFeature)
38
  {
39
    super(eStructuralFeature);
40
    this.editingDomain = editingDomain;
41
  }
42
43
  @Override
44
  protected void doSetValue(Object source, Object value)
45
  {
46
    EObject eObject = (EObject)source;
47
    Command command = SetCommand.create(editingDomain, eObject, getFeature(), value);
48
    editingDomain.getCommandStack().execute(command);
49
  }
50
}
(-)src/org/eclipse/emf/databinding/edit/IEMFEditValueProperty.java (+262 lines)
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2008 Matthew Hall 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
 *   Matthew Hall - initial API and implementation (bug 195222)
12
 *   Tom Schindl <tom.schindl@bestsolution.at> - port to EMF in 262160
13
 * </copyright>
14
 *
15
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
16
 */
17
package org.eclipse.emf.databinding.edit;
18
19
import org.eclipse.core.databinding.property.value.IValueProperty;
20
import org.eclipse.emf.databinding.FeaturePath;
21
import org.eclipse.emf.ecore.EStructuralFeature;
22
import org.eclipse.emf.edit.domain.EditingDomain;
23
24
25
/**
26
 * <p><b>PROVISIONAL:</b> This API is subject to arbitrary change, including renaming or removal.</p>
27
 * 
28
 * An {@link IValueProperty} extension interface with convenience methods for
29
 * creating nested {@link EStructuralFeature} properties and does changes through the {@link EditingDomain}
30
 * 
31
 * @since 2.5
32
 * @noextend This interface is not intended to be extended by clients.
33
 * @noimplement This interface is not intended to be implemented by clients.
34
 */
35
public interface IEMFEditValueProperty extends IEMFEditProperty, IValueProperty
36
{
37
  /**
38
   * Returns a master-detail combination of this property and the specified
39
   * nested value feature.
40
   * 
41
   * @param featurePath
42
   *            the nested value property to observe.
43
   * @return a master-detail combination of this property and the specified
44
   *         nested value feature.
45
   * @see #value(IEMFEditValueProperty)
46
   */
47
  public IEMFEditValueProperty value(FeaturePath featurePath);
48
49
  /**
50
   * Returns a master-detail combination of this property and the specified
51
   * value feature.
52
   * 
53
   * @param feature
54
   *            the nested value property to observe.
55
   * @return a master-detail combination of this property and the specified
56
   *         value feature.
57
   * @see #value(IEMFEditValueProperty)
58
   */
59
  public IEMFEditValueProperty value(EStructuralFeature feature);
60
61
  /**
62
   * Returns a master-detail combination of this property and the specified
63
   * value property. The returned property will observe the specified detail
64
   * value property for the value of the master value property.
65
   * <p>
66
   * Example:
67
   * 
68
   * <pre>
69
   * // Observes the Node-typed &quot;parent&quot; property of a Node object
70
   * IEMFValueProperty parent = EMFProperties.value(MyPackage.Literals.NODE_PARENT);
71
   * // Observes the string-typed &quot;name&quot; property of a Node object
72
   * IEMFValueProperty name = EMFProperties.value(MyPackage.Literals.NODE_NAME);
73
   * // Observes the name of the parent of a Node object.
74
   * IEMFValueProperty parentName = parent.value(name);
75
   * </pre>
76
   * 
77
   * @param property
78
   *            the detail property to observe
79
   * @return a master-detail combination of this property and the specified
80
   *         value property.
81
   */
82
  public IEMFEditValueProperty value(IEMFEditValueProperty property);
83
84
  /**
85
   * Returns a master-detail combination of this property and the specified
86
   * list feature.
87
   * 
88
   * @param feature
89
   *            the list feature to observe
90
   * @return a master-detail combination of this property and the specified
91
   *         list feature.
92
   * @see #list(IEMFEditListProperty)
93
   */
94
  public IEMFEditListProperty list(EStructuralFeature feature);
95
96
  /**
97
   * Returns a master-detail combination of this property and the specified
98
   * list property. The returned property will observe the specified list
99
   * property for the value of the master property.
100
   * <p>
101
   * Example:
102
   * 
103
   * <pre>
104
   * // Observes the Node-typed &quot;parent&quot; property of a Node object.
105
   * IEMFValueProperty parent = EMFProperties.value(MyPackage.Literals.NODE_PARENT);
106
   * // Observes the List-typed &quot;children&quot; property of a Node object
107
   * // where the elements are Node objects
108
   * IEMFListProperty children = EMFProperties.list(MyPackage.Literals.NODE_CHILDREN);
109
   * // Observes the children of the parent (siblings) of a Node object.
110
   * IEMFListProperty siblings = parent.list(children);
111
   * </pre>
112
   * 
113
   * @param property
114
   *            the detail property to observe
115
   * @return a master-detail combination of this property and the specified
116
   *         list property.
117
   */
118
  public IEMFEditListProperty list(IEMFEditListProperty property);
119
120
  /**
121
   * Returns a master-detail combination of this property and the specified
122
   * map feature.
123
   * 
124
   * @param feature
125
   *            the map property to observe
126
   * @return a master-detail combination of this property and the specified
127
   *         map feature.
128
   * @see #map(IEMFEditMapProperty)
129
   */
130
  public IEMFEditMapProperty map(EStructuralFeature feature);
131
132
  /**
133
   * Returns a master-detail combination of this property and the specified
134
   * map property. The returned property will observe the specified map
135
   * property for the value of the master property.
136
   * <p>
137
   * Example:
138
   * 
139
   * <pre>
140
   * // Observes the Contact-typed &quot;supervisor&quot; property of a
141
   * // Contact class 
142
   * IEMFValueProperty supervisor = EMFProperties.value(MyPackage.Literals.CONTACT_SUPERVISOR);
143
   * // Observes the property &quot;phoneNumbers&quot; of a Contact object--a property mapping
144
   * // from PhoneNumberType to PhoneNumber &quot;set-typed &quot;children&quot;,
145
   * IEMFMapProperty phoneNumbers = EMFProperties.map(MyPackage.Literals.CONTACT_PHONENUMBERS);
146
   * // Observes the phone numbers of a contact's supervisor:
147
   * IEMFMapProperty supervisorPhoneNumbers = supervisor.map(phoneNumbers);
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
   *         map property.
154
   */
155
  public IEMFEditMapProperty map(IEMFEditMapProperty property);
156
}
Index: src/org/eclipse/emf/databinding/edit/internal/EMFEditListProperty.java
Added Link Here
1
/**
2
 * <copyright> 
3
 *
4
 * Copyright (c) 2009 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 (bug 262160)
12
 * </copyright>
13
 *
14
 * $Id: EMFObservables.java,v 1.3 2008/04/22 13:36:00 emerks Exp $
15
 */
16
package org.eclipse.emf.databinding.edit.internal;
17
18
import java.util.Collections;
19
import java.util.List;
20
21
import org.eclipse.core.databinding.observable.list.ListDiff;
22
import org.eclipse.core.databinding.observable.list.ListDiffVisitor;
23
import org.eclipse.emf.common.command.Command;
24
import org.eclipse.emf.databinding.internal.EMFListProperty;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.ecore.EStructuralFeature;
27
import org.eclipse.emf.edit.command.AddCommand;
28
import org.eclipse.emf.edit.command.MoveCommand;
29
import org.eclipse.emf.edit.command.RemoveCommand;
30
import org.eclipse.emf.edit.command.ReplaceCommand;
31
import org.eclipse.emf.edit.domain.EditingDomain;
32
33
34
/**
35
 * @since 2.5
36
 */
37
public class EMFEditListProperty extends EMFListProperty
38
{
39
  private final EditingDomain editingDomain;
40
41
  /**
42
   * @param editingDomain
43
   * @param eStructuralFeature
44
   */
45
  public EMFEditListProperty(EditingDomain editingDomain, EStructuralFeature eStructuralFeature)
46
  {
47
    super(eStructuralFeature);
48
    this.editingDomain = editingDomain;
49
  }
50
51
  @SuppressWarnings("unchecked")
52
  @Override
53
  protected void doSetList(Object source, List list, ListDiff diff)
54
  {
55
    diff.accept(new ListVisitorImpl((EObject)source, getFeature()));
56
  }
57
58
  private class ListVisitorImpl extends ListDiffVisitor
59
  {
60
    private EObject eObj;
61
    private EStructuralFeature feature;
62
63
    private ListVisitorImpl(EObject eObj, EStructuralFeature feature)
64
    {
65
      this.eObj = eObj;
66
      this.feature = feature;
67
    }
68
69
    @Override
70
    public void handleAdd(int index, Object element)
71
    {
72
      execute(AddCommand.create(editingDomain, eObj, feature, element, index));
73
    }
74
75
    @Override
76
    public void handleMove(int oldIndex, int newIndex, Object element)
77
    {
78
      execute(MoveCommand.create(editingDomain, eObj, feature, element, newIndex));
79
    }
80
81
    @Override
82
    public void handleReplace(int index, Object oldElement, Object newElement)
83
    {
84
      execute(ReplaceCommand.create(editingDomain, eObj, feature, oldElement, Collections.singleton(newElement)));
85
    }
86
87
    @Override
88
    public void handleRemove(int index, Object element)
89
    {
90
      execute(RemoveCommand.create(editingDomain, eObj, feature, element));
91
    }
92
93
    private boolean execute(Command command)
94
    {
95
      if (command.canExecute())
96
      {
97
        editingDomain.getCommandStack().execute(command);
98
        return true;
99
      }
100
      else
101
      {
102
        return false;
103
      }
104
    }
105
  }
106
}

Return to bug 262160