com.vaadin.ui.

Class Tree

    • Constructor Detail

      • Tree

        public Tree()

        Creates a new empty tree.

      • Tree

        public Tree(String caption)

        Creates a new empty tree with caption.

        Parameters:

        caption -

      • Tree

        public Tree(String caption,
                    Container dataSource)

        Creates a new tree with caption and connect it to a Container.

        Parameters:

        caption -

        dataSource -

    • Method Detail

      • setItemIcon

        public void setItemIcon(Object itemId,
                                Resource icon)

        Description copied from class: AbstractSelect

        Sets the icon for an item.

        Overrides:

        setItemIcon in class AbstractSelect

        Parameters:

        itemId - the id of the item to be assigned an icon.

        icon - the icon to use or null.

      • setItemIcon

        public void setItemIcon(Object itemId,
                                Resource icon,
                                String altText)

        Sets the icon for an item.

        Parameters:

        itemId - the id of the item to be assigned an icon.

        icon - the icon to use or null.

        altText - the alternative text for the icon

      • setItemIconAlternateText

        public void setItemIconAlternateText(Object itemId,
                                             String altText)

        Set the alternate text for an item. Used when the item has an icon.

        Parameters:

        itemId - the id of the item to be assigned an icon.

        altText - the alternative text for the icon

      • getItemIconAlternateText

        public String getItemIconAlternateText(Object itemId)

        Return the alternate text of an icon in a tree item.

        Parameters:

        itemId - Object with the ID of the item

        Returns:

        String with the alternate text of the icon, or null when no icon was set

      • isExpanded

        public boolean isExpanded(Object itemId)

        Check is an item is expanded

        Parameters:

        itemId - the item id.

        Returns:

        true iff the item is expanded.

      • expandItem

        public boolean expandItem(Object itemId)

        Expands an item.

        Parameters:

        itemId - the item id.

        Returns:

        True iff the expand operation succeeded

      • expandItemsRecursively

        public boolean expandItemsRecursively(Object startItemId)

        Expands the items recursively Expands all the children recursively starting from an item. Operation succeeds only if all expandable items are expanded.

        Parameters:

        startItemId -

        Returns:

        True iff the expand operation succeeded

      • collapseItem

        public boolean collapseItem(Object itemId)

        Collapses an item.

        Parameters:

        itemId - the item id.

        Returns:

        True iff the collapse operation succeeded

      • collapseItemsRecursively

        public boolean collapseItemsRecursively(Object startItemId)

        Collapses the items recursively. Collapse all the children recursively starting from an item. Operation succeeds only if all expandable items are collapsed.

        Parameters:

        startItemId -

        Returns:

        True iff the collapse operation succeeded

      • isSelectable

        public boolean isSelectable()

        Returns the current selectable state. Selectable determines if the a node can be selected on the client side. Selectable does not affect AbstractSelect.setValue(Object) or AbstractSelect.select(Object).

        The tree is selectable by default.

        Returns:

        the current selectable state.

      • setSelectable

        public void setSelectable(boolean selectable)

        Sets the selectable state. Selectable determines if the a node can be selected on the client side. Selectable does not affect AbstractSelect.setValue(Object) or AbstractSelect.select(Object).

        The tree is selectable by default.

        Parameters:

        selectable - The new selectable state.

      • setMultiselectMode

        public void setMultiselectMode(MultiSelectMode mode)

        Sets the behavior of the multiselect mode

        Parameters:

        mode - The mode to set

      • getMultiselectMode

        public MultiSelectMode getMultiselectMode()

        Returns the mode the multiselect is in. The mode controls how multiselection can be done.

        Returns:

        The mode

      • changeVariables

        public void changeVariables(Object source,
                                    Map<String,Object> variables)

        Description copied from class: AbstractSelect

        Invoked when the value of a variable has changed.

        Specified by:

        changeVariables in interface VariableOwner

        Overrides:

        changeVariables in class AbstractSelect

        Parameters:

        source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.

        variables - the Mapping from variable names to new variable values.

        See Also:

        AbstractComponent#changeVariables(java.lang.Object, java.util.Map)

      • areChildrenAllowed

        public boolean areChildrenAllowed(Object itemId)

        Tests if the Item with given ID can have any 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.

        See Also:

        Container.Hierarchical#areChildrenAllowed(Object)

      • getChildren

        public Collection<?> getChildren(Object itemId)

        Gets the IDs of all Items that are children of the specified Item.

        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.

        See Also:

        Container.Hierarchical#getChildren(Object)

      • getParent

        public Object getParent(Object itemId)

        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.

        See Also:

        Container.Hierarchical#getParent(Object)

      • hasChildren

        public boolean hasChildren(Object itemId)

        Tests if the Item specified with itemId has child Items.

        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)

        See Also:

        Container.Hierarchical#hasChildren(Object)

      • isRoot

        public boolean isRoot(Object itemId)

        Tests if the Item specified with itemId is a root Item.

        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

        See Also:

        Container.Hierarchical#isRoot(Object)

      • rootItemIds

        public Collection<?> rootItemIds()

        Gets the IDs of all Items in the container that don't have a parent.

        Specified by:

        rootItemIds in interface Container.Hierarchical

        Returns:

        An unmodifiable collection containing IDs of all root elements of the container

        See Also:

        Container.Hierarchical#rootItemIds()

      • setChildrenAllowed

        public boolean setChildrenAllowed(Object itemId,
                                          boolean areChildrenAllowed)

        Sets the given Item's capability to have children.

        Specified by:

        setChildrenAllowed in interface Container.Hierarchical

        Parameters:

        itemId - ID of the Item in the container whose child capability is to be set

        areChildrenAllowed - boolean value specifying if the Item can have children or not

        Returns:

        true if the operation succeeded, false if not

        See Also:

        Container.Hierarchical#setChildrenAllowed(Object, boolean)

      • setParent

        public boolean setParent(Object itemId,
                                 Object newParentId)

        Description copied from interface: Container.Hierarchical

        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.

        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

      • addExpandListener

        public void addExpandListener(Tree.ExpandListener listener)

        Adds the expand listener.

        Parameters:

        listener - the Listener to be added.

      • removeExpandListener

        public void removeExpandListener(Tree.ExpandListener listener)

        Removes the expand listener.

        Parameters:

        listener - the Listener to be removed.

      • fireExpandEvent

        protected void fireExpandEvent(Object itemId)

        Emits the expand event.

        Parameters:

        itemId - the item id.

      • addCollapseListener

        public void addCollapseListener(Tree.CollapseListener listener)

        Adds the collapse listener.

        Parameters:

        listener - the Listener to be added.

      • removeCollapseListener

        public void removeCollapseListener(Tree.CollapseListener listener)

        Removes the collapse listener.

        Parameters:

        listener - the Listener to be removed.

      • fireCollapseEvent

        protected void fireCollapseEvent(Object itemId)

        Emits collapse event.

        Parameters:

        itemId - the item id.

      • removeAllActionHandlers

        public void removeAllActionHandlers()

        Removes all action handlers

      • setItemStyleGenerator

        public void setItemStyleGenerator(Tree.ItemStyleGenerator itemStyleGenerator)

        Sets the Tree.ItemStyleGenerator to be used with this tree.

        Parameters:

        itemStyleGenerator - item style generator or null to remove generator

      • getDropHandler

        public DropHandler getDropHandler()

        Specified by:

        getDropHandler in interface DropTarget

        Returns:

        the drop hanler that will receive the dragged data or null if drops are not currently accepted

      • setDropHandler

        public void setDropHandler(DropHandler dropHandler)
      • translateDropTargetDetails

        public Tree.TreeTargetDetails translateDropTargetDetails(Map<String,Object> clientVariables)

        Description copied from interface: DropTarget

        Called before the DragAndDropEvent is passed to DropHandler. Implementation may for example translate the drop target details provided by the client side (drop target) to meaningful server side values. If null is returned the terminal implementation will automatically create a TargetDetails with raw client side data.

        Specified by:

        translateDropTargetDetails in interface DropTarget

        Parameters:

        clientVariables - data passed from the DropTargets client side counterpart.

        Returns:

        A DropTargetDetails object with the translated data or null to use a default implementation.

        See Also:

        DragSource.getTransferable(Map)

      • setDragMode

        public void setDragMode(Tree.TreeDragMode dragMode)

        Sets the drag mode that controls how Tree behaves as a DragSource .

        Parameters:

        dragMode -

      • getTransferable

        public Transferable getTransferable(Map<String,Object> payload)

        Description copied from interface: DragSource

        DragSource may convert data added by client side component to meaningful values for server side developer or add other data based on it.

        For example Tree converts item identifiers to generated string keys for the client side. Vaadin developer don't and can't know anything about these generated keys, only about item identifiers. When tree node is dragged client puts that key to Transferables client side counterpart. In getTransferable(Map) the key is converted back to item identifier that the server side developer can use.

        Specified by:

        getTransferable in interface DragSource

        Parameters:

        payload - the data that client side initially included in Transferables client side counterpart.

        Returns:

        the Transferable instance that will be passed to DropHandler (and/or AcceptCriterion)

      • setItemDescriptionGenerator

        public void setItemDescriptionGenerator(AbstractSelect.ItemDescriptionGenerator generator)

        Set the item description generator which generates tooltips for the tree items

        Parameters:

        generator - The generator to use or null to disable

      • readItem

        protected String readItem(org.jsoup.nodes.Element node,
                                  Set<String> selected,
                                  DesignContext context)

        Reads an Item from a design and inserts it into the data source. Recursively handles any children of the item as well.

        Overrides:

        readItem in class AbstractSelect

        Parameters:

        node - an element representing the item (tree node).

        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

        Throws:

        DesignException - if the tag name of the node element is not node.

        Since:

        7.5.0

      • writeItems

        protected void writeItems(org.jsoup.nodes.Element design,
                                  DesignContext context)

        Recursively writes the root items and their children to a design.

        Overrides:

        writeItems in class AbstractSelect

        Parameters:

        design - the element into which to insert the items

        context - the DesignContext instance used in writing

        Since:

        7.5.0

      • writeItem

        protected org.jsoup.nodes.Element writeItem(org.jsoup.nodes.Element design,
                                                    Object itemId,
                                                    DesignContext context)

        Recursively writes a data source Item and its children to a design.

        Overrides:

        writeItem in class AbstractSelect

        Parameters:

        design - the element into which to insert the item

        itemId - the id of the item to write

        context - the DesignContext instance used in writing

        Returns:

        Since:

        7.5.0

      • setHtmlContentAllowed

        public void setHtmlContentAllowed(boolean htmlContentAllowed)

        Sets whether html is allowed in the item captions. If set to true, the captions are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the content is passed to the browser as plain text. The default setting is false

        Parameters:

        htmlContentAllowed - true if the captions are used as html, false if used as plain text

        Since:

        7.6

      • isHtmlContentAllowed

        public boolean isHtmlContentAllowed()

        Checks whether captions are interpreted as html or plain text.

        Returns:

        true if the captions are displayed as html, false if displayed as plain text

        Since:

        7.6

        See Also:

        setHtmlContentAllowed(boolean)

      • getState

        protected TreeState 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 AbstractSelect

        Returns:

        updated component shared state