West Farm
吾本布衣,生于川北,躬耕于代码的田地上。
posts - 16,  comments - 15,  trackbacks - 0
If we observe a property of SWT controls, and bind it to another observable value, you must take care of those method calls which will change the property indirectly.
for example, we have a Combo whose "text" property is bound to a bean's "name" property like this:
IObservableValue nameObservable = BeansObservables.observeDetailValue(obserabedDriverProfile, "name", String.class);

ISWTObservableValue nameComboObservable = SWTObservables.observeText(driverClassCombo);

bindingContext.bindValue(nameComboObservable , nameObservable, new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE), null);

The variable "obserabedDriverProfile" is a observed selection in a ListViewer, it's in a master-detail scenario. If we add some code like this:
obserabedDriverProfile.addValueChangeListener(new IValueChangeListener(){

            @Override
            public void handleValueChange(ValueChangeEvent event) {
                DriverProfile dp = (DriverProfile)event.diff.getNewValue();
                driverClassCombo.removeAll();
                driverClassCombo.add(dp.getName();
                driverClassCombo.setText(driverClassCombo.getItem(0));
            }
            
        });
every time you change the selection in the ListViewer,  the selected bean's "name" property will be set to a empty string. Why?  The removeAll method of Combo will clear it's text, and combo's "text" property is bound to selected bean's "name" property. So, the right way is:
obserabedDriverProfile.addValueChangeListener(new IValueChangeListener(){

            @Override
            public void handleValueChange(ValueChangeEvent event) {
                DriverProfile dp = (DriverProfile)event.diff.getNewValue();
                String name = dp.getName;
                driverClassCombo.removeAll();
                driverClassCombo.add(name);
                driverClassCombo.setText(driverClassCombo.getItem(0));
            }
            
        });
posted on 2013-04-14 15:24 West Farmer 阅读(248) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

<2013年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿

随笔分类

随笔档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜