Package com.inmethod.grid.column
Class AbstractColumn<M,I,S>
- java.lang.Object
-
- com.inmethod.grid.column.AbstractColumn<M,I,S>
-
- Type Parameters:
M
- grid model object typeI
- row/item model object type
- All Implemented Interfaces:
IGridColumn<M,I,S>
,Serializable
,IDetachable
,IClusterable
- Direct Known Subclasses:
AbstractLightWeightColumn
,BaseTreeColumn
,CheckBoxColumn
,LinkColumn
,SubmitCancelColumn
,WicketColumnAdapter
public abstract class AbstractColumn<M,I,S> extends Object implements IGridColumn<M,I,S>
Convenience implementation ofIGridColumn
. 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
Constructors Constructor Description AbstractColumn(String columnId, IModel<String> headerModel)
Creates instance with specified column id and header modelAbstractColumn(String columnId, IModel<String> headerModel, S sortProperty)
Creates instance with specified column id, header model and sort property.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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,S>
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 tooltipString
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.S
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 anIRenderable
implementation.boolean
isReorderable()
boolean
isResizable()
Returns whether user will be able to resize this column.abstract Component
newCell(WebMarkupContainer parent, String componentId, IModel<I> rowModel)
Creates a new cell component.IRenderable<I>
newCell(IModel<I> rowModel)
Creates a newIRenderable
instance that is used to render to render the output of cell for given row.Component
newHeader(String componentId)
Creates a new component for column header.void
setGrid(AbstractGrid<M,I,S> grid)
Invoked before the first render of the grid.AbstractColumn<M,I,S>
setHeaderTooltipModel(IModel<String> headerTooltipModel)
Sets the model for header tooltip.AbstractColumn<M,I,S>
setInitialSize(int initialSize)
Sets the initial size for this column.AbstractColumn<M,I,S>
setMaxSize(int maxSize)
Sets the maximal size of this column.AbstractColumn<M,I,S>
setMinSize(int minSize)
Sets the minimal size of this column.AbstractColumn<M,I,S>
setReorderable(boolean reorderable)
Sets whether the user will be able to drag and reorder this column (true by default).AbstractColumn<M,I,S>
setResizable(boolean resizable)
Sets whether the user will be able to resize this column (true by default).AbstractColumn<M,I,S>
setSizeUnit(SizeUnit sizeUnit)
Sets the size unit for this column.AbstractColumn<M,I,S>
setWrapText(boolean wrapText)
Sets whether the text in column will be wrapped when it is too long to fit the column (false
by default).
-
-
-
Constructor Detail
-
AbstractColumn
public AbstractColumn(String columnId, IModel<String> headerModel, S sortProperty)
Creates instance with specified column id, header model and sort property.- Parameters:
columnId
- column identifier - must be unique within the gridheaderModel
- model for column titlesortProperty
- optional string that will be returned byISortState
to indicate that the column is being sorted
-
-
Method Detail
-
setHeaderTooltipModel
public AbstractColumn<M,I,S> 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 interfaceIGridColumn<M,I,S>
- Parameters:
rowModel
- model for given rowrowNum
- index of row forDataGrid
, -1 forTreeGrid
- 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 interfaceIGridColumn<M,I,S>
- 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 interfaceIGridColumn<M,I,S>
- 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 interfaceIGridColumn<M,I,S>
- Returns:
- column identifier
-
setInitialSize
public AbstractColumn<M,I,S> setInitialSize(int initialSize)
Sets the initial size for this column. The unit depends onsetSizeUnit(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 byIGridColumn.getSizeUnit()
.- Specified by:
getInitialSize
in interfaceIGridColumn<M,I,S>
- Returns:
- initial column size
-
setSizeUnit
public AbstractColumn<M,I,S> setSizeUnit(SizeUnit sizeUnit)
Sets the size unit for this column. The default size unit isSizeUnit.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 returnSizeUnit.PX
.- Specified by:
getSizeUnit
in interfaceIGridColumn<M,I,S>
- Returns:
- size unit
-
setMaxSize
public AbstractColumn<M,I,S> setMaxSize(int maxSize)
Sets the maximal size of this column. Only relevant if the column is resizable and the column unit isSizeUnit.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 interfaceIGridColumn<M,I,S>
- Returns:
- maximal size
-
setMinSize
public AbstractColumn<M,I,S> setMinSize(int minSize)
Sets the minimal size of this column. Only relevant if the column is resizable and the column unit isSizeUnit.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 interfaceIGridColumn<M,I,S>
- Returns:
- minimal size
-
getSortProperty
public S 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 throughIGridSortState
.- Specified by:
getSortProperty
in interfaceIGridColumn<M,I,S>
- Returns:
- sort property or
null
if the column is not sortable - See Also:
IGridSortState.ISortStateColumn.getPropertyName()
-
setReorderable
public AbstractColumn<M,I,S> 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()
- Specified by:
isReorderable
in interfaceIGridColumn<M,I,S>
- Returns:
true
if the column is reorderable,false
otherwise
-
setResizable
public AbstractColumn<M,I,S> 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 beSizeUnit.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 returnSizeUnit.PX
, otherwise anIllegalStateException
will be thrown.- Specified by:
isResizable
in interfaceIGridColumn<M,I,S>
- 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 anIRenderable
implementation. Generally, if the cell is non-interactive (label only), it's better to use anIRenderable
implementation, as it has zero memory footprint- Specified by:
isLightWeight
in interfaceIGridColumn<M,I,S>
- 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 interfaceIGridColumn<M,I,S>
- 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 componentsrowModel
- model for given row- Returns:
- new cell component
-
newCell
public IRenderable<I> newCell(IModel<I> rowModel)
Creates a newIRenderable
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)
returnstrue
).- Specified by:
newCell
in interfaceIGridColumn<M,I,S>
- 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 interfaceIGridColumn<M,I,S>
- Parameters:
componentId
- required id that the component must have- Returns:
- Component representing a column header
-
detach
public void detach()
- Specified by:
detach
in interfaceIDetachable
-
setGrid
public void setGrid(AbstractGrid<M,I,S> 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 interfaceIGridColumn<M,I,S>
- Parameters:
grid
- grid that contains this column
-
getGrid
public AbstractGrid<M,I,S> getGrid()
Returns the grid instance associated with this column.- Returns:
- grid instance
-
setWrapText
public AbstractColumn<M,I,S> 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 returnstrue
, the text will be wrapped and row height increased. If the method returnsfalse
, the remaining part of text will be hidden.- Specified by:
getWrapText
in interfaceIGridColumn<M,I,S>
- 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 returnstrue
the default behavior will be suppressed.- Specified by:
cellClicked
in interfaceIGridColumn<M,I,S>
- Parameters:
rowModel
- Model for clicked row- Returns:
true
if the default behavior when row is clicked should be supressed,false
otherwise.
-
-