/**
* Adds/Removes the {@link FieldProperty} as a collection listener
*
* @param observable
* the {@link Observable} collection/map to listen for
* changes on
* @param add
* true to add, false to remove
*/
protected void addRemoveCollectionListener(final Observable observable,
final boolean add) {
final boolean isCol = getCollectionObservable() == observable;
if (isCol
&& ((this.isCollectionListening && add) || (this.isCollectionListening && !add))) {
return;
}
Boolean change = null;
if (observable instanceof ObservableList) {
final ObservableList<?> ol = (ObservableList<?>) observable;
if (add) {
ol.addListener(this);
change = true;
} else {
ol.removeListener(this);
change = false;
}
} else if (observable instanceof ObservableSet) {
final ObservableSet<?> os = (ObservableSet<?>) observable;
if (add) {
os.addListener(this);
change = true;
} else {
os.removeListener(this);
change = false;
}
} else if (observable instanceof ObservableMap) {
final ObservableMap<?, ?> om = (ObservableMap<?, ?>) observable;
if (add) {
om.addListener(this);
change = true;
} else {
om.removeListener(this);
change = false;
}
} else if (observable == null) {
throw new IllegalStateException(String.format(
"Observable collection/map bound to %1$s (item path: %2$s) "
+ "has been garbage collected",
this.fieldHandle.getFieldName(),
this.collectionItemPath, observable,
this.getFieldType()));
} else {
throw new UnsupportedOperationException(String.format(
"%1$s (item path: %2$s) of type \"%4$s\" "
+ "must be bound to a supported "
+ "observable collection/map type... "
+ "Found observable: %3$s",
this.fieldHandle.getFieldName(),
this.collectionItemPath, observable,
this.getFieldType()));
}
if (isCol && change != null) {
this.isCollectionListening = change;
}
}
BeanPathAdapter.java 文件源码
java
阅读 33
收藏 0
点赞 0
评论 0
项目:Java-9-Programming-Blueprints
作者:
评论列表
文章目录