| Home » Eclipse Projects » Eclipse Platform » [Databinding] Converted values not seen in Text
 Goto Forum:| 
| [Databinding] Converted values not seen in Text [message #329295] | Wed, 18 June 2008 10:32  |  | 
| Eclipse User  |  |  |  |  | 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 10:59   |  | 
| Eclipse User  |  |  |  |  | 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 #329438 is a reply to message #329406] | Tue, 24 June 2008 06:03  |  | 
| Eclipse User  |  |  |  |  | Filed an enhancement request 238222 
 https://bugs.eclipse.org/bugs/show_bug.cgi?id=238222
 
 Christoph
 
 Eric Rizzo wrote:
 > 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
 >>
 >>
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 13:45:16 EDT 2025 
 Powered by FUDForum . Page generated in 0.05119 seconds |