org.ujorm.wicket.component.grid
Class AbstractDataProvider<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>
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
Direct Known Subclasses:
ListDataProvider, OrmDataProvider

public abstract class AbstractDataProvider<U extends Ujo>
extends org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider<U,Object>

This class called UjoDataProvider is an common Wicket DataProvider to create an AJAX DataTable component. For a column customizations you can use 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
static String DEFAULT_CSS_ACTION
          Default CSS style for an ACTION COLUMN
protected static String DEFAULT_CSS_SELECTED
          Default CSS style for a SELECTED row
static String DEFAULT_DATATABLE_ID
          Default DataTable ID have got value "datatable".
protected  org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> filter
          Data criterion model for filtering the data resource
protected  org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> highlighting
          Data criterion model for highlighting data rows
protected  Long size
          Data size
 
Constructor Summary
AbstractDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion)
          Constructor
AbstractDataProvider(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> filter, Key<? super U,?> defaultSort)
          Constructor
 
Method Summary
 boolean add(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<? super U,?> column)
          Add table column
<V> boolean
add(Key<? super U,V> column)
          Add table column according to column type
<V> void
add(Key<? super U,V> column, Class<? extends org.apache.wicket.markup.html.WebMarkupContainer> panelClass)
          Create new instance of a Panel from the argument panelClass and add the result to the grid as new column.
<V> void
add(Key<? super U,V> column, CommonAction... actions)
          Create new instance of an Action Panel using actions from the argument list.
<V> boolean
add(Key<? super U,V> column, CssAppender cssClass)
          Add table column according to column type including CSS class
 void add(KeyList<? super U> columns)
          Add table columns according to column type including CSS class
protected
<S> void
createBottomToolbars(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> result)
          Create default bottom table toolbars: NoRecordsToolbar
<S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S>
createDataTable(int rowsPerPage)
          Create AJAX-based DataTable with a DEFAULT_DATATABLE_ID
<S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S>
createDataTable(int rowsPerPage, boolean insertToolbar)
          Create AJAX-based DataTable
<S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S>
createDataTable(String id, int rowsPerPage)
          Create AJAX-based DataTable
<S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S>
createDataTable(String id, int rowsPerPage, boolean insertToolbar)
          Create AJAX-based DataTable.
protected
<S> void
createTopToolbars(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> result)
          Create default top table toolbars: AjaxNavigationToolbar and AjaxFallbackHeadersToolbar
 long deleteRow(org.ujorm.criterion.Criterion<? super U> deleteCondition)
          Delete rows from the data source The method is not implemented by default.
abstract  void detach()
          Commit and close transaction
<T> List<org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<U,T>>
getColumns()
          Column table list
protected  String getCssSelected()
          Returns a CSS style for SELECTED row.
 Class<U> getDomainClass()
          Get a domain class
protected  U getFirstTableRow(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable dataTable)
          A common tool returns the first row of the selected dataTable or the null value if no row was found
 org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> getHighlighting()
          Data criterion model for select data rows
 Key<U,?> getSortKey()
          Returns a sorting Key
 boolean insertRow(U row)
          Insert row to the data source.
 boolean isDefaultColumnSorting()
          Default column sorting for the method #addColumn(org.ujorm.Key) where the feature is enabled by default
protected  boolean isSortingEnabled(Key<U,?> column)
          The sorting is enabled for a persistent Ujorm Key by default
abstract  Iterator<U> iterator(long first, long count)
          Build a JDBC ResultSet always.
 org.apache.wicket.model.IModel<U> model(U object)
          Create a model
 void setCssClass(Key<? super U,?> key, String cssClass)
          Assign a CSS class to a KeyColumn, if exists
 void setDefaultColumnSorting(boolean defaultColumnSorting)
          Default column sorting for the method #addColumn(org.ujorm.Key) where the feature is enabled by default
 void setHighlighting(org.ujorm.criterion.Criterion<U> criterion)
          Data criterion model for select data rows
 void setHighlighting(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterionModel)
          Data criterion model for highlighting data rows
 void setSelected(org.ujorm.criterion.Criterion<U> criterion)
          Deprecated. 
 void setSelected(org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterionModel)
          Deprecated. 
 void setSort(Key<? super U,?> key)
          Sets the current sort state and assign the BaseClass
abstract  long size()
          Method calculate the size using special SQL request.
 long updateRow(org.ujorm.criterion.Criterion<? super U> updateCondition, U updatedRow)
          Update all rows with a condition using the row The method is not implemented by default.
 
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
 

Field Detail

DEFAULT_DATATABLE_ID

public static final String DEFAULT_DATATABLE_ID
Default DataTable ID have got value "datatable".

See Also:
Constant Field Values

DEFAULT_CSS_SELECTED

protected static final String DEFAULT_CSS_SELECTED
Default CSS style for a SELECTED row

See Also:
Constant Field Values

DEFAULT_CSS_ACTION

public static final String DEFAULT_CSS_ACTION
Default CSS style for an ACTION COLUMN

See Also:
Constant Field Values

size

protected Long size
Data size


filter

protected org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U extends Ujo>> filter
Data criterion model for filtering the data resource


highlighting

protected org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U extends Ujo>> highlighting
Data criterion model for highlighting data rows

Constructor Detail

AbstractDataProvider

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

Parameters:
criterion - Condition to a database query

AbstractDataProvider

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

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

setSort

public final void setSort(Key<? super U,?> key)
Sets the current sort state and assign the BaseClass

Parameters:
key - sort key
order - sort order

getSortKey

public Key<U,?> getSortKey()
Returns a sorting Key


iterator

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


size

public abstract long size()
Method calculate the size using special SQL request. Overwrite the method for an optimization.
Original documentation:


detach

public abstract void detach()
Commit and close transaction

Specified by:
detach in interface org.apache.wicket.model.IDetachable
Overrides:
detach in class org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider<U extends Ujo,Object>

getDomainClass

public Class<U> getDomainClass()
Get a domain class


model

public org.apache.wicket.model.IModel<U> model(U object)
Create a model


add

public boolean add(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<? super U,?> column)
Add table column


add

public void add(KeyList<? super U> columns)
Add table columns according to column type including CSS class


add

public <V> boolean add(Key<? super U,V> column,
                       CssAppender cssClass)
Add table column according to column type including CSS class


add

public <V> boolean add(Key<? super U,V> column)
Add table column according to column type


add

public <V> void add(Key<? super U,V> column,
                    Class<? extends org.apache.wicket.markup.html.WebMarkupContainer> panelClass)
Create new instance of a Panel from the argument panelClass and add the result to the grid as new column.

Type Parameters:
V - Value type
Parameters:
column - Key for the column, where the Key can't get data.
panelClass - A panel with two constructor arguments:

add

public <V> void add(Key<? super U,V> column,
                    CommonAction... actions)
Create new instance of an Action Panel using actions from the argument list.

Type Parameters:
V - Value type
Parameters:
column - Key for the column, where the Key can't get data.
actions - Action array

getCssSelected

protected String getCssSelected()
Returns a CSS style for SELECTED row. The default value is DEFAULT_CSS_SELECTED


isSortingEnabled

protected boolean isSortingEnabled(Key<U,?> column)
                            throws IllegalArgumentException
The sorting is enabled for a persistent Ujorm Key by default

Throws:
IllegalArgumentException
See Also:
isDefaultColumnSorting()

createDataTable

public final <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(int rowsPerPage)
Create AJAX-based DataTable with a DEFAULT_DATATABLE_ID


createDataTable

public final <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(String id,
                                                                                                             int rowsPerPage)
Create AJAX-based DataTable


createDataTable

public final <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(int rowsPerPage,
                                                                                                             boolean insertToolbar)
Create AJAX-based DataTable


createDataTable

public <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(String id,
                                                                                                       int rowsPerPage,
                                                                                                       boolean insertToolbar)
Create AJAX-based DataTable. The attribute Component.getOutputMarkupId() is set to the true value.

Parameters:
id - Component ID
rowsPerPage - Row count per the one page
insertToolbar - Append a generic toolbar for an insert action.
Returns:
Create AJAX-based DataTable

createTopToolbars

protected <S> void createTopToolbars(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> result)
Create default top table toolbars: AjaxNavigationToolbar and AjaxFallbackHeadersToolbar


createBottomToolbars

protected <S> void createBottomToolbars(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> result)
Create default bottom table toolbars: NoRecordsToolbar


isDefaultColumnSorting

public final boolean isDefaultColumnSorting()
Default column sorting for the method #addColumn(org.ujorm.Key) where the feature is enabled by default

Returns:
the defaultColumnSorting

setDefaultColumnSorting

public void setDefaultColumnSorting(boolean defaultColumnSorting)
Default column sorting for the method #addColumn(org.ujorm.Key) where the feature is enabled by default

Parameters:
defaultColumnSorting - the defaultColumnSorting to set

getColumns

public <T> List<org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<U,T>> getColumns()
Column table list


setCssClass

public void setCssClass(Key<? super U,?> key,
                        String cssClass)
Assign a CSS class to a KeyColumn, if exists


getHighlighting

@Nullable
public org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> getHighlighting()
Data criterion model for select data rows

Returns:
the highlighting

setHighlighting

public void setHighlighting(@Nullable
                            org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterionModel)
Data criterion model for highlighting data rows

Parameters:
criterionModel - The highlighting criterion model to set

setHighlighting

public void setHighlighting(@Nonnull
                            org.ujorm.criterion.Criterion<U> criterion)
Data criterion model for select data rows

Parameters:
criterion - The highlighting criterion to set

setSelected

@Deprecated
public final void setSelected(@Nullable
                                         org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterionModel)
Deprecated. 

Data criterion model for select data rows

Parameters:
criterionModel - The highlighting criterion model to set

setSelected

@Deprecated
public final void setSelected(@Nonnull
                                         org.ujorm.criterion.Criterion<U> criterion)
Deprecated. 

Data criterion model for highlighting data rows

Parameters:
criterion - The highlighting criterion to set

getFirstTableRow

protected U getFirstTableRow(@Nonnull
                             org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable dataTable)
A common tool returns the first row of the selected dataTable or the null value if no row was found


insertRow

public boolean insertRow(U row)
Insert row to the data source. The method is not implemented by default.

Parameters:
row - Insert one table row

deleteRow

public long deleteRow(org.ujorm.criterion.Criterion<? super U> deleteCondition)
Delete rows from the data source The method is not implemented by default.

Parameters:
deleteCondition - Remove all row with a condition.

updateRow

public long updateRow(org.ujorm.criterion.Criterion<? super U> updateCondition,
                      U updatedRow)
Update all rows with a condition using the row The method is not implemented by default.

Parameters:
updateCondition - Update condition
updatedRow - Updated row


Copyright © 2015. All Rights Reserved.