RWT.getLocale() aware JFace data binding [message #119279] |
Thu, 22 January 2009 13:38  |
Eclipse User |
|
|
|
Hi
Is there a RWT.getLocale() aware JFace data binding? If I use the JFace
data binding to bind a date or a double value to a text field, the
standard NumberToStringConverter uses the default locale and not
RWT.getLocale() to convert it to a string.
Thanks
Norbert
|
|
|
|
Re: RWT.getLocale() aware JFace data binding [message #119344 is a reply to message #119306] |
Fri, 23 January 2009 05:10   |
Eclipse User |
|
|
|
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 10:51  |
Eclipse User |
|
|
|
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
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03397 seconds