Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RWT.getLocale() aware JFace data binding
RWT.getLocale() aware JFace data binding [message #119279] Thu, 22 January 2009 18:38 Go to next message
Norbert Bumm is currently offline Norbert BummFriend
Messages: 4
Registered: July 2009
Junior Member
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 #119306 is a reply to message #119279] Fri, 23 January 2009 08:57 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
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

Norbert Bumm wrote:
> 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 10:10 Go to previous messageGo to next message
Norbert Bumm is currently offline Norbert BummFriend
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 Go to previous message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
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
>
>
>
Previous Topic:RAP and Jboss
Next Topic:tiling views in a folder
Goto Forum:
  


Current Time: Sun Dec 05 21:46:14 GMT 2021

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

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

Back to the top