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 type
- All 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.scssfrom Valo theme.- Since:
- 8.1
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
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 newTreeGridwithout support for creating columns based on property names.protectedTreeGrid(PropertySet<T> propertySet, HierarchicalDataCommunicator<T> dataCommunicator)Creates aTreeGridusing a customPropertySetimplementation and custom data communicator.protectedTreeGrid(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 newTreeGridusing the givenHierarchicalDataProvider, without support for creating columns based on property names.TreeGrid(Class<T> beanType)Creates a newTreeGridthat uses reflection based on the provided bean type to automatically set up an initial set of columns.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RegistrationaddCollapseListener(CollapseEvent.CollapseListener<T> listener)Adds a CollapseListener to this TreeGrid.RegistrationaddExpandListener(ExpandEvent.ExpandListener<T> listener)Adds an ExpandListener to this TreeGrid.voidcollapse(Collection<T> items)Collapse the given items.voidcollapse(T... items)Collapse the given items.voidcollapseRecursively(Collection<T> items, int depth)Collapse the given items and their children recursively until the given depth.voidcollapseRecursively(Stream<T> items, int depth)Collapse the given items and their children recursively until the given depth.protected voiddoReadDesign(org.jsoup.nodes.Element design, DesignContext context)Reads the listing specific state from the given design.protected voiddoWriteDesign(org.jsoup.nodes.Element design, DesignContext designContext)Writes listing specific state into the given design.voidexpand(Collection<T> items)Expands the given items.voidexpand(T... items)Expands the given items.voidexpandRecursively(Collection<T> items, int depth)Expands the given items and their children recursively until the given depth.voidexpandRecursively(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 TreeGridStategetState()Returns the shared state bean with information to be sent from the server to the client.protected TreeGridStategetState(boolean markAsDirty)Returns the shared state for this connector.booleanisExpanded(T item)Returns whether a given item is expanded or collapsed.protected voidreadData(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 givenDeclarativeValueProviders.voidscrollTo(int row)Deprecated.voidscrollTo(int row, ScrollDestination destination)Deprecated.voidsetDataProvider(DataProvider<T,?> dataProvider)Sets the data provider for this listing.voidsetHierarchyColumn(Grid.Column<T,?> column)Set the column that displays the hierarchy of this grid's data.voidsetHierarchyColumn(String id)Set the column that displays the hierarchy of this grid's data.voidsetItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)Sets the item collapse allowed provider for this TreeGrid.static <BEAN> TreeGrid<BEAN>withPropertySet(PropertySet<BEAN> propertySet)Creates aTreeGridusing a customPropertySetimplementation for creating a default set of columns and for resolving property names withGrid.addColumn(String)andGrid.Column.setEditorComponent(HasValue).protected voidwriteData(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, isAccessibleNavigation, isColumnReorderingAllowed, isDetailsVisible, isFooterVisible, isHeaderVisible, isReadOnly, iterator, prependFooterRow, prependHeaderRow, readItems, recalculateColumnWidths, removeAllColumns, removeColumn, removeColumn, removeFooterRow, removeFooterRow, removeHeaderRow, removeHeaderRow, scrollToColumn, scrollToColumn, scrollToColumn, scrollToColumn, scrollToEnd, scrollToStart, select, setAccessibleNavigation, 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 newTreeGridwithout support for creating columns based on property names. Use an alternative constructor, such asTreeGrid(Class), to create aTreeGridthat automatically sets up columns based on the type of presented data.
-
TreeGrid
public TreeGrid(Class<T> beanType)
Creates a newTreeGridthat 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 newTreeGridusing the givenHierarchicalDataProvider, without support for creating columns based on property names. Use an alternative constructor, such asTreeGrid(Class), to create aTreeGridthat 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 aTreeGridusing a customPropertySetimplementation 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, notnulldataCommunicator- 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 aTreeGridusing a customPropertySetimplementation 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 type- Parameters:
propertySet- the property set implementation to use, notnull- Returns:
- a new tree grid using the provided property set, not
null - See Also:
TreeGrid(),TreeGrid(Class)
-
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:
scrollToin classGrid<T>- 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 add- Returns:
- a registration for the listener
- See Also:
ExpandEvent
-
addCollapseListener
public Registration addCollapseListener(CollapseEvent.CollapseListener<T> listener)
Adds a CollapseListener to this TreeGrid.- Parameters:
listener- the listener to add- Returns:
- a registration for the listener
- See Also:
CollapseEvent
-
setDataProvider
public void setDataProvider(DataProvider<T,?> dataProvider)
Description copied from interface:HasDataProviderSets the data provider for this listing. The data provider is queried for displayed items as needed.- Specified by:
setDataProviderin interfaceHasDataProvider<T>- Overrides:
setDataProviderin 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
nullif 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 hierarchy- See Also:
Grid.Column.setId(String)
-
setItemCollapseAllowedProvider
public void setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)
Sets the item collapse allowed provider for this TreeGrid. The provider should returntruefor 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.depthdescribes 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 recursion- Since:
- 8.4
-
expandRecursively
public void expandRecursively(Stream<T> items, int depth)
Expands the given items and their children recursively until the given depth.depthdescribes 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 recursion- Since:
- 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.depthdescribes 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 recursion- Since:
- 8.4
-
collapseRecursively
public void collapseRecursively(Stream<T> items, int depth)
Collapse the given items and their children recursively until the given depth.depthdescribes 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 recursion- Since:
- 8.4
-
isExpanded
public boolean isExpanded(T item)
Returns whether a given item is expanded or collapsed.- Parameters:
item- the item to check- Returns:
- true if the item is expanded, false if collapsed
-
getState
protected TreeGridState getState()
Description copied from class:AbstractComponentReturns 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:AbstractClientConnectorReturns the shared state for this connector.- Overrides:
getStatein classGrid<T>- Parameters:
markAsDirty- true if the connector should automatically be marked dirty, false otherwise- Returns:
- The shared state for this connector. Never null.
- See Also:
AbstractClientConnector.getState()
-
getDataCommunicator
public HierarchicalDataCommunicator<T> getDataCommunicator()
Description copied from class:AbstractListingReturns the data communicator of this listing.- Overrides:
getDataCommunicatorin classAbstractListing<T>- Returns:
- the data communicator, not null
-
getDataProvider
public HierarchicalDataProvider<T,?> getDataProvider()
Description copied from interface:HasItemsReturns the source of data items used by this listing.- Specified by:
getDataProviderin interfaceHasItems<T>- Overrides:
getDataProviderin classGrid<T>- Returns:
- the data provider, not null
-
doReadDesign
protected void doReadDesign(org.jsoup.nodes.Element design, DesignContext context)Description copied from class:AbstractListingReads 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:
doReadDesignin classGrid<T>- Parameters:
design- The element to obtain the state fromcontext- The DesignContext instance used for parsing the design- See Also:
AbstractListing.doWriteDesign(Element, DesignContext)
-
readData
protected void readData(org.jsoup.nodes.Element body, List<com.vaadin.ui.DeclarativeValueProvider<T>> providers)Description copied from class:GridReads the declarative representation of a grid's data from the given element and stores it in the givenDeclarativeValueProviders. 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:AbstractListingWrites 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:
doWriteDesignin 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 design- See Also:
AbstractListing.doReadDesign(Element, DesignContext)
-
writeData
protected void writeData(org.jsoup.nodes.Element body, DesignContext designContext)Description copied from class:GridWrites the data contained in this grid. Used when serializing a grid to its declarative representation, ifDesignContext.shouldWriteData(Component)returnstruefor the grid that is being written.
-
getItemCollapseAllowedProvider
public ItemCollapseAllowedProvider<T> getItemCollapseAllowedProvider()
Gets the item collapse allowed provider.- Returns:
- the item collapse allowed provider
-
-