com.vaadin.ui.
Class TreeGrid<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractListing<T>
-
- com.vaadin.ui.Grid<T>
-
- com.vaadin.ui.TreeGrid<T>
-
Type Parameters:
T
- the grid bean typeAll Implemented Interfaces:
HasDataProvider<T>
,HasHierarchicalDataProvider<T>
,HasItems<T>
,ContextClickEvent.ContextClickNotifier
,MethodEventSource
,SortEvent.SortNotifier<GridSortOrder<T>>
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,HasComponents
,Serializable
,Iterable<Component>
public class TreeGrid<T> extends Grid<T> implements HasHierarchicalDataProvider<T>
A grid component for displaying hierarchical tabular data. Visual hierarchy depth positioning of rows is done via styles, see
_treegrid.scss
from Valo theme.Since:
8.1
Author:
Vaadin Ltd
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.ui.Grid
Grid.AbstractGridExtension<T>, Grid.Column<T,V>, Grid.ColumnReorderEvent, Grid.ColumnResizeEvent, Grid.ColumnVisibilityChangeEvent, Grid.DetailsManager<T>, Grid.FetchItemsCallback<T>, Grid.GridContextClickEvent<T>, Grid.ItemClick<T>, Grid.SelectionMode
-
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractListing
AbstractListing.AbstractListingExtension<T>
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
-
-
Constructor Summary
Constructors Modifier Constructor Description TreeGrid()
Creates a new
TreeGrid
without support for creating columns based on property names.protected
TreeGrid(PropertySet<T> propertySet, HierarchicalDataCommunicator<T> dataCommunicator)
Creates a
TreeGrid
using a customPropertySet
implementation and custom data communicator.protected
TreeGrid(HierarchicalDataCommunicator<T> dataCommunicator)
Creates a new TreeGrid with the given data communicator and without support for creating columns based on property names.
TreeGrid(HierarchicalDataProvider<T,?> dataProvider)
Creates a new
TreeGrid
using the givenHierarchicalDataProvider
, without support for creating columns based on property names.TreeGrid(Class<T> beanType)
Creates a new
TreeGrid
that uses reflection based on the provided bean type to automatically set up an initial set of columns.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addCollapseListener(CollapseEvent.CollapseListener<T> listener)
Adds a CollapseListener to this TreeGrid.
Registration
addExpandListener(ExpandEvent.ExpandListener<T> listener)
Adds an ExpandListener to this TreeGrid.
void
collapse(Collection<T> items)
Collapse the given items.
void
collapse(T... items)
Collapse the given items.
void
collapseRecursively(Collection<T> items, int depth)
Collapse the given items and their children recursively until the given depth.
void
collapseRecursively(Stream<T> items, int depth)
Collapse the given items and their children recursively until the given depth.
protected void
doReadDesign(org.jsoup.nodes.Element design, DesignContext context)
Reads the listing specific state from the given design.
protected void
doWriteDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Writes listing specific state into the given design.
void
expand(Collection<T> items)
Expands the given items.
void
expand(T... items)
Expands the given items.
void
expandRecursively(Collection<T> items, int depth)
Expands the given items and their children recursively until the given depth.
void
expandRecursively(Stream<T> items, int depth)
Expands the given items and their children recursively until the given depth.
HierarchicalDataCommunicator<T>
getDataCommunicator()
Returns the data communicator of this listing.
HierarchicalDataProvider<T,?>
getDataProvider()
Returns the source of data items used by this listing.
Grid.Column<T,?>
getHierarchyColumn()
Get the currently set hierarchy column.
ItemCollapseAllowedProvider<T>
getItemCollapseAllowedProvider()
Gets the item collapse allowed provider.
protected TreeGridState
getState()
Returns the shared state bean with information to be sent from the server to the client.
protected TreeGridState
getState(boolean markAsDirty)
Returns the shared state for this connector.
boolean
isExpanded(T item)
Returns whether a given item is expanded or collapsed.
protected void
readData(org.jsoup.nodes.Element body, List<com.vaadin.ui.DeclarativeValueProvider<T>> providers)
Reads the declarative representation of a grid's data from the given element and stores it in the given
DeclarativeValueProvider
s.void
scrollTo(int row)
Deprecated.
void
scrollTo(int row, ScrollDestination destination)
Deprecated.
void
setDataProvider(DataProvider<T,?> dataProvider)
Sets the data provider for this listing.
void
setHierarchyColumn(Grid.Column<T,?> column)
Set the column that displays the hierarchy of this grid's data.
void
setHierarchyColumn(String id)
Set the column that displays the hierarchy of this grid's data.
void
setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)
Sets the item collapse allowed provider for this TreeGrid.
static <BEAN> TreeGrid<BEAN>
withPropertySet(PropertySet<BEAN> propertySet)
Creates a
TreeGrid
using a customPropertySet
implementation for creating a default set of columns and for resolving property names withGrid.addColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.protected void
writeData(org.jsoup.nodes.Element body, DesignContext designContext)
Writes the data contained in this grid.
-
Methods inherited from class com.vaadin.ui.Grid
addColumn, addColumn, addColumn, addColumn, addColumn, addColumn, addColumn, addColumnReorderListener, addColumnResizeListener, addColumnVisibilityChangeListener, addComponentColumn, addContextClickListener, addFooterRowAt, addHeaderRowAt, addItemClickListener, addSelectionListener, addSortListener, appendFooterRow, appendHeaderRow, asMultiSelect, asSingleSelect, beforeClientResponse, clearSortOrder, createColumn, createEditor, createSortingComparator, deselect, deselectAll, deserializeDeclarativeRepresentation, fireColumnVisibilityChangeEvent, getBeanType, getBodyRowHeight, getColumn, getColumnByInternalId, getColumnResizeMode, getColumns, getCustomAttributes, getDefaultHeaderRow, getDescriptionGenerator, getEditor, getFooter, getFooterRow, getFooterRowCount, getFooterRowHeight, getFrozenColumnCount, getHeader, getHeaderRow, getHeaderRowCount, getHeaderRowHeight, getHeightByRows, getHeightMode, getInternalIdForColumn, getPropertySet, getRowHeight, getSelectedItems, getSelectionModel, getSidebarColumnOrder, getSortOrder, getStyleGenerator, internalSetDataProvider, isColumnReorderingAllowed, isDetailsVisible, isFooterVisible, isHeaderVisible, isReadOnly, iterator, prependFooterRow, prependHeaderRow, readItems, recalculateColumnWidths, removeAllColumns, removeColumn, removeColumn, removeFooterRow, removeFooterRow, removeHeaderRow, removeHeaderRow, scrollToColumn, scrollToColumn, scrollToColumn, scrollToColumn, scrollToEnd, scrollToStart, select, setBeanType, setBeanType, setBodyRowHeight, setColumnId, setColumnOrder, setColumnOrder, setColumnReorderingAllowed, setColumnResizeMode, setColumns, setColumns, setDataProvider, setDefaultHeaderRow, setDescriptionGenerator, setDescriptionGenerator, setDetailsGenerator, setDetailsVisible, setFooterRowHeight, setFooterVisible, setFrozenColumnCount, setHeaderRowHeight, setHeaderVisible, setHeight, setHeightByRows, setHeightMode, setPropertySet, setReadOnly, setRowHeight, setSelectionMode, setSelectionModel, setSidebarColumnOrder, setSortOrder, setSortOrder, setStyleGenerator, sort, sort, sort, sort
-
Methods inherited from class com.vaadin.ui.AbstractListing
addDataGenerator, focus, getItemCaptionGenerator, getItemIconGenerator, getTabIndex, internalGetDataProvider, internalSetDataProvider, readDesign, readItem, removeDataGenerator, serializeDeclarativeRepresentation, setItemCaptionGenerator, setItemIconGenerator, setTabIndex, writeDesign, writeItem, writeItems
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setRequiredIndicatorVisible, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, 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, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, readDesign, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible, writeDesign
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasHierarchicalDataProvider
getTreeData, setItems, setItems, setItems, setItems, setItems, setTreeData
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Constructor Detail
-
TreeGrid
public TreeGrid()
Creates a new
TreeGrid
without support for creating columns based on property names. Use an alternative constructor, such asTreeGrid(Class)
, to create aTreeGrid
that automatically sets up columns based on the type of presented data.
-
TreeGrid
public TreeGrid(Class<T> beanType)
Creates a new
TreeGrid
that uses reflection based on the provided bean type to automatically set up an initial set of columns. All columns will be configured using the sameObject.toString()
renderer that is used byGrid.addColumn(ValueProvider)
.Parameters:
beanType
- the bean type to use, notnull
-
TreeGrid
public TreeGrid(HierarchicalDataProvider<T,?> dataProvider)
Creates a new
TreeGrid
using the givenHierarchicalDataProvider
, without support for creating columns based on property names. Use an alternative constructor, such asTreeGrid(Class)
, to create aTreeGrid
that automatically sets up columns based on the type of presented data.Parameters:
dataProvider
- the data provider, notnull
-
TreeGrid
protected TreeGrid(PropertySet<T> propertySet, HierarchicalDataCommunicator<T> dataCommunicator)
Creates a
TreeGrid
using a customPropertySet
implementation and custom data communicator.Property set is used for configuring the initial columns and resolving property names for
Grid.addColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.Parameters:
propertySet
- the property set implementation to use, notnull
dataCommunicator
- the data communicator to use, notnull
-
TreeGrid
protected TreeGrid(HierarchicalDataCommunicator<T> dataCommunicator)
Creates a new TreeGrid with the given data communicator and without support for creating columns based on property names.
Parameters:
dataCommunicator
- the custom data communicator to set
-
-
Method Detail
-
withPropertySet
public static <BEAN> TreeGrid<BEAN> withPropertySet(PropertySet<BEAN> propertySet)
Creates a
TreeGrid
using a customPropertySet
implementation for creating a default set of columns and for resolving property names withGrid.addColumn(String)
andGrid.Column.setEditorComponent(HasValue)
.This functionality is provided as static method instead of as a public constructor in order to make it possible to use a custom property set without creating a subclass while still leaving the public constructors focused on the common use cases.
Type Parameters:
BEAN
- the tree grid bean typeParameters:
propertySet
- the property set implementation to use, notnull
Returns:
a new tree grid using the provided property set, not
null
See Also:
-
scrollTo
@Deprecated public void scrollTo(int row) throws IllegalArgumentException
Deprecated.This method is inherited from Grid but should never be called directly with a TreeGrid.
Overrides:
Parameters:
row
- zero based index of the item to scroll to in the current view.Throws:
IllegalArgumentException
- if the provided row is outside the item range
-
scrollTo
@Deprecated public void scrollTo(int row, ScrollDestination destination)
Deprecated.This method is inherited from Grid but should never be called directly with a TreeGrid.
-
addExpandListener
public Registration addExpandListener(ExpandEvent.ExpandListener<T> listener)
Adds an ExpandListener to this TreeGrid.
Parameters:
listener
- the listener to addReturns:
a registration for the listener
See Also:
-
addCollapseListener
public Registration addCollapseListener(CollapseEvent.CollapseListener<T> listener)
Adds a CollapseListener to this TreeGrid.
Parameters:
listener
- the listener to addReturns:
a registration for the listener
See Also:
-
setDataProvider
public void setDataProvider(DataProvider<T,?> dataProvider)
Description copied from interface:
HasDataProvider
Sets the data provider for this listing. The data provider is queried for displayed items as needed.
Specified by:
setDataProvider
in interfaceHasDataProvider<T>
Overrides:
setDataProvider
in classGrid<T>
Parameters:
dataProvider
- the data provider, not null
-
getHierarchyColumn
public Grid.Column<T,?> getHierarchyColumn()
Get the currently set hierarchy column.
Returns:
the currently set hierarchy column, or
null
if no column has been explicitly set
-
setHierarchyColumn
public void setHierarchyColumn(Grid.Column<T,?> column)
Set the column that displays the hierarchy of this grid's data. By default the hierarchy will be displayed in the first column.
Setting a hierarchy column by calling this method also sets the column to be visible and not hidable.
Note: Changing the Renderer of the hierarchy column is not supported.
Parameters:
column
- the column to use for displaying hierarchy
-
setHierarchyColumn
public void setHierarchyColumn(String id)
Set the column that displays the hierarchy of this grid's data. By default the hierarchy will be displayed in the first column.
Setting a hierarchy column by calling this method also sets the column to be visible and not hidable.
Note: Changing the Renderer of the hierarchy column is not supported.
Parameters:
id
- id of the column to use for displaying hierarchySee Also:
-
setItemCollapseAllowedProvider
public void setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)
Sets the item collapse allowed provider for this TreeGrid. The provider should return
true
for any item that the user can collapse.Note: This callback will be accessed often when sending data to the client. The callback should not do any costly operations.
This method is a shortcut to method with the same name in
HierarchicalDataCommunicator
.Parameters:
provider
- the item collapse allowed provider, notnull
See Also:
HierarchicalDataCommunicator.setItemCollapseAllowedProvider(ItemCollapseAllowedProvider)
-
expand
public void expand(T... items)
Expands the given items.
If an item is currently expanded, does nothing. If an item does not have any children, does nothing.
Parameters:
items
- the items to expand
-
expand
public void expand(Collection<T> items)
Expands the given items.
If an item is currently expanded, does nothing. If an item does not have any children, does nothing.
Parameters:
items
- the items to expand
-
expandRecursively
public void expandRecursively(Collection<T> items, int depth)
Expands the given items and their children recursively until the given depth.
depth
describes the maximum distance between a given item and its descendant, meaning thatexpandRecursively(items, 0)
expands only the given items whileexpandRecursively(items, 2)
expands the given items as well as their children and grandchildren.This method will not fire events for expanded nodes.
Parameters:
items
- the items to expand recursivelydepth
- the maximum depth of recursionSince:
8.4
-
expandRecursively
public void expandRecursively(Stream<T> items, int depth)
Expands the given items and their children recursively until the given depth.
depth
describes the maximum distance between a given item and its descendant, meaning thatexpandRecursively(items, 0)
expands only the given items whileexpandRecursively(items, 2)
expands the given items as well as their children and grandchildren.This method will not fire events for expanded nodes.
Parameters:
items
- the items to expand recursivelydepth
- the maximum depth of recursionSince:
8.4
-
collapse
public void collapse(T... items)
Collapse the given items.
For items that are already collapsed, does nothing.
Parameters:
items
- the collection of items to collapse
-
collapse
public void collapse(Collection<T> items)
Collapse the given items.
For items that are already collapsed, does nothing.
Parameters:
items
- the collection of items to collapse
-
collapseRecursively
public void collapseRecursively(Collection<T> items, int depth)
Collapse the given items and their children recursively until the given depth.
depth
describes the maximum distance between a given item and its descendant, meaning thatcollapseRecursively(items, 0)
collapses only the given items whilecollapseRecursively(items, 2)
collapses the given items as well as their children and grandchildren.This method will not fire events for collapsed nodes.
Parameters:
items
- the items to collapse recursivelydepth
- the maximum depth of recursionSince:
8.4
-
collapseRecursively
public void collapseRecursively(Stream<T> items, int depth)
Collapse the given items and their children recursively until the given depth.
depth
describes the maximum distance between a given item and its descendant, meaning thatcollapseRecursively(items, 0)
collapses only the given items whilecollapseRecursively(items, 2)
collapses the given items as well as their children and grandchildren.This method will not fire events for collapsed nodes.
Parameters:
items
- the items to collapse recursivelydepth
- the maximum depth of recursionSince:
8.4
-
isExpanded
public boolean isExpanded(T item)
Returns whether a given item is expanded or collapsed.
Parameters:
item
- the item to checkReturns:
true if the item is expanded, false if collapsed
-
getState
protected TreeGridState getState()
Description copied from class:
AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().
-
getState
protected TreeGridState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
getDataCommunicator
public HierarchicalDataCommunicator<T> getDataCommunicator()
Description copied from class:
AbstractListing
Returns the data communicator of this listing.
Overrides:
getDataCommunicator
in classAbstractListing<T>
Returns:
the data communicator, not null
-
getDataProvider
public HierarchicalDataProvider<T,?> getDataProvider()
Description copied from interface:
HasItems
Returns the source of data items used by this listing.
Specified by:
getDataProvider
in interfaceHasItems<T>
Overrides:
getDataProvider
in classGrid<T>
Returns:
the data provider, not null
-
doReadDesign
protected void doReadDesign(org.jsoup.nodes.Element design, DesignContext context)
Description copied from class:
AbstractListing
Reads the listing specific state from the given design.
This method is separated from
AbstractListing.readDesign(Element, DesignContext)
to be overridable in subclasses that need to replace this, but still must be able to callsuper.readDesign(...)
.Overrides:
doReadDesign
in classGrid<T>
Parameters:
design
- The element to obtain the state fromcontext
- The DesignContext instance used for parsing the designSee Also:
-
readData
protected void readData(org.jsoup.nodes.Element body, List<com.vaadin.ui.DeclarativeValueProvider<T>> providers)
Description copied from class:
Grid
Reads the declarative representation of a grid's data from the given element and stores it in the given
DeclarativeValueProvider
s. Each member in the list of value providers corresponds to a column in the grid.
-
doWriteDesign
protected void doWriteDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Description copied from class:
AbstractListing
Writes listing specific state into the given design.
This method is separated from
AbstractListing.writeDesign(Element, DesignContext)
to be overridable in subclasses that need to replace this, but still must be able to callsuper.writeDesign(...)
.Overrides:
doWriteDesign
in classGrid<T>
Parameters:
design
- The element to write the component state to. Any previous attributes or child nodes are not cleared.designContext
- The DesignContext instance used for writing the designSee Also:
-
writeData
protected void writeData(org.jsoup.nodes.Element body, DesignContext designContext)
Description copied from class:
Grid
Writes the data contained in this grid. Used when serializing a grid to its declarative representation, if
DesignContext.shouldWriteData(Component)
returnstrue
for the grid that is being written.
-
getItemCollapseAllowedProvider
public ItemCollapseAllowedProvider<T> getItemCollapseAllowedProvider()
Gets the item collapse allowed provider.
Returns:
the item collapse allowed provider
-
-