示例
列表里的奥秘:Observable
除了 IObservableValue 接口以外,JFace 数据绑定还定义了一个 IObservableList 接口,如清单 17 所示。正如 IObservableValue 将创建一种一般方法来侦听多个值的更改一样,IObservableList 也将指定一种一般方法来访问对象列表。执行赋值有一些标准方法,例如 contains()、add()、remove()、indexOf()、iterators() 等。
清单 17. IObservableList 接口
public interface IObservableList \
extends List, IObservableCollection {
public void addListChangeListener\
(IListChangeListener listener);
public void removeListChangeListener\
(IListChangeListener listener);
public int size();
public boolean isEmpty();
public boolean contains(Object o);
public Iterator iterator();
public Object[] toArray();
public Object[] toArray(Object a[]);
public boolean add(Object o);
public boolean remove(Object o);
public boolean containsAll(Collection c);
public boolean addAll(Collection c);
public boolean addAll(int index, Collection c);
public boolean removeAll(Collection c);
public boolean retainAll(Collection c);
public boolean equals(Object o);
public int hashCode();
public Object get(int index);
public Object set(int index, Object element);
public Object remove(int index);
public int indexOf(Object o);
public int lastIndexOf(Object o);
public ListIterator listIterator();
public ListIterator listIterator(int index);
public List subList(int fromIndex, int toIndex);
Object getElementType();
}
阻盾Eclipse嶄議JFace方象鰯協?及2何蛍: 鰯協議児粥岑紛(14)
扮寂:2011-02-11 IBM Scott Delap
更秀壓 IObservableList 俊笥貧議頁 JavaBeanObservableList 糞??凪嶄議旗鷹頭粁泌賠汽 18 侭幣。壓寄謹方秤趨和?聞喘幗泌 size() 岻窃議圭隈?貧峰糞?繍瓜溜熔公乎糞?侭距屁議双燕。恷嶷勣議圭隈辛嬬頁 updateWrappedList()。緩圭隈繍資函匯倖症井才匯倖仟井双燕?旺繍幹秀匯倖 Diff 斤?。緩斤?繍**根俶勣評茅議?式俶勣耶紗議仟?議厚個芝村。Diff 斤?喘噐揖化 IObservableList 議朕炎糞?侭俶議厚個。
賠汽 18. JavaBeanObservableList 嶄議旗鷹頭粁
public int size() {
getterCalled();
return wrappedList.size();
}
protected void updateWrappedList(List newList) {
List oldList = wrappedList;
ListDiff listDiff = Diffs.computeListDiff(
oldList,
newList);
wrappedList = newList;
fireListChange(listDiff);
}
賠汽 19 ?幣阻 SWTObservableFactory 嶄議旗鷹頭粁。辛參心欺 JFace 方象鰯協**根阻 ComboObservableList 才 ComboObservableValue 窃參工伏撹怏栽崇陣周侭俶勣議 observable 扮聞喘。及匯倖窃繍委怏栽崇議 items 奉來癖塘葎 IObservableList?及屈倖窃繍委 selection 奉來癖塘葎 IObservableValue 俊笥議 selection 奉來。
賠汽 19. SWTObservableFactory 嶄議旗鷹頭粁
if (object instanceof Combo
&& (SWTProperties.TEXT.equals(attribute)
|| SWTProperties.SELECTION.equals(attribute))) {
return new ComboObservableValue(
(Combo) object,
(String) attribute);
} e
|