org.ujorm.wicket.component.grid
Class ListDataProvider<U extends Ujo>

java.lang.Object
  extended by org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider<U,Object>
      extended by org.ujorm.wicket.component.grid.AbstractDataProvider<U>
          extended by org.ujorm.wicket.component.grid.ListDataProvider<U>
All Implemented Interfaces:
Serializable, org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortStateLocator<Object>, org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider<U,Object>, org.apache.wicket.markup.repeater.data.IDataProvider<U>, org.apache.wicket.model.IDetachable, org.apache.wicket.util.io.IClusterable

public class ListDataProvider<U extends Ujo>
extends AbstractDataProvider<U>

This class called ListDataProvider is a List based DataProvider. For a customization you can use a your own IColumn implementations or you can overwrite selected methods of this provider.

The implementation generates two database requests per a one rendering, the first one get size and the second one get paged data. You can overwrite the two data methods: iterator() and the size() for more optimization.

The current class uses a WicketApplication implementation, which must implement the interface OrmHandlerProvider for an ORM support. See the example:

See the simple sample:

 Criterion<Hotel> allActiveHotels = Hotel.ACTIVE.whereEq(true);
  UjoDataProvider<Hotel> dataProvider = UjoDataProvider.of(allActiveHotels);

  dataProvider.addColumn(Hotel.NAME);
  dataProvider.addColumn(Hotel.CITY.add(City.NAME)); // An example of relations
  dataProvider.addColumn(Hotel.STREET);
  dataProvider.addColumn(Hotel.PRICE);
  dataProvider.addColumn(KeyColumn.of(Hotel.CURRENCY, SORTING_OFF));
  dataProvider.addColumn(Hotel.STARS);
  dataProvider.addColumn(Hotel.PHONE);
  dataProvider.setSort(Hotel.NAME);

  panel.add(dataProvider.createDataTable("datatable", 10));
 
 

Author:
Pavel Ponec
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.ujorm.wicket.component.grid.AbstractDataProvider
DEFAULT_CSS_ACTION, DEFAULT_CSS_SELECTED, DEFAULT_DATATABLE_ID, filter, highlighting, size
 
Constructor Summary
ListDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion)
          Constructor
ListDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> filter, Key<? super U,?> defaultSort)
          Constructor
 
Method Summary
protected  void clearBuffer()
          Clear a filterd rows and size
 long deleteRow(org.ujorm.criterion.Criterion<? super U> deleteCondition)
          Delete rows from the data source
 void detach()
          Detaches model after use.
protected  List<U> getFileredRows()
          Returns a filtered rows and cach the result
 List<U> getRows()
          Returns original data rows
 boolean insertRow(U row)
          Insert row to the data source
 Iterator<U> iterator(long first, long count)
          Build a JDBC ResultSet allways.
static
<T extends Ujo>
ListDataProvider<T>
of(org.ujorm.criterion.Criterion<? super T> criterion)
          Factory for the class
static
<T extends Ujo>
ListDataProvider<T>
of(org.ujorm.criterion.Criterion<T> criterion, Key<? super T,?> defaultSort)
          Factory for the class
static
<T extends Ujo>
ListDataProvider<T>
of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
          Factory for the class
static
<T extends Ujo>
ListDataProvider<T>
of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion, Key<? super T,?> defaultSort)
          Factory for the class
 void setRows(List<? super U> dataRows)
          Assign data resource
 long size()
          Method calculate the size of filtered rows
 long updateRow(org.ujorm.criterion.Criterion<? super U> updateCondition, U updatedRow)
          Update all rows with a codition using the row
 
Methods inherited from class org.ujorm.wicket.component.grid.AbstractDataProvider
add, add, add, add, add, add, createBottomToolbars, createDataTable, createDataTable, createDataTable, createDataTable, createTopToolbars, getColumns, getCssSelected, getDomainClass, getFirstTableRow, getHighlighting, getSortKey, isDefaultColumnSorting, isSortingEnabled, model, setCssClass, setDefaultColumnSorting, setHighlighting, setHighlighting, setSelected, setSelected, setSort
 
Methods inherited from class org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider
getSort, getSortState, setSort, setSort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListDataProvider

public ListDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion)
Constructor

Parameters:
criterion - Condition to a database query

ListDataProvider

public ListDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> filter,
                        Key<? super U,?> defaultSort)
Constructor

Parameters:
filter - Model of a condition to a database query
defaultSort - Default sorting can be assigned optionally
Method Detail

setRows

public void setRows(List<? super U> dataRows)
Assign data resource


getRows

@Nonnull
public List<U> getRows()
Returns original data rows


getFileredRows

@Nonnull
protected List<U> getFileredRows()
Returns a filtered rows and cach the result


iterator

public Iterator<U> iterator(long first,
                            long count)
Build a JDBC ResultSet allways. Overwrite the method for an optimization.

Specified by:
iterator in interface org.apache.wicket.markup.repeater.data.IDataProvider<U extends Ujo>
Specified by:
iterator in class AbstractDataProvider<U extends Ujo>

size

public long size()
Method calculate the size of filtered rows

Specified by:
size in interface org.apache.wicket.markup.repeater.data.IDataProvider<U extends Ujo>
Specified by:
size in class AbstractDataProvider<U extends Ujo>

detach

public void detach()
Detaches model after use. This is generally used to null out transient references that can be re-attached later.

Specified by:
detach in interface org.apache.wicket.model.IDetachable
Specified by:
detach in class AbstractDataProvider<U extends Ujo>

clearBuffer

protected void clearBuffer()
Clear a filterd rows and size


insertRow

public boolean insertRow(@Nonnull
                         U row)
Insert row to the data source

Overrides:
insertRow in class AbstractDataProvider<U extends Ujo>
Parameters:
row - Insert the one table row

deleteRow

public long deleteRow(@Nonnull
                      org.ujorm.criterion.Criterion<? super U> deleteCondition)
Delete rows from the data source

Overrides:
deleteRow in class AbstractDataProvider<U extends Ujo>
Parameters:
deleteCondition - Remove all row with a condition.

updateRow

public long updateRow(@Nonnull
                      org.ujorm.criterion.Criterion<? super U> updateCondition,
                      @Nonnull
                      U updatedRow)
Update all rows with a codition using the row

Overrides:
updateRow in class AbstractDataProvider<U extends Ujo>
Parameters:
updateCondition - Update condition
row - Updated row

of

public static <T extends Ujo> ListDataProvider<T> of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion,
                                                     Key<? super T,?> defaultSort)
Factory for the class


of

public static <T extends Ujo> ListDataProvider<T> of(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<T>> criterion)
Factory for the class


of

public static <T extends Ujo> ListDataProvider<T> of(org.ujorm.criterion.Criterion<T> criterion,
                                                     Key<? super T,?> defaultSort)
Factory for the class


of

public static <T extends Ujo> ListDataProvider<T> of(org.ujorm.criterion.Criterion<? super T> criterion)
Factory for the class



Copyright © 2015. All Rights Reserved.