Home » Eclipse Projects » Eclipse Platform » [Databinding] Converted values not seen in Text
[Databinding] Converted values not seen in Text [message #329295] |
Wed, 18 June 2008 14:32 |
Christoph Jäger Messages: 14 Registered: July 2009 |
Junior Member |
|
|
Hi,
I am using Eclipse 3.4RC3.
I have a Text field, which is connected to a String property via data
binding like this:
--
IObservable observable = ... ; // bound to my String property
Text name=new Text(parent, SWT.NONE);
UpdateValueStrategy targetToModelStrategy=new UpdateValueStrategy();
targetToModelStrategy.setConverter(new TrimWhiteSpaceConverter());
IObservableValue textObserveWidget=SWTObservables.observeText(name,
SWT.FocusOut);
dataBindingContext.bindValue(textObserveWidget, observable,
targetToModelStrategy, null);
--
This should trim whitespace (leading and trailing) from the value
entered into the Text field.
Now, this works fine for updating the model, when I enter " Test " into
the Text field, the model gets updated with "Test" (note: whitespace
removed).
What does not work: the value in the Text field stays " Test ".
There must be a simple way to make the Text field also be updated with
the value after conversion. Can anyone point me in the right direction?
Thanks,
Christoph Jäger
|
|
|
Re: [Databinding] Converted values not seen in Text [message #329298 is a reply to message #329295] |
Wed, 18 June 2008 14:59 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
You'll need to call do this manually after your model is updated by calling:
Binding#updateModelToTarget()
Tom
Christoph Jaeger schrieb:
> Hi,
>
> I am using Eclipse 3.4RC3.
>
> I have a Text field, which is connected to a String property via data
> binding like this:
>
> --
> IObservable observable = ... ; // bound to my String property
> Text name=new Text(parent, SWT.NONE);
>
> UpdateValueStrategy targetToModelStrategy=new UpdateValueStrategy();
> targetToModelStrategy.setConverter(new TrimWhiteSpaceConverter());
>
> IObservableValue textObserveWidget=SWTObservables.observeText(name,
> SWT.FocusOut);
>
> dataBindingContext.bindValue(textObserveWidget, observable,
> targetToModelStrategy, null);
> --
>
> This should trim whitespace (leading and trailing) from the value
> entered into the Text field.
>
> Now, this works fine for updating the model, when I enter " Test " into
> the Text field, the model gets updated with "Test" (note: whitespace
> removed).
>
> What does not work: the value in the Text field stays " Test ".
>
> There must be a simple way to make the Text field also be updated with
> the value after conversion. Can anyone point me in the right direction?
>
> Thanks,
>
> Christoph Jäger
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
| | |
Re: [Databinding] Converted values not seen in Text [message #329406 is a reply to message #329365] |
Mon, 23 June 2008 12:58 |
Eclipse User |
|
|
|
Originally posted by: eclipse-news.rizzoweb.com
Boris Bokowski wrote:
> Could you please file an enhancement request in Bugzilla? This seems to be a
> common feature request that we should support. We could also use the
> Bugzilla to discuss possible workarounds.
Please post the Bugzilla number or link here so other interested readers
can follow the progress.
Eric
> "Christoph Jaeger" <christoph.jaeger@cargodata.at> wrote in message
> news:g3b9dr$pm7$1@build.eclipse.org...
>> Tom Schindl wrote:
>>> You'll need to call do this manually after your model is updated by
>>> calling:
>>>
>>> Binding#updateModelToTarget()
>>>
>> Thanks for your hint. So I extended UpdateValueStrategy to override
>>
>> @Override
>> protected IStatus doSet(IObservableValue observableValue, Object value)
>> {
>> IStatus status=super.doSet(observableValue, value);
>> if (binding!=null) binding.updateModelToTarget();
>> return status;
>> }
>>
>> and make sure I set the binding (see last line):
>>
>> --
>> UpdateValueStrategyWithFeedback targetToModelStrategy=new
>> UpdateValueStrategyWithFeedback();
>> targetToModelStrategy.setConverter(new TrimWhiteSpaceConverter());
>>
>> Binding binding=dataBindingContext.bindValue(textObserveWidget,
>> observable, targetToModelStrategy, null);
>>
>> targetToModelStrategy.setBinding(binding);
>> --
>>
>> Looks a bit strange (first I use the targetModelStrategy to create a
>> binding, and then I feed the resulting binding to the
>> targetModelStrategy), but seems to work. Do I need to worry about
>> disposing the binding instance I pass into targetModelStrategy?
>>
>> Or is there an easier way to achieve the same?
>>
>> Thanks,
>>
>> Christoph
>
>
|
|
| |
Goto Forum:
Current Time: Sun Oct 06 12:40:33 GMT 2024
Powered by FUDForum. Page generated in 0.02907 seconds
|