com.vaadin.ui.

Class TreeGrid<T>

    • Constructor Detail

      • TreeGrid

        public TreeGrid()

        Creates a new TreeGrid without support for creating columns based on property names. Use an alternative constructor, such as TreeGrid(Class), to create a TreeGrid 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 same Object.toString() renderer that is used by Grid.addColumn(ValueProvider).

        Parameters:

        beanType - the bean type to use, not null

      • TreeGrid

        public TreeGrid​(HierarchicalDataProvider<T,​?> dataProvider)

        Creates a new TreeGrid using the given HierarchicalDataProvider, without support for creating columns based on property names. Use an alternative constructor, such as TreeGrid(Class), to create a TreeGrid that automatically sets up columns based on the type of presented data.

        Parameters:

        dataProvider - the data provider, not null

      • 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 custom PropertySet implementation for creating a default set of columns and for resolving property names with Grid.addColumn(String) and Grid.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, not null

        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:

        scrollTo in class Grid<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.

        Overrides:

        scrollTo in class Grid<T>

        Parameters:

        row - zero based index of the item to scroll to in the current view.

        destination - value specifying desired position of scrolled-to row, not null

      • 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

      • 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 interface HasDataProvider<T>

        Overrides:

        setDataProvider in class Grid<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 hierarchy

        See Also:

        Grid.Column.setId(String)

      • 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 that expandRecursively(items, 0) expands only the given items while expandRecursively(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 recursively

        depth - 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.

        depth describes the maximum distance between a given item and its descendant, meaning that expandRecursively(items, 0) expands only the given items while expandRecursively(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 recursively

        depth - 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.

        depth describes the maximum distance between a given item and its descendant, meaning that collapseRecursively(items, 0) collapses only the given items while collapseRecursively(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 recursively

        depth - 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.

        depth describes the maximum distance between a given item and its descendant, meaning that collapseRecursively(items, 0) collapses only the given items while collapseRecursively(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 recursively

        depth - 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: 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().

        Overrides:

        getState in class Grid<T>

        Returns:

        updated component shared state

      • getState

        protected TreeGridState getState​(boolean markAsDirty)

        Description copied from class: AbstractClientConnector

        Returns the shared state for this connector.

        Overrides:

        getState in class Grid<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()

      • 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 DeclarativeValueProviders. Each member in the list of value providers corresponds to a column in the grid.

        Overrides:

        readData in class Grid<T>

        Parameters:

        body - the element to read data from

        providers - list of DeclarativeValueProviders to store the data of each column to

      • 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) returns true for the grid that is being written.

        Overrides:

        writeData in class Grid<T>

        Parameters:

        body - the body element to write the declarative representation of data to

        designContext - the design context

      • getItemCollapseAllowedProvider

        public ItemCollapseAllowedProvider<T> getItemCollapseAllowedProvider()

        Gets the item collapse allowed provider.

        Returns:

        the item collapse allowed provider