Package com.inmethod.grid.common
Class AbstractGrid<M,I,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<M,I,S>
- Type Parameters:
M
- grid model object typeI
- row/item model object type
- All Implemented Interfaces:
Serializable
,Iterable<Component>
,IEventSink
,IEventSource
,IFeedbackContributor
,IConverterLocator
,IMetadataContext<Serializable,
,Component> IQueueRegion
,IHeaderContributor
,IRequestableComponent
,IHierarchical<Component>
,IClusterable
- Author:
- Matej Knopp
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PackageResourceReference
static final String
INTERNALstatic final JavaScriptResourceReference
static final JavaScriptResourceReference
static final JavaScriptResourceReference
static final JavaScriptResourceReference
static final JavaScriptResourceReference
static final String
Constant for the Vista theme (default).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
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractGrid
(String id, IModel<M> model, List<IGridColumn<M, I, S>> columns) Creates newAbstractGrid
instance -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBottomToolbar
(AbstractToolbar<M, I, S> toolbar) Adds a toolbar to the bottom section (below the actual data).void
addHeaderToolbar
(AbstractHeaderToolbar<M, I, S> toolbar) Ads a toolbar to the header section (below the grid header, above the actual data).void
addTopToolbar
(AbstractToolbar<M, I, S> toolbar) Adds a toolbar to the top section (above the grid header).void
protected void
columnSanityCheck
(IGridColumn<M, I, S> column) Checks whether the column is a valid grid columnprotected boolean
abstract WebMarkupContainer
findParentRow
(Component child) Returns the row in DataTable that contains the child componentprotected abstract WebMarkupContainer
findRowComponent
(IModel<I> rowModel) Returns the row component for specified item.Collection<IGridColumn<M,
I, S>> Returns collection of currently visible columns.List<IGridColumn<M,
I, S>> Returns the list of all columns in this grid.Returns the column state.int
Returns the content height.Returns the size unit for content height.getForm()
IGridColumn<M,
I, S> abstract Collection<IModel<I>>
Returns the collection of models of all currently selected items.Returns the sort state of this grid.getTheme()
Returns the theme identifierabstract boolean
Returns whether user will be able to select more than one item at a time.boolean
Returns whether clicking a selected row deselects it.boolean
Returns whether a click on grid row should select/deselect the row.boolean
isItemEdited
(IModel<I> rowModel) Returns whether the row is in editable mode.abstract boolean
isItemSelected
(IModel<I> itemModel) Queries whether the item specified by itemModel is currently selected.boolean
Returns whether selected rows are also editable.boolean
isUseYui()
abstract void
markItemDirty
(IModel<I> model) Marks the item from the given model as dirty.protected void
protected void
protected boolean
onCellClicked
(AjaxRequestTarget target, IModel<I> rowModel, IGridColumn<M, I, S> column) void
Invoked when client change the column state (e.g. resize or reorder a column).protected void
protected void
protected void
onItemSelectionChanged
(IModel<I> item, boolean newValue) Invoked when an item selection state has been changed.protected void
onRowClicked
(AjaxRequestTarget target, IModel<I> rowModel) protected void
onRowPopulated
(WebMarkupContainer rowComponent) Called after a grid row has been populated.protected void
onSortStateChanged
(AjaxRequestTarget target) Invoked when sort state of this grid has changed (e.g. user clicked a sortable column header).void
renderHead
(IHeaderResponse response) abstract void
Deselects all items.abstract void
Marks all currently displayed items as selected.abstract void
selectItem
(IModel<I> itemModel, boolean selected) Alters the selection state of item specified by the item model.abstract void
setAllowSelectMultiple
(boolean value) Sets whether user will be able to select more than one item.void
setClickRowToDeselect
(boolean clickRowToDeselect) Sets whether a click on selected grid row should deselect it.AbstractGrid<M,
I, S> setClickRowToSelect
(boolean clickRowToSelect) Sets whether a click on grid row should select/deselect the row.void
setColumnState
(ColumnsState columnState) Sets a new column state.void
setContentHeight
(Integer contentHeight, SizeUnit contentSizeUnit) Sets the height of grid content.void
setItemEdit
(IModel<I> rowModel, boolean edit) Sets the edit mode of the row.void
setSelectToEdit
(boolean selectToEdit) Determines whether selected items should also be editable.void
Sets the grid theme.void
setUseYui
(boolean useYui) abstract void
update()
During an Ajax request this method updates the changed grid rows.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
-
Field Details
-
INTERNAL_TOOLBAR_ITEM_ID
INTERNALId of toolbar item (inside toolbar repeaters).
- See Also:
-
THEME_VISTA
Constant for the Vista theme (default).- See Also:
-
JS_YAHOO
-
JS_EVENT
-
JS_DOM
-
JS_SCRIPT
-
JS_SCRIPT_JQ
-
CSS
-
-
Constructor Details
-
AbstractGrid
Creates newAbstractGrid
instance- Parameters:
id
-model
-columns
-
-
-
Method Details
-
getForm
-
columnSanityCheck
Checks whether the column is a valid grid column- Parameters:
column
-
-
onColumnStateChanged
public void onColumnStateChanged()Invoked when client change the column state (e.g. resize or reorder a column).- See Also:
-
getColumnState
Returns the column state.- Returns:
- state of columns
- See Also:
-
setColumnState
Sets a new column state. The state must not be null and must match current set of columns, i.e. for every column in grid there must be entry in the given state.- Parameters:
columnState
- new column state- See Also:
-
onInitialize
protected void onInitialize()- Overrides:
onInitialize
in classMarkupContainer
-
onBeforeRender
protected void onBeforeRender()- Overrides:
onBeforeRender
in classComponent
-
onAfterRender
protected void onAfterRender()- Overrides:
onAfterRender
in classComponent
-
addTopToolbar
Adds a toolbar to the top section (above the grid header).- Parameters:
toolbar
- toolbar instance- See Also:
-
addBottomToolbar
Adds a toolbar to the bottom section (below the actual data).- Parameters:
toolbar
- toolbar instance- See Also:
-
addHeaderToolbar
Ads a toolbar to the header section (below the grid header, above the actual data).- Parameters:
toolbar
- toolbar instance- See Also:
-
onSortStateChanged
Invoked when sort state of this grid has changed (e.g. user clicked a sortable column header). By default refreshes the grid.- Parameters:
target
-
-
getActiveColumns
Returns collection of currently visible columns.- Returns:
- collection of currently visible columns
-
getAllColumns
Returns the list of all columns in this grid.- Returns:
- list of columns
-
getSortState
Returns the sort state of this grid.- Returns:
- sort state
- See Also:
-
setTheme
Sets the grid theme. Grid theme is used as CSS style class for the grid. The theme itself consist of a proper style definition in stylesheet. For more information on custom theme creation see the custom theme example.- Parameters:
theme
- theme identifier
-
getTheme
Returns the theme identifier- Returns:
- theme identifier
- See Also:
-
onComponentTag
- Overrides:
onComponentTag
in classComponent
-
renderHead
- Specified by:
renderHead
in interfaceIHeaderContributor
- Overrides:
renderHead
in classComponent
-
selectItem
Alters the selection state of item specified by the item model.- Parameters:
itemModel
- item modelselected
-true
if the item should be selected,false
otherwise.
-
selectAllVisibleItems
public abstract void selectAllVisibleItems() -
resetSelectedItems
public abstract void resetSelectedItems()Deselects all items. This method marks all items (not just visible items) as no selected. -
isItemSelected
Queries whether the item specified by itemModel is currently selected.- Parameters:
itemModel
- item model- Returns:
true
if the item is selected,false
otherwise
-
getSelectedItems
Returns the collection of models of all currently selected items.- Returns:
- collection of models of currently selected items
-
setAllowSelectMultiple
public abstract void setAllowSelectMultiple(boolean value) Sets whether user will be able to select more than one item.- Parameters:
value
-true
if the user will be able to select more than one item at a time,false
otherwise (single selection mode).
-
isAllowSelectMultiple
public abstract boolean isAllowSelectMultiple()Returns whether user will be able to select more than one item at a time.- Returns:
true
if multiple items can be selected at a time,false
otherwise.
-
update
public abstract 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 byDataGrid.markItemDirty(IModel)
orDataGrid.markAllItemsDirty()
. The grid itself doesn't track changes to specific items (apart from the selection state).
-
onItemSelectionChanged
Invoked when an item selection state has been changed.- Parameters:
item
- item modelnewValue
-true
if the item became selected,false
otherwise.
-
getLastClickedColumn
-
cleanLastClickedColumn
public void cleanLastClickedColumn() -
disableRowClickNotifications
protected boolean disableRowClickNotifications() -
onRowPopulated
Called after a grid row has been populated. This method allows adding behaviors to grid rows.- Parameters:
rowComponent
-
-
onCellClicked
protected boolean onCellClicked(AjaxRequestTarget target, IModel<I> rowModel, IGridColumn<M, I, S> column) -
onRowClicked
-
setClickRowToSelect
Sets whether a click on grid row should select/deselect the row.- Parameters:
clickRowToSelect
-true
if the row selection state should be changed upon a mouse click,false
otherwise.- Returns:
this
(useful for method chaining)- See Also:
-
isClickRowToSelect
public boolean isClickRowToSelect()Returns whether a click on grid row should select/deselect the row.- Returns:
true
if the row click should alter the row selection state,false
otherwise.
-
setClickRowToDeselect
public void setClickRowToDeselect(boolean clickRowToDeselect) Sets whether a click on selected grid row should deselect it. This only applies whensetClickRowToSelect(boolean)
is set totrue
.- Parameters:
clickRowToDeselect
- whether clicking a selected row should deselect it
-
isClickRowToDeselect
public boolean isClickRowToDeselect()Returns whether clicking a selected row deselects it.- Returns:
true
if clicking a selected row deselects it,false
otherwise.
-
setContentHeight
Sets the height of grid content. Content is the part of grid displaying the actual data (rows), i.e. it doesn't cover the header part and toolbars. When the actual content height is bigger than specified height, a vertical scrollbar is displayed.- Parameters:
contentHeight
- desired height of the content ornull
is the height should be determined by the actual height (no scrollbar displayed, defalt value)contentSizeUnit
- size unit for thecontentHeight
-
getContentHeight
public int getContentHeight()Returns the content height.- Returns:
- content height or 0 if the content height should be determined by the actual content.
- See Also:
-
getContentHeightSizeUnit
Returns the size unit for content height.- Returns:
- size unit
-
findParentRow
Returns the row in DataTable that contains the child component- Parameters:
child
-- Returns:
-
findRowComponent
Returns the row component for specified item.- Parameters:
rowModel
-- Returns:
-
markItemDirty
Marks the item from the given model as dirty. Dirty items are updated during Ajax requests whenupdate()
method is called.- Parameters:
model
- model used to access the item
-
setSelectToEdit
public void setSelectToEdit(boolean selectToEdit) Determines whether selected items should also be editable. This should be set tofalse
when the grid is both selectable and editable (independently).- Parameters:
selectToEdit
- whether selected rows should be editable
-
isSelectToEdit
public boolean isSelectToEdit()Returns whether selected rows are also editable.- Returns:
-
setItemEdit
Sets the edit mode of the row. If selectToEdit is true, this is same as callingselectItem(IModel, boolean)
.- Parameters:
rowModel
- row modeledit
-true
if the row should be in editable mode,false
otherwise.- See Also:
-
isItemEdited
Returns whether the row is in editable mode.- Parameters:
rowModel
-- Returns:
true
if the row is in editable mode,false
otherwise.
-
isUseYui
public boolean isUseYui() -
setUseYui
public void setUseYui(boolean useYui)
-