Reputation: 271
I try to bind the items of a SWT List to a List< String> property via Databinding.
My model class:
public class Config extends ModelObject {
private List<String> tagList;
public List<String> getTagList() {
return tagList;
}
public void setTagList(List<String> tagList) {
firePropertyChange("tagList", this.tagList, this.tagList = tagList);
}
}
My Binding:
...
private List tagList;
...
private void addDataBinding() {
Config config = ConfigHandler.getInstance().getConfig();
DataBindingContext ctx = new DataBindingContext();
IObservableList observableModelTagList = BeanProperties.list(Config.class, "tagList").observe(config);
IObservableList observableWidgetTagList = WidgetProperties.items().observe(tagList);
ctx.bindList(observableWidgetTagList, observableModelTagList);
}
As it didn´t work out that way, I tried to use Converters.
It doesn´t work either but at least I could see that if I use tagList.add(x) or tagList.setItems(x) on the tagList Widget nothing is triggered (the convert method isn´t even called).
So I guess WidgetProperties.items() doesn´t work as I expect it to.
I expected it to fire a change everytime anything regarding the items changes so at adding, removal and on a new set.
How do I bind the SWT List to the List Property in my model?
Upvotes: 0
Views: 220
Reputation: 111142
You could use ListViewer
rather than just List
:
ListViewer viewer = new ListViewer(tagList);
IValueProperty displayValue = ... property to display in the list
ViewerSupport.bind(viewer, observableModelTagList, displayValue);
Without a 'displayValue' you could use:
ListViewer viewer = new ListViewer(tagList);
ObservableListContentProvider contentProvider = new ObservableListContentProvider();
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new LabelProvider());
viewer.setInput(observableModelTagList);
Upvotes: 1