关于org.eclipse.core.databinding数据绑定

来源:百度知道 编辑:UC知道 时间:2024/06/17 08:08:53
我有一个信息管理项目,需要在视图和模型间建立数据绑定:
DataBindingContext dbc=DataBindingFactory.createContext(parent);
dbc.bind(txt_name,new Property(student,"name"), null);
dbc.bind(com_gender,new Property(student,"gender"),null);
dbc.bind(txt_mobile,new Property(student,"mobile"),null);
text的绑定比较好做,而像combo这样的control如何绑定数据哪?
错误信息:org.eclipse.jface.internal.databinding.provisional.BindingException: incompatible observable: target is list, model is org.eclipse.jface.internal.databinding.internal.beans.JavaBeanObservableValue
我现在啃API,希望大家给个思路。
student是hibernate持久化中的数据模型实例,gender是其中的“性别”域,gender的声明为private String
拥有getter/setter方法。

Combo combo = new Combo(shell, SWT.BORDER);
// 绑定初始数据
DataBindingContext ctx = DataBindingContextFactory.createContext(shell);
WritableList ageList = new WritableList(String.class);
ageList.add("0");
ageList.add("10");
ageList.add("20");
ageList.add("30");
ctx.bind(new Property(combo, SWTProperties.ITEMS), ageList, null);

给你个例子