Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-dev] Databinding Labelprovider + Chaining

Thanks Jens, indeed I use the 'typed' variants but haven't found an example to link here :-)

Anyways you showed it worked and it seem I must have messed something up in my code so the type infos got screwed... I'll check that!

Am 21.04.21 um 15:38 schrieb Jens Lideström:
Hello Christoph,

Working with string-based properties got slightly more fiddly after the
addition of type parameters to the databinding classes. But it also got a
bit more clear and got more static type checking!

The Vogella tutorial is apparently not updated to use new versions of the
databinding framework.

The best way to solve your problem is to use the versions of
BeanProperties#value that also specify the return type.

Like this:

import org.eclipse.core.databinding.beans.typed.BeanProperties;

ObservableListContentProvider<Person> contentProvider =
     new ObservableListContentProvider<>();

IObservableSet<Person> knownElements = contentProvider.getKnownElements();

IObservableMap<Person, String> streetName =
BeanProperties.value(Person.class, "address", Address.class)
     .value(BeanProperties.value(Address.class, "street", String.class))
     .observeDetail(knownElements);

The above code type-checks fine.

The other alternative is to specify Object as the type argument of
ObservableListContentProvider. In that case you throw type information
away and you have to work with Object all the way:

ObservableListContentProvider<Object> contentProvider = new
     ObservableListContentProvider<>();

IObservableSet<Object> knownElements = contentProvider.getKnownElements();

IObservableMap<Object, Object> streetName = BeanProperties.value("address")
     .value(BeanProperties.value("street"))
     .observeDetail(knownElements);

BR,
Jens Lideström

On 2021-04-21 10:04, Christoph Läubrich wrote:
[1] shows how to observe a property of an object to have a label updating,
that works as long as it is a direct property of the (person) object.

[2] shows how to chain properties to access "sub-objects" (lets say
persons address)

But how do I combine both?

IObservableMap streetName = BeanProperties.value(Person.class,
     "adress").value(BeanProperties.value(Address.class,
     "street")).observeDetail(knownElements);

obviously won't work as the "knownElements" are of type
IObservableSet<Person> ...


[1]
https://www.vogella.com/tutorials/EclipseDataBinding/article.html#observing-list-details

[2]
https://www.vogella.com/tutorials/EclipseDataBinding/article.html#chaining-properties

_______________________________________________
platform-dev mailing list
platform-dev@xxxxxxxxxxx
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/platform-dev
_______________________________________________
platform-dev mailing list
platform-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/platform-dev



Back to the top