0

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

Jack Clouseau
  • 81
  • 1
  • 11

2 Answers2

1

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

Tom Seidel
  • 9,525
  • 1
  • 26
  • 38
0

you need to use below input observable.

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

bind input observable with the ListObservable.

sambi reddy
  • 3,065
  • 1
  • 13
  • 10
  • thanks for the suggestion. however am very new to databinding, could you please detail on how to bind with the listobservable? – Jack Clouseau Aug 13 '13 at 03:09
  • I have edited my post for bindinng the comboviewer selection with the model. However it would be helpful if you could help me in adding new items to the combo items dynamically – Jack Clouseau Aug 13 '13 at 03:14