Hi all, i am using apache tomahawk tree2 component and i get the tree item from DB. The code like:
This works well only when the items are in the front of their chirdren. How to let it works correctly when the data in the database like :
id------menuid-------menuname------menulevel------parentid
1----------b---------------bb-------------------2------------------a
2----------a---------------aa-------------------1------------------0
Code:
public TreeNode getTreeData() {
List list = getMenuList();
TreeNode treeData = new TreeNodeBase("foo-folder", "Inbox", false);
Iterator it = list.iterator();
HashMap menuTable = new HashMap();
while (it.hasNext()) {
Eosmenu item = (Eosmenu) it.next();
String label = item.getMenuLabel();
boolean isLeaf = item.getIsLeaf() != null
&& item.getIsLeaf().equalsIgnoreCase("Y");
int level = item.getMenuLevel();
String menuId = item.getMenuId();
String parentsID = item.getParentsId();
TreeNodeBase node = new TreeNodeBase();
if(isLeaf){
node.setType("document");
}else{
node.setType("bar-folder");
}
node.setDescription(label);
node.setLeaf(isLeaf);
menuTable.put(menuId, node);
if (level == 1) {
treeData.getChildren().add(node);
} else {
TreeNodeBase pItem = (TreeNodeBase) menuTable.get(parentsID);
if (pItem != null)
pItem.getChildren().add(node);
}
}
return treeData;
}
id------menuid-------menuname------menulevel------parentid
1----------b---------------bb-------------------2------------------a
2----------a---------------aa-------------------1------------------0