public class Grid extends AbstractFocusable implements SelectionEvent.SelectionNotifier, SortEvent.SortNotifier, SelectiveRenderer, ItemClickEvent.ItemClickNotifier
Grid is always bound to a Container.Indexed
, but is not a
Container
of any kind in of itself. The contents of the given
Container is displayed with the help of Renderers
.
Each column has its own Renderer
that displays data into something
that can be displayed in the browser. That data is first converted with a
Converter
into something that the Renderer can process. This can also
be an implicit step - if a column has a simple data type, like a String, no
explicit assignment is needed.
Usually a renderer takes some kind of object, and converts it into a HTML-formatted string.
Grid grid = new Grid(myContainer);
Column column = grid.getColumn(STRING_DATE_PROPERTY);
column.setConverter(new StringToDateConverter());
column.setRenderer(new MyColorfulDateRenderer());
The data is accessed as it is needed by Grid and not any sooner. In other words, if the given Container is huge, but only the first few rows are displayed to the user, only those (and a few more, for caching purposes) are accessed.
Grid supports three selection modes
(single,
multi, none), and comes bundled with one model
for each of the modes. The distinction between a selection mode
and selection model is as follows: a mode essentially says whether
you can have one, many or no rows selected. The model, however, has the
behavioral details of each. A single selection model may require that the
user deselects one row before selecting another one. A variant of a
multiselect might have a configurable maximum of rows that may be selected.
And so on.
Grid grid = new Grid(myContainer);
// uses the bundled SingleSelectionModel class
grid.setSelectionMode(SelectionMode.SINGLE);
// changes the behavior to a custom selection model
grid.setSelectionModel(new MyTwoSelectionModel());
Modifier and Type | Class and Description |
---|---|
static class |
Grid.AbstractGridExtension
An abstract base class for server-side Grid extensions.
|
static class |
Grid.AbstractRenderer<T>
An abstract base class for server-side
Grid renderers . |
static class |
Grid.AbstractSelectionModel
A base class for SelectionModels that contains some of the logic that is
reusable.
|
static interface |
Grid.CellDescriptionGenerator
A callback interface for generating optional descriptions (tooltips) for
Grid cells.
|
static class |
Grid.CellReference
A data class which contains information which identifies a cell in a
Grid . |
static interface |
Grid.CellStyleGenerator
A callback interface for generating custom style names for Grid cells.
|
static class |
Grid.Column
A column in the grid.
|
static class |
Grid.ColumnReorderEvent
An event that is fired when the columns are reordered.
|
static interface |
Grid.ColumnReorderListener
An event listener for column reorder events in the Grid.
|
static class |
Grid.ColumnResizeEvent
An event that is fired when a column is resized, either programmatically
or by the user.
|
static interface |
Grid.ColumnResizeListener
An event listener for column resize events in the Grid.
|
static class |
Grid.ColumnVisibilityChangeEvent
An event that is fired when a column's visibility changes.
|
static interface |
Grid.ColumnVisibilityChangeListener
An event listener for column visibility change events in the Grid.
|
static class |
Grid.CommitErrorEvent
An event which is fired when saving the editor fails
|
class |
Grid.DefaultEditorErrorHandler
Default error handler for the editor
|
static class |
Grid.DetailComponentManager
A class that manages details components by calling
Grid.DetailsGenerator as needed. |
static interface |
Grid.DetailsGenerator
A callback interface for generating details for a particular row in Grid.
|
static class |
Grid.EditorCloseEvent
This event gets fired when an editor is dismissed or closed by other
means.
|
static interface |
Grid.EditorErrorHandler
Error handler for the editor
|
static class |
Grid.EditorEvent
Base class for editor related events
|
static class |
Grid.EditorFieldFactory
Field factory used by default in the editor.
|
static interface |
Grid.EditorListener
Interface for an editor event listener
|
static class |
Grid.EditorMoveEvent
This event gets fired when an editor is opened while another row is being
edited (i.e.
|
static class |
Grid.EditorOpenEvent
This event gets fired when an editor is opened
|
protected static class |
Grid.Footer
Represents the footer section of a Grid.
|
static class |
Grid.FooterCell
Represents a footer cell in Grid.
|
static class |
Grid.FooterRow
Represents a footer row in Grid.
|
static class |
Grid.GridContextClickEvent
ContextClickEvent for the Grid Component.
|
protected static class |
Grid.Header
Represents the header section of a Grid.
|
static class |
Grid.HeaderCell
Represents a header cell in Grid.
|
static class |
Grid.HeaderRow
Represents a header row in Grid.
|
static class |
Grid.MultiSelectionModel
A default implementation of a
Grid.SelectionModel.Multi |
static class |
Grid.NoSelectionModel
A default implementation for a
Grid.SelectionModel.None |
static interface |
Grid.RowDescriptionGenerator
A callback interface for generating optional descriptions (tooltips) for
Grid rows.
|
static class |
Grid.RowReference
A data class which contains information which identifies a row in a
Grid . |
static interface |
Grid.RowStyleGenerator
A callback interface for generating custom style names for Grid rows.
|
static class |
Grid.SelectionMode
Selection modes representing built-in
SelectionModels that come bundled with Grid . |
static interface |
Grid.SelectionModel
The server-side interface that controls Grid's selection state.
|
static class |
Grid.SingleSelectionModel
A default implementation of a
Grid.SelectionModel.Single |
static class |
Grid.StaticSection<ROWTYPE extends Grid.StaticSection.StaticRow<?>>
Abstract base class for Grid header and footer sections.
|
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
Grid()
Creates a new Grid with a new
IndexedContainer as the data
source. |
Grid(Container.Indexed dataSource)
Creates a new Grid using the given data source.
|
Grid(String caption)
Creates a new Grid with the given caption and a new
IndexedContainer data source. |
Grid(String caption,
Container.Indexed dataSource)
Creates a new Grid with the given caption and data source.
|
Modifier and Type | Method and Description |
---|---|
Grid.Column |
addColumn(Object propertyId)
Adds a new Column to Grid.
|
Grid.Column |
addColumn(Object propertyId,
Class<?> type)
Adds a new Column to Grid.
|
protected void |
addColumnProperty(Object propertyId,
Class<?> type,
Object defaultValue) |
void |
addColumnReorderListener(Grid.ColumnReorderListener listener)
Registers a new column reorder listener.
|
void |
addColumnResizeListener(Grid.ColumnResizeListener listener)
Registers a new column resize listener.
|
void |
addColumnVisibilityChangeListener(Grid.ColumnVisibilityChangeListener listener)
Registers a new column visibility change listener
|
Grid.FooterRow |
addFooterRowAt(int index)
Inserts a new row at the given position to the footer section.
|
Grid.HeaderRow |
addHeaderRowAt(int index)
Inserts a new row at the given position to the header section.
|
void |
addItemClickListener(ItemClickEvent.ItemClickListener listener)
Register a listener to handle
ItemClickEvent s. |
void |
addListener(ItemClickEvent.ItemClickListener listener)
Deprecated.
|
Object |
addRow(Object... values)
Adds a row to the underlying container.
|
void |
addSelectionListener(SelectionEvent.SelectionListener listener)
Registers a new selection listener
|
void |
addSortListener(SortEvent.SortListener listener)
Adds a sort order change listener that gets notified when the sort order
changes.
|
Grid.FooterRow |
appendFooterRow()
Adds a new row at the bottom of the footer section.
|
Grid.HeaderRow |
appendHeaderRow()
Adds a new row at the bottom of the header section.
|
void |
beforeClientResponse(boolean initial)
Called before the shared state and RPC invocations are sent to the
client.
|
void |
cancelEditor()
Cancels the currently active edit if any.
|
void |
clearSortOrder()
Clear the current sort order, and re-sort the grid.
|
boolean |
deselect(Object itemId)
Marks an item as unselected.
|
boolean |
deselectAll()
Marks all items as unselected.
|
protected void |
doCancelEditor() |
protected void |
doEditItem() |
void |
editItem(Object itemId)
Opens the editor interface for the provided item.
|
void |
fireSelectionEvent(Collection<Object> oldSelection,
Collection<Object> newSelection)
Fires a selection change event.
|
ContentMode |
getCellDescriptionContentMode()
Gets the content mode used for cell descriptions.
|
Grid.CellDescriptionGenerator |
getCellDescriptionGenerator()
Returns the
CellDescriptionGenerator instance used to generate
descriptions (tooltips) for Grid cells. |
Grid.CellStyleGenerator |
getCellStyleGenerator()
Gets the style generator that is used for generating styles for cells
|
Grid.Column |
getColumn(Object propertyId)
Returns a column based on the property id
|
ColumnResizeMode |
getColumnResizeMode()
Returns the current column resize mode.
|
List<Grid.Column> |
getColumns()
Returns a copy of currently configures columns in their current visual
order in this Grid.
|
Container.Indexed |
getContainerDataSource()
Returns the grid data source.
|
protected Collection<String> |
getCustomAttributes()
Returns a collection of attributes that should not be handled by the
basic implementation of the
readDesign and writeDesign
methods. |
Grid.HeaderRow |
getDefaultHeaderRow()
Returns the current default row of the header section.
|
Grid.DetailsGenerator |
getDetailsGenerator()
Gets the current details generator for row details.
|
Object |
getEditedItemId()
Gets the id of the item that is currently being edited.
|
String |
getEditorCancelCaption()
Gets the current caption of the cancel button in the Grid editor.
|
Grid.EditorErrorHandler |
getEditorErrorHandler()
Gets the error handler used for the editor
|
FieldGroupFieldFactory |
getEditorFieldFactory()
Gets the field factory for the
FieldGroup . |
FieldGroup |
getEditorFieldGroup()
Gets the field group that is backing the item editor of this grid.
|
String |
getEditorSaveCaption()
Gets the current caption of the save button in the Grid editor.
|
protected Grid.Footer |
getFooter()
Returns the footer section of this grid.
|
Grid.FooterRow |
getFooterRow(int rowIndex)
Gets the footer row at given index.
|
int |
getFooterRowCount()
Gets the row count for the footer.
|
int |
getFrozenColumnCount()
Gets the number of frozen columns in this grid.
|
protected Grid.Header |
getHeader()
Returns the header section of this grid.
|
Grid.HeaderRow |
getHeaderRow(int rowIndex)
Gets the header row at given index.
|
int |
getHeaderRowCount()
Gets the row count for the header section.
|
double |
getHeightByRows()
Gets the amount of rows in Grid's body that are shown, while
getHeightMode() is HeightMode.ROW . |
HeightMode |
getHeightMode()
Returns the current
HeightMode the Grid is in. |
ContentMode |
getRowDescriptionContentMode()
Gets the content mode used for row descriptions.
|
Grid.RowDescriptionGenerator |
getRowDescriptionGenerator()
Returns the
RowDescriptionGenerator instance used to generate
descriptions (tooltips) for Grid rows |
Grid.RowStyleGenerator |
getRowStyleGenerator()
Gets the style generator that is used for generating styles for rows
|
Object |
getSelectedRow()
Gets the item id of the currently selected item.
|
Collection<Object> |
getSelectedRows()
Returns a collection of all the currently selected itemIds.
|
Grid.SelectionModel |
getSelectionModel()
Returns the currently used
Grid.SelectionModel . |
List<SortOrder> |
getSortOrder()
Get the current sort order list.
|
protected GridState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected GridState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
boolean |
isColumnReorderingAllowed()
Returns whether column reordering is allowed.
|
boolean |
isDetailsVisible(Object itemId)
Checks whether details are visible for the given item.
|
boolean |
isEditorActive()
Returns whether an item is currently being edited in the editor.
|
boolean |
isEditorBuffered()
Gets the buffered editor mode.
|
boolean |
isEditorEnabled()
Checks whether the item editor UI is enabled for this grid.
|
boolean |
isFooterVisible()
Returns the visibility of the footer section.
|
boolean |
isHeaderVisible()
Returns the visibility of the header section.
|
boolean |
isRendered(Component childComponent)
Checks if the child component should be rendered (sent to the client
side).
|
boolean |
isSelected(Object itemId)
Checks whether an item is selected or not.
|
Iterator<Component> |
iterator()
Gets an iterator to the collection of contained components.
|
Grid.FooterRow |
prependFooterRow()
Adds a new row at the top of the footer section.
|
Grid.HeaderRow |
prependHeaderRow()
Adds a new row at the top of the header section.
|
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext context)
Reads the component state from the given design.
|
void |
recalculateColumnWidths()
Requests that the column widths should be recalculated.
|
void |
refreshAllRows()
Refreshes, i.e.
|
void |
refreshRows(Object... itemIds)
Refreshes, i.e.
|
void |
removeAllColumns()
Removes all columns from this Grid.
|
void |
removeColumn(Object propertyId)
Removes a column from Grid based on a property id.
|
void |
removeColumnReorderListener(Grid.ColumnReorderListener listener)
Removes a previously registered column reorder listener.
|
void |
removeColumnResizeListener(Grid.ColumnResizeListener listener)
Removes a previously registered column resize listener.
|
void |
removeColumnVisibilityChangeListener(Grid.ColumnVisibilityChangeListener listener)
Removes a previously registered column visibility change listener
|
void |
removeFooterRow(Grid.FooterRow row)
Removes the given row from the footer section.
|
void |
removeFooterRow(int rowIndex)
Removes the row at the given position from the footer section.
|
void |
removeHeaderRow(Grid.HeaderRow row)
Removes the given row from the header section.
|
void |
removeHeaderRow(int rowIndex)
Removes the row at the given position from the header section.
|
void |
removeItemClickListener(ItemClickEvent.ItemClickListener listener)
Removes an ItemClickListener.
|
void |
removeListener(ItemClickEvent.ItemClickListener listener)
Deprecated.
|
void |
removeSelectionListener(SelectionEvent.SelectionListener listener)
Removes a previously registered selection change listener
|
void |
removeSortListener(SortEvent.SortListener listener)
Removes a sort order change listener previously added using
#addSortListener(SortListener) . |
void |
saveEditor()
Saves all changes done to the bound fields.
|
void |
scrollTo(Object itemId)
Scrolls to a certain item, using
ScrollDestination.ANY . |
void |
scrollTo(Object itemId,
ScrollDestination destination)
Scrolls to a certain item, using user-specified scroll destination.
|
void |
scrollToEnd()
Scrolls to the end of the last data row.
|
void |
scrollToStart()
Scrolls to the beginning of the first data row.
|
boolean |
select(Object itemId)
Marks an item as selected.
|
void |
setCellDescriptionGenerator(Grid.CellDescriptionGenerator generator)
Sets the
CellDescriptionGenerator instance for generating
optional descriptions (tooltips) for individual Grid cells. |
void |
setCellDescriptionGenerator(Grid.CellDescriptionGenerator generator,
ContentMode contentMode)
Sets the
CellDescriptionGenerator instance and content mode for
generating optional descriptions (tooltips) for individual Grid cells. |
void |
setCellStyleGenerator(Grid.CellStyleGenerator cellStyleGenerator)
Sets the style generator that is used for generating styles for cells
|
void |
setColumnOrder(Object... propertyIds)
Sets a new column order for the grid.
|
void |
setColumnReorderingAllowed(boolean columnReorderingAllowed)
Sets whether or not column reordering is allowed.
|
void |
setColumnResizeMode(ColumnResizeMode mode)
Sets the column resize mode to use.
|
void |
setColumns(Object... propertyIds)
Sets the columns and their order for the grid.
|
void |
setContainerDataSource(Container.Indexed container)
Sets the grid data source.
|
void |
setDefaultHeaderRow(Grid.HeaderRow row)
Sets the default row of the header.
|
void |
setDetailsGenerator(Grid.DetailsGenerator detailsGenerator)
Sets a new details generator for row details.
|
void |
setDetailsVisible(Object itemId,
boolean visible)
Shows or hides the details for a specific item.
|
void |
setEditorBuffered(boolean editorBuffered)
Sets the buffered editor mode.
|
void |
setEditorCancelCaption(String cancelCaption)
Sets the caption on the cancel button in the Grid editor.
|
void |
setEditorEnabled(boolean isEnabled)
Sets whether or not the item editor UI is enabled for this grid.
|
void |
setEditorErrorHandler(Grid.EditorErrorHandler editorErrorHandler)
Sets the error handler for the editor.
|
void |
setEditorFieldFactory(FieldGroupFieldFactory fieldFactory)
Sets the field factory for the
FieldGroup . |
void |
setEditorFieldGroup(FieldGroup fieldGroup)
Sets the field group that is backing the item editor of this grid.
|
void |
setEditorSaveCaption(String saveCaption)
Sets the caption on the save button in the Grid editor.
|
void |
setFooterVisible(boolean visible)
Sets the visibility of the footer section.
|
void |
setFrozenColumnCount(int numberOfColumns)
Sets the number of frozen columns in this grid.
|
void |
setHeaderVisible(boolean visible)
Sets the visibility of the header section.
|
void |
setHeight(float height,
Sizeable.Unit unit)
Sets the height of the object.
|
void |
setHeightByRows(double rows)
Sets the number of rows that should be visible in Grid's body, while
getHeightMode() is HeightMode.ROW . |
void |
setHeightMode(HeightMode heightMode)
Defines the mode in which the Grid widget's height is calculated.
|
void |
setRowDescriptionGenerator(Grid.RowDescriptionGenerator generator)
Sets the
RowDescriptionGenerator instance for generating optional
descriptions (tooltips) for Grid rows. |
void |
setRowDescriptionGenerator(Grid.RowDescriptionGenerator generator,
ContentMode contentMode)
Sets the
RowDescriptionGenerator instance for generating optional
descriptions (tooltips) for Grid rows. |
void |
setRowStyleGenerator(Grid.RowStyleGenerator rowStyleGenerator)
Sets the style generator that is used for generating styles for rows
|
Grid.SelectionModel |
setSelectionMode(Grid.SelectionMode selectionMode)
Sets the Grid's selection mode.
|
void |
setSelectionModel(Grid.SelectionModel selectionModel)
Takes a new
Grid.SelectionModel into use. |
void |
setSortOrder(List<SortOrder> order)
Sets the sort order to use.
|
void |
sort(Object propertyId)
Sort this Grid in ascending order by a specified property.
|
void |
sort(Object propertyId,
SortDirection direction)
Sort this Grid in user-specified
SortOrder by a property. |
void |
sort(Sort s)
Sets the current sort order using the fluid Sort API.
|
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext context)
Writes the component state to the given design.
|
addBlurListener, addFocusListener, addListener, addListener, focus, getTabIndex, removeBlurListener, removeFocusListener, removeListener, removeListener, setTabIndex
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
addAttachListener, addDetachListener, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
forEach, spliterator
public Grid()
IndexedContainer
as the data
source.public Grid(Container.Indexed dataSource)
dataSource
- the indexed container to use as a data sourcepublic Grid(String caption)
IndexedContainer
data source.caption
- the caption of the gridpublic Grid(String caption, Container.Indexed dataSource)
IndexedContainer
will be used.caption
- the caption of the griddataSource
- the indexed container to use as a data sourcepublic void beforeClientResponse(boolean initial)
ClientConnector
beforeClientResponse
in interface ClientConnector
beforeClientResponse
in class AbstractComponent
initial
- true
if the client-side connector will be created
and initialized after this method has been invoked.
false
if there is already an initialized
client-side connector.public void setContainerDataSource(Container.Indexed container)
Note Grid columns are based on properties and try to detect a correct converter for the data type. The columns are not reinitialized automatically if the container is changed, and if the same properties are present after container change, the columns are reused. Properties with same names, but different data types will lead to unpredictable behaviour.
container
- The container data source. Cannot be null.IllegalArgumentException
- if the data source is nullpublic Container.Indexed getContainerDataSource()
public Grid.Column getColumn(Object propertyId)
propertyId
- the property id of the columnnull
if not foundpublic List<Grid.Column> getColumns()
public Grid.Column addColumn(Object propertyId) throws IllegalStateException
Note that adding a new property is only done for the default container that Grid sets up with the default constructor.
propertyId
- the property id of the new columnIllegalStateException
- if column for given property already exists in this gridpublic Grid.Column addColumn(Object propertyId, Class<?> type)
Default value for the new property is 0 if type is Integer, Double and Float. If type is String, default value is an empty string. For all other types the default value is null.
Note that adding a new property is only done for the default container that Grid sets up with the default constructor.
propertyId
- the property id of the new columntype
- the data type for the new propertyIllegalStateException
- if column for given property already exists in this grid or
property already exists in the container with wrong typeprotected void addColumnProperty(Object propertyId, Class<?> type, Object defaultValue) throws IllegalStateException
IllegalStateException
public void removeAllColumns()
public boolean isColumnReorderingAllowed()
false
.public void setColumnReorderingAllowed(boolean columnReorderingAllowed)
false
.columnReorderingAllowed
- specifies whether column reordering is allowedprotected GridState getState()
AbstractComponent
getState
in class AbstractFocusable
protected GridState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractFocusable
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void setColumnResizeMode(ColumnResizeMode mode)
ColumnResizeMode.ANIMATED
.mode
- a ColumnResizeMode valuepublic ColumnResizeMode getColumnResizeMode()
ColumnResizeMode.ANIMATED
.public void removeColumn(Object propertyId) throws IllegalArgumentException
propertyId
- The property id of column to be removedIllegalArgumentException
- if there is no column for given property id in this gridpublic void setColumns(Object... propertyIds)
propertyIds
- properties in the desired column orderpublic void setColumnOrder(Object... propertyIds)
propertyIds
- properties in the order columns should bepublic void setFrozenColumnCount(int numberOfColumns)
The default value is 0.
numberOfColumns
- the number of columns that should be frozenIllegalArgumentException
- if the column count is < 0 or > the number of visible columnspublic int getFrozenColumnCount()
NOTE: this count includes hidden
columns
in the count.
setFrozenColumnCount(int)
public void scrollTo(Object itemId) throws IllegalArgumentException
ScrollDestination.ANY
.
If the item has visible details, its size will also be taken into account.
itemId
- id of item to scroll to.IllegalArgumentException
- if the provided id is not recognized by the data source.public void scrollTo(Object itemId, ScrollDestination destination) throws IllegalArgumentException
If the item has visible details, its size will also be taken into account.
itemId
- id of item to scroll to.destination
- value specifying desired position of scrolled-to row.IllegalArgumentException
- if the provided id is not recognized by the data source.public void scrollToStart()
public void scrollToEnd()
public void setHeightByRows(double rows)
getHeightMode()
is HeightMode.ROW
.
If Grid is currently not in HeightMode.ROW
, the given value is
remembered, and applied once the mode is applied.
rows
- The height in terms of number of rows displayed in Grid's
body. If Grid doesn't contain enough rows, white space is
displayed instead. If null
is given, then Grid's
height is undefinedIllegalArgumentException
- if rows
is zero or lessIllegalArgumentException
- if rows
is infinite
IllegalArgumentException
- if rows
is NaN
public double getHeightByRows()
getHeightMode()
is HeightMode.ROW
.setHeightByRows(double)
public void setHeight(float height, Sizeable.Unit unit)
Note: This method will change the widget's size in the browser
only if getHeightMode()
returns HeightMode.CSS
.
setHeight
in interface Sizeable
setHeight
in class AbstractComponent
height
- the height of the object.unit
- the unit used for the width.setHeightMode(HeightMode)
public void setHeightMode(HeightMode heightMode)
If HeightMode.CSS
is given, Grid will respect the values given
via a setHeight
-method, and behave as a traditional Component.
If HeightMode.ROW
is given, Grid will make sure that the body
will display as many rows as getHeightByRows()
defines.
Note: If headers/footers are inserted or removed, the widget
will resize itself to still display the required amount of rows in its
body. It also takes the horizontal scrollbar into account.
heightMode
- the mode in to which Grid should be setpublic HeightMode getHeightMode()
HeightMode
the Grid is in.
Defaults to HeightMode.CSS
.
public void setSelectionModel(Grid.SelectionModel selectionModel) throws IllegalArgumentException
Grid.SelectionModel
into use.
The SelectionModel that is previously in use will have all its items
deselected. If any items were selected, this will fire a
SelectionEvent
.
If the given SelectionModel is already in use, this method does nothing.
selectionModel
- the new SelectionModel to useIllegalArgumentException
- if selectionModel
is null
public Grid.SelectionModel getSelectionModel()
Grid.SelectionModel
.public Grid.SelectionModel setSelectionMode(Grid.SelectionMode selectionMode) throws IllegalArgumentException
Grid supports three selection modes: multiselect, single select and no selection, and this is a convenience method for choosing between one of them.
Technically, this method is a shortcut that can be used instead of
calling setSelectionModel
with a specific SelectionModel
instance. Grid comes with three built-in SelectionModel classes, and the
Grid.SelectionMode
enum represents each of them.
Essentially, the two following method calls are equivalent:
grid.setSelectionMode(SelectionMode.MULTI);
grid.setSelectionModel(new MultiSelectionMode());
selectionMode
- the selection mode to switch toGrid.SelectionModel
instance that was taken into useIllegalArgumentException
- if selectionMode
is null
Grid.SelectionModel
public boolean isSelected(Object itemId)
itemId
- the item id to check fortrue
iff the item is selectedpublic Collection<Object> getSelectedRows()
This method is a shorthand that delegates to the
selection model
.
public Object getSelectedRow() throws IllegalStateException
This method is a shorthand that delegates to the
selection model
. Only
Grid.SelectionModel.Single
is supported.
null
if nothing is selectedIllegalStateException
- if the selection model does not implement
SelectionModel.Single
public boolean select(Object itemId) throws IllegalArgumentException, IllegalStateException
This method is a shorthand that delegates to the
selection model
. Only
Grid.SelectionModel.Single
and Grid.SelectionModel.Multi
are
supported.
itemId
- the itemId to mark as selectedtrue
if the selection state changed,
false
if the itemId already was selectedIllegalArgumentException
- if the itemId
doesn't exist in the currently active
ContainerIllegalStateException
- if the selection was illegal. One such reason might be that
the implementation already had an item selected, and that
needs to be explicitly deselected before re-selecting
something.IllegalStateException
- if the selection model does not implement
SelectionModel.Single
or SelectionModel.Multi
public boolean deselect(Object itemId) throws IllegalStateException
This method is a shorthand that delegates to the
selection model
. Only
Grid.SelectionModel.Single
and Grid.SelectionModel.Multi
are
supported.
itemId
- the itemId to remove from being selectedtrue
if the selection state changed,
false
if the itemId was already selectedIllegalArgumentException
- if the itemId
doesn't exist in the currently active
ContainerIllegalStateException
- if the deselection was illegal. One such reason might be that
the implementation requires one or more items to be selected
at all times.IllegalStateException
- if the selection model does not implement
SelectionModel.Single
or {code SelectionModel.Multi}public boolean deselectAll() throws IllegalStateException
This method is a shorthand that delegates to the
selection model
. Only
Grid.SelectionModel.Single
and Grid.SelectionModel.Multi
are
supported.
true
if the selection state changed,
false
if the itemId was already selectedIllegalStateException
- if the deselection was illegal. One such reason might be that
the implementation requires one or more items to be selected
at all times.IllegalStateException
- if the selection model does not implement
SelectionModel.Single
or {code SelectionModel.Multi}public void fireSelectionEvent(Collection<Object> oldSelection, Collection<Object> newSelection)
Note: This is not a method that should be called by
application logic. This method is publicly accessible only so that
SelectionModels
would be able to inform Grid of
these events.
newSelection
- the selection that was added by this eventoldSelection
- the selection that was removed by this eventpublic void addSelectionListener(SelectionEvent.SelectionListener listener)
SelectionEvent.SelectionNotifier
addSelectionListener
in interface SelectionEvent.SelectionNotifier
listener
- the listener to registerpublic void removeSelectionListener(SelectionEvent.SelectionListener listener)
SelectionEvent.SelectionNotifier
removeSelectionListener
in interface SelectionEvent.SelectionNotifier
listener
- the listener to removepublic void addColumnReorderListener(Grid.ColumnReorderListener listener)
listener
- the listener to registerpublic void removeColumnReorderListener(Grid.ColumnReorderListener listener)
listener
- the listener to removepublic void addColumnResizeListener(Grid.ColumnResizeListener listener)
listener
- the listener to registerpublic void removeColumnResizeListener(Grid.ColumnResizeListener listener)
listener
- the listener to removepublic void sort(Sort s)
Sort
for more information.
Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
s
- a sort instanceIllegalStateException
- if container is not sortable (does not implement
Container.Sortable)IllegalArgumentException
- if trying to sort by non-existing propertypublic void sort(Object propertyId)
Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
propertyId
- a property IDIllegalStateException
- if container is not sortable (does not implement
Container.Sortable)IllegalArgumentException
- if trying to sort by non-existing propertypublic void sort(Object propertyId, SortDirection direction)
SortOrder
by a property.
Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
propertyId
- a property IDdirection
- a sort order value (ascending/descending)IllegalStateException
- if container is not sortable (does not implement
Container.Sortable)IllegalArgumentException
- if trying to sort by non-existing propertypublic void clearSortOrder()
public void setSortOrder(List<SortOrder> order)
Note: Sorting by a property that has no column in Grid will hide all possible sorting indicators.
order
- a sort order list.IllegalStateException
- if container is not sortable (does not implement
Container.Sortable)IllegalArgumentException
- if order is null or trying to sort by non-existing propertypublic List<SortOrder> getSortOrder()
public void addSortListener(SortEvent.SortListener listener)
addSortListener
in interface SortEvent.SortNotifier
listener
- the sort order change listener to addpublic void removeSortListener(SortEvent.SortListener listener)
#addSortListener(SortListener)
.removeSortListener
in interface SortEvent.SortNotifier
listener
- the sort order change listener to removeprotected Grid.Header getHeader()
public Grid.HeaderRow getHeaderRow(int rowIndex)
rowIndex
- 0 based index for row. Counted from top to bottomIllegalArgumentException
- if no row exists at given indexpublic Grid.HeaderRow addHeaderRowAt(int index)
index
- the position at which to insert the rowIllegalArgumentException
- if the index is less than 0 or greater than row countappendHeaderRow()
,
prependHeaderRow()
,
removeHeaderRow(HeaderRow)
,
removeHeaderRow(int)
public Grid.HeaderRow appendHeaderRow()
prependHeaderRow()
,
addHeaderRowAt(int)
,
removeHeaderRow(HeaderRow)
,
removeHeaderRow(int)
public Grid.HeaderRow getDefaultHeaderRow()
public int getHeaderRowCount()
public Grid.HeaderRow prependHeaderRow()
appendHeaderRow()
,
addHeaderRowAt(int)
,
removeHeaderRow(HeaderRow)
,
removeHeaderRow(int)
public void removeHeaderRow(Grid.HeaderRow row)
row
- the row to be removedIllegalArgumentException
- if the row does not exist in this sectionremoveHeaderRow(int)
,
addHeaderRowAt(int)
,
appendHeaderRow()
,
prependHeaderRow()
public void removeHeaderRow(int rowIndex)
rowIndex
- the position of the rowIllegalArgumentException
- if no row exists at given indexremoveHeaderRow(HeaderRow)
,
addHeaderRowAt(int)
,
appendHeaderRow()
,
prependHeaderRow()
public void setDefaultHeaderRow(Grid.HeaderRow row)
row
- the new default row, or null for no default rowIllegalArgumentException
- header does not contain the rowpublic void setHeaderVisible(boolean visible)
visible
- true to show header section, false to hidepublic boolean isHeaderVisible()
protected Grid.Footer getFooter()
public Grid.FooterRow getFooterRow(int rowIndex)
rowIndex
- 0 based index for row. Counted from top to bottomIllegalArgumentException
- if no row exists at given indexpublic Grid.FooterRow addFooterRowAt(int index)
index
- the position at which to insert the rowIllegalArgumentException
- if the index is less than 0 or greater than row countappendFooterRow()
,
prependFooterRow()
,
removeFooterRow(FooterRow)
,
removeFooterRow(int)
public Grid.FooterRow appendFooterRow()
prependFooterRow()
,
addFooterRowAt(int)
,
removeFooterRow(FooterRow)
,
removeFooterRow(int)
public int getFooterRowCount()
public Grid.FooterRow prependFooterRow()
appendFooterRow()
,
addFooterRowAt(int)
,
removeFooterRow(FooterRow)
,
removeFooterRow(int)
public void removeFooterRow(Grid.FooterRow row)
row
- the row to be removedIllegalArgumentException
- if the row does not exist in this sectionremoveFooterRow(int)
,
addFooterRowAt(int)
,
appendFooterRow()
,
prependFooterRow()
public void removeFooterRow(int rowIndex)
rowIndex
- the position of the rowIllegalArgumentException
- if no row exists at given indexremoveFooterRow(FooterRow)
,
addFooterRowAt(int)
,
appendFooterRow()
,
prependFooterRow()
public void setFooterVisible(boolean visible)
visible
- true to show footer section, false to hidepublic boolean isFooterVisible()
public Iterator<Component> iterator()
HasComponents
iterator
in interface HasComponents
iterator
in interface Iterable<Component>
public boolean isRendered(Component childComponent)
SelectiveRenderer
This method can only prevent updates from reaching the client, not force child components to reach the client. If the child is set to visible, returning false will prevent the child from being sent to the client. If a child is set to invisible, this method has no effect.
isRendered
in interface SelectiveRenderer
childComponent
- The child component to checkpublic void setCellDescriptionGenerator(Grid.CellDescriptionGenerator generator)
CellDescriptionGenerator
instance for generating
optional descriptions (tooltips) for individual Grid cells. If a
Grid.RowDescriptionGenerator
is also set, the row description it
generates is displayed for cells for which generator
returns
null
.
The descriptions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used.
generator
- the description generator to use or null
to
remove a previously set generator if anysetCellDescriptionGenerator(CellDescriptionGenerator, ContentMode)
,
setRowDescriptionGenerator(RowDescriptionGenerator)
public void setCellDescriptionGenerator(Grid.CellDescriptionGenerator generator, ContentMode contentMode)
CellDescriptionGenerator
instance and content mode for
generating optional descriptions (tooltips) for individual Grid cells. If
a Grid.RowDescriptionGenerator
is also set, the row description it
generates is displayed for cells for which generator
returns
null
.generator
- the description generator to use or null
to
remove a previously set generator if anycontentMode
- the content mode for cell tooltips, not null
setRowDescriptionGenerator(RowDescriptionGenerator)
public Grid.CellDescriptionGenerator getCellDescriptionGenerator()
CellDescriptionGenerator
instance used to generate
descriptions (tooltips) for Grid cells.null
if no generator is setpublic ContentMode getCellDescriptionContentMode()
null
setCellDescriptionGenerator(CellDescriptionGenerator, ContentMode)
public void setRowDescriptionGenerator(Grid.RowDescriptionGenerator generator)
RowDescriptionGenerator
instance for generating optional
descriptions (tooltips) for Grid rows. If a
Grid.CellDescriptionGenerator
is also set, the row description
generated by generator
is used for cells for which the cell
description generator returns null
.
The descriptions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used.
generator
- the description generator to use or null
to
remove a previously set generator if anysetRowDescriptionGenerator(RowDescriptionGenerator, ContentMode)
,
setCellDescriptionGenerator(CellDescriptionGenerator)
public void setRowDescriptionGenerator(Grid.RowDescriptionGenerator generator, ContentMode contentMode)
RowDescriptionGenerator
instance for generating optional
descriptions (tooltips) for Grid rows. If a
Grid.CellDescriptionGenerator
is also set, the row description
generated by generator
is used for cells for which the cell
description generator returns null
.generator
- the description generator to use or null
to
remove a previously set generator if anycontentMode
- the content mode for row tooltips, not null
setCellDescriptionGenerator(CellDescriptionGenerator)
public ContentMode getRowDescriptionContentMode()
null
setRowDescriptionGenerator(RowDescriptionGenerator, ContentMode)
public Grid.RowDescriptionGenerator getRowDescriptionGenerator()
RowDescriptionGenerator
instance used to generate
descriptions (tooltips) for Grid rowspublic void setCellStyleGenerator(Grid.CellStyleGenerator cellStyleGenerator)
cellStyleGenerator
- the cell style generator to set, or null
to
remove a previously set generatorpublic Grid.CellStyleGenerator getCellStyleGenerator()
null
if no generator is
setpublic void setRowStyleGenerator(Grid.RowStyleGenerator rowStyleGenerator)
rowStyleGenerator
- the row style generator to set, or null
to remove
a previously set generatorpublic Grid.RowStyleGenerator getRowStyleGenerator()
null
if no generator is
setpublic Object addRow(Object... values)
Please note that it's generally only safe to use this method during
initialization. After Grid has been initialized and the visible column
order might have been changed, it's better to instead add items directly
to the underlying container and use Item.getItemProperty(Object)
to make sure each value is assigned to the intended property.
values
- the cell values of the new row, in the same order as the
visible column order, not null
.IllegalArgumentException
- if values is nullIllegalArgumentException
- if its length does not match the number of visible columnsIllegalArgumentException
- if a parameter value is not an instance of the corresponding
property typeUnsupportedOperationException
- if the container does not support adding new itemspublic void refreshRows(Object... itemIds)
Calling this for a row which is not currently rendered on the client side has no effect.
itemIds
- the item id(s) of the row to refresh.public void refreshAllRows()
public void setEditorEnabled(boolean isEnabled) throws IllegalStateException
editItem(Object)
method.isEnabled
- true
to enable the feature, false
otherwiseIllegalStateException
- if an item is currently being editedgetEditedItemId()
public boolean isEditorEnabled()
true
iff the editor is enabled for this gridsetEditorEnabled(boolean)
,
getEditedItemId()
public Object getEditedItemId()
null
if no item is being edited at the momentpublic FieldGroup getEditorFieldGroup()
public void setEditorFieldGroup(FieldGroup fieldGroup)
fieldGroup
- the backing field groupIllegalStateException
- if the editor is currently activepublic boolean isEditorActive()
public void editItem(Object itemId) throws IllegalStateException, IllegalArgumentException
itemId
- the id of the item to editIllegalStateException
- if the editor is not enabled or already editing an item in
buffered modeIllegalArgumentException
- if the itemId
is not in the backing containersetEditorEnabled(boolean)
protected void doEditItem()
public void saveEditor() throws FieldGroup.CommitException
Note: This is a pass-through call to the backing field group.
FieldGroup.CommitException
- If the commit was abortedFieldGroup.commit()
public void cancelEditor()
protected void doCancelEditor()
public void setEditorFieldFactory(FieldGroupFieldFactory fieldFactory)
FieldGroup
. The field factory is
only used when FieldGroup
creates a new field.
Note: This is a pass-through call to the backing field group.
fieldFactory
- The field factory to usepublic void setEditorErrorHandler(Grid.EditorErrorHandler editorErrorHandler) throws IllegalArgumentException
editorErrorHandler
- The editor error handler to useIllegalArgumentException
- if the error handler is nullpublic Grid.EditorErrorHandler getEditorErrorHandler()
AbstractClientConnector.setErrorHandler(com.vaadin.server.ErrorHandler)
public FieldGroupFieldFactory getEditorFieldFactory()
FieldGroup
. The field factory is
only used when FieldGroup
creates a new field.
Note: This is a pass-through call to the backing field group.
public void setEditorSaveCaption(String saveCaption) throws IllegalArgumentException
saveCaption
- the caption to setIllegalArgumentException
- if saveCaption
is null
public String getEditorSaveCaption()
public void setEditorCancelCaption(String cancelCaption) throws IllegalArgumentException
cancelCaption
- the caption to setIllegalArgumentException
- if cancelCaption
is null
public String getEditorCancelCaption()
public void setEditorBuffered(boolean editorBuffered) throws IllegalStateException
true
).editorBuffered
- true
to enable buffered editor,
false
to disable itIllegalStateException
- If editor is active while attempting to change the buffered
mode.public boolean isEditorBuffered()
true
if buffered editor is enabled,
false
otherwisepublic void addItemClickListener(ItemClickEvent.ItemClickListener listener)
ItemClickEvent.ItemClickNotifier
ItemClickEvent
s.addItemClickListener
in interface ItemClickEvent.ItemClickNotifier
listener
- ItemClickListener to be registered@Deprecated public void addListener(ItemClickEvent.ItemClickListener listener)
addListener
in interface ItemClickEvent.ItemClickNotifier
public void removeItemClickListener(ItemClickEvent.ItemClickListener listener)
ItemClickEvent.ItemClickNotifier
removeItemClickListener
in interface ItemClickEvent.ItemClickNotifier
listener
- ItemClickListener to be removed@Deprecated public void removeListener(ItemClickEvent.ItemClickListener listener)
removeListener
in interface ItemClickEvent.ItemClickNotifier
public void recalculateColumnWidths()
In most cases Grid will know when column widths need to be recalculated but this method can be used to force recalculation in situations when grid does not recalculate automatically.
public void addColumnVisibilityChangeListener(Grid.ColumnVisibilityChangeListener listener)
listener
- the listener to registerpublic void removeColumnVisibilityChangeListener(Grid.ColumnVisibilityChangeListener listener)
listener
- the listener to removepublic void setDetailsGenerator(Grid.DetailsGenerator detailsGenerator) throws IllegalArgumentException
The currently opened row details will be re-rendered.
detailsGenerator
- the details generator to setIllegalArgumentException
- if detailsGenerator is null
;public Grid.DetailsGenerator getDetailsGenerator()
public void setDetailsVisible(Object itemId, boolean visible)
itemId
- the id of the item for which to set details visibilityvisible
- true
to show the details, or false
to hide thempublic boolean isDetailsVisible(Object itemId)
itemId
- the id of the item for which to check details visibilitytrue
iff the details are visiblepublic void readDesign(org.jsoup.nodes.Element design, DesignContext context)
Component
The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
readDesign
in interface Component
readDesign
in class AbstractComponent
design
- The element to obtain the state fromcontext
- The DesignContext instance used for parsing the designpublic void writeDesign(org.jsoup.nodes.Element design, DesignContext context)
Component
The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
writeDesign
in interface Component
writeDesign
in class AbstractComponent
design
- The element to write the component state to. Any previous
attributes or child nodes are not cleared.context
- The DesignContext instance used for writing the designprotected Collection<String> getCustomAttributes()
AbstractComponent
readDesign
and writeDesign
methods. Typically these are handled in a custom way in the overridden
versions of the above methodsgetCustomAttributes
in class AbstractComponent
Copyright © 2019 Vaadin Ltd. All rights reserved.