@Override protected Registration follow(ObservableList<ItemT> srcList) { for (int i = 0; i < srcList.size(); i++) { add(i, srcList.get(i)); } return srcList.addListener( new CollectionAdapter<ItemT>() { @Override public void onItemAdded(CollectionItemEvent<? extends ItemT> event) { add(event.getIndex(), event.getNewItem()); } @Override public void onItemRemoved(CollectionItemEvent<? extends ItemT> event) { remove(event.getIndex()); } }); }
public static <ItemT> ObservableList<ItemT> toObservable(List<ItemT> l) { ObservableList<ItemT> result = new ObservableArrayList<>(); result.addAll(l); return result; }