Package com.inmethod.grid.datagrid
Class DataGrid<D extends IDataSource<T>,T,S>
- java.lang.Object
-
- org.apache.wicket.Component
-
- org.apache.wicket.MarkupContainer
-
- org.apache.wicket.markup.html.WebMarkupContainer
-
- org.apache.wicket.markup.html.panel.Panel
-
- com.inmethod.grid.common.AbstractGrid<D,T,S>
-
- com.inmethod.grid.datagrid.DataGrid<D,T,S>
-
- Type Parameters:
D
- datasource model object type = grid typeT
- row/item model object type
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IMetadataContext<Serializable,Component>
,IQueueRegion
,IHeaderContributor
,IPageable
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Direct Known Subclasses:
DefaultDataGrid
public class DataGrid<D extends IDataSource<T>,T,S> extends AbstractGrid<D,T,S> implements IPageable
Advanced grid component. Supports resizable and reorderable columns.- Author:
- Matej Knopp
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DataGrid.IGridQuery
Extended query interface that makes it possible to obtain theDataGrid
instance.
-
Field Summary
-
Fields inherited from class com.inmethod.grid.common.AbstractGrid
CSS, INTERNAL_TOOLBAR_ITEM_ID, JS_DOM, JS_EVENT, JS_SCRIPT, JS_SCRIPT_JQ, JS_YAHOO, THEME_VISTA
-
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING, RFLAG_CONTAINER_HAS_REMOVALS
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebMarkupContainer
findParentRow(Component child)
Returns the row in DataTable that contains the child componentprotected WebMarkupContainer
findRowComponent(IModel<T> rowModel)
Returns the row component for specified item.long
getCurrentPage()
long
getCurrentPageItemCount()
D
getDataSource()
Returns theIDataSource
instance this data grid uses to fetch the data.long
getPageCount()
Gets the total number of pages this pageable object has.long
getRowsPerPage()
Returns the maximal amount of rows shown on one page.Collection<IModel<T>>
getSelectedItems()
Returns the collection of models of all currently selected items.long
getTotalRowCount()
Returns the total count of items (sum of count of items on all pages) orAbstractPageableView.UNKNOWN_COUNT
in case the count can't be determined.Item<T>
insertRow(T rowData)
Insert the rowData into the gridboolean
isAllowSelectMultiple()
Returns whether user will be able to select more than one item at a time.boolean
isCleanSelectionOnPageChange()
boolean
isItemSelected(IModel<T> itemModel)
Queries whether the item specified by itemModel is currently selected.void
markAllItemsDirty()
Makes the next call toupdate()
refresh the entire grid.void
markItemDirty(IModel<T> itemModel)
Marks the item from the given model as dirty.protected void
onBeforeRender()
void
onItemSelectionChanged(IModel<T> item, boolean newValue)
Invoked when an item selection state has been changed.void
resetSelectedItems()
Deselects all items.void
selectAllVisibleItems()
Marks all currently displayed items as selected.void
selectItem(IModel<T> itemModel, boolean selected)
Alters the selection state of item specified by the item model.void
setAllowSelectMultiple(boolean value)
Sets whether user will be able to select more than one item.DataGrid<D,T,S>
setCleanSelectionOnPageChange(boolean cleanSelectionOnPageChange)
Sets whether the change of current page should clear all selected items.void
setCurrentPage(long page)
Sets the a page that should be rendered.DataGrid<D,T,S>
setRowsPerPage(int rowsPerPage)
Sets the desired amount rows per page.void
update()
During an Ajax request this method updates the changed grid rows.-
Methods inherited from class com.inmethod.grid.common.AbstractGrid
addBottomToolbar, addHeaderToolbar, addTopToolbar, cleanLastClickedColumn, columnSanityCheck, disableRowClickNotifications, getActiveColumns, getAllColumns, getColumnState, getContentHeight, getContentHeightSizeUnit, getForm, getLastClickedColumn, getSortState, getTheme, isClickRowToDeselect, isClickRowToSelect, isItemEdited, isSelectToEdit, isUseYui, onAfterRender, onCellClicked, onColumnStateChanged, onComponentTag, onInitialize, onRowClicked, onRowPopulated, onSortStateChanged, renderHead, setClickRowToDeselect, setClickRowToSelect, setColumnState, setContentHeight, setItemEdit, setSelectToEdit, setTheme, setUseYui
-
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
getRegionMarkup, newMarkupSourcingStrategy
-
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebApplication, getWebPage, getWebRequest, getWebResponse, getWebSession
-
Methods inherited from class org.apache.wicket.MarkupContainer
add, addDequeuedComponent, addOrReplace, autoAdd, canDequeueTag, contains, dequeue, dequeue, dequeuePreamble, findChildComponent, findComponentToDequeue, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, newDequeueContext, onComponentTagBody, onDetach, onRender, queue, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, stream, streamChildren, toString, toString, visitChildren, visitChildren
-
Methods inherited from class org.apache.wicket.Component
add, addStateChange, beforeRender, canCallListener, canCallListenerAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMarkupTag, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isInitialized, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderPart, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlForListener, urlForListener, visitParents, visitParents, warn, wrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.wicket.IQueueRegion
dequeue, newDequeueContext
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
DataGrid
public DataGrid(String id, IModel<D> model, List<IGridColumn<D,T,S>> columns)
Crates a newDataGrid
instance.- Parameters:
id
- component idmodel
- model to access theIDataSource
instance used to fetch the datacolumns
- list of grid columns
-
-
Method Detail
-
getDataSource
public D getDataSource()
Returns theIDataSource
instance this data grid uses to fetch the data.- Returns:
IDataSource
instance
-
setRowsPerPage
public DataGrid<D,T,S> setRowsPerPage(int rowsPerPage)
Sets the desired amount rows per page.- Parameters:
rowsPerPage
- how many rows (max) should be displayed on one page- Returns:
this
(useful for method chaining)
-
getRowsPerPage
public long getRowsPerPage()
Returns the maximal amount of rows shown on one page.- Returns:
- count of rows per page
-
getTotalRowCount
public long getTotalRowCount()
Returns the total count of items (sum of count of items on all pages) orAbstractPageableView.UNKNOWN_COUNT
in case the count can't be determined.- Returns:
- total count of items or -1L
-
getCurrentPage
public long getCurrentPage()
- Specified by:
getCurrentPage
in interfaceIPageable
- Returns:
- The current page that is or will be rendered.
-
getPageCount
public long getPageCount()
Gets the total number of pages this pageable object has.- Specified by:
getPageCount
in interfaceIPageable
- Returns:
- The total number of pages this pageable object has
-
setCurrentPage
public void setCurrentPage(long page)
Sets the a page that should be rendered.- Specified by:
setCurrentPage
in interfaceIPageable
- Parameters:
page
- The page that should be rendered.
-
getCurrentPageItemCount
public long getCurrentPageItemCount()
- Returns:
- the amount of items on current page.
-
getSelectedItems
public Collection<IModel<T>> getSelectedItems()
Returns the collection of models of all currently selected items.- Specified by:
getSelectedItems
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Returns:
- collection of models of currently selected items
-
isAllowSelectMultiple
public boolean isAllowSelectMultiple()
Returns whether user will be able to select more than one item at a time.- Specified by:
isAllowSelectMultiple
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Returns:
true
if multiple items can be selected at a time,false
otherwise.
-
setAllowSelectMultiple
public void setAllowSelectMultiple(boolean value)
Sets whether user will be able to select more than one item.- Specified by:
setAllowSelectMultiple
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Parameters:
value
-true
if the user will be able to select more than one item at a time,false
otherwise (single selection mode).
-
setCleanSelectionOnPageChange
public DataGrid<D,T,S> setCleanSelectionOnPageChange(boolean cleanSelectionOnPageChange)
Sets whether the change of current page should clear all selected items. This means that only items on current page can be selected, i.e. items from multiple pages can not be selected at the same time.- Parameters:
cleanSelectionOnPageChange
- whether the current page change should deselect all selected items- Returns:
this
(useful for method chaining)
-
isCleanSelectionOnPageChange
public boolean isCleanSelectionOnPageChange()
- Returns:
- whether the current page change cleans the selection
-
isItemSelected
public boolean isItemSelected(IModel<T> itemModel)
Queries whether the item specified by itemModel is currently selected.- Specified by:
isItemSelected
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Parameters:
itemModel
- item model- Returns:
true
if the item is selected,false
otherwise
-
resetSelectedItems
public void resetSelectedItems()
Deselects all items. This method marks all items (not just visible items) as no selected.- Specified by:
resetSelectedItems
in classAbstractGrid<D extends IDataSource<T>,T,S>
-
selectAllVisibleItems
public void selectAllVisibleItems()
Marks all currently displayed items as selected. ForDataGrid
this selects all items on current page, forTreeGrid
this selects all currently visible nodes.- Specified by:
selectAllVisibleItems
in classAbstractGrid<D extends IDataSource<T>,T,S>
-
findRowComponent
protected WebMarkupContainer findRowComponent(IModel<T> rowModel)
Returns the row component for specified item.- Specified by:
findRowComponent
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Returns:
-
onBeforeRender
protected void onBeforeRender()
- Overrides:
onBeforeRender
in classAbstractGrid<D extends IDataSource<T>,T,S>
-
markItemDirty
public void markItemDirty(IModel<T> itemModel)
Marks the item from the given model as dirty. Dirty items are updated during Ajax requests whenAbstractGrid.update()
method is called.- Specified by:
markItemDirty
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Parameters:
itemModel
- model used to access the item
-
markAllItemsDirty
public void markAllItemsDirty()
Makes the next call toupdate()
refresh the entire grid.
-
onItemSelectionChanged
public void onItemSelectionChanged(IModel<T> item, boolean newValue)
Invoked when an item selection state has been changed.- Overrides:
onItemSelectionChanged
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Parameters:
item
- item modelnewValue
-true
if the item became selected,false
otherwise.
-
update
public void update()
During an Ajax request this method updates the changed grid rows.The definition of "changed" varies in
DataGrid
andTreeGrid
.- In both grids the items for which the selection state changed are considered changed.
- In
TreeGrid
the changes toTreeModel
itself are being tracked (assuming the proper listeners are fired) and all rows that need to be updated are also considered changed. - In
DataGrid
the items that need to be updated can be marked bymarkItemDirty(IModel)
ormarkAllItemsDirty()
. The grid itself doesn't track changes to specific items (apart from the selection state).
- Specified by:
update
in classAbstractGrid<D extends IDataSource<T>,T,S>
-
insertRow
public Item<T> insertRow(T rowData)
Insert the rowData into the grid- Parameters:
rowData
- data to insert into the new row- Returns:
- Item inserted Item
-
selectItem
public void selectItem(IModel<T> itemModel, boolean selected)
Alters the selection state of item specified by the item model.- Specified by:
selectItem
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Parameters:
itemModel
- item modelselected
-true
if the item should be selected,false
otherwise.
-
findParentRow
public WebMarkupContainer findParentRow(Component child)
Returns the row in DataTable that contains the child component- Specified by:
findParentRow
in classAbstractGrid<D extends IDataSource<T>,T,S>
- Returns:
-
-