Hello Community,
I'm having a problem setting the root of a Tree (com.smartgwt.client.widgets.tree.Tree). I'm using SmartGwt version 6.1 (build 2018-03-09).
I've made a short test example to explain the problem.
In this example I create a small Tree with just two nodes. The Tree is configured in TreeModelType.PARENT mode.
Only to visually represent the Tree, I draw it in a TreeGrid but this is actually not important. Indeed, in our real application the Tree is drawn in a Canvas. The problem seems isolated in the Tree data structure.
After the component has been drawn, following some external triggers, I need to change the root of the Tree, making one of the TreeNode the new root. I simulate this behaviour with the two buttons, each one setting the root of the Tree to one of the nodes in the Tree.
In each case, the setRoot() method seems to go in an infinite loop. After some code debugging, I noticed that the loop is originated when it tries to set the root's parent as the root itself.
Thank you for any feedback you can give me if this is actually a bug or it's me not doing the correct steps to change the root of a Tree.
TreeRootExample.java
I'm having a problem setting the root of a Tree (com.smartgwt.client.widgets.tree.Tree). I'm using SmartGwt version 6.1 (build 2018-03-09).
I've made a short test example to explain the problem.
In this example I create a small Tree with just two nodes. The Tree is configured in TreeModelType.PARENT mode.
Only to visually represent the Tree, I draw it in a TreeGrid but this is actually not important. Indeed, in our real application the Tree is drawn in a Canvas. The problem seems isolated in the Tree data structure.
After the component has been drawn, following some external triggers, I need to change the root of the Tree, making one of the TreeNode the new root. I simulate this behaviour with the two buttons, each one setting the root of the Tree to one of the nodes in the Tree.
In each case, the setRoot() method seems to go in an infinite loop. After some code debugging, I noticed that the loop is originated when it tries to set the root's parent as the root itself.
Thank you for any feedback you can give me if this is actually a bug or it's me not doing the correct steps to change the root of a Tree.
TreeRootExample.java
Code:
import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.types.TreeModelType; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tree.Tree; import com.smartgwt.client.widgets.tree.TreeGrid; import com.smartgwt.client.widgets.tree.TreeNode; public class TreeRootExample implements EntryPoint { @Override public void onModuleLoad() { final TreeNode node1 = new TreeNode(); node1.setAttribute("id", "111"); node1.setAttribute("parentId", (String) null); node1.setAttribute("name", "Node 1"); final TreeNode node2 = new TreeNode(); node2.setAttribute("id", "222"); node2.setAttribute("parentId", "111"); node2.setAttribute("name", "Node 2"); final TreeNode[] nodes = { node1, node2 }; final Tree tree = new Tree(); tree.setModelType(TreeModelType.PARENT); tree.setData(nodes); final TreeGrid grid = new TreeGrid(); grid.setData(tree); final Button rootNode1 = new Button("MAKE ROOT 1"); rootNode1.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { tree.setRoot(node1); } }); final Button rootNode2 = new Button("MAKE ROOT 2"); rootNode2.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { tree.setRoot(node2); } }); final VLayout layout = new VLayout(); layout.setWidth(150); layout.setHeight(150); layout.addMember(grid); layout.addMember(rootNode1); layout.addMember(rootNode2); layout.draw(); } }
Comment