現在eclipse M4已經出來了,其中一個最cool的非UI特性就是JFace data binding framework.
在M5發布的時候JFace binding小組會結束data binding API的開發.
到現在為止,大量我們可以用到JFace data binding的例子在test包里。
關于JFace data binding framework,在下面的網址可以找到具體的文檔.
http://wiki.eclipse.org/index.php/JFace_Data_Binding
http://wiki.eclipse.org/index.php/JFace_Data_Binding_Scenarios
可以通過CVS很方便的下載到test包:
打開CVS Repositories View,選New-->Repository location
在窗口里依次填入:
Host: dev.eclipse.org
Repository path: /home/eclipse
User: anonymous
PassWord:空白
Connection type: pserver
展開HEAD...
“org.eclipse.jface.databinding”
“org.eclipse.jface.tests.databinding”
就是代碼和測試代碼了.
可以先運行檢查配置是否正確:
1. 展開 org.eclipse.jface.tests.databinding
2. 展開 the org.eclipse.jface.tests.databinding package
3. 右擊 “BindingTestSuite.java” 并選 “Run as SWT application”
假如終端出現一些....然后是測試多少個,具體log等,那就沒問題了。
關于JFace data binding framework:
一般的UI都需要自己保存數據,然后向每個text,combo寫監聽器,然后返回到主程序中,非常繁瑣,但是現在因為UI和data的綁定,簡單地讓人吃驚....
以我的財務治理程序舉例來說,現在我只需要寫完數據結構和圖形界面,然后在代碼里加上下面這樣的代碼:
IDataBindingContext dbc = DataBinding.createContext(composite);
dbc.bind(departmentCombo, new dbc.bind(projectCombo, new Property(depatments, "project"), null);
dbc.bind(dateText, new Property(depatments, "date), null);
dbc.bind(wareText, new Property(depatments, "ware"), null);
dbc.bind(priceText, new Property(depatments, "price"), null);
我不需要自己再很多的代碼,只需要加上兩個方法:
dialog.getDepartments()
dialog.setDepartments(...)
就完全搞定數據在UI和數據結構之間的傳輸:)
新聞熱點
疑難解答