Home » Eclipse Projects » Eclipse Platform » [Databinding] Access to nested object attributes
|
Re: [Databinding] Access to nested object attributes [message #317258 is a reply to message #317236] |
Fri, 29 June 2007 14:25 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Thomas Schindl![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=tom.schindl%40bestsolution.at) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Brad Reynolds![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=bradleyjames%40gmail.com) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
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 #317718 is a reply to message #317713] |
Thu, 12 July 2007 08:56 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Thomas Schindl![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=tom.schindl%40bestsolution.at) 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 #317890 is a reply to message #317877] |
Mon, 16 July 2007 11:12 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Boris Bokowski![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=bokowski%40google.com) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Thomas Schindl![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=tom.schindl%40bestsolution.at) 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
------------------------------------------------------------ --------
|
|
| | |
Goto Forum:
Current Time: Sun Sep 01 12:44:13 GMT 2024
Powered by FUDForum. Page generated in 0.04850 seconds
|