[DataBinding] Databinding a ListViewer to a model list [message #335874] |
Thu, 07 May 2009 12:00  |
Eclipse User |
|
|
|
Originally posted by: markus.wolf.nmmn.com
Hi there,
I try to incorporate Databinding into our application and struggle with
a usecase we require. I cannot find any documentation on this so I ask here.
We have a model with a list property and we have a ListViewer displaying
this items. This does work fine. Also adding and removing works as
expected.
But we want to validate on changes that the list is not empty and show a
warning to the user. So far no problem if we could create a binding of
the two lists and add a IValidator. And this is the problem.
We created the code with a WritableList and the
ObservableListContentProvider but this does not give us a binding.
So how do we create a binding between the WritableList and our model or
the WritableList and the viewer? Which type of IOberservable is useful
for this?
Thanks for any help
Markus Wolf
--
NMMN - New Media Markets & Networks GmbH
Langbehnstrasse 6, 22761 Hamburg
Geschäftsführung: Kfm. Michael Schütt
Finanzamt HH-Altona - UStID DE 812 699 852 - HRB 71102 Hamburg
HypoVereinsbank - BLZ 200 300 00 - Konto-Nr. 156 29 82
http://www.nmmn.com
Tel.: +49 40 284 118-0 - Fax: +49 40 284118-999
Softwareentwicklung LLynch: -720
|
|
|
|
|
|
|
Re: [DataBinding] Databinding a ListViewer to a model list [message #335899 is a reply to message #335893] |
Fri, 08 May 2009 04:39   |
Eclipse User |
|
|
|
Originally posted by: markus.wolf.nmmn.com
Hi Matthew,
Thanks for your help so far. :)
>> I could request the validation status on my own, but this
>> will not need the entire databinding since then i could check manually
>> on each UI update.
>
> If you could provide a small example of the problematic code I think
> I'll be able to help a little more.
>
Here is some example code. Its not my complete code, because it would be
too much but I hope it is enough:
### snip ###
// These attributes I declare in my class:
private ListViewer viewer;
private WritableList nameservers;
private MultiValidator nameserversValidator;
// ---------------------------
// To create the GUI I use this:
this.viewer = new ListWithButtons().create(listParent, GridDataFactory
.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 100)
.create(), getView().getToolkit());
this.viewer.setContentProvider(new ObservableListContentProvider());
// ---------------------------
// When I load my model I execute this code:
if (this.nameserversValidator != null) {
getView().getDataBindingContext()
.removeValidationStatusProvider(this.nameserversValidator);
}
this.nameservers = new WritableList(getBusinessObject()
.getNameservers(), Nameserver.class);
this.nameserversValidator = new MultiValidator() {
@Override
protected IStatus validate() {
if (NameserverPart.this.nameservers.isEmpty()) {
ValidationStatus.error("Select at least two nameservers");
}
return ValidationStatus.ok();
}
};
getView().getDataBindingContext().addValidationStatusProvide r(
this.nameserversValidator);
this.viewer.setInput(this.nameservers);
// ---------------------------
### snip ###
And I have to buttons in my GUI to add and remove its from the list.
There just call nameservers.add(object) and nameservers.remove(object).
But when adding or removing something no validation is triggered.
If you need some more code then please tell me.
Thanks
Markus Wolf
--
NMMN - New Media Markets & Networks GmbH
Langbehnstrasse 6, 22761 Hamburg
Geschäftsführung: Kfm. Michael Schütt
Finanzamt HH-Altona - UStID DE 812 699 852 - HRB 71102 Hamburg
HypoVereinsbank - BLZ 200 300 00 - Konto-Nr. 156 29 82
http://www.nmmn.com
Tel.: +49 40 284 118-0 - Fax: +49 40 284118-999
Softwareentwicklung LLynch: -720
|
|
|
|
|
|
|
Re: [DataBinding] Databinding a ListViewer to a model list [message #335954 is a reply to message #335899] |
Mon, 11 May 2009 10:45  |
Eclipse User |
|
|
|
Originally posted by: markus.wolf.nmmn.com
Hi Matthew,
I found the problem. Its my fault. In the posted code snippet the
ValidationStatus.error(...) was missing the return statement. Therefore
the Validator always returns ValiationStatus.ok(...).
Thanks for all your help :)
Markus Wolf
--
NMMN - New Media Markets & Networks GmbH
Langbehnstrasse 6, 22761 Hamburg
Geschäftsführung: Kfm. Michael Schütt
Finanzamt HH-Altona - UStID DE 812 699 852 - HRB 71102 Hamburg
HypoVereinsbank - BLZ 200 300 00 - Konto-Nr. 156 29 82
http://www.nmmn.com
Tel.: +49 40 284 118-0 - Fax: +49 40 284118-999
Softwareentwicklung LLynch: -720
|
|
|
Powered by
FUDForum. Page generated in 0.09430 seconds