Home » Eclipse Projects » Remote Application Platform (RAP) » RWT.getLocale() aware JFace data binding
| |
Re: RWT.getLocale() aware JFace data binding [message #119344 is a reply to message #119306] |
Fri, 23 January 2009 10:10 |
Norbert Bumm Messages: 4 Registered: July 2009 |
Junior Member |
|
|
Hi Rüdiger,
thanks for your reply. Yes I can do this, but it would be nice if it
dont't have to care about this. The standard code if I use the JFace data
binding to bind an double property "weight" of person object to a SWT text
widget is.
...
Realm realm = SWTObservables.getRealm( Display.getCurrent() );
DataBindingContext bindingContext = new DataBindingContext( realm );
bindingContext.bindValue( SWTObservables.observeText( text, SWT.Modify ),
BeansObservables.observeValue( realm,
person,
"weight" ),
null,
null );
If I have to use explicit locale aware conversion:
...
UpdateValueStrategy modelToText = new UpdateValueStrategy();
NumberFormat numberFormat = NumberFormat.getInstance( RWT.getLocale() );
IConverter numberToStringConverter = NumberToStringConverter.fromDouble(
numberFormat, true );
modelToText.setConverter( numberToStringConverter );
UpdateValueStrategy textToModel = new UpdateValueStrategy();
IConverter stringToNumberConverter = StringToNumberConverter.toDouble(
numberFormat, true );
textToModel.setConverter( stringToNumberConverter );
bindingContext.bindValue( SWTObservables.observeText( text, SWT.Modify ),
BeansObservables.observeValue( realm,
person,
"weight" ),
textToModel,
modelToText );
This is a lot of additional code to write for each number or date property
to bind. I think it would be better if the internal registry for the
standard converters could be configured to use the session locale.
Norbert
Rüdiger Herrmann wrote:
> Norbert,
> maybe I don't see your actual problem, but why don't you use the
> locale-aware NumberFormat methods?
> Something along these lines:
> Locale locale = RWT.getLocale();
> NumberFormat format = NumberFormat.getIntegerInstance( locale );
> NumberToStringConverter.fromInteger( format, true );
> HTH
> Rüdiger
|
|
|
Re: RWT.getLocale() aware JFace data binding [message #119396 is a reply to message #119344] |
Fri, 23 January 2009 15:51 |
Rüdiger Herrmann Messages: 581 Registered: July 2009 |
Senior Member |
|
|
Norbert,
I agree with you that it takes a couple of lines to make the
convertsion locale aware.
But from what I understand you only need to write it once. Then
extract it to let's say modelToTextConverter() and
textToModelConverter() and pass these to the bindValue() call.
If that still doesn't fit your needs, you may file an enhancement
request against Platform / Databinding. This is where the
org.eclipse.core.databinding plug-in is maintained.
Cheers,
Rüdiger
Norbert Bumm wrote:
> Hi Rüdiger,
>
> thanks for your reply. Yes I can do this, but it would be nice if it
> dont't have to care about this. The standard code if I use the JFace
> data binding to bind an double property "weight" of person object to a
> SWT text widget is.
>
> ...
> Realm realm = SWTObservables.getRealm( Display.getCurrent() );
> DataBindingContext bindingContext = new DataBindingContext( realm );
>
> bindingContext.bindValue( SWTObservables.observeText( text, SWT.Modify ),
> BeansObservables.observeValue( realm,
> person,
> "weight" ),
> null,
> null );
>
>
> If I have to use explicit locale aware conversion:
>
> ...
> UpdateValueStrategy modelToText = new UpdateValueStrategy();
> NumberFormat numberFormat = NumberFormat.getInstance( RWT.getLocale() );
> IConverter numberToStringConverter = NumberToStringConverter.fromDouble(
> numberFormat, true );
> modelToText.setConverter( numberToStringConverter );
> UpdateValueStrategy textToModel = new UpdateValueStrategy();
> IConverter stringToNumberConverter = StringToNumberConverter.toDouble(
> numberFormat, true );
> textToModel.setConverter( stringToNumberConverter );
>
> bindingContext.bindValue( SWTObservables.observeText( text, SWT.Modify ),
> BeansObservables.observeValue( realm,
> person,
> "weight" ),
> textToModel,
> modelToText );
>
> This is a lot of additional code to write for each number or date
> property to bind. I think it would be better if the internal registry
> for the standard converters could be configured to use the session locale.
>
> Norbert
>
> Rüdiger Herrmann wrote:
>
>> Norbert,
>
>> maybe I don't see your actual problem, but why don't you use the
>> locale-aware NumberFormat methods?
>> Something along these lines:
>> Locale locale = RWT.getLocale();
>> NumberFormat format = NumberFormat.getIntegerInstance( locale );
>> NumberToStringConverter.fromInteger( format, true );
>
>> HTH
>> Rüdiger
>
>
>
|
|
|
Goto Forum:
Current Time: Thu Sep 26 12:23:04 GMT 2024
Powered by FUDForum. Page generated in 0.04304 seconds
|