T
- the grid bean typeV
- the column value typepublic static class Grid.Column<T,V> extends AbstractExtension
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Modifier | Constructor and Description |
---|---|
protected |
Column(ValueProvider<T,V> valueProvider,
Renderer<? super V> renderer)
Constructs a new Column configuration with given renderer and value
provider.
|
protected |
Column(ValueProvider<T,V> valueProvider,
ValueProvider<V,P> presentationProvider,
Renderer<? super P> renderer)
Constructs a new Column configuration with given renderer and value
provider.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkColumnIsAttached()
Checks if column is attached and throws an
IllegalStateException if it is not. |
Grid.Column<T,V> |
clearExpandRatio()
Clears the expand ratio for this column.
|
String |
getAssistiveCaption()
Gets the header caption for this column.
|
String |
getCaption()
Gets the header caption for this column.
|
SerializableComparator<T> |
getComparator(SortDirection sortDirection)
Gets the comparator to use with in-memory sorting for this column
when sorting in the given direction.
|
DescriptionGenerator<T> |
getDescriptionGenerator()
Gets the description generator that is used for generating
descriptions for cells.
|
Binder.Binding<T,?> |
getEditorBinding()
Gets the binder binding that is currently used for this column.
|
int |
getExpandRatio()
Returns the column's expand ratio.
|
protected Grid<T> |
getGrid()
Gets the grid that this column belongs to.
|
String |
getHidingToggleCaption()
Gets the caption of the hiding toggle for this column.
|
String |
getId()
Returns the user-defined identifier for this column.
|
double |
getMaximumWidth()
Returns the maximum width for this column.
|
double |
getMinimumWidth()
Return the minimum width for this column.
|
Renderer<?> |
getRenderer()
Gets the Renderer for this Column.
|
Stream<QuerySortOrder> |
getSortOrder(SortDirection direction)
Gets the sort orders to use with back-end sorting for this column
when sorting in the given direction.
|
protected ColumnState |
getState()
Returns the shared state for this connector.
|
protected ColumnState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
StyleGenerator<T> |
getStyleGenerator()
Gets the style generator that is used for generating styles for
cells.
|
ValueProvider<T,V> |
getValueProvider()
Gets the function used to produce the value for data in this column
based on the row item.
|
double |
getWidth()
Returns the width (in pixels).
|
boolean |
isEditable()
Gets whether this Column has a component displayed in Editor or not.
|
boolean |
isHandleWidgetEvents()
Gets whether Grid is handling the events in this Column from
Component and Widgets.
|
boolean |
isHidable()
Returns whether this column can be hidden by the user.
|
boolean |
isHidden()
Returns whether this column is hidden.
|
boolean |
isMinimumWidthFromContent()
Gets whether the width of the contents in the column should be
considered minimum width for this column.
|
boolean |
isResizable()
Returns whether this column can be resized by the user.
|
boolean |
isSortable()
Gets whether sorting is enabled for this column.
|
boolean |
isSortableByUser()
Gets whether the user can actually sort this column.
|
boolean |
isWidthUndefined()
Returns whether this column has an undefined width.
|
protected void |
readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Reads the design attributes for this column from given element.
|
Grid.Column<T,V> |
setAssistiveCaption(String caption)
Sets the header aria-label for this column.
|
Grid.Column<T,V> |
setCaption(String caption)
Sets the header caption for this column.
|
Grid.Column<T,V> |
setComparator(SerializableComparator<T> comparator)
Sets a comparator to use with in-memory sorting with this column.
|
Grid.Column<T,V> |
setDescriptionGenerator(DescriptionGenerator<T> cellDescriptionGenerator)
Sets the description generator that is used for generating
descriptions for cells in this column.
|
Grid.Column<T,V> |
setDescriptionGenerator(DescriptionGenerator<T> cellDescriptionGenerator,
ContentMode tooltipContentMode)
Sets the description generator that is used for generating
descriptions for cells in this column.
|
Grid.Column<T,V> |
setEditable(boolean editable)
Sets whether this Column has a component displayed in Editor or not.
|
Grid.Column<T,V> |
setEditorBinding(Binder.Binding<T,?> binding)
Sets an editor binding for this column.
|
<F,C extends HasValue<F> & Component> |
setEditorComponent(C editorComponent)
Sets a component to use for editing values of this columns in the
editor row.
|
<C extends HasValue<V> & Component> |
setEditorComponent(C editorComponent,
Setter<T,V> setter)
Sets a component and setter to use for editing values of this column
in the editor row.
|
Grid.Column<T,V> |
setExpandRatio(int expandRatio)
Sets the ratio with which the column expands.
|
Grid.Column<T,V> |
setHandleWidgetEvents(boolean handleWidgetEvents)
Sets whether Grid should handle events in this Column from Components
and Widgets rendered by certain Renderers.
|
Grid.Column<T,V> |
setHidable(boolean hidable)
Sets whether this column can be hidden by the user.
|
Grid.Column<T,V> |
setHidden(boolean hidden)
Hides or shows the column.
|
Grid.Column<T,V> |
setHidingToggleCaption(String hidingToggleCaption)
Sets the caption of the hiding toggle for this column.
|
Grid.Column<T,V> |
setId(String id)
Sets the user-defined identifier to map this column.
|
Grid.Column<T,V> |
setMaximumWidth(double pixels)
Sets the maximum width for this column.
|
Grid.Column<T,V> |
setMinimumWidth(double pixels)
Sets the minimum width for this column.
|
Grid.Column<T,V> |
setMinimumWidthFromContent(boolean minimumWidthFromContent)
Sets whether the width of the contents in the column should be
considered minimum width for this column.
|
Grid.Column<T,V> |
setRenderer(Renderer<? super V> renderer)
Sets the Renderer for this Column.
|
<P> Grid.Column<T,V> |
setRenderer(ValueProvider<V,P> presentationProvider,
Renderer<? super P> renderer)
Sets the Renderer for this Column.
|
Grid.Column<T,V> |
setResizable(boolean resizable)
Sets whether this column can be resized by the user.
|
Grid.Column<T,V> |
setSortable(boolean sortable)
Sets whether the user can sort this column or not.
|
Grid.Column<T,V> |
setSortOrderProvider(SortOrderProvider provider)
Sets the sort orders when sorting this column.
|
Grid.Column<T,V> |
setSortProperty(String... properties)
Sets strings describing back end properties to be used when sorting
this column.
|
Grid.Column<T,V> |
setStyleGenerator(StyleGenerator<T> cellStyleGenerator)
Sets the style generator that is used for generating class names for
cells in this column.
|
Grid.Column<T,V> |
setWidth(double pixelWidth)
Sets the width (in pixels).
|
Grid.Column<T,V> |
setWidthUndefined()
Marks the column width as undefined.
|
protected void |
writeDesign(org.jsoup.nodes.Element element,
DesignContext designContext)
Writes the design attributes for this column into given element.
|
extend, getParent, getSupportedParentType, remove, setParent
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isConnectorEnabled, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
protected Column(ValueProvider<T,V> valueProvider, Renderer<? super V> renderer)
valueProvider
- the function to get values from items, not
null
renderer
- the value renderer, not null
protected Column(ValueProvider<T,V> valueProvider, ValueProvider<V,P> presentationProvider, Renderer<? super P> renderer)
For a more complete explanation on presentation provider, see
setRenderer(ValueProvider, Renderer)
.
P
- the presentation typevalueProvider
- the function to get values from items, not
null
presentationProvider
- the function to get presentations from the value of this
column, not null
. For more details, see
setRenderer(ValueProvider, Renderer)
renderer
- the presentation renderer, not null
protected ColumnState getState()
AbstractClientConnector
As a side effect, marks the connector dirty so any changes done to the
state will be sent to the client. Use getState(false)
to avoid
marking the connector as dirty.
getState
in class AbstractClientConnector
protected ColumnState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractClientConnector
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public String getId()
public Grid.Column<T,V> setId(String id)
Grid.getColumn(String)
.
The id is also used as the backend
sort property
for this column if no sort property or sort order
provider has been set for this column.
id
- the identifier stringsetSortProperty(String...)
,
setSortOrderProvider(SortOrderProvider)
public ValueProvider<T,V> getValueProvider()
public Grid.Column<T,V> setSortable(boolean sortable)
setSortable(true)
depends on the
DataProvider
and the defined sort order for this column. When
using an InMemoryDataProvider
sorting can be automatic.sortable
- true
to enable sorting for this column;
false
to disable itpublic boolean isSortable()
true
if the sorting is enabled for this column;
false
if notpublic boolean isSortableByUser()
true
if the column can be sorted by the user;
false
if notpublic Grid.Column<T,V> setAssistiveCaption(String caption)
caption
- the header aria-label, null removes the aria-label from
this columnpublic String getAssistiveCaption()
public Grid.Column<T,V> setCaption(String caption)
caption
- the header caption, not nullpublic String getCaption()
public Grid.Column<T,V> setComparator(SerializableComparator<T> comparator)
setSortProperty(String...)
.comparator
- the comparator to use when sorting data in this columnpublic SerializableComparator<T> getComparator(SortDirection sortDirection)
sortDirection
- the direction this column is sorted bypublic Grid.Column<T,V> setSortProperty(String... properties)
By default, the column id
will be used as the
sort property.
properties
- the array of strings describing backend propertiespublic Grid.Column<T,V> setSortOrderProvider(SortOrderProvider provider)
QuerySortOrder
objects
to describe how to sort by this column.
By default, the column id
will be used as the
sort property.
provider
- the function to use when generating sort orders with the
given directionpublic Stream<QuerySortOrder> getSortOrder(SortDirection direction)
direction
- the sorting directionsetSortProperty(String...)
,
setId(String)
,
setSortOrderProvider(SortOrderProvider)
public Grid.Column<T,V> setStyleGenerator(StyleGenerator<T> cellStyleGenerator)
cellStyleGenerator
- the cell style generator to set, not nullNullPointerException
- if cellStyleGenerator
is null
public StyleGenerator<T> getStyleGenerator()
public Grid.Column<T,V> setDescriptionGenerator(DescriptionGenerator<T> cellDescriptionGenerator)
ContentMode.PREFORMATTED
content mode.cellDescriptionGenerator
- the cell description generator to set, or null
to
remove a previously set generatorsetDescriptionGenerator(DescriptionGenerator, ContentMode)
public Grid.Column<T,V> setDescriptionGenerator(DescriptionGenerator<T> cellDescriptionGenerator, ContentMode tooltipContentMode)
cellDescriptionGenerator
- the cell description generator to set, or null
to
remove a previously set generatortooltipContentMode
- the content mode for tooltipssetDescriptionGenerator(DescriptionGenerator)
public DescriptionGenerator<T> getDescriptionGenerator()
null
if no
generator is setpublic Grid.Column<T,V> setExpandRatio(int expandRatio) throws IllegalStateException
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.
expandRatio
- the expand ratio of this column. 0
to not have it
expand at all. A negative number to clear the expand
value.IllegalStateException
- if the column is no longer attached to any gridsetWidth(double)
public int getExpandRatio()
setExpandRatio(int)
public Grid.Column<T,V> clearExpandRatio() throws IllegalStateException
Equal to calling setExpandRatio(-1)
IllegalStateException
- if the column is no longer attached to any gridpublic double getWidth() throws IllegalStateException
IllegalStateException
- if the column is no longer attached to any gridpublic Grid.Column<T,V> setWidth(double pixelWidth) throws IllegalStateException, IllegalArgumentException
This overrides any configuration set by any of
setExpandRatio(int)
, setMinimumWidth(double)
or
setMaximumWidth(double)
.
pixelWidth
- the new pixel width of the columnIllegalStateException
- if the column is no longer attached to any gridIllegalArgumentException
- thrown if pixel width is less than zeropublic boolean isWidthUndefined()
IllegalStateException
- if the column is no longer attached to any gridpublic Grid.Column<T,V> setWidthUndefined()
public Grid.Column<T,V> setMinimumWidth(double pixels) throws IllegalStateException
This defines the minimum guaranteed pixel width of the column when it is set to expand.
pixels
- the minimum width for the columnIllegalStateException
- if the column is no longer attached to any gridsetExpandRatio(int)
public double getMinimumWidth()
setMinimumWidth(double)
public Grid.Column<T,V> setMinimumWidthFromContent(boolean minimumWidthFromContent) throws IllegalStateException
If this is set to true
(default for backwards
compatibility), then a column will not shrink to smaller than the
width required to show the contents available when calculating the
widths (only the widths of the initially rendered rows are
considered).
If this is set to false
and the column has been set to
expand using #setExpandRatio(int), then the contents of the column
will be ignored when calculating the width, and the column will thus
shrink down to the minimum width defined by #setMinimumWidth(double)
if necessary.
minimumWidthFromContent
- true
to reserve space for all contents,
false
to allow the column to shrink smaller
than the contentsIllegalStateException
- if the column is no longer attached to any gridsetMinimumWidth(double)
public boolean isMinimumWidthFromContent()
true
to reserve space for all contents,
false
to allow the column to shrink smaller than
the contentssetMinimumWidthFromContent(boolean)
public Grid.Column<T,V> setMaximumWidth(double pixels)
This defines the maximum allowed pixel width of the column when it is set to expand.
pixels
- the maximum widthIllegalStateException
- if the column is no longer attached to any gridsetExpandRatio(int)
public double getMaximumWidth()
setMaximumWidth(double)
public Grid.Column<T,V> setResizable(boolean resizable)
resizable
- true
if this column should be resizable,
false
otherwiseIllegalStateException
- if the column is no longer attached to any gridpublic String getHidingToggleCaption()
setHidingToggleCaption(String)
public Grid.Column<T,V> setHidingToggleCaption(String hidingToggleCaption)
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.
hidingToggleCaption
- the text to show in the column hiding togglepublic Grid.Column<T,V> setHidden(boolean hidden)
hidden
- true
to hide the column, false
to showIllegalStateException
- if the column is no longer attached to any gridpublic boolean isHidden()
false
.true
if the column is currently hidden,
false
otherwisepublic Grid.Column<T,V> setHidable(boolean hidable)
hidable
- true
if the column may be hidable by the user
via UI interactionpublic boolean isHidable()
false
.
Note: the column can be programmatically hidden using
setHidden(boolean)
regardless of the returned value.
true
if the user can hide the column,
false
if notpublic boolean isResizable()
true
.
Note: the column can be programmatically resized using
setWidth(double)
and setWidthUndefined()
regardless
of the returned value.
true
if this column is resizable, false
otherwisepublic Grid.Column<T,V> setEditable(boolean editable)
editable
- true
if column is editable; false
if notsetEditorComponent(HasValue, Setter)
,
#setEditorBinding(Binding)
public boolean isEditable()
true
if the column displays an editor component;
false
if notpublic Grid.Column<T,V> setEditorBinding(Binder.Binding<T,?> binding)
Binder.Binding
is used
when a row is in editor mode to define how to populate an editor
component based on the edited row and how to update an item based on
the value in the editor component.
To create a binding to use with a column, define a binding for the
editor binder (grid.getEditor().getBinder()
) using e.g.
Binder.forField(HasValue)
. You can also use
setEditorComponent(HasValue, Setter)
if no validator or
converter is needed for the binding.
The HasValue
that the binding is defined to use must be a
Component
.
binding
- the binding to use for this columnsetEditorComponent(HasValue, Setter)
,
Binder.Binding
,
Grid.getEditor()
,
Editor.getBinder()
public Binder.Binding<T,?> getEditorBinding()
null
if no binding
is configured#setEditorBinding(Binding)
public <C extends HasValue<V> & Component> Grid.Column<T,V> setEditorComponent(C editorComponent, Setter<T,V> setter)
#setEditorBinding(Binding)
to support more complex cases.
Note: The same component cannot be used for multiple columns.
editorComponent
- the editor componentsetter
- a setter that stores the component value in the row item#setEditorBinding(Binding)
,
Grid.getEditor()
,
Binder.bind(HasValue, ValueProvider, Setter)
public <F,C extends HasValue<F> & Component> Grid.Column<T,V> setEditorComponent(C editorComponent)
id
and the Grid
has been created using
Grid.Grid(Class)
or some other way that allows finding
properties based on property names.
This is a shorthand for use in simple cases where no validator or
converter is needed. Use #setEditorBinding(Binding)
to
support more complex cases.
Note: The same component cannot be used for multiple columns.
editorComponent
- the editor component#setEditorBinding(Binding)
,
Grid.getEditor()
,
Binder.bind(HasValue, String)
,
Grid.Grid(Class)
public Grid.Column<T,V> setRenderer(Renderer<? super V> renderer)
renderer
- the new rendererpublic <P> Grid.Column<T,V> setRenderer(ValueProvider<V,P> presentationProvider, Renderer<? super P> renderer)
The presentation provider is a method that takes the value of this column on a single row, and maps that to a value that the renderer accepts. This feature can be used for storing a complex value in a column for editing, but providing a simplified presentation for the user when not editing.
P
- the presentation typepresentationProvider
- the function to get presentations from the value of this
column, not null
renderer
- the new renderer, not null
public Renderer<?> getRenderer()
public Grid.Column<T,V> setHandleWidgetEvents(boolean handleWidgetEvents)
Note: Enabling this feature will for example select
a row when a component is clicked. For example in the case of a
ComboBox
or TextField
it might be problematic as the
component gets re-rendered and might lose focus.
handleWidgetEvents
- true
to handle events; false
to notpublic boolean isHandleWidgetEvents()
true
if handling events; false
if notsetHandleWidgetEvents(boolean)
protected Grid<T> getGrid()
null
if
this column has not yet been associated with any gridprotected void checkColumnIsAttached() throws IllegalStateException
IllegalStateException
if it is not.IllegalStateException
- if the column is no longer attached to any gridprotected void writeDesign(org.jsoup.nodes.Element element, DesignContext designContext)
element
- Element to write attributes intodesignContext
- the design contextprotected void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
design
- Element to read attributes fromdesignContext
- the design contextCopyright © 2018 Vaadin Ltd. All rights reserved.