Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Observing EList size
Observing EList size [message #485437] Fri, 11 September 2009 17:40 Go to next message
Pierre Francis Roy is currently offline Pierre Francis RoyFriend
Messages: 12
Registered: July 2009
Junior Member
Dear,

I have the following code used for observing EMF object attributes for
binding with table TableViewer columns.

IObservableMap[] map = new IObservableMap[3];
map[0] =
EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__DATE_CREATION).observeDetail(set);
map[1] =
EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__TYPE).observeDetail(set);
map[2] =
EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__SAMPLES).observeDetail(set);

In the third properties I'm currently observing an EList<Sample> object.
In this case what I want to do is to observ the size of that EList
(EList.size()).

Any idea how this can be done?

Thanks for helping me getting a good start with databinding.

Pierre Francis
Re: Observing EList size [message #485441 is a reply to message #485437] Fri, 11 September 2009 17:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Pierre,

Comments below.

Pierre Francis Roy wrote:
> Dear,
>
> I have the following code used for observing EMF object attributes for
> binding with table TableViewer columns.
>
> IObservableMap[] map = new IObservableMap[3];
> map[0] =
> EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__DATE_CREATION).observeDetail(set);
>
> map[1] =
> EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__TYPE).observeDetail(set);
>
> map[2] =
> EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__SAMPLES).observeDetail(set);
>
>
> In the third properties I'm currently observing an EList<Sample>
> object. In this case what I want to do is to observ the size of that
> EList (EList.size()).
> Any idea how this can be done?
In terms of notifications, EMF produces notifications for all things
that affect the list so there's certainly enough information to know
when to check the size. In particular, add and remove notifications
will affect the size.
>
> Thanks for helping me getting a good start with databinding.
I'm not sure how you'd hook data binding up for that though.
>
> Pierre Francis
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Observing EList size [message #485482 is a reply to message #485437] Fri, 11 September 2009 21:49 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
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(eLis t)

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);
Re: Observing EList size [message #485490 is a reply to message #485482] Sat, 12 September 2009 00:23 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Matthew Hall schrieb:
> 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(eLis t)

There isn't one :-(

>
> 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);

Might make sense to add it to our library would you file a bug Matt and
attach your source from above?

Tom
Re: Observing EList size [message #485495 is a reply to message #485490] Sat, 12 September 2009 04:51 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
> Might make sense to add it to our library would you file a bug Matt and
> attach your source from above?

Sure, but I'm not sure which product/component to attach it to.

Matthew
Re: Observing EList size [message #485505 is a reply to message #485495] Sat, 12 September 2009 07:12 Go to previous messageGo to next message
Pierre Francis Roy is currently offline Pierre Francis RoyFriend
Messages: 12
Registered: July 2009
Junior Member
Dear Tom and Matthew,

Thanks for your interest in that problem. I think my situation is quite
current. It applies in the case when you want to display the number of
elements in master object in a master/details situation.

The solution of Matthew seem to me quite conveniant except for the fact
that I'm not quite sure how to get an IObservableMap from that example
instead of an IObservableValue.

Required by your solution:
IObservableValue listSize = new
NotifyingListSizeProperty().observe(eList);

Required in my situation
IObservableMap[] map = new IObservableMap[3];
...
IEMFValueProperty prop =
EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__SAMPLES);
??? map[2] = new NotifyingListSizeProperty().observe(prop); ???

Thanks a lot guys
Re: Observing EList size [message #485508 is a reply to message #485495] Sat, 12 September 2009 09:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Matt,

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EMF& component=Edit&version=2.5.0&bug_severity=enhancemen t&rep_platform=All&op_sys=All&short_desc=[Databinding]

Thanks

Tom

@Ed: Could we add the databinding bundles to the description of EMF-Edit
component shown in bugzilla?

Matthew Hall schrieb:
>> Might make sense to add it to our library would you file a bug Matt and
>> attach your source from above?
>
> Sure, but I'm not sure which product/component to attach it to.
>
> Matthew
Re: Observing EList size [message #485696 is a reply to message #485505] Mon, 14 September 2009 14:20 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Pierre Francis Roy wrote:
> Required in my situation
> IObservableMap[] map = new IObservableMap[3];
> ..
> IEMFValueProperty prop =
> EMFProperties.value(DairyStudioQualityPackage.Literals.SAMPL E_SET__SAMPLES);
>
> ??? map[2] = new NotifyingListSizeProperty().observe(prop); ???

You can make a nested property as follows:

IEMFValueProperty eListSizeProp = EMFProperties
.value(DairyStudioQualityPackage.Literals.SAMPLE_SET__SAMPLE S)
.value(new NotifyingListSizeProperty());

Assuming you are binding this property to a JFace viewer, your code
would be something like:

IObservableSet knownElements =
observableListContentProvider.getKnownElements();
map[2] = eListSizeProperty.observeDetail(knownElements);

I've also been thinking that we should provide a property reducer method
for collection properties:

interface IListProperty {
+ public IValueProperty reduce(IValueProperty)
}

interface ISetProperty {
+ public IValueProperty reduce(IValueProperty)
}

interface IMapProperty {
+ public IValueProperty reduce(IValueProperty)
}

This way we could just provide a generic property Properties.size(), thus:

IValueProperty listSizeProp = EMFProperties
.list(DairyStudioQualityPackage.Literals.SAMPLE_SET__SAMPLES )
.reduce(Properties.size());

We could also include several generic reducer properties like average,
median, sum, min, max, etc. What do you think?

Matthew
Re: Observing EList size [message #485700 is a reply to message #485508] Mon, 14 September 2009 14:26 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Filed https://bugs.eclipse.org/bugs/show_bug.cgi?id=289353

Matthew

Tom Schindl wrote:
> Hi Matt,
>
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EMF& component=Edit&version=2.5.0&bug_severity=enhancemen t&rep_platform=All&op_sys=All&short_desc=[Databinding]
>
> Thanks
>
> Tom
>
> @Ed: Could we add the databinding bundles to the description of EMF-Edit
> component shown in bugzilla?
>
> Matthew Hall schrieb:
>>> Might make sense to add it to our library would you file a bug Matt and
>>> attach your source from above?
>> Sure, but I'm not sure which product/component to attach it to.
>>
>> Matthew
Previous Topic:EMF Databinding without generated models?
Next Topic:ecore editor that only shows a specific type of annotation
Goto Forum:
  


Current Time: Fri Apr 19 01:23:06 GMT 2024

Powered by FUDForum. Page generated in 0.02703 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top