简体   繁体   English

具有动态组合项目的Comboviewer数据绑定

[英]Comboviewer Databinding with dynamic combo items

I have a comboviewer, and i need to have the databinding on it, so that the combo selection is automatically updated in the Model. 我有一个comboviewer,并且我需要在其上进行数据绑定,以便该组合选择在模型中自动更新。

Also i need to add the combo items dynamically (to the exisitng combo items). 我还需要动态地添加组合项(到exisitng组合项)。 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). 作为数据绑定的新手,请为我提供一些有关带有动态项目(组合项目)的comboviewer数据绑定的优秀教程。

The below code is for binding the comboviewer selection to the model: 以下代码用于将comboviewer选择绑定到模型:

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 其中“ cmpObj”是我的模型对象,其中包含将被设置为comboviewer的输入的对象列表

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 现在创建一个可模型化的模型并将其与swtObs绑定

you need to use below input observable. 您需要使用下面的可观察输入。

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

bind input observable with the ListObservable . 将可观察的输入与ListObservable绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM