Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Databinding] Validate that item only appears once in IObservableList
[Databinding] Validate that item only appears once in IObservableList [message #517472] Sun, 28 February 2010 13:00 Go to next message
Philipp Kursawe is currently offline Philipp KursaweFriend
Messages: 135
Registered: July 2009
Senior Member
Hello,

I have a table editor that allows the creation of new entries.
There should be only one entry in the table with a specific name.
The table cell editor should therefor prevent the user from changing the
name to a value already existing in the table (list).

What kind of binding would do that automatically?

Thanks,
Phil
Re: [Databinding] Validate that item only appears once in IObservableList [message #517707 is a reply to message #517472] Mon, 01 March 2010 18:49 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 2371
Registered: July 2009
Senior Member
On 2/28/10 8:00 AM, Philipp Kursawe wrote:
> Hello,
>
> I have a table editor that allows the creation of new entries.
> There should be only one entry in the table with a specific name.
> The table cell editor should therefor prevent the user from changing the
> name to a value already existing in the table (list).
>
> What kind of binding would do that automatically?

One idea is to wrap the observable in an
org.eclipse.core.databinding.observable.value.IVetoableValue (see
org.eclipse.core.databinding.observable.value.DecoratingVeto ableValue)

Another idea is to provide a custom UpdateValueStrategy to the binding.


Hope this helps,
Eric
Re: [Databinding] Validate that item only appears once in IObservableList [message #518431 is a reply to message #517472] Thu, 04 March 2010 06:07 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Philipp Kursawe wrote:
> Hello,
>
> I have a table editor that allows the creation of new entries.
> There should be only one entry in the table with a specific name.
> The table cell editor should therefor prevent the user from changing the
> name to a value already existing in the table (list).
>
> What kind of binding would do that automatically?
>
> Thanks,
> Phil

You could allow the change in the UI but prevent invalid changes from
propagating to the model using a MultiValidator:

IObservableList items = ...

final IObservableList itemNames =
BeanProperties.value("name").observeDetail(items);

MultiValidator uniqueNamesValidator = new MultiValidator() {
protected IStatus validate() {
Set names = new HashSet();
for (Iterator it = itemNames.iterator(); it.hasNext();) {
String name = (String) it.next();
if (!names.add(name) {
return ValidationStatus.error("The name \""+name+
"\"" cannot appear more than once.");
}
}
}
};

bindingContext.addValidationStatusProvider(uniqueNamesValida tor);

This much will flag a validation error in your UI (assuming you have the
validation status wired up and displayed somewhere--right?).

Next you can tell uniqueNamesValidator to wrap your target observable
list in a validated wrapper. Changes to the wrapped observable will
only propagate out to the wrapper when the validator is in a passing status:

bindingContext.bindList(uniqueNamesValidator.observeValidate dList(items),
modelList);

Hope this helps,

Matthew
Previous Topic:Can not set ContributionItem size for dynamic toolbar contributions
Next Topic:Re: Shift-tab does not work in compare
Goto Forum:
  


Current Time: Thu Nov 27 03:24:09 GMT 2014

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

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