org.wicketstuff.egrid.provider.EditableListDataProvider Maven / Gradle / Ivy
package org.wicketstuff.egrid.provider;
import java.io.Serializable;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
/**
*
* @author Nadeem Mohammad
*
*/
public class EditableListDataProvider implements IEditableDataProvider
{
private static final long serialVersionUID = 1L;
private final List list;
public EditableListDataProvider()
{
this(Collections.emptyList());
}
public EditableListDataProvider(List list)
{
if (list == null)
{
throw new IllegalArgumentException("argument [list] cannot be null");
}
this.list = list;
}
protected List getData()
{
return list;
}
@Override
public Iterator extends T> iterator(final long first, final long count)
{
List list = getData();
long toIndex = first + count;
if (toIndex > list.size())
{
toIndex = list.size();
}
return list.subList((int)first, (int)toIndex).listIterator();
}
@Override
public long size()
{
return getData().size();
}
@Override
public IModel model(T object)
{
return new Model(object);
}
@Override
public void detach()
{
}
@Override
public void add(T item)
{
list.add(item);
}
@Override
public void remove(T item)
{
list.remove(item);
}
@Override
public ISortState getSortState() {
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy