[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.tools.emf] Re: Observing EList size
|
Pierre Francis Roy wrote:
In this case what I want to do is to observ the size of that EList
(EList.size()).
If there is an EStructuralFeature for EList.size() somewhere then you
could observe it using:
EMFProperties.value(eListSizeStructuralFeature).observe(eList)
Otherwise you can write a custom IValueProperty:
class NotifyingListSizeProperty extends SimpleValueProperty {
protected Object doGetValue(Object source) {
return ((NotifyingList)source).size();
}
protected void doSetValue(Object source, Object value) {
throw new UnsupportedOperationException(
toString() + " is unmodifiable");
}
public INativePropertyListener adaptListener(
ISimplePropertyListener listener) {
return new Listener(listener);
}
private class Listener extends AdapterImpl
implements INativePropertyListener {
ISimplePropertyListener delegate;
public Listener(ISimplePropertyListener delegate) {
this.delegate = delegate;
}
public void addTo(Object source) {
if (source != null)
((Notifier) ((NotifyingList)source).getNotifier())
.eAdapters().add(this);
}
public void removeFrom(Object source) {
if (source != null)
((Notifier) ((NotifyingList)source).getNotifier())
.eAdapters().remove(this);
}
public void notifyChanged(Notification msg) {
delegate.handleEvent(new SimplePropertyEvent(
SimplePropertyEvent.CHANGE,
msg.getNotifier(),
NotifyingListenerProperty.this,
null);
}
}
public String toString() { return "EList.size <int>"; }
}
With this property you can basically do the same the first example code:
IObservableValue listSize =
new NotifyingListSizeProperty().observe(eList);