Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [Databinding] ViewerSupport and WizardPageSupport
[Databinding] ViewerSupport and WizardPageSupport [message #484313] Sun, 06 September 2009 06:04 Go to next message
Matt Biggs is currently offline Matt Biggs
Messages: 68
Registered: July 2009
Member
Is there a correct way to get WizardPageSupport to work in conjunction with ViewerSupport and other bindings (via DataBindingContext)?

I'm trying to get the page to become incomplete when the table contains no entries. On a wizardpage with just a table on it, i can manually add an IListChangeListener to the IObservableList and then set the page to incomplete (ignoring WizardPageSupport).

On a page with other databindings, i don't see how i can get them to all play nicely together as it doesn't look like the ViewerSupport takes into account any kind of validation.
Re: [Databinding] ViewerSupport and WizardPageSupport [message #484318 is a reply to message #484313] Sun, 06 September 2009 09:55 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew Hall
Messages: 368
Registered: July 2009
Senior Member
Use a MultiValidator to express the "not empty" constraint.

MultiValidator notEmptyValidator = new MultiValidator() {
protected IStatus validate() {
if (input.isEmpty())
return ValidationStatus.error("Need at least one entry");
return ValidationStatus.ok();
}
};

bindingContext.addValidationStatusProvider(notEmptyValidator );

Matthew


Matt Biggs wrote:
> Is there a correct way to get WizardPageSupport to work in conjunction
> with ViewerSupport and other bindings (via DataBindingContext)?
> I'm trying to get the page to become incomplete when the table contains
> no entries. On a wizardpage with just a table on it, i can manually add
> an IListChangeListener to the IObservableList and then set the page to
> incomplete (ignoring WizardPageSupport)ValidationStatus.error("At least .
>
> On a page with other databindings, i don't see how i can get them to all
> play nicely together as it doesn't look like the ViewerSupport takes
> into account any kind of validation.
Re: [Databinding] ViewerSupport and WizardPageSupport [message #488670 is a reply to message #484313] Tue, 29 September 2009 12:57 Go to previous messageGo to next message
Matt Biggs is currently offline Matt Biggs
Messages: 68
Registered: July 2009
Member
Matthew,

I think i'm missing something here. I've tried using a MultiValidator, and the validate() method only ever gets called once on the wizard page startup. How do i get it to be called everytime an item within the model that the tableviewer is displaying changes?




		
ViewerSupport.bind(
  viewer, 
  getEmfObservableList(getEditingDomain(), getModel(), FamilytreePackage.Literals.FACT__AFFECTED), 
  getEmfObservableProperty(getEditingDomain(), FamilytreePackage.Literals.PERSON__FRIENDLY_NAME)
);
		
getDataBindingContext().addValidationStatusProvider(new MultiValidator() {			
  protected IStatus validate() {
    return ValidationStatus.ok();
  }
});

WizardPageSupport.create(this, getDataBindingContext());
Re: [Databinding] ViewerSupport and WizardPageSupport [message #488686 is a reply to message #488670] Tue, 29 September 2009 13:53 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew Hall
Messages: 368
Registered: July 2009
Senior Member
Matt Biggs wrote:
> getDataBindingContext().addValidationStatusProvider(new MultiValidator()
> {
> protected IStatus validate() {
> return ValidationStatus.ok();
> }
> });

MultiValidator uses ObservableTracker magic to figure out which
observables you use to determine validation status. Any method you call
on an IObservable within MultiValidator.validate() that is documented
with the tag "@TrackedGetter" (see the IObservableValue javadoc for an
example) will flag that observable as a dependency. After the initial
validation status is computed, MultiValidator will automatically add
listeners to all those observable dependencies, which trigger a
revalidation any time one of those dependencies change.

So the fact that you are not getting a change event from the validation
status of the MultiValidator above is not surprising, given that there
are no observable dependencies from which to trigger a revalidation.

Matthew
Re: [Databinding] ViewerSupport and WizardPageSupport [message #488784 is a reply to message #484313] Wed, 30 September 2009 05:07 Go to previous messageGo to next message
Matt Biggs is currently offline Matt Biggs
Messages: 68
Registered: July 2009
Member
Matthew,

Thanks for that. I have now changed the validate() method to iterate through the contents of the list to check for the validity and this works.

One thing however is that as specified in the API the IObservableList wont be notified when the elements it contains change, only when an element is added / removed etc.

So what would be the best way to listen for changes to the elements? For example, my IObservableList contains a bunch of Person objects. I was hoping i could fire off my MultiValidator whenever the name property of one of those Person objects changed to then validate the contents of the list.

Is this possible?

cheers

Matt
Re: [Databinding] ViewerSupport and WizardPageSupport [message #488896 is a reply to message #488784] Wed, 30 September 2009 11:46 Go to previous message
Matthew Hall is currently offline Matthew Hall
Messages: 368
Registered: July 2009
Senior Member
Observe a detail list of the Person list using an IValueProperty:

IValueProperty nameProp = BeanProperties.value(Person.class, "name");
IObservableList personNamesList = nameProp.observeDetail(personList);

Then in your MultiValidator, compute the validation result using
"personNamesList" instead of the person list.

Matthew

Matt Biggs wrote:
> So what would be the best way to listen for changes to the elements? For
> example, my IObservableList contains a bunch of Person objects. I was
> hoping i could fire off my MultiValidator whenever the name property of
> one of those Person objects changed to then validate the contents of the
> list.
> Is this possible?
>
> cheers
>
> Matt
Previous Topic:Adding code folding to a ProjectionViewer
Next Topic:Text Editor - Highlight Text with Regular Expressions
Goto Forum:
  


Current Time: Sat Jul 26 01:25:15 EDT 2014

Powered by FUDForum. Page generated in 0.02333 seconds