com.inmethod.grid.column
Class AbstractColumn<M,I>

java.lang.Object
  extended by com.inmethod.grid.column.AbstractColumn<M,I>
Type Parameters:
M - grid model object type
I - row/item model object type
All Implemented Interfaces:
IGridColumn<M,I>, Serializable, IClusterable, IDetachable
Direct Known Subclasses:
AbstractLightWeightColumn, BaseTreeColumn, CheckBoxColumn, LinkColumn, SubmitCancelColumn, WicketColumnAdapter

public abstract class AbstractColumn<M,I>
extends Object
implements IGridColumn<M,I>

Convenience implementation of IGridColumn. This class should be used as base for non-lightweight columns.

Contains getters and setters for most properties and takes care of the header component. The only method necessary to implement is newCell(WebMarkupContainer, String, IModel).

Author:
Matej Knopp
See Also:
AbstractLightWeightColumn, Serialized Form

Constructor Summary
AbstractColumn(String columnId, IModel<String> headerModel)
          Creates instance with specified column id and header model
AbstractColumn(String columnId, IModel<String> headerModel, String sortProperty)
          Creates instance with specified column id, header model and sort property.
 
Method Summary
 boolean cellClicked(IModel<I> rowModel)
          Allows to override default behavior when a row is clicked.
 void detach()
          
 String getCellCssClass(IModel<I> rowModel, int rowNum)
          Returns the cell specified by rowModel.
 int getColSpan(IModel<I> rowModel)
          Returns the spanning value for cell specified by rowModel.
 AbstractGrid<M,I> getGrid()
          Returns the grid instance associated with this column.
 String getHeaderCssClass()
          Returns the CSS class for this column header.
 IModel<String> getHeaderModel()
          Returns the model for header (caption)
 IModel<String> getHeaderTooltipModel()
          Returns the model for header tooltip
 String getId()
          Returns the column id.
 int getInitialSize()
          Returns the initial size of column.
 int getMaxSize()
          Returns the maximal size of resizable column.
 int getMinSize()
          Returns the minimal size of resizable column.
 SizeUnit getSizeUnit()
          Returns the unit in which sizes are specified.
 String getSortProperty()
          Result of this method determines whether the column is sortable and in case it is, also determines the sort property.
 boolean getWrapText()
          Determines the behavior when there is more text in cell than it fits in it.
 boolean isLightWeight(IModel<I> rowModel)
          Returns whether this column is uses a component for cell in given row (not lightweight) or an IRenderable implementation.
 boolean isReorderable()
          #see IGridColumn.isReorderable()
 boolean isResizable()
          Returns whether user will be able to resize this column.
 IRenderable<I> newCell(IModel<I> rowModel)
          Creates a new IRenderable instance that is used to render to render the output of cell for given row.
abstract  Component newCell(WebMarkupContainer parent, String componentId, IModel<I> rowModel)
          Creates a new cell component.
 Component newHeader(String componentId)
          Creates a new component for column header.
 void setGrid(AbstractGrid<M,I> grid)
          Invoked before the first render of the grid.
 AbstractColumn<M,I> setHeaderTooltipModel(IModel<String> headerTooltipModel)
          Sets the model for header tooltip.
 AbstractColumn<M,I> setInitialSize(int initialSize)
          Sets the initial size for this column.
 AbstractColumn<M,I> setMaxSize(int maxSize)
          Sets the maximal size of this column.
 AbstractColumn<M,I> setMinSize(int minSize)
          Sets the minimal size of this column.
 AbstractColumn<M,I> setReorderable(boolean reorderable)
          Sets whether the user will be able to drag and reorder this column (true by default).
 AbstractColumn<M,I> setResizable(boolean resizable)
          Sets whether the user will be able to resize this column (true by default).
 AbstractColumn<M,I> setSizeUnit(SizeUnit sizeUnit)
          Sets the size unit for this column.
 AbstractColumn<M,I> setWrapText(boolean wrapText)
          Sets whether the text in column will be wrapped when it is too long to fit the column ( false by default).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractColumn

public AbstractColumn(String columnId,
                      IModel<String> headerModel,
                      String sortProperty)
Creates instance with specified column id, header model and sort property.

Parameters:
columnId - column identifier - must be unique within the grid
headerModel - model for column title
sortProperty - optional string that will be returned by ISortState to indicate that the column is being sorted

AbstractColumn

public AbstractColumn(String columnId,
                      IModel<String> headerModel)
Creates instance with specified column id and header model

Parameters:
columnId - column identifier - must be unique within the grid
headerModel - model for column title
Method Detail

setHeaderTooltipModel

public AbstractColumn<M,I> setHeaderTooltipModel(IModel<String> headerTooltipModel)
Sets the model for header tooltip.

Parameters:
headerTooltipModel - model for header tooltip
Returns:
this (useful for method chaining)

getHeaderTooltipModel

public IModel<String> getHeaderTooltipModel()
Returns the model for header tooltip

Returns:
model for header tooltip

getHeaderModel

public IModel<String> getHeaderModel()
Returns the model for header (caption)

Returns:
header model

getCellCssClass

public String getCellCssClass(IModel<I> rowModel,
                              int rowNum)
Returns the cell specified by rowModel. The class is applied to the appropriate <td> element in the grid.

Specified by:
getCellCssClass in interface IGridColumn<M,I>
Parameters:
rowModel - model for given row
rowNum - index of row for DataGrid, -1 for TreeGrid
Returns:
cell style class or null

getColSpan

public int getColSpan(IModel<I> rowModel)
Returns the spanning value for cell specified by rowModel. The cell can span over certain number of adjacent cells. The value determines how many cell will this column take. Values less than 2 mean that no extra spanning will be done.

Specified by:
getColSpan in interface IGridColumn<M,I>
Parameters:
rowModel - model for given row
Returns:
colspan value

getHeaderCssClass

public String getHeaderCssClass()
Returns the CSS class for this column header. The class is applied to the appropriate <th> element in the grid.

Specified by:
getHeaderCssClass in interface IGridColumn<M,I>
Returns:
CSS class for this column header or null

getId

public String getId()
Returns the column id. Each column must have a unique Id. The only allowed characters in a column id are alphanumeric characters, dash, dot and underscore.

Specified by:
getId in interface IGridColumn<M,I>
Returns:
column identifier

setInitialSize

public AbstractColumn<M,I> setInitialSize(int initialSize)
Sets the initial size for this column. The unit depends on setSizeUnit(SizeUnit). By default the unit is pixels.

Parameters:
initialSize - initial size of the column
Returns:
this (useful for method chaining)

getInitialSize

public int getInitialSize()
Returns the initial size of column. The unit is determined by IGridColumn.getSizeUnit().

Specified by:
getInitialSize in interface IGridColumn<M,I>
Returns:
initial column size

setSizeUnit

public AbstractColumn<M,I> setSizeUnit(SizeUnit sizeUnit)
Sets the size unit for this column. The default size unit is SizeUnit.PX.

Parameters:
sizeUnit -
Returns:
this (useful for method chaining)

getSizeUnit

public SizeUnit getSizeUnit()
Returns the unit in which sizes are specified. If the column is resizable, this method must always return SizeUnit.PX.

Specified by:
getSizeUnit in interface IGridColumn<M,I>
Returns:
size unit

setMaxSize

public AbstractColumn<M,I> setMaxSize(int maxSize)
Sets the maximal size of this column. Only relevant if the column is resizable and the column unit is SizeUnit.PX (pixels).

Parameters:
maxSize - maximal column size
Returns:
this (useful for method chaining)

getMaxSize

public int getMaxSize()
Returns the maximal size of resizable column. Return values not greater than zero will be ignored.

Specified by:
getMaxSize in interface IGridColumn<M,I>
Returns:
maximal size

setMinSize

public AbstractColumn<M,I> setMinSize(int minSize)
Sets the minimal size of this column. Only relevant if the column is resizable and the column unit is SizeUnit.PX (pixels).

Parameters:
minSize - minimal column size
Returns:
this (useful for method chaining)

getMinSize

public int getMinSize()
Returns the minimal size of resizable column. Return values not greater than zero will be ignored.

Specified by:
getMinSize in interface IGridColumn<M,I>
Returns:
minimal size

getSortProperty

public String getSortProperty()
Result of this method determines whether the column is sortable and in case it is, also determines the sort property. If the column is sortable and user sorts by it, the sort property can then be obtained through IGridSortState.

Specified by:
getSortProperty in interface IGridColumn<M,I>
Returns:
sort property or null if the column is not sortable
See Also:
IGridSortState.ISortStateColumn.getPropertyName()

setReorderable

public AbstractColumn<M,I> setReorderable(boolean reorderable)
Sets whether the user will be able to drag and reorder this column (true by default).

Parameters:
reorderable - true if the column will be reorderable, false otherwise
Returns:
this (useful for method chaining)

isReorderable

public boolean isReorderable()
#see IGridColumn.isReorderable()

Specified by:
isReorderable in interface IGridColumn<M,I>
Returns:
true if the column is reorderable, false otherwise

setResizable

public AbstractColumn<M,I> setResizable(boolean resizable)
Sets whether the user will be able to resize this column (true by default). In order for the column to be resizable, the size unit must be SizeUnit.PX.

Parameters:
resizable - true if the column will be resizable, false otherwise
Returns:
this (useful for method chaining)
See Also:
setSizeUnit(SizeUnit)

isResizable

public boolean isResizable()
Returns whether user will be able to resize this column. If the column is resizable, IGridColumn.getSizeUnit() must return SizeUnit.PX, otherwise an IllegalStateException will be thrown.

Specified by:
isResizable in interface IGridColumn<M,I>
Returns:
true if the column is resizable, false otherwise.

isLightWeight

public boolean isLightWeight(IModel<I> rowModel)
Returns whether this column is uses a component for cell in given row (not lightweight) or an IRenderable implementation. Generally, if the cell is non-interactive (label only), it's better to use an IRenderable implementation, as it has zero memory footprint

Specified by:
isLightWeight in interface IGridColumn<M,I>
Parameters:
rowModel - model for given row
Returns:
true if the cell is lightweight, false otherwise

newCell

public abstract Component newCell(WebMarkupContainer parent,
                                  String componentId,
                                  IModel<I> rowModel)
Creates a new cell component. This method is called for rows that are not lightweight ( IGridColumn.isLightWeight(IModel) returns false ).

Specified by:
newCell in interface IGridColumn<M,I>
Parameters:
parent - Parent component. This is passed in only for convenience, the method implementation is not supposed to add the newly created component to the parent.
componentId - required id of newly created components
rowModel - model for given row
Returns:
new cell component

newCell

public IRenderable<I> newCell(IModel<I> rowModel)
Creates a new IRenderable instance that is used to render to render the output of cell for given row. This method is called for rows that are lightweight ( IGridColumn.isLightWeight(IModel) returns true ).

Specified by:
newCell in interface IGridColumn<M,I>
Parameters:
rowModel - model for given row
Returns:
IRenderable instance

newHeader

public Component newHeader(String componentId)
Creates a new component for column header.

Specified by:
newHeader in interface IGridColumn<M,I>
Parameters:
componentId - required id that the component must have
Returns:
Component representing a column header

detach

public void detach()

Specified by:
detach in interface IDetachable

setGrid

public void setGrid(AbstractGrid<M,I> grid)
Invoked before the first render of the grid. Column that need grid reference can implement this method and store the reference.

Specified by:
setGrid in interface IGridColumn<M,I>
Parameters:
grid - grid that contains this column

getGrid

public AbstractGrid<M,I> getGrid()
Returns the grid instance associated with this column.

Returns:
grid instance

setWrapText

public AbstractColumn<M,I> setWrapText(boolean wrapText)
Sets whether the text in column will be wrapped when it is too long to fit the column ( false by default).

Parameters:
wrapText - true if the text will be wrapped, false otherwise.
Returns:
this (useful for method chaining)

getWrapText

public boolean getWrapText()
Determines the behavior when there is more text in cell than it fits in it. If the method returns true, the text will be wrapped and row height increased. If the method returns false, the remaining part of text will be hidden.

Specified by:
getWrapText in interface IGridColumn<M,I>
Returns:
whether this colulmn's text should wrap or not

cellClicked

public boolean cellClicked(IModel<I> rowModel)
Allows to override default behavior when a row is clicked. Depending on grid settings the default behavior can select the item. If this method returns true the default behavior will be suppressed.

Specified by:
cellClicked in interface IGridColumn<M,I>
Parameters:
rowModel - Model for clicked row
Returns:
true if the default behavior when row is clicked should be supressed, false otherwise.


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