Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Databinding] Validating at least one selection in a Checkbox Table Viewer
[Databinding] Validating at least one selection in a Checkbox Table Viewer [message #333872] Sun, 11 January 2009 20:37 Go to next message
Marcelo Alcantara is currently offline Marcelo AlcantaraFriend
Messages: 48
Registered: July 2009
Member
Hi,

I am using JFace Databinding and I need to validate that at least a single
item is selected in a checkbox table viewer.

I tried many things without success.

As the UpdateSetStrategy does not allow to provide a validator, I could not
find a nice solution to this.

I tried to use the MultiValidator also without success.

I also extended the doAdd and doRemove on the UpdateSetStrategy, but it does
not cover all required validation situations (like when the view/form is
first opened, before selecting or deselecting anything from the list).

Somebody has a snippet on how to provide this kind of validation? I have an
urgent requirement for this on the current project. Trying to consolidate
the rcp platform here.

Thanks for the help.

Marcelo Alcantara
Re: [Databinding] Validating at least one selection in a Checkbox Table Viewer [message #333887 is a reply to message #333872] Mon, 12 January 2009 17:12 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
We should probably add validators to SetBinding. Would you file a bug?

Other than that, I'm pretty sure that you should be able to use
MultiValidator:

final IObservableSet checkedElements =
ViewersObservables.observeCheckedElements(checkboxTable);
MultiValidator notEmptyValidator = new MultiValidator() {
protected IStatus validate() {
if (checkedElements.isEmpty())
return ValidationStatus.error("Please select at least one item");
return ValidationStatus.ok();
}
}
dbc.addValidationStatusProvider(notEmptyValidator);

dbc.bindSet(
notEmptyValidator.observeValidatedSet(checkedElements),
myModelSet,
null,
null);

Matthew

Marcelo Alcantara wrote:
> Hi,
>
> I am using JFace Databinding and I need to validate that at least a single
> item is selected in a checkbox table viewer.
>
> I tried many things without success.
>
> As the UpdateSetStrategy does not allow to provide a validator, I could not
> find a nice solution to this.
>
> I tried to use the MultiValidator also without success.
>
> I also extended the doAdd and doRemove on the UpdateSetStrategy, but it does
> not cover all required validation situations (like when the view/form is
> first opened, before selecting or deselecting anything from the list).
>
> Somebody has a snippet on how to provide this kind of validation? I have an
> urgent requirement for this on the current project. Trying to consolidate
> the rcp platform here.
>
> Thanks for the help.
>
> Marcelo Alcantara
>
>
Re: [Databinding] Validating at least one selection in a Checkbox Table Viewer [message #334077 is a reply to message #333887] Mon, 19 January 2009 13:24 Go to previous message
Eclipse UserFriend
Originally posted by: malloovidio.bluewin.ch

Actually, there already is a bug report for adding validation to
collection bindings:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=168225

Doing so might be a bit tricky since validation probably leads
to the target/model collections getting out of sync.

Best regards,
Ovidio


Matthew Hall wrote:
> We should probably add validators to SetBinding. Would you file a bug?
>
> Other than that, I'm pretty sure that you should be able to use
> MultiValidator:
>
> final IObservableSet checkedElements =
> ViewersObservables.observeCheckedElements(checkboxTable);
> MultiValidator notEmptyValidator = new MultiValidator() {
> protected IStatus validate() {
> if (checkedElements.isEmpty())
> return ValidationStatus.error("Please select at least one item");
> return ValidationStatus.ok();
> }
> }
> dbc.addValidationStatusProvider(notEmptyValidator);
>
> dbc.bindSet(
> notEmptyValidator.observeValidatedSet(checkedElements),
> myModelSet,
> null,
> null);
>
> Matthew
>
> Marcelo Alcantara wrote:
>> Hi,
>>
>> I am using JFace Databinding and I need to validate that at least a
>> single item is selected in a checkbox table viewer.
>>
>> I tried many things without success.
>>
>> As the UpdateSetStrategy does not allow to provide a validator, I
>> could not find a nice solution to this.
>>
>> I tried to use the MultiValidator also without success.
>>
>> I also extended the doAdd and doRemove on the UpdateSetStrategy, but
>> it does not cover all required validation situations (like when the
>> view/form is first opened, before selecting or deselecting anything
>> from the list).
>>
>> Somebody has a snippet on how to provide this kind of validation? I
>> have an urgent requirement for this on the current project. Trying to
>> consolidate the rcp platform here.
>>
>> Thanks for the help.
>>
>> Marcelo Alcantara
>>
Previous Topic:Z-Order of Windows
Next Topic:Custom ISelectionProvider and checkEnabled for Visibility of commands does not work properly
Goto Forum:
  


Current Time: Thu Dec 26 20:21:07 GMT 2024

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

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

Back to the top