[Logo] Enterprise Client Community
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
FIXGRIDListBinding Extension for Loading on Demand  XML
Forum Index -> Development - Code Snippets
Author Message
mreich

Power User
[Avatar]

Joined: 30/01/2009 08:34:23
Messages: 744
Offline

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
[WWW]
 
Forum Index -> Development - Code Snippets
Go to:   
Powered by JForum 2.1.6 © JForum Team