Package com.jk.web.util
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.
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
ConstructorsConstructorDescriptionJKPrimefacesTreeWrapper(String modelType, List<T> modelList) This method constructs a newJKPrimefacesTreeWrapper. - 
Method Summary
Modifier and TypeMethodDescriptionvoidaddItemToTree(JKBaseModel model) This method adds a model item to the root of the tree.org.primefaces.model.DefaultTreeNodeaddItemToTree(JKBaseModel parentModel, JKBaseModel newItem) This method adds an item to the tree under a parent model.org.primefaces.model.DefaultTreeNodeaddItemToTree(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.DefaultTreeNodeThis method builds the tree structure based on the model list and type.voidbuildSubTree(org.primefaces.model.DefaultTreeNode parent, JKListHolder<?> listHolder) This method builds a sub-tree for a given parent node.voidThis method deletes the currently selected tree node.voidexpand(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.DefaultTreeNodegetNodeByValue(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.DefaultTreeNodegetRoot()This method gets the root node of the tree.org.primefaces.model.DefaultTreeNodeThis method retrieves the currently selected tree node.<T> TgetValueFromtNodeByType(org.primefaces.model.TreeNode child, Class<T> clas) This method recursively searches for a tree node of a specified type and returns its value.booleanisSelectedNodeOfType(Class<? extends JKBaseModel> clas) This method checks if the selected node in the tree is of the specified class type.voidonNodeCollapsed(org.primefaces.event.NodeCollapseEvent e) This method is a callback method invoked when a tree node is collapsed.voidonNodeDropped(org.primefaces.event.TreeDragDropEvent ev) This method handles the event when a node is dropped in the tree.voidonNodeExpand(org.primefaces.event.NodeExpandEvent event) This method is a callback method invoked when a tree node is expanded.voidonNodeSelected(org.primefaces.event.NodeSelectEvent ev) This method is a callback method invoked when a tree node is selected.voidrefresh()This method clears the child nodes of the root node, effectively refreshing the tree structure.voidremoveItemFromTree(JKBaseModel model) This method removes a JKBaseModel item from the tree structure.voidsetModelList(List<T> modelList) This method sets the list of model objects to be used in the tree to the provided one.voidsetModelType(String modelType) This method sets the type identifier for the model to the provided value.voidsetSelectedNode(org.primefaces.model.DefaultTreeNode selectedNode) This method sets the currently selected tree node to the provided value.org.primefaces.model.DefaultTreeNodesetSelectedNodeByValue(org.primefaces.model.TreeNode root, Object value) This method sets the selected tree node by matching the provided value within the tree structure. 
- 
Constructor Details
- 
JKPrimefacesTreeWrapper
This method constructs a newJKPrimefacesTreeWrapper.- 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
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
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
This method retrieves the type identifier for the model.- Returns:
 - the type identifier for the model.
 
 - 
setModelType
This method sets the type identifier for the model to the provided value.- Parameters:
 modelType- Specifies the new type identifier for the model.
 - 
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
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
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
This method removes a JKBaseModel item from the tree structure.- Parameters:
 model- Specifies the JKBaseModel item to be removed.
 - 
isSelectedNodeOfType
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. 
 -