public abstract class AbstractDataProvider<U extends org.ujorm.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:
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));
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
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,
org.ujorm.Key<? super U,?> defaultSort)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<? super U,?> column)
Add table column
|
<V> boolean |
add(org.ujorm.Key<? super U,V> column)
Add a table column according to column type
|
<V> void |
add(org.ujorm.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(org.ujorm.Key<? super U,V> column,
Class<? extends org.apache.wicket.markup.html.WebMarkupContainer> panelClass,
boolean sortable,
String cssClass)
Create new instance of a Panel from the argument
panelClass
and add the result to the grid as new column. |
<V> void |
add(org.ujorm.Key<? super U,V> column,
Class<? extends org.apache.wicket.markup.html.WebMarkupContainer> panelClass,
org.ujorm.Key<? super U,V> sortColumn,
String cssClass)
Create new instance of a Panel from the argument
panelClass
and add the result to the grid as new column. |
<V> void |
add(org.ujorm.Key<? super U,V> column,
CommonAction... actions)
Create new instance of an Action Panel using actions from the argument list.
|
<V> boolean |
add(org.ujorm.Key<? super U,V> column,
CssAppender cssClass)
Add table column according to column type including CSS class
|
void |
add(org.ujorm.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.
|
<V> KeyColumn<? super U,V> |
createKeyColumn(org.ujorm.Key<? super U,V> column)
Create new object type of
KeyColumn |
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 <S> List<KeyColumnExportable<U,S>> |
getExportableColumns(boolean exportable)
Returns columns type of
IExportableColumn for a true argument. |
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
|
org.ujorm.Key<U,?> |
getSortKey()
Returns a sorting Key
|
org.ujorm.Key<U,?>[] |
getSortKeys()
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(org.ujorm.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(org.ujorm.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(org.ujorm.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.
|
public static final String DEFAULT_DATATABLE_ID
"datatable".protected static final String DEFAULT_CSS_SELECTED
public static final String DEFAULT_CSS_ACTION
protected Long size
@Nonnull protected final org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U extends org.ujorm.Ujo>> filter
protected org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U extends org.ujorm.Ujo>> highlighting
public AbstractDataProvider(@Nonnull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterion)
criterion - Condition to a database querypublic AbstractDataProvider(@Nonnull org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> filter, @Nullable org.ujorm.Key<? super U,?> defaultSort)
filter - Model of a condition to a database querydefaultSort - Default sorting can be assigned optionallypublic final void setSort(org.ujorm.Key<? super U,?> key)
key - sort keypublic org.ujorm.Key<U,?>[] getSortKeys()
public abstract Iterator<U> iterator(long first, long count)
public abstract long size()
public abstract void detach()
public boolean add(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<? super U,?> column)
public void add(org.ujorm.KeyList<? super U> columns)
public <V> boolean add(org.ujorm.Key<? super U,V> column, CssAppender cssClass)
public <V> boolean add(org.ujorm.Key<? super U,V> column)
public <V> KeyColumn<? super U,V> createKeyColumn(org.ujorm.Key<? super U,V> column)
KeyColumnpublic <V> void add(org.ujorm.Key<? super U,V> column, Class<? extends org.apache.wicket.markup.html.WebMarkupContainer> panelClass)
panelClass
and add the result to the grid as new column. Column is no-sortedV - Value typecolumn - Key for the column, where the Key can't get data.panelClass - A panel with two constructor arguments:
Key.getDomainType()public <V> void add(@Nonnull org.ujorm.Key<? super U,V> column, @Nonnull Class<? extends org.apache.wicket.markup.html.WebMarkupContainer> panelClass, boolean sortable, @Nullable String cssClass)
panelClass
and add the result to the grid as new column.V - Value typecolumn - Key for the column, where the Key can't get data.panelClass - A panel with two constructor arguments:
Key.getDomainType()sortable - Column sorting is requiredcssClass - CSS classpublic <V> void add(@Nonnull org.ujorm.Key<? super U,V> column, @Nonnull Class<? extends org.apache.wicket.markup.html.WebMarkupContainer> panelClass, @Nullable org.ujorm.Key<? super U,V> sortColumn, @Nullable String cssClass)
panelClass
and add the result to the grid as new column.V - Value typecolumn - Key for the column, where the Key can't get data.panelClass - A panel with two constructor arguments:
Key.getDomainType()sortColumn - Sorting columncssClass - CSS classpublic <V> void add(@Nonnull org.ujorm.Key<? super U,V> column, CommonAction... actions)
V - Value typecolumn - Key for the column, where the Key can't get data.actions - Action arrayprotected String getCssSelected()
DEFAULT_CSS_SELECTEDprotected boolean isSortingEnabled(org.ujorm.Key<U,?> column) throws IllegalArgumentException
IllegalArgumentExceptionisDefaultColumnSorting()public <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(int rowsPerPage)
DEFAULT_DATATABLE_IDpublic <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(String id, int rowsPerPage)
public <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(int rowsPerPage, boolean insertToolbar)
public <S> org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> createDataTable(String id, int rowsPerPage, boolean insertToolbar)
Component.getOutputMarkupId() is set to the true value.id - Component IDrowsPerPage - Row count per the one pageinsertToolbar - Append a generic toolbar for an insert action.protected <S> void createTopToolbars(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> result)
protected <S> void createBottomToolbars(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<U,S> result)
public final boolean isDefaultColumnSorting()
#addColumn(org.ujorm.Key)
where the feature is enabled by defaultpublic void setDefaultColumnSorting(boolean defaultColumnSorting)
#addColumn(org.ujorm.Key)
where the feature is enabled by defaultdefaultColumnSorting - the defaultColumnSorting to setpublic <T> List<org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn<U,T>> getColumns()
protected <S> List<KeyColumnExportable<U,S>> getExportableColumns(boolean exportable)
IExportableColumn for a true argument.public void setCssClass(org.ujorm.Key<? super U,?> key, String cssClass)
@Nullable public org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> getHighlighting()
public void setHighlighting(@Nullable org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterionModel)
criterionModel - The highlighting criterion model to setpublic void setHighlighting(@Nonnull org.ujorm.criterion.Criterion<U> criterion)
criterion - The highlighting criterion to set@Deprecated public final void setSelected(@Nullable org.apache.wicket.model.IModel<org.ujorm.criterion.Criterion<U>> criterionModel)
criterionModel - The highlighting criterion model to set@Deprecated public final void setSelected(@Nonnull org.ujorm.criterion.Criterion<U> criterion)
criterion - The highlighting criterion to setprotected U getFirstTableRow(@Nonnull org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable dataTable)
null value if no row was foundpublic boolean insertRow(U row)
row - Insert one table rowpublic long deleteRow(org.ujorm.criterion.Criterion<? super U> deleteCondition)
deleteCondition - Remove all row with a condition.Copyright © 2019. All rights reserved.