Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Databinding with DateTime
Databinding with DateTime [message #482245] Tue, 25 August 2009 19:59 Go to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 71
Registered: July 2009
Member
All,

I have an RCP app where a dialog view is backed by an EMF model. I want
to bind the data values using SWTObservables, and EMFObservables. All
goes well except with dates.

How can I get this to work with dates?

My EMF model is already populated with values when binding occurs.

1. If I do this using EMFObservables:

Text txtBegin...
IObservableValue uiElement = SWTObservables.observeText(txtBegin,
SWT.Modify);
IObservableValue modelElement = EMFObservables.observeValue(scenario,
ScenarioPackage.Literals.SCENARIO__BEGIN);
bindingContext.bindValue(uiElement, modelElement, null, null);

The view displays with txtBegin as blank even though the attribute was
already populated in the model.

2. If I do this using BeansObservables:

Text txtBegin...
IObservableValue uiElement = SWTObservables.observeText(txtBegin,
SWT.Modify);
IObservableValue modelElement = BeansObservables.observeValue(scenario,
"begin");
bindingContext.bindValue(uiElement, modelElement, null, null);


The view displays with txtBegin properly populated but changes to txtBegin
in the view do not seem to propagate to the model.

With all other dataypes, things are working as they should.
Re: Databinding with DateTime [message #482247 is a reply to message #482245] Tue, 25 August 2009 20:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Geoffry,

Which particular EDataTypes are you using. EDate from EcorePackage or
things from XMLTypePackage?


Geoffry Roberts wrote:
> All,
>
> I have an RCP app where a dialog view is backed by an EMF model. I
> want to bind the data values using SWTObservables, and
> EMFObservables. All goes well except with dates.
> How can I get this to work with dates?
>
> My EMF model is already populated with values when binding occurs.
>
> 1. If I do this using EMFObservables:
>
> Text txtBegin...
> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
> SWT.Modify);
> IObservableValue modelElement = EMFObservables.observeValue(scenario,
> ScenarioPackage.Literals.SCENARIO__BEGIN);
> bindingContext.bindValue(uiElement, modelElement, null, null);
>
> The view displays with txtBegin as blank even though the attribute was
> already populated in the model.
>
> 2. If I do this using BeansObservables:
>
> Text txtBegin...
> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
> SWT.Modify);
> IObservableValue modelElement =
> BeansObservables.observeValue(scenario, "begin");
> bindingContext.bindValue(uiElement, modelElement, null, null);
>
>
> The view displays with txtBegin properly populated but changes to
> txtBegin in the view do not seem to propagate to the model.
>
> With all other dataypes, things are working as they should.
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Databinding with DateTime [message #482252 is a reply to message #482247] Tue, 25 August 2009 20:22 Go to previous messageGo to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 71
Registered: July 2009
Member
Ed Merks wrote:

> Geoffry,

> Which particular EDataTypes are you using. EDate from EcorePackage or
> things from XMLTypePackage?


> Geoffry Roberts wrote:
>> All,
>>
>> I have an RCP app where a dialog view is backed by an EMF model. I
>> want to bind the data values using SWTObservables, and
>> EMFObservables. All goes well except with dates.
>> How can I get this to work with dates?
>>
>> My EMF model is already populated with values when binding occurs.
>>
>> 1. If I do this using EMFObservables:
>>
>> Text txtBegin...
>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>> SWT.Modify);
>> IObservableValue modelElement = EMFObservables.observeValue(scenario,
>> ScenarioPackage.Literals.SCENARIO__BEGIN);
>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>
>> The view displays with txtBegin as blank even though the attribute was
>> already populated in the model.
>>
>> 2. If I do this using BeansObservables:
>>
>> Text txtBegin...
>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>> SWT.Modify);
>> IObservableValue modelElement =
>> BeansObservables.observeValue(scenario, "begin");
>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>
>>
>> The view displays with txtBegin properly populated but changes to
>> txtBegin in the view do not seem to propagate to the model.
>>
>> With all other dataypes, things are working as they should.
>>
>>
I think its the XMLTypePackage.

I am using whatever the model generator generates. The data type is
XMLGregorianCalendar.

I generate from a schema. The data type in the schema is xs:dateTime.

In my generated ecore file I see:
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//DateTime"
Re: Databinding with DateTime [message #482256 is a reply to message #482245] Tue, 25 August 2009 20:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Wild guess is that you need to set your custom conversion strategy
because no default mapping could be found to convert from your DateTime
to String and String to DateTime incase of an EMFUpdateValueStrategy
(which is the default one created for you when passing null).

There's an on going discussion between me and Ed about this and probably
it works somehow with BeanObservables because they are using the
instance type to search for default converts.

Out of curiosity are you using an EMFDatabindingContext or the default
DatabindingContext? If it is the latter you should give
EMFDatabindingContext a try.

Tom

Geoffry Roberts schrieb:
> All,
>
> I have an RCP app where a dialog view is backed by an EMF model. I want
> to bind the data values using SWTObservables, and EMFObservables. All
> goes well except with dates.
> How can I get this to work with dates?
>
> My EMF model is already populated with values when binding occurs.
>
> 1. If I do this using EMFObservables:
>
> Text txtBegin...
> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
> SWT.Modify);
> IObservableValue modelElement = EMFObservables.observeValue(scenario,
> ScenarioPackage.Literals.SCENARIO__BEGIN);
> bindingContext.bindValue(uiElement, modelElement, null, null);
>
> The view displays with txtBegin as blank even though the attribute was
> already populated in the model.
>
> 2. If I do this using BeansObservables:
>
> Text txtBegin...
> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
> SWT.Modify);
> IObservableValue modelElement = BeansObservables.observeValue(scenario,
> "begin");
> bindingContext.bindValue(uiElement, modelElement, null, null);
>
>
> The view displays with txtBegin properly populated but changes to
> txtBegin in the view do not seem to propagate to the model.
>
> With all other dataypes, things are working as they should.
>
>
Re: Databinding with DateTime [message #482257 is a reply to message #482256] Tue, 25 August 2009 20:57 Go to previous messageGo to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 71
Registered: July 2009
Member
Tom,

I am using DataBindingContext. As per your suggestion, I'll give
EMFUpdateValueStrategy a try.

Thanks.

Tom Schindl wrote:

> Wild guess is that you need to set your custom conversion strategy
> because no default mapping could be found to convert from your DateTime
> to String and String to DateTime incase of an EMFUpdateValueStrategy
> (which is the default one created for you when passing null).

> There's an on going discussion between me and Ed about this and probably
> it works somehow with BeanObservables because they are using the
> instance type to search for default converts.

> Out of curiosity are you using an EMFDatabindingContext or the default
> DatabindingContext? If it is the latter you should give
> EMFDatabindingContext a try.

> Tom

> Geoffry Roberts schrieb:
>> All,
>>
>> I have an RCP app where a dialog view is backed by an EMF model. I want
>> to bind the data values using SWTObservables, and EMFObservables. All
>> goes well except with dates.
>> How can I get this to work with dates?
>>
>> My EMF model is already populated with values when binding occurs.
>>
>> 1. If I do this using EMFObservables:
>>
>> Text txtBegin...
>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>> SWT.Modify);
>> IObservableValue modelElement = EMFObservables.observeValue(scenario,
>> ScenarioPackage.Literals.SCENARIO__BEGIN);
>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>
>> The view displays with txtBegin as blank even though the attribute was
>> already populated in the model.
>>
>> 2. If I do this using BeansObservables:
>>
>> Text txtBegin...
>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>> SWT.Modify);
>> IObservableValue modelElement = BeansObservables.observeValue(scenario,
>> "begin");
>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>
>>
>> The view displays with txtBegin properly populated but changes to
>> txtBegin in the view do not seem to propagate to the model.
>>
>> With all other dataypes, things are working as they should.
>>
>>
Re: Databinding with DateTime [message #482264 is a reply to message #482257] Tue, 25 August 2009 21:55 Go to previous messageGo to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 71
Registered: July 2009
Member
tom,

Your suggestion worked. Thanks.

Here's what I did. It worked for all datatypes.

EMFDataBindingContext bindingContext = new EMFDataBindingContext();

IObservableValue uiElement = SWTObservables.observeText(txtBegin,
SWT.Modify);
IObservableValue modelElement = EMFObservables.observeValue(scenario,
ScenarioPackage.Literals.SCENARIO__BEGIN);
bindingContext.bindValue(uiElement, modelElement, null, null);


Geoffry Roberts wrote:

> Tom,

> I am using DataBindingContext. As per your suggestion, I'll give
> EMFUpdateValueStrategy a try.

> Thanks.

> Tom Schindl wrote:

>> Wild guess is that you need to set your custom conversion strategy
>> because no default mapping could be found to convert from your DateTime
>> to String and String to DateTime incase of an EMFUpdateValueStrategy
>> (which is the default one created for you when passing null).

>> There's an on going discussion between me and Ed about this and probably
>> it works somehow with BeanObservables because they are using the
>> instance type to search for default converts.

>> Out of curiosity are you using an EMFDatabindingContext or the default
>> DatabindingContext? If it is the latter you should give
>> EMFDatabindingContext a try.

>> Tom

>> Geoffry Roberts schrieb:
>>> All,
>>>
>>> I have an RCP app where a dialog view is backed by an EMF model. I want
>>> to bind the data values using SWTObservables, and EMFObservables. All
>>> goes well except with dates.
>>> How can I get this to work with dates?
>>>
>>> My EMF model is already populated with values when binding occurs.
>>>
>>> 1. If I do this using EMFObservables:
>>>
>>> Text txtBegin...
>>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>>> SWT.Modify);
>>> IObservableValue modelElement = EMFObservables.observeValue(scenario,
>>> ScenarioPackage.Literals.SCENARIO__BEGIN);
>>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>>
>>> The view displays with txtBegin as blank even though the attribute was
>>> already populated in the model.
>>>
>>> 2. If I do this using BeansObservables:
>>>
>>> Text txtBegin...
>>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>>> SWT.Modify);
>>> IObservableValue modelElement = BeansObservables.observeValue(scenario,
>>> "begin");
>>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>>
>>>
>>> The view displays with txtBegin properly populated but changes to
>>> txtBegin in the view do not seem to propagate to the model.
>>>
>>> With all other dataypes, things are working as they should.
>>>
>>>
Re: Databinding with DateTime [message #482304 is a reply to message #482264] Wed, 26 August 2009 07:51 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi Geoffry,

In case you are interested in some background why it works with
EMFDatabindingContext and not with DatabindingContext is that
EMFObservables return the EStructuredFeature as the type (in contrast to
BeanObservables who return the instance type).

The default configuration of the UpdateValueStrategy uses the type
informations from the target and model observable to automatically
assign converters but naturally it fails for EMFObservables because it
doesn't know what to do with EStructuralFeature.

When using EMFDatabindingContext it creates an EMFUpdateValueStrategy
which knows about this EMFObservables-Feature and uses EMFs
StringToType/TypeToString converters based upon the EStructuralFeature.

Tom

Geoffry Roberts schrieb:
> tom,
>
> Your suggestion worked. Thanks.
>
> Here's what I did. It worked for all datatypes.
>
> EMFDataBindingContext bindingContext = new EMFDataBindingContext();
>
> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
> SWT.Modify);
> IObservableValue modelElement = EMFObservables.observeValue(scenario,
> ScenarioPackage.Literals.SCENARIO__BEGIN);
> bindingContext.bindValue(uiElement, modelElement, null, null);
>
>
> Geoffry Roberts wrote:
>
>> Tom,
>
>> I am using DataBindingContext. As per your suggestion, I'll give
>> EMFUpdateValueStrategy a try.
>
>> Thanks.
>
>> Tom Schindl wrote:
>
>>> Wild guess is that you need to set your custom conversion strategy
>>> because no default mapping could be found to convert from your DateTime
>>> to String and String to DateTime incase of an EMFUpdateValueStrategy
>>> (which is the default one created for you when passing null).
>
>>> There's an on going discussion between me and Ed about this and probably
>>> it works somehow with BeanObservables because they are using the
>>> instance type to search for default converts.
>
>>> Out of curiosity are you using an EMFDatabindingContext or the default
>>> DatabindingContext? If it is the latter you should give
>>> EMFDatabindingContext a try.
>
>>> Tom
>
>>> Geoffry Roberts schrieb:
>>>> All,
>>>>
>>>> I have an RCP app where a dialog view is backed by an EMF model. I
>>>> want
>>>> to bind the data values using SWTObservables, and EMFObservables. All
>>>> goes well except with dates. How can I get this to work with dates?
>>>>
>>>> My EMF model is already populated with values when binding occurs.
>>>>
>>>> 1. If I do this using EMFObservables:
>>>>
>>>> Text txtBegin...
>>>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>>>> SWT.Modify);
>>>> IObservableValue modelElement = EMFObservables.observeValue(scenario,
>>>> ScenarioPackage.Literals.SCENARIO__BEGIN);
>>>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>>>
>>>> The view displays with txtBegin as blank even though the attribute was
>>>> already populated in the model.
>>>>
>>>> 2. If I do this using BeansObservables:
>>>>
>>>> Text txtBegin...
>>>> IObservableValue uiElement = SWTObservables.observeText(txtBegin,
>>>> SWT.Modify);
>>>> IObservableValue modelElement = BeansObservables.observeValue(scenario,
>>>> "begin");
>>>> bindingContext.bindValue(uiElement, modelElement, null, null);
>>>>
>>>>
>>>> The view displays with txtBegin properly populated but changes to
>>>> txtBegin in the view do not seem to propagate to the model.
>>>>
>>>> With all other dataypes, things are working as they should.
>>>>
>>>>
>
>
Previous Topic:How do I add no duplicates to cdo resource?
Next Topic:Avoid #-prefix in reference
Goto Forum:
  


Current Time: Wed Sep 25 02:06:46 GMT 2024

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

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

Back to the top