|
|
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 |
Eclipse User |
|
|
|
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
>>
|
|
|
Powered by
FUDForum. Page generated in 0.03491 seconds