Class Treeview

All Implemented Interfaces:
Animatable<Treeview>, CanDrop<Treeview>, Clickable<Treeview>, Draggable<Treeview>, Fetchable<Treeview>, HandleHotKey<Treeview>, HandleMouseEvents<Treeview>, BasedOnDataDescriptor<Treeview>, Filterable<Treeview>, Scrollable<Treeview>, Touchable<Treeview>

Treeview component

The component enables you to visualize a hierarchical data structure in a tree view on the interface. The component is capable of selecting, expanding and collapsing individual nodes (items).

TThe component has a default renderer, that allows the the treeview item icon, component, name or label to be specified, but it is also possible to create a custom renderer that uses custom components to visualize a TreeView. Thus, a simple or complex tree can be displayed, in which the data hierarchy is visualized.

The component’s contents may be programmatically specified or automatically using a DataDescriptor. In this case the tree data originates from a DataDescriptor and is displayed based on individual parameter settings.

Supported events:

AnimationStart AnimationEnd, Click, DoubleClick, MouseDown, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, Scrollable TouchCancel, TouchEnd, TouchMove, TouchStart, Drop, DragStart, DragEnd HotKey

Since:
4.0
Author:
JBStrap
See Also:
  • Constructor Details

    • Treeview

      public Treeview()
      Creates an empty TreeView component
    • Treeview

      public Treeview(String language)
      Creates an empty Treeview component based on the language settings
      Parameters:
      language - Language code according to which the component is created. If not provided or the entered value is null, the component is created using the framework’s default language. The default language of the framework is set via the JBStrap parameter JBStrapParamType.DEFAULT_LANGUAGE.
    • Treeview

      public Treeview(String id, String language)
      Creates an empty Treeview component based on the language settings
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      language - Language code according to which the component is created. If not provided or the entered value is null, the component is created using the framework’s default language. The default language of the framework is set via the JBStrap parameter JBStrapParamType.DEFAULT_LANGUAGE.
  • Method Details

    • setSelectable

      public Treeview setSelectable(boolean selectable, TreeviewSelectionTypes selectionType)
      Sets the selection mode for the treeview. Items of the treeview component cannot be selected by default.
      Parameters:
      selectable - If true is set, the treeview component’s items are selectable. If the items can be selected, a small tick box appears in front of them.
      selectionType - Sets selection mode Available selection types are listed in the enum TreeviewSelectionTypes. If the null value is set, the default TreeviewSelectionTypes.SINGLE_NODE_SELECT mode is selected.
      Returns:
      TreeView component
    • setSelectable

      public Treeview setSelectable(boolean selectable)
      Enables/disables whether a treeview component is selectable By default, nodes are not selectable.
      Parameters:
      selectable - If a true value is set, a checkbox appears in front of a treeview node, enabling the user to select individual nodes. If a false value is set, the checkbox is not displayed and the user is unable to select a node.
      Returns:
      TreeView component
    • isSelectable

      public boolean isSelectable()
      Specifies if nodes of the treeview component are selectable or not.
      Returns:
      If true, the component’s nodes are selectable. Otherwise false.
    • setSelectionType

      public Treeview setSelectionType(TreeviewSelectionTypes selectionType)
      Sets the selection mode for the treeview. The default selection setting is TreeviewSelectionTypes.SINGLE_NODE_SELECT.
      Parameters:
      selectionType - The selection mode to be set Available selection types are listed in the enum TreeviewSelectionTypes. If null is set, the default selection mode is used.
      Returns:
      TreeView component
    • getSelectionType

      public TreeviewSelectionTypes getSelectionType()
      Gets the selection mode for the treeview component
      Returns:
      The selection mode for the treeview component
    • addNode

      public Treeview addNode(TreeviewNode node)
      Adds a node to the treeview
      Parameters:
      node - An instance of the node we want to add to the treeview. The node specified here is added as a root node to the component
      Returns:
      TreeView component
    • addNodes

      public Treeview addNodes(TreeviewNode... nodes)
      Adds multiple nodes to the treeview component
      Parameters:
      nodes - A list of nodes we want to add to the treeview component. All of the nodes specified here are added to the component as separate root nodes.
      Returns:
      TreeView component
    • removeNode

      public Treeview removeNode(String name)
      Removes a root node from the component by its name. If no root node is found by that name on the component, the method does nothing.
      Parameters:
      name - The name of the root node we want to remove from the component
      Returns:
      TreeView component
    • removeNode

      public Treeview removeNode(TreeviewNode node)
      Removes a root node from the component. If the specified node does not exist on the component, the method does nothing.
      Parameters:
      node - An instance of the node we want to remove from the component
      Returns:
      TreeView component
    • removeNodes

      public Treeview removeNodes(String... names)
      Removes multiple root nodes from the component by name. If the list contains a name that references to root node in the component, it will be ignored.
      Parameters:
      names - An enumeration of all nodes we want to remove from the component
      Returns:
      TreeView component
    • removeNodes

      public Treeview removeNodes(TreeviewNode... nodes)
      Removes multiple root nodes from the component. If the enumeration contains a name that is not listed among the component’s root nodes, it will be ignored.
      Parameters:
      nodes - An enumeration of all node instances we want to remove from the component
      Returns:
      TreeView component
    • getNodes

      public Collection<TreeviewNode> getNodes()
      Gets all root nodes not in the component
      Returns:
      A collection containing all root nodes of the treeview component. If the treeview component does not contain any nodes, the result is null.
    • getNode

      public TreeviewNode getNode(String name)
      Gets a root node by its name
      Parameters:
      name - The name of the root node we want to get from the component
      Returns:
      The root node identified by the name or null if no root node exists by that name in the component
    • findFirst

      public final TreeviewNode findFirst(Predicate<TreeviewNode> filter)
      Gets the first node from the component that fulfils the specified criterion. Search is performed in the entire tree.
      Parameters:
      filter - The predicate based on which the first node is returned
      Returns:
      The first node in the tree fulfilling the predicate or null if none of the nodes correspond to the entered predicate.
      Throws:
      NullPointerException - Thrown if the specified predicate is null
    • find

      public final List<TreeviewNode> find(Predicate<TreeviewNode> filter)
      Gets all nodes from the component fulfilling the specified predicate. Search is performed in the entire tree.
      Parameters:
      filter - The predicate based on which the corresponding nodes are returned
      Returns:
      A list of the nodes corresponding the predicate. If no nodes correspond to the predicate, an empty list is returned.
      Throws:
      NullPointerException - Thrown if the specified predicate is null
    • findByName

      public TreeviewNode findByName(String name)
      Gets a node by its name. The search is performed in the entire tree which means not necessarily the root node is returned.
      Parameters:
      name - The name whose referenced node we want to get
      Returns:
      The node with the specified name or null if there is no node by that name in the tree.
    • findByTitle

      public List<TreeviewNode> findByTitle(String title)
      Gets nodes from the tree by their title. Search is performed in the entire tree.
      Parameters:
      title - The title we want to use to get the nodes
      Returns:
      A list of all nodes that have the specified title. If no node has the specified title, an empty list is returned.
    • openAllNodes

      public final Treeview openAllNodes()
      Opens all the nodes in the tree.
      Returns:
      TreeView component
    • closeAllNodes

      public final Treeview closeAllNodes()
      Closes all nodes in the tree.
      Returns:
      TreeView component
    • setFilterCriteria

      public Treeview setFilterCriteria(Criteria criteria)
      If the treeview component retrieves its values from a DataDescriptor, a filter criterion to get the data must be specified.
      Specified by:
      setFilterCriteria in interface Filterable<Treeview>
      Parameters:
      criteria - The filter criterion used to query data from the database
      Returns:
      TreeView component
    • getFilterCriteria

      public Criteria getFilterCriteria()
      Gets the filter criterion used to query data from the database.
      Returns:
      The current filter criterion or null if no filter criterion is set
    • setDefaultCriteria

      public final Treeview setDefaultCriteria(Criteria criteria)
      Sets the Default Criteria used for filtering the treeview items.
      Parameters:
      criteria - The default filter criteria. If null, no default criteria will be used, but if a simple criteria was specified, that will be applied
      Returns:
      The treeview component
    • getDefaultCriteria

      public final Criteria getDefaultCriteria()
      If the treeview retrieves its data from a DataDescriptor, the criterion used to query the data must be specified. The filter criterion specified here is concatenated with an ‘AND’ operator to the criterion specified in the setFilterCriteria method and then used in the query.
      Returns:
      Default filter criterion
    • getCriteria

      public Criteria getCriteria()
      Gets the filter criterion used for the query.
      Specified by:
      getCriteria in interface Filterable<Treeview>
      Returns:
      Filter criterion used for the query, containing the default and the specified filter criterion, concatenated using an ‘AND’ operator
    • fetchData

      public Treeview fetchData()
      Queries data from the database. The method can only be used if the treeview is bound to a DataDescriptor.
      Specified by:
      fetchData in interface Fetchable<Treeview>
      Specified by:
      fetchData in interface Filterable<Treeview>
      Returns:
      The component
      Throws:
      UnsupportedOperationException - Thrown if there is no DataDescriptor defined for the component
      IllegalArgumentException - Thrown if either the name of the identifying column or the parent node ID column or the node label column is not specified.
    • getIdColumnName

      public String getIdColumnName()
      Gets the name of the column used to identify the DataDescriptor items.
      Returns:
      Name of the node ID column or null if not specified.
    • setIdColumnName

      public Treeview setIdColumnName(String idColumnName)
      Sets the node ID column name
      Parameters:
      idColumnName - The name of the column in the DataDescriptor in which node Ids are stored. The name specified here must be referenced in the DataDescriptor in order to work properly.
      Returns:
      Treeview component
    • getParentColumnName

      public String getParentColumnName()
      DataDescriptor parent ID column name
      Returns:
      DataDescriptor parent ID column name or null if not specified
    • setParentColumnName

      public Treeview setParentColumnName(String parentColumnName)
      Sets the name of the DataDescriptor column containing the parent node ID In order to work properly, the DataDescriptor must contain a column by the name specified here.
      Parameters:
      parentColumnName - The name of the DataDescriptor column containing parent node ID
      Returns:
      Treeview component
    • getTitleColumnName

      public String getTitleColumnName()
      Gets the DataDescriptor column name that contains the node label.
      Returns:
      The name of the DataDescriptor column that contains node label or null if not specified
    • setTitleColumnName

      public Treeview setTitleColumnName(String titleColumnName)
      Sets the name of the DataDescriptor column containing the node label In order to work properly, the DataDescriptor must contain a column by the name specified here.
      Parameters:
      titleColumnName - The name of the DataDescriptor column that contains the node title
      Returns:
      Treeview component
    • getIconColumnName

      public String getIconColumnName()
      Gets the name of the DataDescriptor column containing the node icon name
      Returns:
      The name of the DataDescriptor column containing the node icon or null if not set
    • setIconColumnName

      public Treeview setIconColumnName(String iconColumnName)
      Sets the name of the DataDescriptor containing the node icon In order to work properly, the DataDescriptor must contain a column by the name s specified here.
      Parameters:
      iconColumnName - The name of the column in the DataDescriptor containing the node icon
      Returns:
      Treeview component
    • getColorColumnName

      public String getColorColumnName()
      Gets the name of the DataDescriptor column containing node icon color
      Returns:
      The name of the DataDescriptor column containing the node icon color or null if not set
    • setColorColumnName

      public Treeview setColorColumnName(String colorColumnName)
      Sets the name of the DataDescriptor column containing the node icon color. In order to work properly, the DataDescriptor must contain a column by the name specified here.
      Parameters:
      colorColumnName - The name of the DataDescriptor column containing node icon color
      Returns:
      Treeview component
    • getDataDescriptor

      public final DataDescriptor getDataDescriptor()
      Gets treeview DataDescriptor
      Specified by:
      getDataDescriptor in interface BasedOnDataDescriptor<Treeview>
      Returns:
      The DataDescriptor from where treeview data are retrieved, or null if no DataDescriptor is set
    • setDataDescriptor

      public final Treeview setDataDescriptor(DataDescriptor dataDescriptor)
      Sets the treeview DataDescriptor
      Specified by:
      setDataDescriptor in interface BasedOnDataDescriptor<Treeview>
      Parameters:
      dataDescriptor - The DataDescriptor instance from where treeview data is retrieved
      Returns:
      Treeview component
    • setDataDescriptor

      public final Treeview setDataDescriptor(DataDescriptor dataDescriptor, TreeviewNodeCreator nodeCreator)
      Sets the treeview DataDescriptor and defines an own node renderer implementation
      Parameters:
      dataDescriptor - The DataDescriptor instance from where treeview data is retrieved
      nodeCreator - The node creator implementation
      Returns:
      Treeview component
      See Also:
    • setNodeCreator

      public final Treeview setNodeCreator(TreeviewNodeCreator nodeCreator)

      Sets the node creator implementation

      If you do not want to use the default visualization, you can also write your own node renderer, which gives you the possibility to place any component into the nodes. The renderer defined here must implement the TreeviewNodeCreator interface.

      Parameters:
      nodeCreator - Node renderer implementation
      Returns:
      Treeview component
      See Also:
    • getNodeCreator

      public final TreeviewNodeCreator getNodeCreator()
      Gets the renderer used to create nodes
      Returns:
      An own implementation of renderer used to create nodes
    • addComponent

      public Treeview addComponent(Component<?> component)
      No further component can be added to the treeview component
      Overrides:
      addComponent in class Component<Treeview>
      Parameters:
      component - The component to be added
      Returns:
      The component
      Throws:
      UnsupportedOperationException - Every time the method is called
    • removeComponent

      public Treeview removeComponent(Component<?> component)
      No component can be removed from the treeview component
      Overrides:
      removeComponent in class Component<Treeview>
      Parameters:
      component - The component instance
      Returns:
      The component
      Throws:
      UnsupportedOperationException - Every time the method is called
    • getOrders

      public final List<Order> getOrders()
      Gets the ordering criterion used for data query
      Returns:
      A list of ordering criteria used for data query or null if no ordering criteria are used for database query
    • addOrder

      public final Treeview addOrder(String columnName)
      Adds an ordering criterion to the criteria used for database query
      Parameters:
      columnName - The name of the DataDescriptor column based on which data is queried in ascending order
      Returns:
      Treeview component
    • addOrder

      public final Treeview addOrder(String columnName, OrderType orderType)
      Adds an ordering criterion to the list of criteria used for database query
      Parameters:
      columnName - The name of a DataDescriptor column based on which data is to be ordered
      orderType - Ordering sequence Available ordering sequences are listed in the enum OrderType
      Returns:
      Treeview component
    • setDefaultIconColor

      public final Treeview setDefaultIconColor(String color)
      Sets the default icon color
      Parameters:
      color - Default icon color as defined in the CSS3 standard
      Returns:
      Treeview component
    • getDefaultIconColor

      public String getDefaultIconColor()
      Gets the default icon color
      Returns:
      The default icon color in the specified format or null if no default icon color is specified
    • getDefaultFolderIcon

      public Icon getDefaultFolderIcon()
      Queries the icon of the default collapsed folder
      Returns:
      The icon of the default collapsed folder or null if not specified
    • setDefaultFolderIcon

      public Treeview setDefaultFolderIcon(Icon defaultFolderIcon)
      Sets the icon of the default collapsed folder If no expanded folder is specified, the icon specified here is used also as an expanded folder icon.
      Parameters:
      defaultFolderIcon - The icon of the default collapsed folder Available icon are listed in the enum Icon.
      Returns:
      Treeview component
    • getDefaultFolderOpenIcon

      public Icon getDefaultFolderOpenIcon()
      Queries the default expanded folder icon
      Returns:
      The default expanded folder icon, or null if not specified
    • setDefaultFolderOpenIcon

      public Treeview setDefaultFolderOpenIcon(Icon defaultfolderOpenIcon)
      Sets the default expanded folder icon. If it is not specified, the default collapsed folder icon is displayed even when the folder is expanded.
      Parameters:
      defaultfolderOpenIcon - The default expanded folder icon Available icon are listed in the enum Icon.
      Returns:
      Treeview component
    • getDefaultItemIcon

      public Icon getDefaultItemIcon()
      Gets the default icon for the leaf nodes.
      Returns:
      The default icon for the leaf nodes or null if not specified
    • setDefaultItemIcon

      public Treeview setDefaultItemIcon(Icon defaultItemIcon)
      Sets the default icon for the leaf nodes.
      Parameters:
      defaultItemIcon - The default leaf node icon Available icons are listed in the enum Icon.
      Returns:
      Treeview component
    • setNodeOpenHandler

      public final Treeview setNodeOpenHandler(TreeviewNodeOpenEvent handler)
      Sets the implementation of the event handler associated with expanding a parent node
      Parameters:
      handler - The implementation of an event handler associated with expanding a parent node
      Returns:
      Treeview component
    • getNodeOpenHandler

      public final TreeviewNodeOpenEvent getNodeOpenHandler()
      Gets the event handler associated with expanding a parent node
      Returns:
      The implementation of an event handler associated with expanding a parent node or null if not specified
    • setNodeCloseHandler

      public final Treeview setNodeCloseHandler(TreeviewNodeCloseEvent handler)
      Sets the implementation of the event handler associated with collapsing a parent node
      Parameters:
      handler - The implementation of the event handler associated with collapsing a parent node
      Returns:
      Treeview component
    • getNodeCloseHandler

      public final TreeviewNodeCloseEvent getNodeCloseHandler()
      Gets the event handler associated with collapsing a parent node.
      Returns:
      The implementation of the event handler associated with collapsing a parent node or null if not specified
    • setNodeClickHandler

      public final Treeview setNodeClickHandler(TreeviewNodeClickEvent handler)
      Sets the implementation of the event handler associated with clicking on a node.
      Parameters:
      handler - The implementation of the event handler associated with clicking on a node
      Returns:
      Treeview component
    • getNodeClickHandler

      public final TreeviewNodeClickEvent getNodeClickHandler()
      Gets the event handler associated with clicking on a node.
      Returns:
      The implementation of the event handler associated with clicking on a node or null if not specified
    • setNodeSelectionChangedHandler

      public final Treeview setNodeSelectionChangedHandler(TreeviewNodeSelectEvent handler)
      Sets the event handler associated with changing the selection of a node.
      Parameters:
      handler - The implementation of the event handler associated with changing the selection of a node
      Returns:
      Treeview component
    • getNodeSelectionChangedHandler

      public final TreeviewNodeSelectEvent getNodeSelectionChangedHandler()
      Gets the event handler associated with changing the selection of a node.
      Returns:
      The implementaton of the event handler associated with changing the selection of a node or null if not specified
    • setAutoFetchData

      public Treeview setAutoFetchData(boolean autoFetch)
      Sets if the data is to be queried automatically from the database upon component loading This function is disabled by default, that is, data is only queried if the method fetchData() is called.
      Specified by:
      setAutoFetchData in interface Fetchable<Treeview>
      Specified by:
      setAutoFetchData in interface Filterable<Treeview>
      Parameters:
      autoFetch - If true, then the auto fetch is enabled. If disabled, the query must be started manually, through code.
      Returns:
      The component
    • isAutoFetchData

      public boolean isAutoFetchData()
      Description copied from interface: Fetchable
      Determines if the component can fetch data from the database automatically.
      Specified by:
      isAutoFetchData in interface Fetchable<Treeview>
      Specified by:
      isAutoFetchData in interface Filterable<Treeview>
      Returns:
      If true, then the auto fetch is enabled.
    • onShow

      public void onShow()
      Description copied from class: Component
      The operations to be executed after the component is displayed on the client

      By default, this is an empty method. It has to be overwritten on a component or page, if additional operations have to be executed after the component is displayed. This method is nearly identical to the afterDraw() method, they differ in when they are executed. This method runs after the component is displayed on the client. Meaning that it is executed even if the component isn't redrawn, but only set to be visible after being hidden.

      Overrides:
      onShow in class Component<Treeview>
    • setHighlightingCurrentNode

      public final Treeview setHighlightingCurrentNode(Boolean hilightingCurrentNode)
      Sets if the clicked node is highlighted or not. This option is disabled by default
      Parameters:
      hilightingCurrentNode - If true is set, the clicked node is highlighted If the value is set to false, the clicked node is not automatically highlighted
      Returns:
      Treeview component
    • isHighlightingCurrentNode

      public final boolean isHighlightingCurrentNode()
      Sets if the clicked node is automatically highlighted in the component
      Returns:
      If true, the clicked node is automatically highlighted, otherwise false.
    • setCurrentNode

      protected Treeview setCurrentNode(TreeviewNode node)
      Parameters:
      node - The node we want to set as the current one
      Returns:
      Treeview component
    • getCurrentNode

      public final TreeviewNode getCurrentNode()
      Gets the current (highlighted) node.
      Returns:
      The current node or null if there is no current node
    • clear

      public Treeview clear()
      Deletes all data from the component and sets the component back to default.
      Returns:
      Treeview component
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Description copied from class: Component
      Creates the component's HTML equivalent

      This method doesn't need to be used during application development. This method is used when developing a custom component. When creating a custom component, this method needs to be implemented. In the parameter (StringWriter class) the component's HTML equivalent must be specified, and the method has to return with a Boolean value. This boolean value determines if the component was drawn. If the user doesn't have access right to the component, or if the component couldn't be drawn, it should return with false. Otherwise, it must return with true.

      Specified by:
      writeHTML in class Component<Treeview>
      Returns:
      If the componentwas drawn, true, otherwise false
    • setCustomFetch

      public Treeview setCustomFetch(FetchEvent fetchEvent)
      Sets a custom query. When calling the fetchData method, the specified FetchEvent implementation is called, then callback methods are run on records returned by the onFetch method.
      Parameters:
      fetchEvent - Custom query implementation
    • fetch

      public List<Record> fetch(int startRow, int endRow, Criteria criteria, List<Order> orders, Client client) throws FindException, DataAccessException
      Description copied from interface: Fetchable
      This method implements actual data retrieval. The Fetchable.fetchData() function runs callback methods on the returned records.
      Specified by:
      fetch in interface Fetchable<Treeview>
      Parameters:
      startRow - The first row of the query that appears in the returned list
      endRow - The last row of the query that appears in the returned list
      criteria - The criteria used during the query If null, no criteria will be used, every record is queried.
      orders - The orderings that will be applied to the query results. If null, the data will not be ordered.
      client - The client that started the query. If null, the query will happen without checking for access rights.
      Returns:
      The list of records that meet the specified filter criteria.
      Throws:
      FindException - Occurs if an error was encountered during the query
      DataAccessException - Occurs if the user in the specified client has no access to read the data