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

Return to bug 262160