com.vaadin.ui
Class Grid.Column

java.lang.Object
  extended by com.vaadin.ui.Grid.Column
All Implemented Interfaces:
java.io.Serializable
Enclosing class:
Grid

public static class Grid.Column
extends java.lang.Object
implements java.io.Serializable

A column in the grid. Can be obtained by calling Grid.getColumn(Object propertyId).

See Also:
Serialized Form

Method Summary
protected  void checkColumnIsAttached()
          Checks if column is attached and throws an IllegalStateException if it is not
 Grid.Column clearExpandRatio()
          Clears the expand ratio for this column.
 Converter<?,?> getConverter()
          Returns the converter instance used by this column.
 Field<?> getEditorField()
          Returns the editor field used to edit the properties in this column when the item editor is active.
 int getExpandRatio()
          Returns the column's expand ratio.
 java.lang.String getHeaderCaption()
          Returns the caption of the header.
 java.lang.String getHidingToggleCaption()
          Gets the caption of the hiding toggle for this column.
 double getMaximumWidth()
          Returns the maximum width for this column.
 double getMinimumWidth()
          Return the minimum width for this column.
 java.lang.Object getPropertyId()
          Returns the property id for the backing property of this Column
 Renderer<?> getRenderer()
          Returns the renderer instance used by this column.
 double getWidth()
          Returns the width (in pixels).
 boolean isEditable()
          Returns whether the properties corresponding to this column should be editable when the item editor is active.
 boolean isHidable()
          Is it possible for the the user to hide this column.
 boolean isHidden()
          Is this column hidden.
 boolean isSortable()
          Returns whether the user is able to sort the grid by this column.
protected  void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
          Reads the design attributes for this column from given element.
 Grid.Column setConverter(Converter<?,?> converter)
          Sets the converter used to convert from the property value type to the renderer presentation type.
 Grid.Column setEditable(boolean editable)
          Sets whether the properties corresponding to this column should be editable when the item editor is active.
 Grid.Column setEditorField(Field<?> editor)
          Sets the field component used to edit the properties in this column when the item editor is active.
 Grid.Column setExpandRatio(int expandRatio)
          Sets the ratio with which the column expands.
 Grid.Column setHeaderCaption(java.lang.String caption)
          Sets the caption of the header.
 Grid.Column setHidable(boolean hidable)
          Set whether it is possible for the user to hide this column or not.
 Grid.Column setHidden(boolean hidden)
          Hides or shows the column.
 Grid.Column setHidingToggleCaption(java.lang.String hidingToggleCaption)
          Sets the caption of the hiding toggle for this column.
 Grid.Column setLastFrozenColumn()
          Sets this column as the last frozen column in its grid.
 Grid.Column setMaximumWidth(double pixels)
          Sets the maximum width for this column.
 Grid.Column setMinimumWidth(double pixels)
          Sets the minimum width for this column.
 Grid.Column setRenderer(Renderer<?> renderer)
          Sets the renderer for this column.
<T> Grid.Column
setRenderer(Renderer<T> renderer, Converter<? extends T,?> converter)
          Sets the renderer for this column and the converter used to convert from the property value type to the renderer presentation type.
 Grid.Column setSortable(boolean sortable)
          Sets whether the column should be sortable by the user.
 Grid.Column setWidth(double pixelWidth)
          Sets the width (in pixels).
 Grid.Column setWidthUndefined()
          Marks the column width as undefined meaning that the grid is free to resize the column based on the cell contents and available space in the grid.
 java.lang.String toString()
           
protected  void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
          Writes the design attributes for this column into given element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getPropertyId

public java.lang.Object getPropertyId()
Returns the property id for the backing property of this Column

Returns:
property id

getHeaderCaption

public java.lang.String getHeaderCaption()
                                  throws java.lang.IllegalStateException
Returns the caption of the header. By default the header caption is the property id of the column.

Returns:
the text in the default row of header, null if no default row
Throws:
java.lang.IllegalStateException - if the column no longer is attached to the grid

setHeaderCaption

public Grid.Column setHeaderCaption(java.lang.String caption)
                             throws java.lang.IllegalStateException
Sets the caption of the header. This caption is also used as the hiding toggle caption, unless it is explicitly set via setHidingToggleCaption(String).

Parameters:
caption - the text to show in the caption
Returns:
the column itself
Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid

getHidingToggleCaption

public java.lang.String getHidingToggleCaption()
                                        throws java.lang.IllegalStateException
Gets the caption of the hiding toggle for this column.

Returns:
the caption for the hiding toggle for this column
Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid
Since:
7.5.0
See Also:
setHidingToggleCaption(String)

setHidingToggleCaption

public Grid.Column setHidingToggleCaption(java.lang.String hidingToggleCaption)
                                   throws java.lang.IllegalStateException
Sets the caption of the hiding toggle for this column. Shown in the toggle for this column in the grid's sidebar when the column is hidable.

The default value is null, and in that case the column's header caption is used.

NOTE: setting this to empty string might cause the hiding toggle to not render correctly.

Parameters:
hidingToggleCaption - the text to show in the column hiding toggle
Returns:
the column itself
Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid
Since:
7.5.0

getWidth

public double getWidth()
                throws java.lang.IllegalStateException
Returns the width (in pixels). By default a column is 100px wide.

Returns:
the width in pixels of the column
Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid

setWidth

public Grid.Column setWidth(double pixelWidth)
                     throws java.lang.IllegalStateException,
                            java.lang.IllegalArgumentException
Sets the width (in pixels).

This overrides any configuration set by any of setExpandRatio(int), setMinimumWidth(double) or setMaximumWidth(double).

Parameters:
pixelWidth - the new pixel width of the column
Returns:
the column itself
Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid
java.lang.IllegalArgumentException - thrown if pixel width is less than zero

setWidthUndefined

public Grid.Column setWidthUndefined()
Marks the column width as undefined meaning that the grid is free to resize the column based on the cell contents and available space in the grid.

Returns:
the column itself

checkColumnIsAttached

protected void checkColumnIsAttached()
                              throws java.lang.IllegalStateException
Checks if column is attached and throws an IllegalStateException if it is not

Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid

setLastFrozenColumn

public Grid.Column setLastFrozenColumn()
Sets this column as the last frozen column in its grid.

Returns:
the column itself
Throws:
java.lang.IllegalArgumentException - if the column is no longer attached to any grid
See Also:
Grid.setFrozenColumnCount(int)

setRenderer

public Grid.Column setRenderer(Renderer<?> renderer)
Sets the renderer for this column.

If a suitable converter isn't defined explicitly, the session converter factory is used to find a compatible converter.

Parameters:
renderer - the renderer to use
Returns:
the column itself
Throws:
java.lang.IllegalArgumentException - if no compatible converter could be found
See Also:
VaadinSession.getConverterFactory(), ConverterUtil.getConverter(Class, Class, VaadinSession), setConverter(Converter)

setRenderer

public <T> Grid.Column setRenderer(Renderer<T> renderer,
                                   Converter<? extends T,?> converter)
Sets the renderer for this column and the converter used to convert from the property value type to the renderer presentation type.

Parameters:
renderer - the renderer to use, cannot be null
converter - the converter to use
Returns:
the column itself
Throws:
java.lang.IllegalArgumentException - if the renderer is already associated with a grid column

setConverter

public Grid.Column setConverter(Converter<?,?> converter)
                         throws java.lang.IllegalArgumentException
Sets the converter used to convert from the property value type to the renderer presentation type.

Parameters:
converter - the converter to use, or null to not use any converters
Returns:
the column itself
Throws:
java.lang.IllegalArgumentException - if the types are not compatible

getRenderer

public Renderer<?> getRenderer()
Returns the renderer instance used by this column.

Returns:
the renderer

getConverter

public Converter<?,?> getConverter()
Returns the converter instance used by this column.

Returns:
the converter

setSortable

public Grid.Column 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 - true if the user should be able to sort the column, false otherwise
Returns:
the column itself

isSortable

public boolean isSortable()
Returns whether the user is able to sort the grid by this column.

Returns:
true if the column is sortable by the user, false otherwise

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setExpandRatio

public Grid.Column setExpandRatio(int expandRatio)
                           throws java.lang.IllegalStateException
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, because we have 3 parts total, and this column reserves 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.

Parameters:
expandRatio - the expand ratio of this column. 0 to not have it expand at all. A negative number to clear the expand value.
Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid
See Also:
setWidth(double)

getExpandRatio

public int getExpandRatio()
Returns the column's expand ratio.

Returns:
the column's expand ratio
See Also:
setExpandRatio(int)

clearExpandRatio

public Grid.Column clearExpandRatio()
                             throws java.lang.IllegalStateException
Clears the expand ratio for this column.

Equal to calling setExpandRatio(-1)

Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid

setMinimumWidth

public Grid.Column setMinimumWidth(double pixels)
                            throws java.lang.IllegalStateException
Sets the minimum width for this column.

This defines the minimum guaranteed pixel width of the column when it is set to expand.

Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid
See Also:
setExpandRatio(int)

getMinimumWidth

public double getMinimumWidth()
Return the minimum width for this column.

Returns:
the minimum width for this column
See Also:
setMinimumWidth(double)

setMaximumWidth

public Grid.Column 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.

Parameters:
pixels - the maximum width
Throws:
java.lang.IllegalStateException - if the column is no longer attached to any grid
See Also:
setExpandRatio(int)

getMaximumWidth

public double getMaximumWidth()
Returns the maximum width for this column.

Returns:
the maximum width for this column
See Also:
setMaximumWidth(double)

setEditable

public Grid.Column setEditable(boolean editable)
Sets whether the properties corresponding to this column should be editable when the item editor is active. By default columns are editable.

Values in non-editable columns are currently not displayed when the editor is active, but this will probably change in the future. They are not automatically assigned an editor field and, if one is manually assigned, it is not used. Columns that cannot (or should not) be edited even in principle should be set non-editable.

Parameters:
editable - true if this column should be editable, false otherwise
Returns:
this column
Throws:
java.lang.IllegalStateException - if the editor is currently active
See Also:
Grid.editItem(Object), Grid.isEditorActive()

isEditable

public boolean isEditable()
Returns whether the properties corresponding to this column should be editable when the item editor is active.

Returns:
true if this column is editable, false otherwise
See Also:
Grid.editItem(Object), setEditable(boolean)

setEditorField

public Grid.Column setEditorField(Field<?> editor)
Sets the field component used to edit the properties in this column when the item editor is active. If an item has not been set, then the binding is postponed until the item is set using Grid.editItem(Object).

Setting the field to null clears any previously set field, causing a new field to be created the next time the item editor is opened.

Parameters:
editor - the editor field
Returns:
this column

getEditorField

public Field<?> getEditorField()
Returns the editor field used to edit the properties in this column when the item editor is active. Returns null if the column is not editable.

When editItem is called, fields are automatically created and bound for any unbound properties.

Getting a field before the editor has been opened depends on special support from the FieldGroup in use. Using this method with a user-provided FieldGroup might cause BindException to be thrown.

Returns:
the bound field; or null if the respective column is not editable
Throws:
java.lang.IllegalArgumentException - if there is no column for the provided property id
FieldGroup.BindException - if no field has been configured and there is a problem building or binding

setHidden

public Grid.Column setHidden(boolean hidden)
Hides or shows the column. By default columns are visible before explicitly hiding them.

Parameters:
hidden - true to hide the column, false to show
Returns:
this column
Since:
7.5.0

isHidden

public boolean isHidden()
Is this column hidden. Default is false.

Returns:
true if the column is currently hidden, false otherwise
Since:
7.5.0

setHidable

public Grid.Column setHidable(boolean hidable)
Set whether it is possible for the user to hide this column or not. Default is false.

Note: it is still possible to hide the column programmatically using setHidden(boolean)

Parameters:
hidable - true iff the column may be hidable by the user via UI interaction
Returns:
this column
Since:
7.5.0

isHidable

public boolean isHidable()
Is it possible for the the user to hide this column. Default is false.

Note: the column can be programmatically hidden using setHidden(boolean) regardless of the returned value.

Returns:
true if the user can hide the column, false if not
Since:
7.5.0

writeDesign

protected void writeDesign(org.jsoup.nodes.Element design,
                           DesignContext designContext)
Writes the design attributes for this column into given element.

Parameters:
design - Element to write attributes into
designContext - the design context
Since:
7.5.0

readDesign

protected void readDesign(org.jsoup.nodes.Element design,
                          DesignContext designContext)
Reads the design attributes for this column from given element.

Parameters:
design - Element to read attributes from
designContext - the design context
Since:
7.5.0


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.