package com.app.client;

import com.smartgwt.client.types.ExpansionMode;
import com.smartgwt.client.types.SelectionAppearance;
import com.smartgwt.client.types.SortArrow;
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeNode;
//import com.smartgwt.sample.showcase.client.PanelFactory;
//import com.smartgwt.sample.showcase.client.ShowcasePanel;

//public class LocalDataTreeSample extends ShowcasePanel {
public class LocalDataTreeSample {
    private static final String DESCRIPTION = "Load tree data from a collection of local beans.";
/***
   // public static class Factory implements PanelFactory {
  
    
    public static class Factory {

        private String id;

  
        public Canvas create() {
            LocalDataTreeSample panel = new LocalDataTreeSample();
            id = panel.getID();
            return panel;
        }

        public String getID() {
            return id;
        }

        public String getDescription() {
            return DESCRIPTION;
        }
    }

    ***/
  
    public TreeGrid getTreeGrid() {
        TreeGrid treeGrid = new TreeGrid();
        treeGrid.setWidth(600);
        treeGrid.setHeight(400);
        treeGrid.setBorder("4px");
        //treeGrid.addStyleName("treeGrid");
        treeGrid.setStyleName("treeGrid");
        //treeGrid.setIconSize(14);
        treeGrid.setShowAllColumns(Boolean.TRUE);
        treeGrid.setExpansionMode(ExpansionMode.DETAILS);
        //treeGrid.setImage("collapsedImage", "icons/16/person.png");
        treeGrid.setNodeIcon( "http:/localhost:8080/SmartGwtTest/icons/person.png");
        treeGrid.setFolderIcon( "icons/16/person.png");
        //treeGrid.setAutoFetchData(Boolean.TRUE);setNodeIcon("silk/application_view_list.png");
        
        
        treeGrid.setShowSortArrow(SortArrow.CORNER);
        treeGrid.setShowAllRecords(true);
        treeGrid.setLoadDataOnDemand(false);
        treeGrid.setCanSort(false);
        
        
        
        
        
        
        treeGrid.setSelectionAppearance(SelectionAppearance.ROW_STYLE);
        //treeGrid.setBackgroundColor("grey");
        TreeGridField field = new TreeGridField("Name", "Tree from local data");
        field.setCanSort(false);
        
        treeGrid.setFields(field);
        //treeGrid.show();
        
///**
        Tree tree = new Tree();
        tree.setModelType(TreeModelType.PARENT);
        //tree.setRootValue("1");
        tree.setNameProperty("Name");
        tree.setIdField("EmployeeId");
        tree.setParentIdField("ReportsTo");
        tree.setShowRoot(true);
        System.out.println("2222");
        EmployeeTreeNode root = new EmployeeTreeNode("4", "1", "Charles-or Madigen");
        EmployeeTreeNode node2 = new EmployeeTreeNode("188", "4", "Rogine Leger");
        EmployeeTreeNode node3 = new EmployeeTreeNode("189", "4", "Gene Porter");
        EmployeeTreeNode node4 = new EmployeeTreeNode("265", "189", "Olivier Doucet");
        EmployeeTreeNode node5 = new EmployeeTreeNode("264", "189", "Cheryl Pearson");

        //tree.setRoot(rootNode);
        
        tree.setData(new TreeNode[]{root, node2, node3, node4, node5});
        
        //tree.setData(new TreeNode[]{rootNode});

       //tree.setRoot(root);

        treeGrid.setData(tree);

        
        
        System.out.println("2223333");
        return treeGrid;
    }

    
    public static class EmployeeTreeNode extends TreeNode {

        public EmployeeTreeNode(String employeeId, String reportsTo, String name) {
            setEmployeeId(employeeId);
            setReportsTo(reportsTo);
            System.out.println(" in constructor 11");
            setIcon("icons/16/person.png");
            setName(name);
        }

        public void setEmployeeId(String value) {
            setAttribute("EmployeeId", value);
        }

        public void setReportsTo(String value) {
            setAttribute("ReportsTo", value);
        }

        public void setName(String name) {
            setAttribute("Name", name);
        }
    }
    public String getIntro() {
        return DESCRIPTION;
    }
}
