com.inmethod.grid.datagrid
Class DataGrid<D extends IDataSource<T>,T>

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.panel.Panel
                  extended by com.inmethod.grid.common.AbstractGrid<D,T>
                      extended by com.inmethod.grid.datagrid.DataGrid<D,T>
Type Parameters:
D - datasource model object type = grid type
T - row/item model object type
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IClusterable, IConverterLocator, IHeaderContributor, IPageable, IRequestableComponent, IHierarchical<Component>
Direct Known Subclasses:
DefaultDataGrid

public class DataGrid<D extends IDataSource<T>,T>
extends AbstractGrid<D,T>
implements IPageable

Advanced grid component. Supports resizable and reorderable columns.

Author:
Matej Knopp
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.inmethod.grid.common.AbstractGrid
INTERNAL_TOOLBAR_ITEM_ID, THEME_VISTA
 
Fields inherited from class org.apache.wicket.markup.html.panel.Panel
PANEL
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
DataGrid(String id, D dataSource, List<IGridColumn<D,T>> columns)
          Crates a new DataGrid instance.
DataGrid(String id, IModel<D> model, List<IGridColumn<D,T>> columns)
          Crates a new DataGrid instance.
 
Method Summary
 WebMarkupContainer findParentRow(Component child)
          Returns the row in DataTable that contains the child component
protected  WebMarkupContainer findRowComponent(IModel<T> rowModel)
          Returns the row component for specified item.
 int getCurrentPage()
           
 int getCurrentPageItemCount()
           
 D getDataSource()
          Returns the IDataSource instance this data grid uses to fetch the data.
 int getPageCount()
          Gets the total number of pages this pageable object has.
 int 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.
 int getTotalRowCount()
          Returns the total count of items (sum of count of items on all pages) or AbstractPageableView.UNKOWN_COUNT in case the count can't be determined.
 Item insertRow(T rowData)
          Insert the rowData into the grid
 boolean 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 to update() 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> setCleanSelectionOnPageChange(boolean cleanSelectionOnPageChange)
          Sets whether the change of current page should clear all selected items.
 void setCurrentPage(int page)
          Sets the a page that should be rendered.
 DataGrid<D,T> 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, onAfterRender, onCellClicked, onColumnStateChanged, onComponentTag, onInitialize, onRowClicked, onRowPopulated, onSortStateChanged, renderHead, setClickRowToDeselect, setClickRowToSelect, setColumnState, setContentHeight, setItemEdit, setSelectToEdit, setTheme
 
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
newMarkupSourcingStrategy
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebPage, getWebRequest
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, hasAssociatedMarkup, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, onMarkupAttached, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, canCallListenerInterface, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, 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, getFeedbackMessage, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, 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, internalPrepareForRender, internalRenderComponent, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, locateMarkupStream, markRendering, modelChanged, modelChanging, onConfigure, onDetach, onEvent, onModelChanged, onModelChanging, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataGrid

public DataGrid(String id,
                IModel<D> model,
                List<IGridColumn<D,T>> columns)
Crates a new DataGrid instance.

Parameters:
id - component id
model - model to access the IDataSource instance used to fetch the data
columns - list of grid columns

DataGrid

public DataGrid(String id,
                D dataSource,
                List<IGridColumn<D,T>> columns)
Crates a new DataGrid instance.

Parameters:
id - component id
dataSource - data source used to fetch the data
columns - list of grid columns
Method Detail

getDataSource

public D getDataSource()
Returns the IDataSource instance this data grid uses to fetch the data.

Returns:
IDataSource instance

setRowsPerPage

public DataGrid<D,T> 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 int getRowsPerPage()
Returns the maximal amount of rows shown on one page.

Returns:
count of rows per page

getTotalRowCount

public int getTotalRowCount()
Returns the total count of items (sum of count of items on all pages) or AbstractPageableView.UNKOWN_COUNT in case the count can't be determined.

Returns:
total count of items or

getCurrentPage

public int getCurrentPage()
Specified by:
getCurrentPage in interface IPageable
Returns:
The current page that is or will be rendered.

getPageCount

public int getPageCount()
Gets the total number of pages this pageable object has.

Specified by:
getPageCount in interface IPageable
Returns:
The total number of pages this pageable object has

setCurrentPage

public void setCurrentPage(int page)
Sets the a page that should be rendered.

Specified by:
setCurrentPage in interface IPageable
Parameters:
page - The page that should be rendered.

getCurrentPageItemCount

public int 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 class AbstractGrid<D extends IDataSource<T>,T>
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 class AbstractGrid<D extends IDataSource<T>,T>
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 class AbstractGrid<D extends IDataSource<T>,T>
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> 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 class AbstractGrid<D extends IDataSource<T>,T>
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 class AbstractGrid<D extends IDataSource<T>,T>

selectAllVisibleItems

public void selectAllVisibleItems()
Marks all currently displayed items as selected. For DataGrid this selects all items on current page, for TreeGrid this selects all currently visible nodes.

Specified by:
selectAllVisibleItems in class AbstractGrid<D extends IDataSource<T>,T>

findRowComponent

protected WebMarkupContainer findRowComponent(IModel<T> rowModel)
Returns the row component for specified item.

Specified by:
findRowComponent in class AbstractGrid<D extends IDataSource<T>,T>
Returns:

onBeforeRender

protected void onBeforeRender()
Overrides:
onBeforeRender in class AbstractGrid<D extends IDataSource<T>,T>

markItemDirty

public void markItemDirty(IModel<T> itemModel)
Marks the item from the given model as dirty. Dirty items are updated during Ajax requests when AbstractGrid.update() method is called.

Specified by:
markItemDirty in class AbstractGrid<D extends IDataSource<T>,T>
Parameters:
itemModel - model used to access the item

markAllItemsDirty

public void markAllItemsDirty()
Makes the next call to update() 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 class AbstractGrid<D extends IDataSource<T>,T>
Parameters:
item - item model
newValue - 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 and TreeGrid.

Specified by:
update in class AbstractGrid<D extends IDataSource<T>,T>

insertRow

public Item 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 class AbstractGrid<D extends IDataSource<T>,T>
Parameters:
itemModel - item model
selected - 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 class AbstractGrid<D extends IDataSource<T>,T>
Returns:


Copyright © 2007-2012 inMethod s.r.o.. All Rights Reserved.