Hi community,
I've created a class and an interface to dynamically add the Load on Demand functionality (see Demos) for a FIXGRIDListBinding.
Therefore I use the callback pattern.
Code:
public class MyFIXGRIDListBinding<T extends FIXGRIDItem> extends FIXGRIDListBinding<T> {
private IFIXGRIDCallback<T> callback;
public MyFIXGRIDListBinding(IFIXGRIDCallback<T> callback, boolean changeIndexIsSupported) {
super(changeIndexIsSupported);
this.callback = callback;
}
public MyFIXGRIDListBinding(IFIXGRIDCallback<T> callback) {
super();
this.callback = callback;
}
public List<T> getRows() {
List<T> result = super.getRows();
// check if all items are read
boolean foundNullItem = false;
for (int i = 0; i < result.size(); i++) {
if (result.get(i) == null) {
foundNullItem = true;
int gridIndex = getSbvalue() + i;
T item = callback.createItem(gridIndex);
getItems().set(gridIndex, item);
}
}
return foundNullItem ? super.getRows() : result;
}
}
Code:
public interface IFIXGRIDCallback<T> {
public T createItem(int index);
}
Usage
Code:
protected MyFIXGRIDListBinding<GridListItem> m_gridList = new MyFIXGRIDListBinding<GridListItem>(new IFIXGRIDCallback<GridListItem>(){
@Override
public GridListItem createItem(int index) {
if(Helper.isEmpty(gridData)) return null;
return new GridListItem(gridData.get(index));
}
}, false);
public FIXGRIDListBinding<GridListItem> getGridList() {
return m_gridList;
}
Markus