Home » Modeling » EMF » Problem with databinding to an attribute of type java.lang.Object
Problem with databinding to an attribute of type java.lang.Object [message #429866] |
Tue, 05 May 2009 16:39 |
Damian Hofmann Messages: 16 Registered: July 2009 |
Junior Member |
|
|
Hi again,
I'm trying to bind an attribute of "MyClass" (part of my emf model) to a
Text-widget using databinding. I defined the type of the attribute as
java.lang.Object, because the values are excepted to be of different
types like Integer, Date, String, etc.
I except the the string representation (like attr.toString()) of the
attribute to show up in the Text-widget, but instead I get an unreadable
hex code. Looks like emf databinding support isn't able to determine the
concrete type of the object.
There are two problems I'm facing:
1st: How do I get databinding to convert my, e.g., Integer-Object
correctly, so a readable value is displayed in the Text-widget?
2nd: Opossite direction If I enter a value in the Text-widget, how do I
tell databinding the type to use for converting the string in the
Text-widget?
These questions may, at least partly, be general databinding questions,
but the problem of not recognizing the attribute's type seems
emf-related to me.
Thanks for your help
Damian
Here is the code of the model class:
/**
* @model
*/
public interface MyClass {
/**
* @model
*/
public Object getValue();
}
And here is my databinding code (model is an instance of MyClass):
EStructuralFeature valueFeature =
model.eClass().getEStructuralFeature("value");
dbc.bindValue(
SWTObservables.observeText(text, SWT.Modify),
EMFObservables.observeValue(
model,
valueFeature),
new EMFUpdateValueStrategy(),
new EMFUpdateValueStrategy()
);
|
|
|
Re: Problem with databinding to an attribute of type java.lang.Object [message #429867 is a reply to message #429866] |
Tue, 05 May 2009 16:42 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
You need to pass converters to your EMFUpdateValueStrategy()!
Tom
Damian Hofmann schrieb:
> Hi again,
>
> I'm trying to bind an attribute of "MyClass" (part of my emf model) to a
> Text-widget using databinding. I defined the type of the attribute as
> java.lang.Object, because the values are excepted to be of different
> types like Integer, Date, String, etc.
>
> I except the the string representation (like attr.toString()) of the
> attribute to show up in the Text-widget, but instead I get an unreadable
> hex code. Looks like emf databinding support isn't able to determine the
> concrete type of the object.
>
> There are two problems I'm facing:
> 1st: How do I get databinding to convert my, e.g., Integer-Object
> correctly, so a readable value is displayed in the Text-widget?
>
> 2nd: Opossite direction If I enter a value in the Text-widget, how do I
> tell databinding the type to use for converting the string in the
> Text-widget?
>
> These questions may, at least partly, be general databinding questions,
> but the problem of not recognizing the attribute's type seems
> emf-related to me.
>
>
> Thanks for your help
> Damian
>
>
>
>
> Here is the code of the model class:
>
> /**
>
> * @model
>
> */
>
> public interface MyClass {
>
> /**
>
> * @model
>
> */
>
> public Object getValue();
>
> }
>
>
>
> And here is my databinding code (model is an instance of MyClass):
>
>
> EStructuralFeature valueFeature =
> model.eClass().getEStructuralFeature("value");
> dbc.bindValue(
> SWTObservables.observeText(text, SWT.Modify),
> EMFObservables.observeValue(
> model,
> valueFeature),
> new EMFUpdateValueStrategy(),
> new EMFUpdateValueStrategy()
> );
|
|
|
Re: Problem with databinding to an attribute of type java.lang.Object [message #429900 is a reply to message #429867] |
Wed, 06 May 2009 14:30 |
Damian Hofmann Messages: 16 Registered: July 2009 |
Junior Member |
|
|
Thank you Tom. Your hint helped me alot.
My solution was to implement a new UpdateValueStrategy-class, extending
from EMFUpdateValueStrategy and overwriting the createConverter-Method.
In this method I create my own Converter.
While experimenting with the debugger I found, that
EMFUpdateValueStrategy delegates the creation of converters for
"unknown" types to it's superclass UpdateValueStrategy(). I didn't want
to break this chain of delegation.
Damian
Tom Schindl wrote:
> You need to pass converters to your EMFUpdateValueStrategy()!
>
> Tom
>
> Damian Hofmann schrieb:
>> Hi again,
>>
>> I'm trying to bind an attribute of "MyClass" (part of my emf model) to a
>> Text-widget using databinding. I defined the type of the attribute as
>> java.lang.Object, because the values are excepted to be of different
>> types like Integer, Date, String, etc.
>>
>> I except the the string representation (like attr.toString()) of the
>> attribute to show up in the Text-widget, but instead I get an unreadable
>> hex code. Looks like emf databinding support isn't able to determine the
>> concrete type of the object.
>>
>> There are two problems I'm facing:
>> 1st: How do I get databinding to convert my, e.g., Integer-Object
>> correctly, so a readable value is displayed in the Text-widget?
>>
>> 2nd: Opossite direction If I enter a value in the Text-widget, how do I
>> tell databinding the type to use for converting the string in the
>> Text-widget?
>>
>> These questions may, at least partly, be general databinding questions,
>> but the problem of not recognizing the attribute's type seems
>> emf-related to me.
>>
>>
>> Thanks for your help
>> Damian
>>
>>
>>
>>
>> Here is the code of the model class:
>>
>> /**
>>
>> * @model
>>
>> */
>>
>> public interface MyClass {
>>
>> /**
>>
>> * @model
>>
>> */
>>
>> public Object getValue();
>>
>> }
>>
>>
>>
>> And here is my databinding code (model is an instance of MyClass):
>>
>>
>> EStructuralFeature valueFeature =
>> model.eClass().getEStructuralFeature("value");
>> dbc.bindValue(
>> SWTObservables.observeText(text, SWT.Modify),
>> EMFObservables.observeValue(
>> model,
>> valueFeature),
>> new EMFUpdateValueStrategy(),
>> new EMFUpdateValueStrategy()
>> );
|
|
|
Re: Problem with databinding to an attribute of type java.lang.Object [message #429901 is a reply to message #429900] |
Wed, 06 May 2009 14:39 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Why are you not simply setting the converter on the strategy?
Tom
Damian Hofmann schrieb:
> Thank you Tom. Your hint helped me alot.
>
> My solution was to implement a new UpdateValueStrategy-class, extending
> from EMFUpdateValueStrategy and overwriting the createConverter-Method.
> In this method I create my own Converter.
>
> While experimenting with the debugger I found, that
> EMFUpdateValueStrategy delegates the creation of converters for
> "unknown" types to it's superclass UpdateValueStrategy(). I didn't want
> to break this chain of delegation.
>
>
> Damian
>
>
> Tom Schindl wrote:
>> You need to pass converters to your EMFUpdateValueStrategy()!
>>
>> Tom
>>
>> Damian Hofmann schrieb:
>>> Hi again,
>>>
>>> I'm trying to bind an attribute of "MyClass" (part of my emf model) to a
>>> Text-widget using databinding. I defined the type of the attribute as
>>> java.lang.Object, because the values are excepted to be of different
>>> types like Integer, Date, String, etc.
>>>
>>> I except the the string representation (like attr.toString()) of the
>>> attribute to show up in the Text-widget, but instead I get an unreadable
>>> hex code. Looks like emf databinding support isn't able to determine the
>>> concrete type of the object.
>>>
>>> There are two problems I'm facing:
>>> 1st: How do I get databinding to convert my, e.g., Integer-Object
>>> correctly, so a readable value is displayed in the Text-widget?
>>>
>>> 2nd: Opossite direction If I enter a value in the Text-widget, how do I
>>> tell databinding the type to use for converting the string in the
>>> Text-widget?
>>>
>>> These questions may, at least partly, be general databinding questions,
>>> but the problem of not recognizing the attribute's type seems
>>> emf-related to me.
>>>
>>>
>>> Thanks for your help
>>> Damian
>>>
>>>
>>>
>>>
>>> Here is the code of the model class:
>>>
>>> /**
>>>
>>> * @model
>>>
>>> */
>>>
>>> public interface MyClass {
>>>
>>> /**
>>>
>>> * @model
>>>
>>> */
>>>
>>> public Object getValue();
>>>
>>> }
>>>
>>>
>>>
>>> And here is my databinding code (model is an instance of MyClass):
>>>
>>>
>>> EStructuralFeature valueFeature =
>>> model.eClass().getEStructuralFeature("value");
>>> dbc.bindValue(
>>> SWTObservables.observeText(text, SWT.Modify),
>>> EMFObservables.observeValue(
>>> model,
>>> valueFeature),
>>> new EMFUpdateValueStrategy(),
>>> new EMFUpdateValueStrategy()
>>> );
|
|
|
Re: Problem with databinding to an attribute of type java.lang.Object [message #429902 is a reply to message #429901] |
Wed, 06 May 2009 14:47 |
Damian Hofmann Messages: 16 Registered: July 2009 |
Junior Member |
|
|
Hi Tom,
Because I have seen in the createConverter-Method of
EMFUpdateValueStrategy, that the method delegates the creation of the
converter to it's superclass (UpdateValueStrategy), if it can't handle
the type of a value to convert. I didn't want to break this delegation,
but instead extend it.
Im my createConverter-Method I also test, if I can handle the value
types. If not I delegate the creation of a converter to the superclasses.
Damian
Tom Schindl wrote:
> Why are you not simply setting the converter on the strategy?
>
> Tom
>
> Damian Hofmann schrieb:
>> Thank you Tom. Your hint helped me alot.
>>
>> My solution was to implement a new UpdateValueStrategy-class, extending
>> from EMFUpdateValueStrategy and overwriting the createConverter-Method.
>> In this method I create my own Converter.
>>
>> While experimenting with the debugger I found, that
>> EMFUpdateValueStrategy delegates the creation of converters for
>> "unknown" types to it's superclass UpdateValueStrategy(). I didn't want
>> to break this chain of delegation.
>>
>>
>> Damian
>>
>>
>> Tom Schindl wrote:
>>> You need to pass converters to your EMFUpdateValueStrategy()!
>>>
>>> Tom
>>>
>>> Damian Hofmann schrieb:
>>>> Hi again,
>>>>
>>>> I'm trying to bind an attribute of "MyClass" (part of my emf model) to a
>>>> Text-widget using databinding. I defined the type of the attribute as
>>>> java.lang.Object, because the values are excepted to be of different
>>>> types like Integer, Date, String, etc.
>>>>
>>>> I except the the string representation (like attr.toString()) of the
>>>> attribute to show up in the Text-widget, but instead I get an unreadable
>>>> hex code. Looks like emf databinding support isn't able to determine the
>>>> concrete type of the object.
>>>>
>>>> There are two problems I'm facing:
>>>> 1st: How do I get databinding to convert my, e.g., Integer-Object
>>>> correctly, so a readable value is displayed in the Text-widget?
>>>>
>>>> 2nd: Opossite direction If I enter a value in the Text-widget, how do I
>>>> tell databinding the type to use for converting the string in the
>>>> Text-widget?
>>>>
>>>> These questions may, at least partly, be general databinding questions,
>>>> but the problem of not recognizing the attribute's type seems
>>>> emf-related to me.
>>>>
>>>>
>>>> Thanks for your help
>>>> Damian
>>>>
>>>>
>>>>
>>>>
>>>> Here is the code of the model class:
>>>>
>>>> /**
>>>>
>>>> * @model
>>>>
>>>> */
>>>>
>>>> public interface MyClass {
>>>>
>>>> /**
>>>>
>>>> * @model
>>>>
>>>> */
>>>>
>>>> public Object getValue();
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> And here is my databinding code (model is an instance of MyClass):
>>>>
>>>>
>>>> EStructuralFeature valueFeature =
>>>> model.eClass().getEStructuralFeature("value");
>>>> dbc.bindValue(
>>>> SWTObservables.observeText(text, SWT.Modify),
>>>> EMFObservables.observeValue(
>>>> model,
>>>> valueFeature),
>>>> new EMFUpdateValueStrategy(),
>>>> new EMFUpdateValueStrategy()
>>>> );
|
|
|
Goto Forum:
Current Time: Fri Apr 26 20:31:36 GMT 2024
Powered by FUDForum. Page generated in 0.02706 seconds
|