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 閱讀(258) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

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

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 河南省| 叶城县| 巫溪县| 额济纳旗| 台东县| 大英县| 布尔津县| 璧山县| 海城市| 页游| 隆化县| 阳西县| 刚察县| 铜鼓县| 金阳县| 靖边县| 云龙县| 兴义市| 永善县| 怀化市| 石狮市| 图们市| 双辽市| 麟游县| 孟州市| 正蓝旗| 海原县| 山东省| 西宁市| 辉县市| 米泉市| 二连浩特市| 密山市| 青川县| 馆陶县| 安达市| 桐柏县| 峨眉山市| 顺平县| 农安县| 寻乌县|