Class Grid.Column<C,T>
- java.lang.Object
-
- com.vaadin.v7.client.widgets.Grid.Column<C,T>
-
- Type Parameters:
C- the column typeT- the row type
- Direct Known Subclasses:
Grid.SelectionColumn
public abstract static class Grid.Column<C,T> extends Object
Base class for grid columns internally used by the Grid. The user should useGrid.Columnwhen creating new columns.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleaneditableThe editable state of this column.protected intexpandRatioThe expand ratio of this column.protected StringheaderCaptionThe header-caption of this column.protected booleanhidableThe hidable state of this column.protected booleanhiddenThe hidden state of this column.protected StringhidingToggleCaptionThe hiding-toggle-caption of this column.protected doublemaximumWidthPxThe maximum width in pixels of this column.protected doubleminimumWidthPxThe minimum width in pixels of this column.protected booleanresizableThe resizable state of this column.protected booleansortableThe sortable state of this column.protected doublewidthUserWidth of column in pixels assetWidth(double)has been called.
-
Constructor Summary
Constructors Constructor Description Column()Constructs a new column with a simple TextRenderer.Column(Renderer<? super C> renderer)Constructs a new column with a custom renderer.Column(String caption)Constructs a new column with a simple TextRenderer.Column(String caption, Renderer<? super C> renderer)Constructs a new column with a custom renderer.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Grid.Column<C,T>clearExpandRatio()Clears the column's expand ratio.intgetExpandRatio()Gets the expand ratio for this column.StringgetHeaderCaption()Returns the current header caption for this column.StringgetHidingToggleCaption()Gets the hiding toggle caption for this column.doublegetMaximumWidth()Gets the maximum width for this column.doublegetMinimumWidth()Gets the minimum width for this column.Renderer<? super C>getRenderer()The renderer to render the cell with.abstract CgetValue(T row)Returns the data that should be rendered into the cell.doublegetWidth()Returns the pixel width of the column as given by the user.doublegetWidthActual()Returns the effective pixel width of the column.booleanisEditable()Returns whether the values in this column are editable by the user when the row editor is active.booleanisHidable()Is it possible for the the user to hide this column.booleanisHidden()Returns whether this column is hidden.booleanisResizable()Returns whether this column can be resized by the user.booleanisSortable()Returns whether the user can sort the grid by this column.protected voidsetDefaultHeaderContent(Grid.HeaderCell cell)Resets the default header cell contents to column header captions.Grid.Column<C,T>setEditable(boolean editable)Sets whether the values in this column should be editable by the user when the row editor is active.Grid.Column<C,T>setExpandRatio(int ratio)Sets the ratio with which the column expands.Grid.Column<C,T>setHeaderCaption(String caption)Sets a header caption for this column.Grid.Column<C,T>setHidable(boolean hidable)Set whether it is possible for the user to hide this column or not.Grid.Column<C,T>setHidden(boolean hidden)Hides or shows the column.Grid.Column<C,T>setHidingToggleCaption(String hidingToggleCaption)Sets the hiding toggle's caption for this column.Grid.Column<C,T>setMaximumWidth(double pixels)Sets the maximum width for this column.Grid.Column<C,T>setMinimumWidth(double pixels)Sets the minimum width for this column.Grid.Column<C,T>setRenderer(Renderer<? super C> renderer)Sets a customRendererfor this column.Grid.Column<C,T>setResizable(boolean resizable)Sets whether this column can be resized by the user.Grid.Column<C,T>setSortable(boolean sortable)Sets whether the column should be sortable by the user.Grid.Column<C,T>setWidth(double pixels)Sets the pixel width of the column.StringtoString()
-
-
-
Field Detail
-
widthUser
protected double widthUser
Width of column in pixels assetWidth(double)has been called.
-
sortable
protected boolean sortable
The sortable state of this column.
-
editable
protected boolean editable
The editable state of this column.
-
resizable
protected boolean resizable
The resizable state of this column.
-
hidden
protected boolean hidden
The hidden state of this column.
-
hidable
protected boolean hidable
The hidable state of this column.
-
headerCaption
protected String headerCaption
The header-caption of this column.
-
hidingToggleCaption
protected String hidingToggleCaption
The hiding-toggle-caption of this column.
-
minimumWidthPx
protected double minimumWidthPx
The minimum width in pixels of this column.
-
maximumWidthPx
protected double maximumWidthPx
The maximum width in pixels of this column.
-
expandRatio
protected int expandRatio
The expand ratio of this column.
-
-
Constructor Detail
-
Column
public Column()
Constructs a new column with a simple TextRenderer.
-
Column
public Column(String caption) throws IllegalArgumentException
Constructs a new column with a simple TextRenderer.- Parameters:
caption- The header caption for this column- Throws:
IllegalArgumentException- if given header caption is null
-
Column
public Column(Renderer<? super C> renderer) throws IllegalArgumentException
Constructs a new column with a custom renderer.- Parameters:
renderer- The renderer to use for rendering the cells- Throws:
IllegalArgumentException- if given Renderer is null
-
Column
public Column(String caption, Renderer<? super C> renderer) throws IllegalArgumentException
Constructs a new column with a custom renderer.- Parameters:
renderer- The renderer to use for rendering the cellscaption- The header caption for this column- Throws:
IllegalArgumentException- if given Renderer or header caption is null
-
-
Method Detail
-
setHeaderCaption
public Grid.Column<C,T> setHeaderCaption(String caption)
Sets a header caption for this column.- Parameters:
caption- The header caption for this column- Returns:
- the column itself
-
getHeaderCaption
public String getHeaderCaption()
Returns the current header caption for this column.- Returns:
- the header caption string
- Since:
- 7.6
-
getValue
public abstract C getValue(T row)
Returns the data that should be rendered into the cell. By default returning Strings and Widgets are supported. If the return type is a String then it will be treated as preformatted text.To support other types you will need to pass a custom renderer to the column via the column constructor.
- Parameters:
row- The row object that provides the cell content.- Returns:
- The cell content
-
getRenderer
public Renderer<? super C> getRenderer()
The renderer to render the cell with. By default renders the data as a String or adds the widget into the cell if the column type is of widget type.- Returns:
- The renderer to render the cell content with
-
setRenderer
public Grid.Column<C,T> setRenderer(Renderer<? super C> renderer) throws IllegalArgumentException
Sets a customRendererfor this column.- Parameters:
renderer- The renderer to use for rendering the cells- Returns:
- the column itself
- Throws:
IllegalArgumentException- if given Renderer is null
-
setWidth
public Grid.Column<C,T> setWidth(double pixels)
Sets the pixel width of the column. Use a negative value for the grid to autosize column based on content and available space.This action is done "finally", once the current execution loop returns. This is done to reduce overhead of unintentionally always recalculate all columns, when modifying several columns at once.
If the column is currently
hidden, then this set width has effect only once the column has been made visible again.- Parameters:
pixels- the width in pixels or negative for auto sizing
-
getWidth
public double getWidth()
Returns the pixel width of the column as given by the user.Note: If a negative value was given to
setWidth(double), that same negative value is returned here.Note: Returns the value, even if the column is currently
hidden.- Returns:
- pixel width of the column, or a negative number if the column width has been automatically calculated.
- See Also:
setWidth(double),getWidthActual()
-
getWidthActual
public double getWidthActual()
Returns the effective pixel width of the column.This differs from
getWidth()only when the column has been automatically resized, or when the column is currentlyhidden, when the value is 0.- Returns:
- pixel width of the column.
-
setSortable
public Grid.Column<C,T> setSortable(boolean sortable)
Sets whether the column should be sortable by the user. The grid can be sorted by a sortable column by clicking or tapping the column's default header. Programmatic sorting using the Grid#sort methods is not affected by this setting.- Parameters:
sortable-trueif the user should be able to sort the column,falseotherwise- Returns:
- the column itself
-
isSortable
public boolean isSortable()
Returns whether the user can sort the grid by this column.Note: it is possible to sort by this column programmatically using the Grid#sort methods regardless of the returned value.
- Returns:
trueif the column is sortable by the user,falseotherwise
-
setResizable
public Grid.Column<C,T> setResizable(boolean resizable)
Sets whether this column can be resized by the user.- Parameters:
resizable-trueif this column should be resizable,falseotherwise- Since:
- 7.6
-
isResizable
public boolean isResizable()
Returns whether this column can be resized by the user. Default istrue.Note: the column can be programmatically resized using
setWidth(double)and#setWidthUndefined()regardless of the returned value.- Returns:
trueif this column is resizable,falseotherwise- Since:
- 7.6
-
setHidden
public Grid.Column<C,T> setHidden(boolean hidden)
Hides or shows the column. By default columns are visible before explicitly hiding them.- Parameters:
hidden-trueto hide the column,falseto show- Since:
- 7.5.0
-
isHidden
public boolean isHidden()
Returns whether this column is hidden. Default isfalse.- Returns:
trueif the column is currently hidden,falseotherwise- Since:
- 7.5.0
-
setHidable
public Grid.Column<C,T> setHidable(boolean hidable)
Set whether it is possible for the user to hide this column or not. Default isfalse.Note: it is still possible to hide the column programmatically using
setHidden(boolean).- Parameters:
hidable-truethe user can hide this column,falseotherwise- Since:
- 7.5.0
-
isHidable
public boolean isHidable()
Is it possible for the the user to hide this column. Default isfalse.Note: the column can be programmatically hidden using
setHidden(boolean)regardless of the returned value.- Returns:
trueif the user can hide the column,falseif not- Since:
- 7.5.0
-
setHidingToggleCaption
public Grid.Column<C,T> setHidingToggleCaption(String hidingToggleCaption)
Sets the hiding toggle's caption for this column. Shown in the toggle for this column in the grid's sidebar when the column ishidable.The default value is
null. In this case the header caption is used, seesetHeaderCaption(String).- Parameters:
hidingToggleCaption- the caption for the hiding toggle for this column- Since:
- 7.5.0
-
getHidingToggleCaption
public String getHidingToggleCaption()
Gets the hiding toggle caption for this column.- Returns:
- the hiding toggle's caption for this column
- Since:
- 7.5.0
- See Also:
setHidingToggleCaption(String)
-
setMinimumWidth
public Grid.Column<C,T> setMinimumWidth(double pixels)
Sets the minimum width for this column.This defines the minimum guaranteed pixel width of the column when it is set to expand.
This action is done "finally", once the current execution loop returns. This is done to reduce overhead of unintentionally always recalculate all columns, when modifying several columns at once.
- Parameters:
pixels- the minimum width- Returns:
- this column
-
setMaximumWidth
public Grid.Column<C,T> setMaximumWidth(double pixels)
Sets the maximum width for this column.This defines the maximum allowed pixel width of the column when it is set to expand.
This action is done "finally", once the current execution loop returns. This is done to reduce overhead of unintentionally always recalculate all columns, when modifying several columns at once.
- Parameters:
pixels- the maximum width- Returns:
- this column
-
setExpandRatio
public Grid.Column<C,T> setExpandRatio(int ratio)
Sets the ratio with which the column expands.By default, all columns expand equally (treated as if all of them had an expand ratio of 1). Once at least one column gets a defined expand ratio, the implicit expand ratio is removed, and only the defined expand ratios are taken into account.
If a column has a defined width (
setWidth(double)), it overrides this method's effects.Example: A grid with three columns, with expand ratios 0, 1 and 2, respectively. The column with a ratio of 0 is exactly as wide as its contents requires. The column with a ratio of 1 is as wide as it needs, plus a third of any excess space, bceause we have 3 parts total, and this column reservs only one of those. The column with a ratio of 2, is as wide as it needs to be, plus two thirds of the excess width.
This action is done "finally", once the current execution loop returns. This is done to reduce overhead of unintentionally always recalculate all columns, when modifying several columns at once.
- Parameters:
ratio- the expand ratio of this column.0to not have it expand at all. A negative number to clear the expand value.- Returns:
- this column
-
clearExpandRatio
public Grid.Column<C,T> clearExpandRatio()
Clears the column's expand ratio.Same as calling
setExpandRatio(-1)- Returns:
- this column
-
getMinimumWidth
public double getMinimumWidth()
Gets the minimum width for this column.- Returns:
- the minimum width for this column
- See Also:
setMinimumWidth(double)
-
getMaximumWidth
public double getMaximumWidth()
Gets the maximum width for this column.- Returns:
- the maximum width for this column
- See Also:
setMaximumWidth(double)
-
getExpandRatio
public int getExpandRatio()
Gets the expand ratio for this column.- Returns:
- the expand ratio for this column
- See Also:
setExpandRatio(int)
-
setEditable
public Grid.Column<C,T> setEditable(boolean editable)
Sets whether the values in this column should be editable by the user when the row editor is active. By default columns are editable.- Parameters:
editable-trueto set this column editable,falseotherwise- Returns:
- this column
- Throws:
IllegalStateException- if the editor is currently active- See Also:
Grid.editRow(int),Grid.isEditorActive()
-
isEditable
public boolean isEditable()
Returns whether the values in this column are editable by the user when the row editor is active.- Returns:
trueif this column is editable,falseotherwise- See Also:
setEditable(boolean)
-
setDefaultHeaderContent
protected void setDefaultHeaderContent(Grid.HeaderCell cell)
Resets the default header cell contents to column header captions.- Parameters:
cell- default header cell for this column- Since:
- 7.5.1
-
-