views:

119

answers:

1

I'm trying to bind a TableViewer to a

models = List<ModelObject>

, but I don't really get the hang of it. The binding should be possible via master-detail and a databinding context (DataBindingContext), so that I'm able to write the changes of the list (and its elements) to the model only on request (dbc being set to POLICY_ON_REQUEST), i.e. in a saving action of an editor. With simple Text fields this works like a charm, but I can't find any similar example for TableViewers. When I look at the API for instance of ViewerSupport, then I can only bind it, but without the option of giving a DBC or a master-detail. This works:

ViewerSupport.bind(aViewer, new WritableList(models, ModelObject.class), BeanProperties.value(ModelObject.class, "name")));

But as stated it doesn't allow to use a dbc nor a master-detail.

Is there a solution to that, or does TableViewer just not support databinding as I intend to use it? Is there a workaround or some API i missed?

Thx for the answers in advance!

A: 

Now that I looked a bit further I figured out how to use master-detail:

tmp = BeansObservables.observeDetailList(masterObservable,
                            "name", ModelObject.class)
ViewerSupport.bind(aViewer, tmp, BeanProperties.value(ModelObject.class, "name")));

The question remains, how to make the changes in the list and the list elements not directly persisting (that is POLICY_ON_REQUEST), so that I can save them on user request. More specifically: How do I inject a DataBindingContext somewhere...

I just noticed that you have to make sure that you update your data on the input.This is usually tmp, if you use ViewerSupport#bind to bind the columns or you can just get it from the viewer.