Databinding Confusion [message #497039] |
Thu, 12 November 2009 10:54 |
Christoph Jäger Messages: 14 Registered: July 2009 |
Junior Member |
|
|
Hi,
I am a bit confused about how to use Eclipse databinding in my RCP
application.
The very simple bindings you can find in every tutorial work fine (bind
a Text field to a String property of some bean).
Also the next step, binding for instance a java.util.Date property to a
Text field, with custom IConverter instances (StringToXXXConverter and
XXXToStringConverter) to convert between Date and String work fine. If
you keep it simple: a user can enter a date as yyyy-MM-dd, it gets
converted to a java.util.Date and the result is stored in some property
in the model.
But then, you want to improve things: also accept yyyyMMdd (same date
format as before, but without "-"). Not very difficult to enhance the
converter. Also stores the new date in the model. But the Text field
still shows yyyyMMdd after everything is done. Would be nice to have
yyyy-MM-dd. How do you accomplish this? After the model is set with the
value returned from the converter, overwrite the content of the Text
field with the "canonical" representation returned from the
XXXToStringConverter.
Basically, I want each update to the date property in my model (no
matter if this is done by entering a value in my Text field, or by
hitting a button that recalculates the date property, or a background
thread updating my model) to recalculate the content of the Text field.
Without triggering another conversion from String to Date, just because
the Text field content changed.
Any advice from an expert in this field? I already tried several things,
but none worked reliably. Maybe there is a very simple solution, which I
just overlooked.
Thanks,
Christoph
|
|
|
Re: Databinding Confusion [message #497052 is a reply to message #497039] |
Thu, 12 November 2009 11:37 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Christoph Jaeger schrieb:
> Hi,
>
> I am a bit confused about how to use Eclipse databinding in my RCP
> application.
>
> The very simple bindings you can find in every tutorial work fine (bind
> a Text field to a String property of some bean).
>
> Also the next step, binding for instance a java.util.Date property to a
> Text field, with custom IConverter instances (StringToXXXConverter and
> XXXToStringConverter) to convert between Date and String work fine. If
> you keep it simple: a user can enter a date as yyyy-MM-dd, it gets
> converted to a java.util.Date and the result is stored in some property
> in the model.
>
> But then, you want to improve things: also accept yyyyMMdd (same date
> format as before, but without "-"). Not very difficult to enhance the
> converter. Also stores the new date in the model. But the Text field
> still shows yyyyMMdd after everything is done. Would be nice to have
> yyyy-MM-dd. How do you accomplish this? After the model is set with the
> value returned from the converter, overwrite the content of the Text
> field with the "canonical" representation returned from the
> XXXToStringConverter.
You need to trigger manually an update from model to UI using
Display.asyncExec() not really nice the only solution I'm aware of for
now. See ValueBinding#updateModelToTarget()
>
> Basically, I want each update to the date property in my model (no
> matter if this is done by entering a value in my Text field, or by
> hitting a button that recalculates the date property, or a background
> thread updating my model) to recalculate the content of the Text field.
> Without triggering another conversion from String to Date, just because
> the Text field content changed.
If the update is not coming through the UI-Widget Databinding will
update it automatically if your domain object is a JavaBean whether you
update your model from a background thread is something DB is handling
nicely (though you also need to make sure your domain model is threadsafe!)
>
> Any advice from an expert in this field? I already tried several things,
> but none worked reliably. Maybe there is a very simple solution, which I
> just overlooked.
>
> Thanks,
>
> Christoph
|
|
|
Powered by
FUDForum. Page generated in 0.03143 seconds