Package com.vaadin.ui

Class TreeTable

    • Constructor Detail

      • TreeTable

        public TreeTable()
        Creates an empty TreeTable with a default container.
      • TreeTable

        public TreeTable​(String caption)
        Creates an empty TreeTable with a default container.
        Parameters:
        caption - the caption for the TreeTable
      • TreeTable

        public TreeTable​(String caption,
                         Container dataSource)
        Creates a TreeTable instance with given captions and data source.
        Parameters:
        caption - the caption for the component
        dataSource - the dataSource that is used to list items in the component
    • Method Detail

      • rowHeadersAreEnabled

        protected boolean rowHeadersAreEnabled()
        Description copied from class: Table
        Checks whether row headers are visible.
        Overrides:
        rowHeadersAreEnabled in class Table
        Returns:
        false if row headers are hidden, true otherwise
      • isPartialRowUpdate

        protected boolean isPartialRowUpdate()
        Description copied from class: Table
        Subclass and override this to enable partial row updates and additions, which bypass the normal caching mechanism. This is useful for e.g. TreeTable.
        Overrides:
        isPartialRowUpdate in class Table
        Returns:
        true if this update is a partial row update, false if not. For plain Table it is always false.
      • getFirstAddedItemIndex

        protected int getFirstAddedItemIndex()
        Description copied from class: Table
        Subclass and override this to enable partial row additions, bypassing the normal caching mechanism. This is useful for e.g. TreeTable, where expanding a node should only fetch and add the items inside of that node.
        Overrides:
        getFirstAddedItemIndex in class Table
        Returns:
        The index of the first added item. For plain Table it is always 0.
      • getAddedRowCount

        protected int getAddedRowCount()
        Description copied from class: Table
        Subclass and override this to enable partial row additions, bypassing the normal caching mechanism. This is useful for e.g. TreeTable, where expanding a node should only fetch and add the items inside of that node.
        Overrides:
        getAddedRowCount in class Table
        Returns:
        the number of rows to be added, starting at the index returned by Table.getFirstAddedItemIndex(). For plain Table it is always 0.
      • getFirstUpdatedItemIndex

        protected int getFirstUpdatedItemIndex()
        Description copied from class: Table
        Subclass and override this to enable partial row updates, bypassing the normal caching and lazy loading mechanism. This is useful for updating the state of certain rows, e.g. in the TreeTable the collapsed state of a single node is updated using this mechanism.
        Overrides:
        getFirstUpdatedItemIndex in class Table
        Returns:
        the index of the first item to be updated. For plain Table it is always 0.
      • getUpdatedRowCount

        protected int getUpdatedRowCount()
        Description copied from class: Table
        Subclass and override this to enable partial row updates, bypassing the normal caching and lazy loading mechanism. This is useful for updating the state of certain rows, e.g. in the TreeTable the collapsed state of a single node is updated using this mechanism.
        Overrides:
        getUpdatedRowCount in class Table
        Returns:
        the number of rows to update, starting at the index returned by Table.getFirstUpdatedItemIndex(). For plain table it is always 0.
      • setContainerDataSource

        public void setContainerDataSource​(Container newDataSource)
        Description copied from class: Table
        Sets the Container that serves as the data source of the viewer. As a side-effect the table's selection value is set to null as the old selection might not exist in new Container.

        All rows and columns are generated as visible using this method. If the new container contains properties that are not meant to be shown you should use Table.setContainerDataSource(Container, Collection) instead, especially if the table is editable.

        Keeps propertyValueConverters if the corresponding id exists in the new data source and is of a compatible type.

        Specified by:
        setContainerDataSource in interface Container.Viewer
        Overrides:
        setContainerDataSource in class Table
        Parameters:
        newDataSource - the new data source.
        See Also:
        Container.Viewer.setContainerDataSource(Container)
      • getIdByIndex

        protected Object getIdByIndex​(int index)
        Description copied from class: Table
        Returns the item ID for the item represented by the index given. Assumes that the current container implements Container.Indexed. See Container.Indexed.getIdByIndex(int) for more information about the exceptions that can be thrown.
        Overrides:
        getIdByIndex in class Table
        Parameters:
        index - the index for which the item ID should be fetched
        Returns:
        the item ID for the given index
      • areChildrenAllowed

        public boolean areChildrenAllowed​(Object itemId)
        Description copied from interface: Container.Hierarchical
        Tests if the Item with given ID can have children.
        Specified by:
        areChildrenAllowed in interface Container.Hierarchical
        Parameters:
        itemId - ID of the Item in the container whose child capability is to be tested
        Returns:
        true if the specified Item exists in the Container and it can have children, false if it's not found from the container or it can't have children.
      • getChildren

        public Collection<?> getChildren​(Object itemId)
        Description copied from interface: Container.Hierarchical
        Gets the IDs of all Items that are children of the specified Item. The returned collection is unmodifiable.
        Specified by:
        getChildren in interface Container.Hierarchical
        Parameters:
        itemId - ID of the Item whose children the caller is interested in
        Returns:
        An unmodifiable collection containing the IDs of all other Items that are children in the container hierarchy; null if item does not have any children.
      • getParent

        public Object getParent​(Object itemId)
        Description copied from interface: Container.Hierarchical
        Gets the ID of the parent Item of the specified Item.
        Specified by:
        getParent in interface Container.Hierarchical
        Parameters:
        itemId - ID of the Item whose parent the caller wishes to find out.
        Returns:
        the ID of the parent Item. Will be null if the specified Item is a root element.
      • hasChildren

        public boolean hasChildren​(Object itemId)
        Description copied from interface: Container.Hierarchical

        Tests if the Item specified with itemId has child Items or if it is a leaf. The Container.Hierarchical.getChildren(Object itemId) method always returns null for leaf Items.

        Note that being a leaf does not imply whether or not an Item is allowed to have children.

        Specified by:
        hasChildren in interface Container.Hierarchical
        Parameters:
        itemId - ID of the Item to be tested
        Returns:
        true if the specified Item has children, false if not (is a leaf)
      • isRoot

        public boolean isRoot​(Object itemId)
        Description copied from interface: Container.Hierarchical
        Tests if the Item specified with itemId is a root Item. The hierarchical container can have more than one root and must have at least one unless it is empty. The Container.Hierarchical.getParent(Object itemId) method always returns null for root Items.
        Specified by:
        isRoot in interface Container.Hierarchical
        Parameters:
        itemId - ID of the Item whose root status is to be tested
        Returns:
        true if the specified Item is a root, false if not
      • rootItemIds

        public Collection<?> rootItemIds()
        Description copied from interface: Container.Hierarchical
        Gets the IDs of all Items in the container that don't have a parent. Such items are called root Items. The returned collection is unmodifiable.
        Specified by:
        rootItemIds in interface Container.Hierarchical
        Returns:
        An unmodifiable collection containing IDs of all root elements of the container
      • setParent

        public boolean setParent​(Object itemId,
                                 Object newParentId)
                          throws UnsupportedOperationException

        Sets the parent of an Item. The new parent item must exist and be able to have children. ( Container.Hierarchical.areChildrenAllowed(Object) == true ). It is also possible to detach a node from the hierarchy (and thus make it root) by setting the parent null.

        This operation is optional.

        Note: Constructing a big hierarchical data set using the methods in TreeTable may cause a decrease in performance.

        Specified by:
        setParent in interface Container.Hierarchical
        Parameters:
        itemId - ID of the item to be set as the child of the Item identified with newParentId
        newParentId - ID of the Item that's to be the new parent of the Item identified with itemId
        Returns:
        true if the operation succeeded, false if not
        Throws:
        UnsupportedOperationException
      • addItem

        public Object addItem()
                       throws UnsupportedOperationException
        Creates a new item into container with container managed id. The id of the created new item is returned. The item can be fetched with getItem() method. if the creation fails, null is returned.

        Note: Constructing a big hierarchical data set using the methods in TreeTable may cause a decrease in performance. Instead a Container.Hierarchical container should be populated before setting it to the TreeTable.

        Specified by:
        addItem in interface Container
        Overrides:
        addItem in class AbstractSelect
        Returns:
        the Id of the created item or null in case of failure.
        Throws:
        UnsupportedOperationException - if adding an item without an explicit item ID is not supported by the container
        See Also:
        Container.addItem()
      • addItem

        public Item addItem​(Object itemId)
                     throws UnsupportedOperationException
        Create a new item into container. The created new item is returned and ready for setting property values. if the creation fails, null is returned. In case the container already contains the item, null is returned. This functionality is optional. If the function is unsupported, it always returns null.

        Note: Constructing a big hierarchical data set using the methods in TreeTable may cause a decrease in performance. Instead a Container.Hierarchical container should be populated before setting it to the TreeTable.

        Specified by:
        addItem in interface Container
        Overrides:
        addItem in class AbstractSelect
        Parameters:
        itemId - the Identification of the item to be created.
        Returns:
        the Created item with the given id, or null in case of failure.
        Throws:
        UnsupportedOperationException - if adding an item with an explicit item ID is not supported by the container
        See Also:
        Container.addItem(java.lang.Object)
      • addItem

        public Object addItem​(Object[] cells,
                              Object itemId)
                       throws UnsupportedOperationException
        Adds the new row to table and fill the visible cells (except generated columns) with given values.

        Note: Constructing a big hierarchical data set using the methods in TreeTable may cause a decrease in performance. Instead a Container.Hierarchical container should be populated before setting it to the TreeTable.

        Overrides:
        addItem in class Table
        Parameters:
        cells - the Object array that is used for filling the visible cells new row. The types must be settable to visible column property types.
        itemId - the Id the new row. If null, a new id is automatically assigned. If given, the table cannot already have a item with given id.
        Returns:
        Returns item id for the new row. Returns null if operation fails.
        Throws:
        UnsupportedOperationException
      • addItems

        public void addItems​(Object... itemId)
                      throws UnsupportedOperationException
        Adds given items with given item ids to container.

        Note: Constructing a big hierarchical data set using the methods in TreeTable may cause a decrease in performance. Instead a Container.Hierarchical container should be populated before setting it to the TreeTable.

        Overrides:
        addItems in class AbstractSelect
        Parameters:
        itemId - item identifiers to be added to underlying container
        Throws:
        UnsupportedOperationException - if the underlying container don't support adding items with identifiers
      • setCollapsed

        public void setCollapsed​(Object itemId,
                                 boolean collapsed)
        Sets the Item specified by given identifier as collapsed or expanded. If the Item is collapsed, its children are not displayed to the user.
        Parameters:
        itemId - the identifier of the Item
        collapsed - true if the Item should be collapsed, false if expanded
      • isCollapsed

        public boolean isCollapsed​(Object itemId)
        Checks if Item with given identifier is collapsed in the UI.

        Parameters:
        itemId - the identifier of the checked Item
        Returns:
        true if the Item with given id is collapsed
        See Also:
        Collapsible.isCollapsed(Object)
      • setHierarchyColumn

        public void setHierarchyColumn​(Object hierarchyColumnId)
        Explicitly sets the column in which the TreeTable visualizes the hierarchy. If hierarchyColumnId is not set, the hierarchy is visualized in the first visible column.
        Parameters:
        hierarchyColumnId -
      • getHierarchyColumnId

        public Object getHierarchyColumnId()
        Returns:
        the identifier of column into which the hierarchy will be visualized or null if the column is not explicitly defined.
      • addExpandListener

        public void addExpandListener​(Tree.ExpandListener listener)
        Adds an expand listener.
        Parameters:
        listener - the Listener to be added.
      • removeExpandListener

        public void removeExpandListener​(Tree.ExpandListener listener)
        Removes an expand listener.
        Parameters:
        listener - the Listener to be removed.
      • fireExpandEvent

        protected void fireExpandEvent​(Object itemId)
        Emits an expand event.
        Parameters:
        itemId - the item id.
      • addCollapseListener

        public void addCollapseListener​(Tree.CollapseListener listener)
        Adds a collapse listener.
        Parameters:
        listener - the Listener to be added.
      • removeCollapseListener

        public void removeCollapseListener​(Tree.CollapseListener listener)
        Removes a collapse listener.
        Parameters:
        listener - the Listener to be removed.
      • fireCollapseEvent

        protected void fireCollapseEvent​(Object itemId)
        Emits a collapse event.
        Parameters:
        itemId - the item id.
      • isAnimationsEnabled

        public boolean isAnimationsEnabled()
        Returns:
        true if animations are enabled
      • setAnimationsEnabled

        public void setAnimationsEnabled​(boolean animationsEnabled)
        Animations can be enabled by passing true to this method. Currently expanding rows slide in from the top and collapsing rows slide out the same way. NOTE! not supported in Internet Explorer 6 or 7.
        Parameters:
        animationsEnabled - true or false whether to enable animations or not.
      • readBody

        protected void readBody​(org.jsoup.nodes.Element design,
                                DesignContext context)
        Overrides:
        readBody in class Table
      • readItem

        protected Object readItem​(org.jsoup.nodes.Element tr,
                                  Set<String> selected,
                                  DesignContext context)
        Description copied from class: AbstractSelect
        Reads an Item from a design and inserts it into the data source. Hierarchical select components should override this method to recursively recursively read any child items as well.
        Overrides:
        readItem in class Table
        Parameters:
        tr - a child element representing the item
        selected - A set accumulating selected items. If the item that is read is marked as selected, its item id should be added to this set.
        context - the DesignContext instance used in parsing
        Returns:
        the item id of the new item
      • writeItems

        protected void writeItems​(org.jsoup.nodes.Element design,
                                  DesignContext context)
        Description copied from class: AbstractSelect
        Writes the data source items to a design. Hierarchical select components should override this method to only write the root items.
        Overrides:
        writeItems in class Table
        Parameters:
        design - the element into which to insert the items
        context - the DesignContext instance used in writing
      • writeItems

        protected void writeItems​(org.jsoup.nodes.Element tbody,
                                  Collection<?> itemIds,
                                  int depth,
                                  DesignContext context)
      • writeItem

        protected org.jsoup.nodes.Element writeItem​(org.jsoup.nodes.Element tbody,
                                                    Object itemId,
                                                    DesignContext context)
        Description copied from class: AbstractSelect
        Writes a data source Item to a design. Hierarchical select components should override this method to recursively write any child items as well.
        Overrides:
        writeItem in class Table
        Parameters:
        tbody - the element into which to insert the item
        itemId - the id of the item to write
        context - the DesignContext instance used in writing
        Returns:
      • getState

        protected TreeTableState 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 Table
        Returns:
        updated component shared state