com.inmethod.grid.common
Class AbstractGrid<M,I,S>

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<M,I,S>
Type Parameters:
M - grid model object type
I - row/item model object type
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IConverterLocator, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable
Direct Known Subclasses:
DataGrid, TreeGrid

public abstract class AbstractGrid<M,I,S>
extends Panel

Provides common functionality for DataGrid and TreeGrid.

Author:
Matej Knopp
See Also:
Serialized Form

Field Summary
static PackageResourceReference CSS
           
static String INTERNAL_TOOLBAR_ITEM_ID
          INTERNAL
static JavaScriptResourceReference JS_DOM
           
static JavaScriptResourceReference JS_EVENT
           
static JavaScriptResourceReference JS_SCRIPT
           
static JavaScriptResourceReference JS_SCRIPT_JQ
           
static JavaScriptResourceReference JS_YAHOO
           
static String THEME_VISTA
          Constant for the Vista theme (default).
 
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
AbstractGrid(String id, IModel<M> model, List<IGridColumn<M,I,S>> columns)
          Creates new AbstractGrid instance
 
Method Summary
 void 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 cleanLastClickedColumn()
           
protected  void columnSanityCheck(IGridColumn<M,I,S> column)
          Checks whether the column is a valid grid column
protected  boolean disableRowClickNotifications()
           
abstract  WebMarkupContainer findParentRow(Component child)
          Returns the row in DataTable that contains the child component
protected abstract  WebMarkupContainer findRowComponent(IModel<I> rowModel)
          Returns the row component for specified item.
 Collection<IGridColumn<M,I,S>> getActiveColumns()
          Returns collection of currently visible columns.
 List<IGridColumn<M,I,S>> getAllColumns()
          Returns the list of all columns in this grid.
 ColumnsState getColumnState()
          Returns the column state.
 int getContentHeight()
          Returns the content height.
 SizeUnit getContentHeightSizeUnit()
          Returns the size unit for content height.
 Form<Void> getForm()
           
 IGridColumn<M,I,S> getLastClickedColumn()
           
abstract  Collection<IModel<I>> getSelectedItems()
          Returns the collection of models of all currently selected items.
 GridSortState<S> getSortState()
          Returns the sort state of this grid.
 String getTheme()
          Returns the theme identifier
abstract  boolean isAllowSelectMultiple()
          Returns whether user will be able to select more than one item at a time.
 boolean isClickRowToDeselect()
          Returns whether clicking a selected row deselects it.
 boolean isClickRowToSelect()
          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 isSelectToEdit()
          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 onAfterRender()
           
protected  void onBeforeRender()
           
protected  boolean onCellClicked(AjaxRequestTarget target, IModel<I> rowModel, IGridColumn<M,I,S> column)
           
 void onColumnStateChanged()
          Invoked when client change the column state (e.g.
protected  void onComponentTag(ComponentTag tag)
          
protected  void onInitialize()
           
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.
 void renderHead(org.apache.wicket.markup.head.IHeaderResponse response)
          
abstract  void resetSelectedItems()
          Deselects all items.
abstract  void selectAllVisibleItems()
          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 setTheme(String theme)
          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
newMarkupSourcingStrategy
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebPage, getWebRequest, getWebResponse, getWebSession
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, 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, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, 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, 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, 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, visitParents, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTERNAL_TOOLBAR_ITEM_ID

public static final String INTERNAL_TOOLBAR_ITEM_ID
INTERNAL

Id of toolbar item (inside toolbar repeaters).

See Also:
Constant Field Values

THEME_VISTA

public static final String THEME_VISTA
Constant for the Vista theme (default).

See Also:
Constant Field Values

JS_YAHOO

public static final JavaScriptResourceReference JS_YAHOO

JS_EVENT

public static final JavaScriptResourceReference JS_EVENT

JS_DOM

public static final JavaScriptResourceReference JS_DOM

JS_SCRIPT

public static final JavaScriptResourceReference JS_SCRIPT

JS_SCRIPT_JQ

public static final JavaScriptResourceReference JS_SCRIPT_JQ

CSS

public static final PackageResourceReference CSS
Constructor Detail

AbstractGrid

public AbstractGrid(String id,
                    IModel<M> model,
                    List<IGridColumn<M,I,S>> columns)
Creates new AbstractGrid instance

Parameters:
id -
model -
columns -
Method Detail

getForm

public Form<Void> getForm()

columnSanityCheck

protected void columnSanityCheck(IGridColumn<M,I,S> column)
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()

getColumnState

public ColumnsState getColumnState()
Returns the column state.

Returns:
state of columns
See Also:
ColumnsState

setColumnState

public void setColumnState(ColumnsState columnState)
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:
ColumnsState

onInitialize

protected void onInitialize()
Overrides:
onInitialize in class Component

onBeforeRender

protected void onBeforeRender()
Overrides:
onBeforeRender in class Component

onAfterRender

protected void onAfterRender()
Overrides:
onAfterRender in class Component

addTopToolbar

public void addTopToolbar(AbstractToolbar<M,I,S> toolbar)
Adds a toolbar to the top section (above the grid header).

Parameters:
toolbar - toolbar instance
See Also:
AbstractToolbar

addBottomToolbar

public void addBottomToolbar(AbstractToolbar<M,I,S> toolbar)
Adds a toolbar to the bottom section (below the actual data).

Parameters:
toolbar - toolbar instance
See Also:
AbstractToolbar

addHeaderToolbar

public void addHeaderToolbar(AbstractHeaderToolbar<M,I,S> toolbar)
Ads a toolbar to the header section (below the grid header, above the actual data).

Parameters:
toolbar - toolbar instance
See Also:
AbstractToolbar

onSortStateChanged

protected void onSortStateChanged(AjaxRequestTarget target)
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

public Collection<IGridColumn<M,I,S>> getActiveColumns()
Returns collection of currently visible columns.

Returns:
collection of currently visible columns

getAllColumns

public List<IGridColumn<M,I,S>> getAllColumns()
Returns the list of all columns in this grid.

Returns:
list of columns

getSortState

public GridSortState<S> getSortState()
Returns the sort state of this grid.

Returns:
sort state
See Also:
IGridSortState, GridSortState

setTheme

public void setTheme(String theme)
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

public String getTheme()
Returns the theme identifier

Returns:
theme identifier
See Also:
setTheme(String)

onComponentTag

protected void onComponentTag(ComponentTag tag)

Overrides:
onComponentTag in class Component

renderHead

public void renderHead(org.apache.wicket.markup.head.IHeaderResponse response)

Specified by:
renderHead in interface IHeaderContributor
Overrides:
renderHead in class Component

selectItem

public abstract void selectItem(IModel<I> itemModel,
                                boolean selected)
Alters the selection state of item specified by the item model.

Parameters:
itemModel - item model
selected - true if the item should be selected, false otherwise.

selectAllVisibleItems

public abstract 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.


resetSelectedItems

public abstract void resetSelectedItems()
Deselects all items. This method marks all items (not just visible items) as no selected.


isItemSelected

public abstract boolean isItemSelected(IModel<I> itemModel)
Queries whether the item specified by itemModel is currently selected.

Parameters:
itemModel - item model
Returns:
true if the item is selected, false otherwise

getSelectedItems

public abstract Collection<IModel<I>> 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 and TreeGrid.


onItemSelectionChanged

protected void onItemSelectionChanged(IModel<I> item,
                                      boolean newValue)
Invoked when an item selection state has been changed.

Parameters:
item - item model
newValue - true if the item became selected, false otherwise.

getLastClickedColumn

public IGridColumn<M,I,S> getLastClickedColumn()

cleanLastClickedColumn

public void cleanLastClickedColumn()

disableRowClickNotifications

protected boolean disableRowClickNotifications()

onRowPopulated

protected void onRowPopulated(WebMarkupContainer rowComponent)
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

protected void onRowClicked(AjaxRequestTarget target,
                            IModel<I> rowModel)

setClickRowToSelect

public AbstractGrid<M,I,S> setClickRowToSelect(boolean clickRowToSelect)
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:
setClickRowToDeselect(boolean)

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 when setClickRowToSelect(boolean) is set to true.

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

public void setContentHeight(Integer contentHeight,
                             SizeUnit contentSizeUnit)
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 or null is the height should be determined by the actual height (no scrollbar displayed, defalt value)
contentSizeUnit - size unit for the contentHeight

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:
setContentHeight(Integer, SizeUnit)

getContentHeightSizeUnit

public SizeUnit getContentHeightSizeUnit()
Returns the size unit for content height.

Returns:
size unit

findParentRow

public abstract WebMarkupContainer findParentRow(Component child)
Returns the row in DataTable that contains the child component

Parameters:
child -
Returns:

findRowComponent

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

Parameters:
rowModel -
Returns:

markItemDirty

public abstract void markItemDirty(IModel<I> model)
Marks the item from the given model as dirty. Dirty items are updated during Ajax requests when update() 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 to false 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

public void setItemEdit(IModel<I> rowModel,
                        boolean edit)
Sets the edit mode of the row. If selectToEdit is true, this is same as calling selectItem(IModel, boolean).

Parameters:
rowModel - row model
edit - true if the row should be in editable mode, false otherwise.
See Also:
setSelectToEdit(boolean)

isItemEdited

public boolean isItemEdited(IModel<I> rowModel)
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)


Copyright © 2007–2014 inMethod s.r.o.. All rights reserved.