Comboviewer Databinding with dynamic combo items

2.1k views Asked by At

I have a comboviewer, and i need to have the databinding on it, so that the combo selection is automatically updated in the Model.

Also i need to add the combo items dynamically (to the exisitng combo items). With databinding how can i acheive this?

As am new to databinding, please point me to some good tutorial on comboviewer databinding with dynamic items (combo items).

The below code is for binding the comboviewer selection to the model:

final IObservableValue entityComboObservable = ViewersObservables.
observeSingleSelection(myComboViewer);        
final IObservableValue modelSelectedEntityObservable = BeansObservables.
observeValue (cmpObj, Company.EMP_SELCTION);        
bindingCntxt.bindValue(modelSelectedEntityObservable, entityComboObservable); 

where "cmpObj" is my model object which contains the list of objects which will be set as the input to the comboviewer

2

There are 2 answers

0
Tom Seidel On BEST ANSWER

You can do something like

 comboViewer.setContentProvider(new ObservableListContentProvider());
 comboViewer.setLabelProvider(labelProvider);
 // input must be a List
 comboViewer.setInput(input);
 IViewerObservableValue swtObs = ViewersObservables.observeSingleSelection(comboViewer);

Now create a model-ovservable and bind it with swtObs

2
sambi reddy On

you need to use below input observable.

org.eclipse.jface.databinding.viewers.ViewersObservables.observeInput(Viewer)

bind input observable with the ListObservable.