Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Databinding]
[EMF Databinding] [message #429285] Fri, 17 April 2009 05:33 Go to next message
Stephen Egan is currently offline Stephen EganFriend
Messages: 21
Registered: July 2009
Junior Member
Hi,

I have been using EMF Databinding with much success, however I have come
across a case that has me stumped. I want to bind a Spinner widget to
each value in a multiplicity-many attribute list, but cannot find a
straight forward way to do so. Specifically, one of my EObjects has a
multiplicity-many attribute of type Integer to hold a value for each month
of the year. I have created a Spinner widget for each month and would
like to bind those Spinners to the values in the attribute's EList by
index.

Is there already support for this case? If not, could anybody please
offer me some tips on what I need to subclass, and what should be
overridden?

Many thanks,

Stephen Egan

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: [EMF Databinding] [message #429288 is a reply to message #429285] Fri, 17 April 2009 07:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

EMF-Databinding nor the Core of Databinding can't bind to indices of an
array (as of now :-). What you need to do is to provided transient,
volatile attributes you can bind the spinners to who make the value look
like a single valued attribute for EclipseDatabinding. Maybe it would be
better to use an EMF-Feature-Map for your use case?

I'm going to wrap my head around in the inofficial databinding port I
created for the up coming 3.5-Databinding-Properties-API (but I need to
update that to the latest M6 and M7 changes because it doesn't compile
there any more) and discuss with the Core developers how such a support
of List-Indices could work but I'm not even sure this can work. The get
is easy but how does the set look like?

Tom

[1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
[2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter

Stephen Egan schrieb:
>
> Hi,
>
> I have been using EMF Databinding with much success, however I have come
> across a case that has me stumped. I want to bind a Spinner widget to
> each value in a multiplicity-many attribute list, but cannot find a
> straight forward way to do so. Specifically, one of my EObjects has a
> multiplicity-many attribute of type Integer to hold a value for each
> month of the year. I have created a Spinner widget for each month and
> would like to bind those Spinners to the values in the attribute's EList
> by index.
>
> Is there already support for this case? If not, could anybody please
> offer me some tips on what I need to subclass, and what should be
> overridden?
>
> Many thanks,
>
> Stephen Egan
>
Re: [EMF Databinding] [message #429289 is a reply to message #429288] Fri, 17 April 2009 09:22 Go to previous messageGo to next message
Stephen Egan is currently offline Stephen EganFriend
Messages: 21
Registered: July 2009
Junior Member
Thanks Tom,

I might just do things the old fashioned way. I agree that it probably
isn't straight forward to implement something like this with
Databinding, and is probably an unusual use case anyway. My model is
derived from legacy XSD, which was derived from legacy Delphi code, so
gets 0/10 for best OO practices!

Stephen

Tom Schindl wrote:
> Hi,
>
> EMF-Databinding nor the Core of Databinding can't bind to indices of an
> array (as of now :-). What you need to do is to provided transient,
> volatile attributes you can bind the spinners to who make the value look
> like a single valued attribute for EclipseDatabinding. Maybe it would be
> better to use an EMF-Feature-Map for your use case?
>
> I'm going to wrap my head around in the inofficial databinding port I
> created for the up coming 3.5-Databinding-Properties-API (but I need to
> update that to the latest M6 and M7 changes because it doesn't compile
> there any more) and discuss with the Core developers how such a support
> of List-Indices could work but I'm not even sure this can work. The get
> is easy but how does the set look like?
>
> Tom
>
> [1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
> [2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter
>
> Stephen Egan schrieb:
>> Hi,
>>
>> I have been using EMF Databinding with much success, however I have come
>> across a case that has me stumped. I want to bind a Spinner widget to
>> each value in a multiplicity-many attribute list, but cannot find a
>> straight forward way to do so. Specifically, one of my EObjects has a
>> multiplicity-many attribute of type Integer to hold a value for each
>> month of the year. I have created a Spinner widget for each month and
>> would like to bind those Spinners to the values in the attribute's EList
>> by index.
>>
>> Is there already support for this case? If not, could anybody please
>> offer me some tips on what I need to subclass, and what should be
>> overridden?
>>
>> Many thanks,
>>
>> Stephen Egan
>>
Re: [EMF Databinding] [message #429290 is a reply to message #429289] Fri, 17 April 2009 09:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Stephen,

Then I guess you have 2 possibilities:
a) Write a specialized IObservableValue for your list and because you
exactly know how the list-feature is structured it is a quite simple.
Is the assumption correct that the list always holds 12 values?

b) Add those volatile transient features in your Ecore-Model.

By the way the use case is not really unusual because I answered this
kind of question multiple times already.

Tom

Stephen Egan schrieb:
> Thanks Tom,
>
> I might just do things the old fashioned way. I agree that it probably
> isn't straight forward to implement something like this with
> Databinding, and is probably an unusual use case anyway. My model is
> derived from legacy XSD, which was derived from legacy Delphi code, so
> gets 0/10 for best OO practices!
>
> Stephen
>
> Tom Schindl wrote:
>> Hi,
>>
>> EMF-Databinding nor the Core of Databinding can't bind to indices of an
>> array (as of now :-). What you need to do is to provided transient,
>> volatile attributes you can bind the spinners to who make the value look
>> like a single valued attribute for EclipseDatabinding. Maybe it would be
>> better to use an EMF-Feature-Map for your use case?
>>
>> I'm going to wrap my head around in the inofficial databinding port I
>> created for the up coming 3.5-Databinding-Properties-API (but I need to
>> update that to the latest M6 and M7 changes because it doesn't compile
>> there any more) and discuss with the Core developers how such a support
>> of List-Indices could work but I'm not even sure this can work. The get
>> is easy but how does the set look like?
>>
>> Tom
>>
>> [1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
>> [2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter
>>
>> Stephen Egan schrieb:
>>> Hi,
>>>
>>> I have been using EMF Databinding with much success, however I have come
>>> across a case that has me stumped. I want to bind a Spinner widget to
>>> each value in a multiplicity-many attribute list, but cannot find a
>>> straight forward way to do so. Specifically, one of my EObjects has a
>>> multiplicity-many attribute of type Integer to hold a value for each
>>> month of the year. I have created a Spinner widget for each month and
>>> would like to bind those Spinners to the values in the attribute's EList
>>> by index.
>>>
>>> Is there already support for this case? If not, could anybody please
>>> offer me some tips on what I need to subclass, and what should be
>>> overridden?
>>>
>>> Many thanks,
>>>
>>> Stephen Egan
>>>
Re: [EMF Databinding] [message #429293 is a reply to message #429290] Fri, 17 April 2009 10:46 Go to previous messageGo to next message
Stephen Egan is currently offline Stephen EganFriend
Messages: 21
Registered: July 2009
Junior Member
Thanks again Tom,

I'll have a go at specialising IObservableValue. The list always holds
12 values, so it should be ok. Do you know of any code snippets that
might help me out please?

Stephen

Tom Schindl wrote:
> Hi Stephen,
>
> Then I guess you have 2 possibilities:
> a) Write a specialized IObservableValue for your list and because you
> exactly know how the list-feature is structured it is a quite simple.
> Is the assumption correct that the list always holds 12 values?
>
> b) Add those volatile transient features in your Ecore-Model.
>
> By the way the use case is not really unusual because I answered this
> kind of question multiple times already.
>
> Tom
>
> Stephen Egan schrieb:
>> Thanks Tom,
>>
>> I might just do things the old fashioned way. I agree that it probably
>> isn't straight forward to implement something like this with
>> Databinding, and is probably an unusual use case anyway. My model is
>> derived from legacy XSD, which was derived from legacy Delphi code, so
>> gets 0/10 for best OO practices!
>>
>> Stephen
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> EMF-Databinding nor the Core of Databinding can't bind to indices of an
>>> array (as of now :-). What you need to do is to provided transient,
>>> volatile attributes you can bind the spinners to who make the value look
>>> like a single valued attribute for EclipseDatabinding. Maybe it would be
>>> better to use an EMF-Feature-Map for your use case?
>>>
>>> I'm going to wrap my head around in the inofficial databinding port I
>>> created for the up coming 3.5-Databinding-Properties-API (but I need to
>>> update that to the latest M6 and M7 changes because it doesn't compile
>>> there any more) and discuss with the Core developers how such a support
>>> of List-Indices could work but I'm not even sure this can work. The get
>>> is easy but how does the set look like?
>>>
>>> Tom
>>>
>>> [1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
>>> [2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter
>>>
>>> Stephen Egan schrieb:
>>>> Hi,
>>>>
>>>> I have been using EMF Databinding with much success, however I have come
>>>> across a case that has me stumped. I want to bind a Spinner widget to
>>>> each value in a multiplicity-many attribute list, but cannot find a
>>>> straight forward way to do so. Specifically, one of my EObjects has a
>>>> multiplicity-many attribute of type Integer to hold a value for each
>>>> month of the year. I have created a Spinner widget for each month and
>>>> would like to bind those Spinners to the values in the attribute's EList
>>>> by index.
>>>>
>>>> Is there already support for this case? If not, could anybody please
>>>> offer me some tips on what I need to subclass, and what should be
>>>> overridden?
>>>>
>>>> Many thanks,
>>>>
>>>> Stephen Egan
>>>>
Re: [EMF Databinding] [message #429294 is a reply to message #429293] Fri, 17 April 2009 11:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Not really but if you look at the code of the EMF-Observables it is
quite straight forward.

Tom

Stephen Egan schrieb:
> Thanks again Tom,
>
> I'll have a go at specialising IObservableValue. The list always holds
> 12 values, so it should be ok. Do you know of any code snippets that
> might help me out please?
>
> Stephen
>
> Tom Schindl wrote:
>> Hi Stephen,
>>
>> Then I guess you have 2 possibilities:
>> a) Write a specialized IObservableValue for your list and because you
>> exactly know how the list-feature is structured it is a quite simple.
>> Is the assumption correct that the list always holds 12 values?
>>
>> b) Add those volatile transient features in your Ecore-Model.
>>
>> By the way the use case is not really unusual because I answered this
>> kind of question multiple times already.
>>
>> Tom
>>
>> Stephen Egan schrieb:
>>> Thanks Tom,
>>>
>>> I might just do things the old fashioned way. I agree that it probably
>>> isn't straight forward to implement something like this with
>>> Databinding, and is probably an unusual use case anyway. My model is
>>> derived from legacy XSD, which was derived from legacy Delphi code, so
>>> gets 0/10 for best OO practices!
>>>
>>> Stephen
>>>
>>> Tom Schindl wrote:
>>>> Hi,
>>>>
>>>> EMF-Databinding nor the Core of Databinding can't bind to indices of an
>>>> array (as of now :-). What you need to do is to provided transient,
>>>> volatile attributes you can bind the spinners to who make the value
>>>> look
>>>> like a single valued attribute for EclipseDatabinding. Maybe it
>>>> would be
>>>> better to use an EMF-Feature-Map for your use case?
>>>>
>>>> I'm going to wrap my head around in the inofficial databinding port I
>>>> created for the up coming 3.5-Databinding-Properties-API (but I need to
>>>> update that to the latest M6 and M7 changes because it doesn't compile
>>>> there any more) and discuss with the Core developers how such a support
>>>> of List-Indices could work but I'm not even sure this can work. The get
>>>> is easy but how does the set look like?
>>>>
>>>> Tom
>>>>
>>>> [1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
>>>> [2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter
>>>>
>>>> Stephen Egan schrieb:
>>>>> Hi,
>>>>>
>>>>> I have been using EMF Databinding with much success, however I have
>>>>> come
>>>>> across a case that has me stumped. I want to bind a Spinner widget to
>>>>> each value in a multiplicity-many attribute list, but cannot find a
>>>>> straight forward way to do so. Specifically, one of my EObjects has a
>>>>> multiplicity-many attribute of type Integer to hold a value for each
>>>>> month of the year. I have created a Spinner widget for each month and
>>>>> would like to bind those Spinners to the values in the attribute's
>>>>> EList
>>>>> by index.
>>>>>
>>>>> Is there already support for this case? If not, could anybody please
>>>>> offer me some tips on what I need to subclass, and what should be
>>>>> overridden?
>>>>>
>>>>> Many thanks,
>>>>>
>>>>> Stephen Egan
>>>>>
Re: [EMF Databinding] [message #429345 is a reply to message #429294] Tue, 21 April 2009 03:38 Go to previous messageGo to next message
Stephen Egan is currently offline Stephen EganFriend
Messages: 21
Registered: July 2009
Junior Member
Hi Tom,

Your quite right, it was fairly straight forward to implement. A code
snippet is below for other's reference. I subclassed
DetailObservableList, as I have been using the Master Detail pattern.
This class is restricted, but this approach is doing the job for me.
Also, my attribute is a BigInteger rather than Integer, so a suitable
converter is required.

I create an instance using the following snippet:

IObservableValue spinnerObservableValue = new ListIndexObservableValue(
shadingSelection, EMFEditObservables.valueFactory(r, editingDomain,
pkg.getShadingType_ShBlockingFactors()),
pkg.getShadingType_ShBlockingFactors(), i);

Where shadingSelection is an instance of IViewerObservableValue
r is an instance of Realm
editingDomain is an instance of EditingDomain
pkg is my EPackage instance
i is the index of the List element I am interested in.


public class ListIndexObservableValue extends DetailObservableValue {

private int index;

/**
* Constructor calls
* {@link DetailObservableValue#DetailObservableValue(IObservableValue ,
IObservableFactory, Object)}
* , and stores the index to the {@link List} element to bind to.
*
* @param outerObservableValue
* @param factory
* @param detailType
* @param index
*/
public ListIndexObservableValue(IObservableValue outerObservableValue,
IObservableFactory factory, Object detailType, int index) {
super(outerObservableValue, factory, detailType);
this.index = index;
}

/**
* Gets the instance object from {@link
DetailObservableValue#doGetValue()},
* casts it to an instance of {@link List} if possible, and returns the
* element at {@link #index}, or the {@link List} itself if it does not
have
* enough elements, or the Object returned from the super method if it is
* not an instance of {@link List}
*/
@Override
public Object doGetValue() {
Object obj = super.doGetValue();
if (obj instanceof List<?>) {
List<?> l = (List<?>) obj;
if (l.size() > index) {
return l.get(index);
}
}
return obj;
}

/**
* Gets the instance object from {@link
DetailObservableValue#doGetValue()},
* casts it to an instance of {@link List} if possible. If the {@link List}
* size is greater than {@link #index}, the element at that index is
* replaced with the input parameter.
*
*/
@SuppressWarnings("unchecked")
@Override
public void doSetValue(Object value) {
Object obj = super.doGetValue();
if (obj instanceof List<?>) {
List<Object> l = (List<Object>) obj;
if (l.size() > index) {
l.remove(index);
l.add(index, value);
}
}
}

/**
* Returns {@link BigInteger} class, as the List is expected to only
conatin
* {@link BigInteger} elements.
*/
@Override
public Object getValueType() {
return BigInteger.class;
}


Tom Schindl wrote:
> Hi,
>
> Not really but if you look at the code of the EMF-Observables it is
> quite straight forward.
>
> Tom
>
> Stephen Egan schrieb:
>> Thanks again Tom,
>>
>> I'll have a go at specialising IObservableValue. The list always holds
>> 12 values, so it should be ok. Do you know of any code snippets that
>> might help me out please?
>>
>> Stephen
>>
>> Tom Schindl wrote:
>>> Hi Stephen,
>>>
>>> Then I guess you have 2 possibilities:
>>> a) Write a specialized IObservableValue for your list and because you
>>> exactly know how the list-feature is structured it is a quite simple.
>>> Is the assumption correct that the list always holds 12 values?
>>>
>>> b) Add those volatile transient features in your Ecore-Model.
>>>
>>> By the way the use case is not really unusual because I answered this
>>> kind of question multiple times already.
>>>
>>> Tom
>>>
>>> Stephen Egan schrieb:
>>>> Thanks Tom,
>>>>
>>>> I might just do things the old fashioned way. I agree that it probably
>>>> isn't straight forward to implement something like this with
>>>> Databinding, and is probably an unusual use case anyway. My model is
>>>> derived from legacy XSD, which was derived from legacy Delphi code, so
>>>> gets 0/10 for best OO practices!
>>>>
>>>> Stephen
>>>>
>>>> Tom Schindl wrote:
>>>>> Hi,
>>>>>
>>>>> EMF-Databinding nor the Core of Databinding can't bind to indices of an
>>>>> array (as of now :-). What you need to do is to provided transient,
>>>>> volatile attributes you can bind the spinners to who make the value
>>>>> look
>>>>> like a single valued attribute for EclipseDatabinding. Maybe it
>>>>> would be
>>>>> better to use an EMF-Feature-Map for your use case?
>>>>>
>>>>> I'm going to wrap my head around in the inofficial databinding port I
>>>>> created for the up coming 3.5-Databinding-Properties-API (but I need to
>>>>> update that to the latest M6 and M7 changes because it doesn't compile
>>>>> there any more) and discuss with the Core developers how such a support
>>>>> of List-Indices could work but I'm not even sure this can work. The get
>>>>> is easy but how does the set look like?
>>>>>
>>>>> Tom
>>>>>
>>>>> [1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
>>>>> [2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter
>>>>>
>>>>> Stephen Egan schrieb:
>>>>>> Hi,
>>>>>>
>>>>>> I have been using EMF Databinding with much success, however I have
>>>>>> come
>>>>>> across a case that has me stumped. I want to bind a Spinner widget to
>>>>>> each value in a multiplicity-many attribute list, but cannot find a
>>>>>> straight forward way to do so. Specifically, one of my EObjects has a
>>>>>> multiplicity-many attribute of type Integer to hold a value for each
>>>>>> month of the year. I have created a Spinner widget for each month and
>>>>>> would like to bind those Spinners to the values in the attribute's
>>>>>> EList
>>>>>> by index.
>>>>>>
>>>>>> Is there already support for this case? If not, could anybody please
>>>>>> offer me some tips on what I need to subclass, and what should be
>>>>>> overridden?
>>>>>>
>>>>>> Many thanks,
>>>>>>
>>>>>> Stephen Egan
>>>>>>
Re: [EMF Databinding] [message #429349 is a reply to message #429345] Tue, 21 April 2009 08:46 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Stephen,

Great you managed it. I'm working on a support this kind of scenario in
the up-coming EMF-Databinding version and made good progress last
weekend but didn't finished the implementation.

---------------8<---------------
int i = 0;

IEMFListValueProperty prop = EMFProperties.listValue(
MyPackage.Literals.AddressBook_Persons,
new Condition() {
public boolean match(int index, Object object) {
return i == index;
}
}
);

IObservableValue v =
prop.observeDetail(master,MyPackage.Literals.Person_Name);
---------------8<---------------

This would make the system extremly flexible because one could select
the not only based on the index but e.g. also by the value some other
attribute.

Tom

Stephen Egan schrieb:
> Hi Tom,
>
> Your quite right, it was fairly straight forward to implement. A code
> snippet is below for other's reference. I subclassed
> DetailObservableList, as I have been using the Master Detail pattern.
> This class is restricted, but this approach is doing the job for me.
> Also, my attribute is a BigInteger rather than Integer, so a suitable
> converter is required.
>
> I create an instance using the following snippet:
>
> IObservableValue spinnerObservableValue = new ListIndexObservableValue(
> shadingSelection, EMFEditObservables.valueFactory(r,
> editingDomain, pkg.getShadingType_ShBlockingFactors()),
> pkg.getShadingType_ShBlockingFactors(), i);
>
> Where shadingSelection is an instance of IViewerObservableValue
> r is an instance of Realm
> editingDomain is an instance of EditingDomain
> pkg is my EPackage instance
> i is the index of the List element I am interested in.
>
>
> public class ListIndexObservableValue extends DetailObservableValue {
>
> private int index;
>
> /**
> * Constructor calls
> * {@link
> DetailObservableValue#DetailObservableValue(IObservableValue ,
> IObservableFactory, Object)}
> * , and stores the index to the {@link List} element to bind to.
> *
> * @param outerObservableValue
> * @param factory
> * @param detailType
> * @param index
> */
> public ListIndexObservableValue(IObservableValue outerObservableValue,
> IObservableFactory factory, Object detailType, int index) {
> super(outerObservableValue, factory, detailType);
> this.index = index;
> }
>
> /**
> * Gets the instance object from {@link
> DetailObservableValue#doGetValue()},
> * casts it to an instance of {@link List} if possible, and returns the
> * element at {@link #index}, or the {@link List} itself if it does
> not have
> * enough elements, or the Object returned from the super method if
> it is
> * not an instance of {@link List}
> */
> @Override
> public Object doGetValue() {
> Object obj = super.doGetValue();
> if (obj instanceof List<?>) {
> List<?> l = (List<?>) obj;
> if (l.size() > index) {
> return l.get(index);
> }
> }
> return obj;
> }
>
> /**
> * Gets the instance object from {@link
> DetailObservableValue#doGetValue()},
> * casts it to an instance of {@link List} if possible. If the
> {@link List}
> * size is greater than {@link #index}, the element at that index is
> * replaced with the input parameter.
> *
> */
> @SuppressWarnings("unchecked")
> @Override
> public void doSetValue(Object value) {
> Object obj = super.doGetValue();
> if (obj instanceof List<?>) {
> List<Object> l = (List<Object>) obj;
> if (l.size() > index) {
> l.remove(index);
> l.add(index, value);
> }
> }
> }
>
> /**
> * Returns {@link BigInteger} class, as the List is expected to only
> conatin
> * {@link BigInteger} elements.
> */
> @Override
> public Object getValueType() {
> return BigInteger.class;
> }
>
>
> Tom Schindl wrote:
>> Hi,
>>
>> Not really but if you look at the code of the EMF-Observables it is
>> quite straight forward.
>>
>> Tom
>>
>> Stephen Egan schrieb:
>>> Thanks again Tom,
>>>
>>> I'll have a go at specialising IObservableValue. The list always holds
>>> 12 values, so it should be ok. Do you know of any code snippets that
>>> might help me out please?
>>>
>>> Stephen
>>>
>>> Tom Schindl wrote:
>>>> Hi Stephen,
>>>>
>>>> Then I guess you have 2 possibilities:
>>>> a) Write a specialized IObservableValue for your list and because you
>>>> exactly know how the list-feature is structured it is a quite
>>>> simple.
>>>> Is the assumption correct that the list always holds 12 values?
>>>>
>>>> b) Add those volatile transient features in your Ecore-Model.
>>>>
>>>> By the way the use case is not really unusual because I answered this
>>>> kind of question multiple times already.
>>>>
>>>> Tom
>>>>
>>>> Stephen Egan schrieb:
>>>>> Thanks Tom,
>>>>>
>>>>> I might just do things the old fashioned way. I agree that it
>>>>> probably
>>>>> isn't straight forward to implement something like this with
>>>>> Databinding, and is probably an unusual use case anyway. My model is
>>>>> derived from legacy XSD, which was derived from legacy Delphi code, so
>>>>> gets 0/10 for best OO practices!
>>>>>
>>>>> Stephen
>>>>>
>>>>> Tom Schindl wrote:
>>>>>> Hi,
>>>>>>
>>>>>> EMF-Databinding nor the Core of Databinding can't bind to indices
>>>>>> of an
>>>>>> array (as of now :-). What you need to do is to provided transient,
>>>>>> volatile attributes you can bind the spinners to who make the value
>>>>>> look
>>>>>> like a single valued attribute for EclipseDatabinding. Maybe it
>>>>>> would be
>>>>>> better to use an EMF-Feature-Map for your use case?
>>>>>>
>>>>>> I'm going to wrap my head around in the inofficial databinding port I
>>>>>> created for the up coming 3.5-Databinding-Properties-API (but I
>>>>>> need to
>>>>>> update that to the latest M6 and M7 changes because it doesn't
>>>>>> compile
>>>>>> there any more) and discuss with the Core developers how such a
>>>>>> support
>>>>>> of List-Indices could work but I'm not even sure this can work.
>>>>>> The get
>>>>>> is easy but how does the set look like?
>>>>>>
>>>>>> Tom
>>>>>>
>>>>>> [1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
>>>>>> [2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter
>>>>>>
>>>>>> Stephen Egan schrieb:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I have been using EMF Databinding with much success, however I have
>>>>>>> come
>>>>>>> across a case that has me stumped. I want to bind a Spinner
>>>>>>> widget to
>>>>>>> each value in a multiplicity-many attribute list, but cannot find a
>>>>>>> straight forward way to do so. Specifically, one of my EObjects
>>>>>>> has a
>>>>>>> multiplicity-many attribute of type Integer to hold a value for each
>>>>>>> month of the year. I have created a Spinner widget for each
>>>>>>> month and
>>>>>>> would like to bind those Spinners to the values in the attribute's
>>>>>>> EList
>>>>>>> by index.
>>>>>>>
>>>>>>> Is there already support for this case? If not, could anybody
>>>>>>> please
>>>>>>> offer me some tips on what I need to subclass, and what should be
>>>>>>> overridden?
>>>>>>>
>>>>>>> Many thanks,
>>>>>>>
>>>>>>> Stephen Egan
>>>>>>>
Re: [EMF Databinding] [message #429427 is a reply to message #429349] Thu, 23 April 2009 01:52 Go to previous message
Stephen Egan is currently offline Stephen EganFriend
Messages: 21
Registered: July 2009
Junior Member
Hi Tom,

I was a bit ahead of myself posting the snippet. Although the values
are getting read and set, they are not being set through the editing
domain and command stack, so a bit more work is required.

Will post an update when I've got it.

Stephen.

Tom Schindl wrote:
> Hi Stephen,
>
> Great you managed it. I'm working on a support this kind of scenario in
> the up-coming EMF-Databinding version and made good progress last
> weekend but didn't finished the implementation.
>
> ---------------8<---------------
> int i = 0;
>
> IEMFListValueProperty prop = EMFProperties.listValue(
> MyPackage.Literals.AddressBook_Persons,
> new Condition() {
> public boolean match(int index, Object object) {
> return i == index;
> }
> }
> );
>
> IObservableValue v =
> prop.observeDetail(master,MyPackage.Literals.Person_Name);
> ---------------8<---------------
>
> This would make the system extremly flexible because one could select
> the not only based on the index but e.g. also by the value some other
> attribute.
>
> Tom
>
> Stephen Egan schrieb:
>> Hi Tom,
>>
>> Your quite right, it was fairly straight forward to implement. A code
>> snippet is below for other's reference. I subclassed
>> DetailObservableList, as I have been using the Master Detail pattern.
>> This class is restricted, but this approach is doing the job for me.
>> Also, my attribute is a BigInteger rather than Integer, so a suitable
>> converter is required.
>>
>> I create an instance using the following snippet:
>>
>> IObservableValue spinnerObservableValue = new ListIndexObservableValue(
>> shadingSelection, EMFEditObservables.valueFactory(r,
>> editingDomain, pkg.getShadingType_ShBlockingFactors()),
>> pkg.getShadingType_ShBlockingFactors(), i);
>>
>> Where shadingSelection is an instance of IViewerObservableValue
>> r is an instance of Realm
>> editingDomain is an instance of EditingDomain
>> pkg is my EPackage instance
>> i is the index of the List element I am interested in.
>>
>>
>> public class ListIndexObservableValue extends DetailObservableValue {
>>
>> private int index;
>>
>> /**
>> * Constructor calls
>> * {@link
>> DetailObservableValue#DetailObservableValue(IObservableValue ,
>> IObservableFactory, Object)}
>> * , and stores the index to the {@link List} element to bind to.
>> *
>> * @param outerObservableValue
>> * @param factory
>> * @param detailType
>> * @param index
>> */
>> public ListIndexObservableValue(IObservableValue outerObservableValue,
>> IObservableFactory factory, Object detailType, int index) {
>> super(outerObservableValue, factory, detailType);
>> this.index = index;
>> }
>>
>> /**
>> * Gets the instance object from {@link
>> DetailObservableValue#doGetValue()},
>> * casts it to an instance of {@link List} if possible, and returns the
>> * element at {@link #index}, or the {@link List} itself if it does
>> not have
>> * enough elements, or the Object returned from the super method if
>> it is
>> * not an instance of {@link List}
>> */
>> @Override
>> public Object doGetValue() {
>> Object obj = super.doGetValue();
>> if (obj instanceof List<?>) {
>> List<?> l = (List<?>) obj;
>> if (l.size() > index) {
>> return l.get(index);
>> }
>> }
>> return obj;
>> }
>>
>> /**
>> * Gets the instance object from {@link
>> DetailObservableValue#doGetValue()},
>> * casts it to an instance of {@link List} if possible. If the
>> {@link List}
>> * size is greater than {@link #index}, the element at that index is
>> * replaced with the input parameter.
>> *
>> */
>> @SuppressWarnings("unchecked")
>> @Override
>> public void doSetValue(Object value) {
>> Object obj = super.doGetValue();
>> if (obj instanceof List<?>) {
>> List<Object> l = (List<Object>) obj;
>> if (l.size() > index) {
>> l.remove(index);
>> l.add(index, value);
>> }
>> }
>> }
>>
>> /**
>> * Returns {@link BigInteger} class, as the List is expected to only
>> conatin
>> * {@link BigInteger} elements.
>> */
>> @Override
>> public Object getValueType() {
>> return BigInteger.class;
>> }
>>
>>
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> Not really but if you look at the code of the EMF-Observables it is
>>> quite straight forward.
>>>
>>> Tom
>>>
>>> Stephen Egan schrieb:
>>>> Thanks again Tom,
>>>>
>>>> I'll have a go at specialising IObservableValue. The list always holds
>>>> 12 values, so it should be ok. Do you know of any code snippets that
>>>> might help me out please?
>>>>
>>>> Stephen
>>>>
>>>> Tom Schindl wrote:
>>>>> Hi Stephen,
>>>>>
>>>>> Then I guess you have 2 possibilities:
>>>>> a) Write a specialized IObservableValue for your list and because you
>>>>> exactly know how the list-feature is structured it is a quite
>>>>> simple.
>>>>> Is the assumption correct that the list always holds 12 values?
>>>>>
>>>>> b) Add those volatile transient features in your Ecore-Model.
>>>>>
>>>>> By the way the use case is not really unusual because I answered this
>>>>> kind of question multiple times already.
>>>>>
>>>>> Tom
>>>>>
>>>>> Stephen Egan schrieb:
>>>>>> Thanks Tom,
>>>>>>
>>>>>> I might just do things the old fashioned way. I agree that it
>>>>>> probably
>>>>>> isn't straight forward to implement something like this with
>>>>>> Databinding, and is probably an unusual use case anyway. My model is
>>>>>> derived from legacy XSD, which was derived from legacy Delphi code, so
>>>>>> gets 0/10 for best OO practices!
>>>>>>
>>>>>> Stephen
>>>>>>
>>>>>> Tom Schindl wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> EMF-Databinding nor the Core of Databinding can't bind to indices
>>>>>>> of an
>>>>>>> array (as of now :-). What you need to do is to provided transient,
>>>>>>> volatile attributes you can bind the spinners to who make the value
>>>>>>> look
>>>>>>> like a single valued attribute for EclipseDatabinding. Maybe it
>>>>>>> would be
>>>>>>> better to use an EMF-Feature-Map for your use case?
>>>>>>>
>>>>>>> I'm going to wrap my head around in the inofficial databinding port I
>>>>>>> created for the up coming 3.5-Databinding-Properties-API (but I
>>>>>>> need to
>>>>>>> update that to the latest M6 and M7 changes because it doesn't
>>>>>>> compile
>>>>>>> there any more) and discuss with the Core developers how such a
>>>>>>> support
>>>>>>> of List-Indices could work but I'm not even sure this can work.
>>>>>>> The get
>>>>>>> is easy but how does the set look like?
>>>>>>>
>>>>>>> Tom
>>>>>>>
>>>>>>> [1]https://bugs.eclipse.org/bugs/show_bug.cgi?id=262160
>>>>>>> [2] http://github.com/tomsontom/emf-databinding-example/tree/mas ter
>>>>>>>
>>>>>>> Stephen Egan schrieb:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I have been using EMF Databinding with much success, however I have
>>>>>>>> come
>>>>>>>> across a case that has me stumped. I want to bind a Spinner
>>>>>>>> widget to
>>>>>>>> each value in a multiplicity-many attribute list, but cannot find a
>>>>>>>> straight forward way to do so. Specifically, one of my EObjects
>>>>>>>> has a
>>>>>>>> multiplicity-many attribute of type Integer to hold a value for each
>>>>>>>> month of the year. I have created a Spinner widget for each
>>>>>>>> month and
>>>>>>>> would like to bind those Spinners to the values in the attribute's
>>>>>>>> EList
>>>>>>>> by index.
>>>>>>>>
>>>>>>>> Is there already support for this case? If not, could anybody
>>>>>>>> please
>>>>>>>> offer me some tips on what I need to subclass, and what should be
>>>>>>>> overridden?
>>>>>>>>
>>>>>>>> Many thanks,
>>>>>>>>
>>>>>>>> Stephen Egan
>>>>>>>>
Previous Topic:Keep uppercase of the EAttribute names
Next Topic:use another attribute for cross-references instead of "href"
Goto Forum:
  


Current Time: Wed Apr 24 19:00:02 GMT 2024

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

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

Back to the top