Class JKPrimefacesTreeWrapper<T extends JKBaseModel>

java.lang.Object
com.jk.web.util.JKPrimefacesTreeWrapper<T>
Type Parameters:
T - Specifies the type of the model objects stored in the tree.

public class JKPrimefacesTreeWrapper<T extends JKBaseModel> extends Object
This class is a utility for managing tree structures in JavaServer Faces (JSF) applications using PrimeFaces components.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
    JKPrimefacesTreeWrapper(String modelType, List<T> modelList)
    This method constructs a new JKPrimefacesTreeWrapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method adds a model item to the root of the tree.
    org.primefaces.model.DefaultTreeNode
    addItemToTree(JKBaseModel parentModel, JKBaseModel newItem)
    This method adds an item to the tree under a parent model.
    org.primefaces.model.DefaultTreeNode
    addItemToTree(org.primefaces.model.DefaultTreeNode parent, String type, JKBaseModel model)
    This method adds an item to the tree under the specified parent node.
    org.primefaces.model.DefaultTreeNode
    This method builds the tree structure based on the model list and type.
    void
    buildSubTree(org.primefaces.model.DefaultTreeNode parent, JKListHolder<?> listHolder)
    This method builds a sub-tree for a given parent node.
    void
    This method deletes the currently selected tree node.
    void
    expand(org.primefaces.model.TreeNode treeNode)
    This method recursively expands a tree node and its parent nodes.
    This method retrieves the list of model objects to be used in the tree.
    This method retrieves the type identifier for the model.
    org.primefaces.model.DefaultTreeNode
    getNodeByValue(org.primefaces.model.TreeNode root, JKBaseModel model)
    This method retrieves the tree node containing a specific JKBaseModel by recursively searching within the tree structure starting from the specified root node.
    org.primefaces.model.DefaultTreeNode
    This method gets the root node of the tree.
    org.primefaces.model.DefaultTreeNode
    This method retrieves the currently selected tree node.
    <T> T
    getValueFromtNodeByType(org.primefaces.model.TreeNode child, Class<T> clas)
    This method recursively searches for a tree node of a specified type and returns its value.
    boolean
    This method checks if the selected node in the tree is of the specified class type.
    void
    onNodeCollapsed(org.primefaces.event.NodeCollapseEvent e)
    This method is a callback method invoked when a tree node is collapsed.
    void
    onNodeDropped(org.primefaces.event.TreeDragDropEvent ev)
    This method handles the event when a node is dropped in the tree.
    void
    onNodeExpand(org.primefaces.event.NodeExpandEvent event)
    This method is a callback method invoked when a tree node is expanded.
    void
    onNodeSelected(org.primefaces.event.NodeSelectEvent ev)
    This method is a callback method invoked when a tree node is selected.
    void
    This method clears the child nodes of the root node, effectively refreshing the tree structure.
    void
    This method removes a JKBaseModel item from the tree structure.
    void
    setModelList(List<T> modelList)
    This method sets the list of model objects to be used in the tree to the provided one.
    void
    setModelType(String modelType)
    This method sets the type identifier for the model to the provided value.
    void
    setSelectedNode(org.primefaces.model.DefaultTreeNode selectedNode)
    This method sets the currently selected tree node to the provided value.
    org.primefaces.model.DefaultTreeNode
    setSelectedNodeByValue(org.primefaces.model.TreeNode root, Object value)
    This method sets the selected tree node by matching the provided value within the tree structure.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JKPrimefacesTreeWrapper

      public JKPrimefacesTreeWrapper(String modelType, List<T> modelList)
      This method constructs a new JKPrimefacesTreeWrapper.
      Parameters:
      modelType - Specifies the type identifier for the model.
      modelList - Specifies the list of model objects to be used in the tree.
  • Method Details

    • getRoot

      public org.primefaces.model.DefaultTreeNode getRoot()
      This method gets the root node of the tree.
      Returns:
      the root node of the tree.
    • buildMenuModel

      public org.primefaces.model.DefaultTreeNode buildMenuModel()
      This method builds the tree structure based on the model list and type.
      Returns:
      the root node of the tree.
    • buildSubTree

      public void buildSubTree(org.primefaces.model.DefaultTreeNode parent, JKListHolder<?> listHolder)
      This method builds a sub-tree for a given parent node.
      Parameters:
      parent - Specifies the parent node to which the sub-tree is attached.
      listHolder - Specifies the list holder from which sub-tree items are derived.
    • addItemToTree

      public org.primefaces.model.DefaultTreeNode addItemToTree(org.primefaces.model.DefaultTreeNode parent, String type, JKBaseModel model)
      This method adds an item to the tree under the specified parent node.
      Parameters:
      parent - Specifies the parent node to which the item is added.
      type - Specifies the type identifier for the item.
      model - Specifies the model object to be added to the tree.
      Returns:
      the newly created tree node for the added item.
    • addItemToTree

      public org.primefaces.model.DefaultTreeNode addItemToTree(JKBaseModel parentModel, JKBaseModel newItem)
      This method adds an item to the tree under a parent model.
      Parameters:
      parentModel - Specifies the parent model object under which the new item is added.
      newItem - Specifies the model object to be added to the tree.
      Returns:
      the newly created tree node for the added item.
    • addItemToTree

      public void addItemToTree(JKBaseModel model)
      This method adds a model item to the root of the tree.
      Parameters:
      model - Specifies the model object to be added to the root of the tree.
    • setSelectedNodeByValue

      public org.primefaces.model.DefaultTreeNode setSelectedNodeByValue(org.primefaces.model.TreeNode root, Object value)
      This method sets the selected tree node by matching the provided value within the tree structure.
      Parameters:
      root - Specifies the root node of the tree to search within.
      value - Specifies the value to match within the tree structure to set as the selected node.
      Returns:
      the selected tree node with the matched value.
    • getNodeByValue

      public org.primefaces.model.DefaultTreeNode getNodeByValue(org.primefaces.model.TreeNode root, JKBaseModel model)
      This method retrieves the tree node containing a specific JKBaseModel by recursively searching within the tree structure starting from the specified root node.
      Parameters:
      root - Specifies the root node of the tree to search within.
      model - Specifies the JKBaseModel object to find within the tree structure.
      Returns:
      the tree node containing the specified JKBaseModel.
    • refresh

      public void refresh()
      This method clears the child nodes of the root node, effectively refreshing the tree structure.
    • getSelectedNode

      public org.primefaces.model.DefaultTreeNode getSelectedNode()
      This method retrieves the currently selected tree node.
      Returns:
      the currently selected tree node.
    • setSelectedNode

      public void setSelectedNode(org.primefaces.model.DefaultTreeNode selectedNode)
      This method sets the currently selected tree node to the provided value.
      Parameters:
      selectedNode - Specifies the new currently selected tree node.
    • getModelType

      public String getModelType()
      This method retrieves the type identifier for the model.
      Returns:
      the type identifier for the model.
    • setModelType

      public void setModelType(String modelType)
      This method sets the type identifier for the model to the provided value.
      Parameters:
      modelType - Specifies the new type identifier for the model.
    • getModelList

      public List<T> getModelList()
      This method retrieves the list of model objects to be used in the tree.
      Returns:
      the list of model objects to be used in the tree.
    • setModelList

      public void setModelList(List<T> modelList)
      This method sets the list of model objects to be used in the tree to the provided one.
      Parameters:
      modelList - Specifies the new list of model objects to be used in the tree.
    • onNodeSelected

      public void onNodeSelected(org.primefaces.event.NodeSelectEvent ev)
      This method is a callback method invoked when a tree node is selected.
      Parameters:
      ev - Specifies the NodeSelectEvent representing the selection event.
    • onNodeExpand

      public void onNodeExpand(org.primefaces.event.NodeExpandEvent event)
      This method is a callback method invoked when a tree node is expanded.
      Parameters:
      event - Specifies the NodeSelectEvent representing the expansion event.
    • expand

      public void expand(org.primefaces.model.TreeNode treeNode)
      This method recursively expands a tree node and its parent nodes.
      Parameters:
      treeNode - Specifies the TreeNode to expand.
    • onNodeCollapsed

      public void onNodeCollapsed(org.primefaces.event.NodeCollapseEvent e)
      This method is a callback method invoked when a tree node is collapsed.
      Parameters:
      e - Specifies the NodeSelectEvent representing the collapsing event.
    • getValueFromtNodeByType

      public <T> T getValueFromtNodeByType(org.primefaces.model.TreeNode child, Class<T> clas)
      This method recursively searches for a tree node of a specified type and returns its value.
      Type Parameters:
      T - Specifies the type of value to return.
      Parameters:
      child - Specifies the TreeNode to start the search from.
      clas - Specifies the Class representing the type of value to search for.
      Returns:
      the value of the first tree node of the specified type found.
    • removeItemFromTree

      public void removeItemFromTree(JKBaseModel model)
      This method removes a JKBaseModel item from the tree structure.
      Parameters:
      model - Specifies the JKBaseModel item to be removed.
    • isSelectedNodeOfType

      public boolean isSelectedNodeOfType(Class<? extends JKBaseModel> clas)
      This method checks if the selected node in the tree is of the specified class type.
      Parameters:
      clas - Specifies the class type to check against.
      Returns:
      true, if the selected node matches the specified class type, false otherwise.
    • onNodeDropped

      public void onNodeDropped(org.primefaces.event.TreeDragDropEvent ev)
      This method handles the event when a node is dropped in the tree.
      Parameters:
      ev - Specifies the TreeDragDropEvent containing information about the dropped node.
    • deleteSelectedNode

      public void deleteSelectedNode()
      This method deletes the currently selected tree node.