Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Databinding} Mess with tables/ Validation in structured Beans
[Databinding} Mess with tables/ Validation in structured Beans [message #333400] Tue, 09 December 2008 16:27 Go to next message
Thomas Kratz is currently offline Thomas KratzFriend
Messages: 165
Registered: July 2009
Senior Member
This is parially a cross post to something I asked on the SWT group.
Guess I have an editor that edits a person object. a person has many
adresses so the editor shows them in a table. but withmy current
solution the fields in the table can only be validated when the user
edits cells (via EditingSupport) bindings are dynamically created. But
in my scenario I cant create a valid new record. So if the user doesnt
edit it he will never see any validating message. Are there any ideas
out there to solve that ?
Re: [Databinding} Mess with tables/ Validation in structured Beans [message #333402 is a reply to message #333400] Tue, 09 December 2008 17:05 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Any cross-observable or compound constraint validators should be
enforced using a ValidationStatusProvider. You can extend
ValidationStatusProvider and manually monitor your address collection
for validation errors. Or, you could extend MultiValidator and have it
monitor the relevant observables to check for errors. If you are using
ObservableMapLabelProvider then I would suggest observing the values()
for the IObservableMap used by the relevant table column.

As an example:

TableViewer addressViewer = ...
ObservableListContentProvider cp = new ObservableListContentProvider();
final IObservableMap[] maps = BeansObservables.observeMaps(
cp.getKnownElements,
Address.class,
new String[] {"street", "street2", "city", "province", "code" } );
addressViewer.setLabelProvider(new ObservableMapLabelProvider(maps));

MultiValidator addressValidator = new MultiValidator(realm) {
protected IStatus validate() {
Set addresses = maps[0].keySet();
IStatus status = ValidationStatus.ok();
for (Iterator it = addresses.iterator(); it.hasNext(); ) {
Address address = (Address) it.next();
// validate address, update status variable if more severe
// than current value
}
return status;
}
}

Hope this helps,

Matthew Hall

Thomas wrote:
> This is parially a cross post to something I asked on the SWT group.
> Guess I have an editor that edits a person object. a person has many
> adresses so the editor shows them in a table. but withmy current
> solution the fields in the table can only be validated when the user
> edits cells (via EditingSupport) bindings are dynamically created. But
> in my scenario I cant create a valid new record. So if the user doesnt
> edit it he will never see any validating message. Are there any ideas
> out there to solve that ?
Re: [Databinding} Mess with tables/ Validation in structured Beans [message #333403 is a reply to message #333402] Tue, 09 December 2008 17:07 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Matthew Hall wrote:
> TableViewer addressViewer = ...
> ObservableListContentProvider cp = new ObservableListContentProvider();
> final IObservableMap[] maps = BeansObservables.observeMaps(
> cp.getKnownElements,
> Address.class,
> new String[] {"street", "street2", "city", "province", "code" } );
> addressViewer.setLabelProvider(new ObservableMapLabelProvider(maps));
>
> MultiValidator addressValidator = new MultiValidator(realm) {
> protected IStatus validate() {
> Set addresses = maps[0].keySet();
> IStatus status = ValidationStatus.ok();
> for (Iterator it = addresses.iterator(); it.hasNext(); ) {
> Address address = (Address) it.next();
> // validate address, update status variable if more severe
> // than current value
> }
> return status;
> }
> }

Forgot to say, you need to add the MultiValidator to the DataBindingContext:

dbc.addValidationStatusProvider(addressValidator);

Matthew
Re: [Databinding} Mess with tables/ Validation in structured Beans [message #333419 is a reply to message #333403] Wed, 10 December 2008 14:25 Go to previous messageGo to next message
Thomas Kratz is currently offline Thomas KratzFriend
Messages: 165
Registered: July 2009
Senior Member
Thanks Matthew,

thats exactly what I was looking for !

Thomas

Matthew Hall schrieb:
> Matthew Hall wrote:
>> TableViewer addressViewer = ...
>> ObservableListContentProvider cp = new ObservableListContentProvider();
>> final IObservableMap[] maps = BeansObservables.observeMaps(
>> cp.getKnownElements,
>> Address.class,
>> new String[] {"street", "street2", "city", "province", "code" } );
>> addressViewer.setLabelProvider(new ObservableMapLabelProvider(maps));
>>
>> MultiValidator addressValidator = new MultiValidator(realm) {
>> protected IStatus validate() {
>> Set addresses = maps[0].keySet();
>> IStatus status = ValidationStatus.ok();
>> for (Iterator it = addresses.iterator(); it.hasNext(); ) {
>> Address address = (Address) it.next();
>> // validate address, update status variable if more severe
>> // than current value
>> }
>> return status;
>> }
>> }
>
> Forgot to say, you need to add the MultiValidator to the
> DataBindingContext:
>
> dbc.addValidationStatusProvider(addressValidator);
>
> Matthew
Re: [Databinding} Mess with tables/ Validation in structured Beans [message #333443 is a reply to message #333419] Thu, 11 December 2008 15:06 Go to previous message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
Hi Thomas,

Would you be able to write a new snippet for this and contribute it through
Bugzilla?

Thanks
Boris

"Thomas" <thomas.kratz@eiswind.de> wrote in message
news:ghojga$ta5$1@build.eclipse.org...
> Thanks Matthew,
>
> thats exactly what I was looking for !
>
> Thomas
>
> Matthew Hall schrieb:
>> Matthew Hall wrote:
>>> TableViewer addressViewer = ...
>>> ObservableListContentProvider cp = new ObservableListContentProvider();
>>> final IObservableMap[] maps = BeansObservables.observeMaps(
>>> cp.getKnownElements,
>>> Address.class,
>>> new String[] {"street", "street2", "city", "province", "code" } );
>>> addressViewer.setLabelProvider(new ObservableMapLabelProvider(maps));
>>>
>>> MultiValidator addressValidator = new MultiValidator(realm) {
>>> protected IStatus validate() {
>>> Set addresses = maps[0].keySet();
>>> IStatus status = ValidationStatus.ok();
>>> for (Iterator it = addresses.iterator(); it.hasNext(); ) {
>>> Address address = (Address) it.next();
>>> // validate address, update status variable if more severe
>>> // than current value
>>> }
>>> return status;
>>> }
>>> }
>>
>> Forgot to say, you need to add the MultiValidator to the
>> DataBindingContext:
>>
>> dbc.addValidationStatusProvider(addressValidator);
>>
>> Matthew
Previous Topic:[jface] ComboBoxCellEditor activation with EditingSupport API
Next Topic:Job.schedule( ) performance problem
Goto Forum:
  


Current Time: Wed Jul 17 10:35:45 GMT 2024

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

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

Back to the top