Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Problem with dynamic Tree

    Hello,

    I use the latest version of smartgwt and after updating my code does not work anymore.

    I used the example code of the showcase:
    Code:
     public static final TreeNode employeeRoot = new EmployeeTreeNode("1", "Root",   
                new EmployeeTreeNode("4", "Charles Madigen",   
                        new EmployeeTreeNode("188", "Rogine Leger"),  
                        new EmployeeTreeNode("189", "Gene Porter",   
                                new EmployeeTreeNode("265", "Olivier Doucet"),  
                                new EmployeeTreeNode("264", "Cheryl Pearson")  
                        )  
                )  
        );  
      
        public void onModuleLoad() {  
            Tree employeeTree = new Tree();  
            employeeTree.setModelType(TreeModelType.CHILDREN);  
            employeeTree.setNameProperty("Name");  
            employeeTree.setChildrenProperty("directReports");  
            employeeTree.setRoot(employeeRoot);  
              
            TreeGrid employeeTreeGrid = new TreeGrid();  
            employeeTreeGrid.setWidth(500);  
            employeeTreeGrid.setHeight(400);  
            employeeTreeGrid.setNodeIcon("icons/16/person.png");  
            employeeTreeGrid.setFolderIcon("icons/16/person.png");  
            employeeTreeGrid.setShowOpenIcons(false);  
            employeeTreeGrid.setShowDropIcons(false);  
            employeeTreeGrid.setClosedIconSuffix("");  
            employeeTreeGrid.setFields(new TreeGridField("Name"));  
            employeeTreeGrid.setData(employeeTree);  
              
            employeeTreeGrid.getData().openAll();  
              
            employeeTreeGrid.draw();  
        }  
      
        public static class EmployeeTreeNode extends TreeNode {  
            public EmployeeTreeNode(String employeeId, String name) {  
                this(employeeId, name, new EmployeeTreeNode[] {});  
            }  
      
            public EmployeeTreeNode(String employeeId, String name, EmployeeTreeNode... children) {  
                setAttribute("EmployeeId", employeeId);  
                setAttribute("Name", name);  
                setAttribute("directReports", children);  
            }  
        }
    I only changed the employeeRoot to be not static and final to be able to change the attribute. Additionally I added the following method to set new childrends the EmployeeTreeNode:
    Code:
     public void setNewChildren(EmployeeTreeNode... children) {
    	        	setAttribute("childrens", children);  
    	        }
    First try:
    After pressing a button I invoke the method setNewChildren with new children and employeeTree.reloadChildren.
    Instead of displaying the new children the Tree is empty.

    Second try:
    If I create a new root object and add the object as new root node, the tree structure does not work any more. All elements are at the same level (no childs).
    Code:
    TreeNode newEmployeeRoot = new EmployeeTreeNode("1", "Root",   
                new EmployeeTreeNode("4", "Charles Madigen",   
                        new EmployeeTreeNode("188", "Rogine Leger"),  
                        new EmployeeTreeNode("189", "Gene Porter",   
                                new EmployeeTreeNode("265", "Olivier Doucet"),  
                                new EmployeeTreeNode("264", "Cheryl Pearson")  
                        )  
                )  
        );  
     employeeTree.setRoot(newEmployeeRoot);
    What is my mistake?
    Thanks
    Last edited by ludi; 16 Jun 2011, 06:01.
Working...
X