Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Databinding] Access to nested object attributes
[Databinding] Access to nested object attributes [message #317236] Fri, 29 June 2007 00:56 Go to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Say I have an

Person {
Address address;
}

Address {
String street;
}

I now that that I could write the following:

BeansObservables.observeDetailValue(
Realm.getDefault(),
observableMaster,
"address.street",
String.class
);


But this fails?


So I've written it this way:
----------------------------
IObservable address = BeansObservables.observeDetailValue(
Realm.getDefault(),
observableMaster,
"address",
Address.class
);

IObservable address = BeansObservables.observeDetailValue(
Realm.getDefault(),
address,
"street"
String.class
);

Is this the right way? Is there API for this?

Tom
Re: [Databinding] Access to nested object attributes [message #317258 is a reply to message #317236] Fri, 29 June 2007 14:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

just to follow up to myself. What I envision is the to have something
like XPath to bind widgets. Although I might already be happy with
"address.street" a cool feature would be if you could even write
something like this "addresses[1].street". In case addresses is type of
java.util.List :-)

Tom

Tom Schindl schrieb:
> Say I have an
>
> Person {
> Address address;
> }
>
> Address {
> String street;
> }
>
> I now that that I could write the following:
>
> BeansObservables.observeDetailValue(
> Realm.getDefault(),
> observableMaster,
> "address.street",
> String.class
> );
>
>
> But this fails?
>
>
> So I've written it this way:
> ----------------------------
> IObservable address = BeansObservables.observeDetailValue(
> Realm.getDefault(),
> observableMaster,
> "address",
> Address.class
> );
>
> IObservable address = BeansObservables.observeDetailValue(
> Realm.getDefault(),
> address,
> "street"
> String.class
> );
>
> Is this the right way? Is there API for this?
>
> Tom
Re: [Databinding] Access to nested object attributes [message #317341 is a reply to message #317258] Tue, 03 July 2007 00:43 Go to previous messageGo to next message
Brad Reynolds is currently offline Brad ReynoldsFriend
Messages: 309
Registered: July 2009
Senior Member
Tom, can you log an enhancement request for providing better API for
observing nested attributes? At this point in time my preference would
something along the lines of a builder. It would be simpler to debug
than XPath, provide a little type safety, and would provide room for
extensibility.

observe("street").of("address").ofObservable(person)

-brad


Tom Schindl wrote:
> Hi,
>
> just to follow up to myself. What I envision is the to have something
> like XPath to bind widgets. Although I might already be happy with
> "address.street" a cool feature would be if you could even write
> something like this "addresses[1].street". In case addresses is type of
> java.util.List :-)
>
> Tom
>
> Tom Schindl schrieb:
>> Say I have an
>>
>> Person {
>> Address address;
>> }
>>
>> Address {
>> String street;
>> }
>>
>> I now that that I could write the following:
>>
>> BeansObservables.observeDetailValue(
>> Realm.getDefault(),
>> observableMaster,
>> "address.street",
>> String.class
>> );
>>
>>
>> But this fails?
>>
>>
>> So I've written it this way:
>> ----------------------------
>> IObservable address = BeansObservables.observeDetailValue(
>> Realm.getDefault(),
>> observableMaster,
>> "address",
>> Address.class
>> );
>>
>> IObservable address = BeansObservables.observeDetailValue(
>> Realm.getDefault(),
>> address,
>> "street"
>> String.class
>> );
>>
>> Is this the right way? Is there API for this?
>>
>> Tom
Re: [Databinding] Access to nested object attributes [message #317394 is a reply to message #317341] Tue, 03 July 2007 13:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse5.rizzoweb.com

Brad Reynolds wrote:
> Tom, can you log an enhancement request for providing better API for
> observing nested attributes? At this point in time my preference would
> something along the lines of a builder. It would be simpler to debug
> than XPath, provide a little type safety, and would provide room for
> extensibility.
>
> observe("street").of("address").ofObservable(person)

It is probably worth discussing the merits of keeping as similar as
possible to how nested beans are typically accessed in JSP, which is
just dot-separated Strings: "person.address.street"
There is also accommodation for referring to individual instances in
Maps, Lists, and arrays: "person[Smith].children[1].age"

I'm not saying Eclipse Databinding absolutely must use this kind of
notation, just that the issue of familiarity and consistency shouldn't
be ignored.

Is there a Bugzilla for this?

Eric


> Tom Schindl wrote:
>> Hi,
>>
>> just to follow up to myself. What I envision is the to have something
>> like XPath to bind widgets. Although I might already be happy with
>> "address.street" a cool feature would be if you could even write
>> something like this "addresses[1].street". In case addresses is type
>> of java.util.List :-)
>>
>> Tom
>>
>> Tom Schindl schrieb:
>>> Say I have an
>>>
>>> Person {
>>> Address address;
>>> }
>>>
>>> Address {
>>> String street;
>>> }
>>>
>>> I now that that I could write the following:
>>>
>>> BeansObservables.observeDetailValue(
>>> Realm.getDefault(),
>>> observableMaster,
>>> "address.street",
>>> String.class
>>> );
>>>
>>>
>>> But this fails?
>>>
>>>
>>> So I've written it this way:
>>> ----------------------------
>>> IObservable address = BeansObservables.observeDetailValue(
>>> Realm.getDefault(),
>>> observableMaster,
>>> "address",
>>> Address.class
>>> );
>>>
>>> IObservable address = BeansObservables.observeDetailValue(
>>> Realm.getDefault(),
>>> address,
>>> "street"
>>> String.class
>>> );
>>>
>>> Is this the right way? Is there API for this?
>>>
>>> Tom
Re: [Databinding] Access to nested object attributes [message #317395 is a reply to message #317394] Tue, 03 July 2007 13:01 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Eric Rizzo schrieb:
> Brad Reynolds wrote:
>> Tom, can you log an enhancement request for providing better API for
>> observing nested attributes? At this point in time my preference
>> would something along the lines of a builder. It would be simpler to
>> debug than XPath, provide a little type safety, and would provide room
>> for extensibility.
>>
>> observe("street").of("address").ofObservable(person)
>
> It is probably worth discussing the merits of keeping as similar as
> possible to how nested beans are typically accessed in JSP, which is
> just dot-separated Strings: "person.address.street"
> There is also accommodation for referring to individual instances in
> Maps, Lists, and arrays: "person[Smith].children[1].age"
>
> I'm not saying Eclipse Databinding absolutely must use this kind of
> notation, just that the issue of familiarity and consistency shouldn't
> be ignored.
>
> Is there a Bugzilla for this?
>
https://bugs.eclipse.org/bugs/show_bug.cgi?id=195222
Re: [Databinding] Access to nested object attributes [message #317713 is a reply to message #317236] Thu, 12 July 2007 08:44 Go to previous messageGo to next message
Frank Gerhardt is currently offline Frank GerhardtFriend
Messages: 81
Registered: July 2009
Member
I went to the newsgroup to ask exactly the same question.

What is the "right" way to do this with the 3.3 API?

I don't want to go into extending the API but use it as is. A simple
solution for address.street would make me happy too :-)

Frank.
Re: [Databinding] Access to nested object attributes [message #317718 is a reply to message #317713] Thu, 12 July 2007 08:56 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Frank Gerhardt schrieb:
> I went to the newsgroup to ask exactly the same question.
>
> What is the "right" way to do this with the 3.3 API?
>
> I don't want to go into extending the API but use it as is. A simple
> solution for address.street would make me happy too :-)
>
> Frank.

/*********************************************************** ********************
* Copyright (c) 2007 BestSolution Systemhaus GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tom Schindl<tom.schindl@bestsolution.at> - initial API and
implementation

************************************************************ ******************/
package at.bestsolution.core.databinding.util.beans;

import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableVal ue;

/**
* This class provides easy creating of observable for nested objects
*
* @author Tom Schindl <tom.schindl@bestsolution.at>
* @since 1.0
*/
public class NestedBeansObservables {
/**
* Separtor used to split nested attributes
*/
public static final String SEPARATOR = ".";

/**
* Create an observableValue from a nested detail-attribute
*
* @param observableMaster
* the master
* @param attributePath
* the path to get to the attribute
* @param detailPathClazzes
* the clazzes from top to bottom
* @return the onservable
*/
@SuppressWarnings("unchecked")
public static IObservableValue observeNestedDetailValue(
IObservableValue observableMaster, String attributePath,
Class[] detailPathClazzes) {
String[] parts = attributePath.split("\\.");

IObservableValue detailObservable = BeansObservables
.observeDetailValue(Realm.getDefault(), observableMaster,
parts[0], detailPathClazzes[0]);

for (int i = 1; i < parts.length; i++) {
detailObservable = BeansObservables.observeDetailValue(Realm
.getDefault(), detailObservable, parts[i], detailPathClazzes[i]);
}

return detailObservable;
}
}

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: [Databinding] Access to nested object attributes [message #317845 is a reply to message #317718] Fri, 13 July 2007 12:47 Go to previous messageGo to next message
Frank Gerhardt is currently offline Frank GerhardtFriend
Messages: 81
Registered: July 2009
Member
Tom Schindl schrieb:

> public class NestedBeansObservables {

Great! :-) I get the point.

Now I would like to use this in a TableViewer. In
BeansObservables.observeMaps(...) I would ike to pass in a String[] {
"name", "address.street" } so that I can hand this to the
ObservableMapLabelProvider. I would then have two ObservableMaps, one
for the Person, one nested for the Address.
And then I need a modified ObservableMapLabelProvider that goes to the
second ObservableMap for the "address.street" attribute (?).

Does that look like a good plan?

Frank.
Re: [Databinding] Access to nested object attributes [message #317877 is a reply to message #317845] Mon, 16 July 2007 07:32 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Frank,

I took a short look yesterday and it seems to be tricky to do this kind
of thing with the current databinding API. I not sure how this can be
solved currently. In theory the same I'm doing above has to be done
inside the observeMaps-Method.

Tom

Frank Gerhardt schrieb:
> Tom Schindl schrieb:
>
>> public class NestedBeansObservables {
>
> Great! :-) I get the point.
>
> Now I would like to use this in a TableViewer. In
> BeansObservables.observeMaps(...) I would ike to pass in a String[] {
> "name", "address.street" } so that I can hand this to the
> ObservableMapLabelProvider. I would then have two ObservableMaps, one
> for the Person, one nested for the Address.
> And then I need a modified ObservableMapLabelProvider that goes to the
> second ObservableMap for the "address.street" attribute (?).
>
> Does that look like a good plan?
>
> Frank.
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: [Databinding] Access to nested object attributes [message #317890 is a reply to message #317877] Mon, 16 July 2007 11:12 Go to previous messageGo to next message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
It should be possible to compose IObservableMap/List/Set instances to do
this. We need more helper classes and/or methods, though.

In Frank's example, if you have a table of Person objects with a column for
"address.street", you could write the following (ALL_CAPS methods and
classes are not implemented yet; generics added for clarity; there might be
a better factoring of the API...):

IObservableMap<Person, Address> personToAddress =
BeansObservables.observeMap(cp.getKnownElements(), Person.class,
"address");
IObservableMap<Address, String> addressToStreet =
BeansObservables.observeMap(personToAddress.GET_OBSERVABLE_R ANGE(),
Address.class, "street");
IObservableMap<Person, String> personToStreet = new
COMPOSED_OBSERVABLE_MAP(personToAddress, addressToStreet);

The implementation of ComposedObservableMap would use an internal
BidirectionalMap (we already have an incomplete implementation for this) to
solve the following problem: Take Mary's address (object "addressMary") for
example and imagine her street was renamed: addressToStreet will fire an
event saying that for key addressMary, the value changed.
ComposedObservableMap will listen to changes like this and would have to
transform that into a map change event for its listeners. To do that, it
needs to know which persons in personToAddress map to addressMary.
BidirectionalMap tracks exactly this except that it does not have an API
method yet that would return a set of keys given a certain value. It appears
that this is just missing from the class:

/**
* Returns a set of keys for the given value. The returned set will be empty
if the given value is not an element of
* values().
**/
public Set getKeys(Object value) {
Object keyOrSet = valueToElements.get(value);
if (keyOrSet == null) return Collections.EMPTY_SET;
// TODO: use a private subclass of HashSet to avoid problems with wrapped
maps that have sets as keys.
if (keyOrSet instanceof Set) return (Set) keyOrSet;
return Collections.singleton(keyOrSet);
}

Should we create a dedicated bug for an in-depth discussion?

Boris

"Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
news:f7f6vc$3g8$1@build.eclipse.org...
> Hi Frank,
>
> I took a short look yesterday and it seems to be tricky to do this kind of
> thing with the current databinding API. I not sure how this can be solved
> currently. In theory the same I'm doing above has to be done inside the
> observeMaps-Method.
>
> Tom
>
> Frank Gerhardt schrieb:
>> Tom Schindl schrieb:
>>
>>> public class NestedBeansObservables {
>>
>> Great! :-) I get the point.
>>
>> Now I would like to use this in a TableViewer. In
>> BeansObservables.observeMaps(...) I would ike to pass in a String[] {
>> "name", "address.street" } so that I can hand this to the
>> ObservableMapLabelProvider. I would then have two ObservableMaps, one
>> for the Person, one nested for the Address.
>> And then I need a modified ObservableMapLabelProvider that goes to the
>> second ObservableMap for the "address.street" attribute (?).
>>
>> Does that look like a good plan?
>>
>> Frank.
>>
>
>
> --
> B e s t S o l u t i o n . at
> ------------------------------------------------------------ --------
> Tom Schindl JFace-Committer
> ------------------------------------------------------------ --------
Re: [Databinding] Access to nested object attributes [message #317894 is a reply to message #317890] Mon, 16 July 2007 11:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Boris,

I think this makes sense. I need to study your solution to the problem
and will reply later on.

Tom

Boris Bokowski schrieb:
> It should be possible to compose IObservableMap/List/Set instances to do
> this. We need more helper classes and/or methods, though.
>
> In Frank's example, if you have a table of Person objects with a column for
> "address.street", you could write the following (ALL_CAPS methods and
> classes are not implemented yet; generics added for clarity; there might be
> a better factoring of the API...):
>
> IObservableMap<Person, Address> personToAddress =
> BeansObservables.observeMap(cp.getKnownElements(), Person.class,
> "address");
> IObservableMap<Address, String> addressToStreet =
> BeansObservables.observeMap(personToAddress.GET_OBSERVABLE_R ANGE(),
> Address.class, "street");
> IObservableMap<Person, String> personToStreet = new
> COMPOSED_OBSERVABLE_MAP(personToAddress, addressToStreet);
>
> The implementation of ComposedObservableMap would use an internal
> BidirectionalMap (we already have an incomplete implementation for this) to
> solve the following problem: Take Mary's address (object "addressMary") for
> example and imagine her street was renamed: addressToStreet will fire an
> event saying that for key addressMary, the value changed.
> ComposedObservableMap will listen to changes like this and would have to
> transform that into a map change event for its listeners. To do that, it
> needs to know which persons in personToAddress map to addressMary.
> BidirectionalMap tracks exactly this except that it does not have an API
> method yet that would return a set of keys given a certain value. It appears
> that this is just missing from the class:
>
> /**
> * Returns a set of keys for the given value. The returned set will be empty
> if the given value is not an element of
> * values().
> **/
> public Set getKeys(Object value) {
> Object keyOrSet = valueToElements.get(value);
> if (keyOrSet == null) return Collections.EMPTY_SET;
> // TODO: use a private subclass of HashSet to avoid problems with wrapped
> maps that have sets as keys.
> if (keyOrSet instanceof Set) return (Set) keyOrSet;
> return Collections.singleton(keyOrSet);
> }
>
> Should we create a dedicated bug for an in-depth discussion?
>
> Boris
>
> "Tom Schindl" <tom.schindl@bestsolution.at> wrote in message
> news:f7f6vc$3g8$1@build.eclipse.org...
>> Hi Frank,
>>
>> I took a short look yesterday and it seems to be tricky to do this kind of
>> thing with the current databinding API. I not sure how this can be solved
>> currently. In theory the same I'm doing above has to be done inside the
>> observeMaps-Method.
>>
>> Tom
>>
>> Frank Gerhardt schrieb:
>>> Tom Schindl schrieb:
>>>
>>>> public class NestedBeansObservables {
>>> Great! :-) I get the point.
>>>
>>> Now I would like to use this in a TableViewer. In
>>> BeansObservables.observeMaps(...) I would ike to pass in a String[] {
>>> "name", "address.street" } so that I can hand this to the
>>> ObservableMapLabelProvider. I would then have two ObservableMaps, one
>>> for the Person, one nested for the Address.
>>> And then I need a modified ObservableMapLabelProvider that goes to the
>>> second ObservableMap for the "address.street" attribute (?).
>>>
>>> Does that look like a good plan?
>>>
>>> Frank.
>>>
>>
>> --
>> B e s t S o l u t i o n . at
>> ------------------------------------------------------------ --------
>> Tom Schindl JFace-Committer
>> ------------------------------------------------------------ --------
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: [Databinding] Access to nested object attributes [message #317895 is a reply to message #317894] Mon, 16 July 2007 12:01 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Tom Schindl schrieb:
> Hi Boris,
>
> I think this makes sense. I need to study your solution to the problem

I meant creating a dedicated bug report for this feature.

Tom

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: [Databinding] Access to nested object attributes [message #317932 is a reply to message #317890] Tue, 17 July 2007 08:46 Go to previous message
Frank Gerhardt is currently offline Frank GerhardtFriend
Messages: 81
Registered: July 2009
Member
Boris Bokowski schrieb:
> Should we create a dedicated bug for an in-depth discussion?

Here it is https://bugs.eclipse.org/bugs/show_bug.cgi?id=196785

Frank.
Previous Topic:Java compiler compliance level
Next Topic:Can't see all the content of a package
Goto Forum:
  


Current Time: Sat Nov 09 06:49:41 GMT 2024

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

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

Back to the top