0 Replies Latest reply on Jul 11, 2007 11:28 AM by Tushar Bapat

    Add child nodes to tree

    Tushar Bapat Newbie

      How do i add child nodes to tree ?
      this.htmlTree = new HtmlTree();
      htmlTree.setIconCollapsed("/images/btn_node_collapse.gif");
      htmlTree.setIconExpanded("/images/btn_node_expand.gif");
      htmlTree.setIconLeaf("/images/btn_node_circle.gif");
      htmlTree.setSwitchType("CLIENT");
      htmlTree.setRendered(true);
      htmlTree.setShowConnectingLines(true);
      htmlTree.setValue(parent.getOrgs());

      parent.getOrgs() returns an object of Map with all child nodes.
      Can anyone point out where i am getting wrong ?

      public class ParentOrgDO implements TreeNode
      {


      // COH_ID
      private int cohId;

      private Map<Object,TreeNode> orgs = null;

      // CD_ID
      private int cdId;

      // COH_TYPE
      private int cohType;

      // COH_PARENT_ORG_ID
      private String cohParentOrgId;

      // COH_PARENT_ORG_NAME
      private String cohParentOrgName;

      // COH_ORG_ID
      private String cohOrgId;

      // COH_ORG_NAME
      private String cohOrgName;

      // datagate Id
      private int cohDatagateId;


      /**
      * @return the orgs
      */
      public Map<Object, TreeNode> getOrgs()
      {
      if (this.orgs == null)
      {
      initData();
      }
      return this.orgs;
      }

      /**
      * @param orgs the orgs to set
      */
      public void setOrgs(Map<Object, TreeNode> orgs) {
      this.orgs = orgs;
      }

      public void initData()
      {
      this.orgs = new HashMap<Object, TreeNode>();
      ParentOrgDO parentOrgDO = new ParentOrgDO();
      parentOrgDO.setCohId(1);
      parentOrgDO.setCohType(1);
      parentOrgDO.setCohOrgId("101");
      parentOrgDO.setCohOrgName("Microsoft");
      parentOrgDO.setCohParentOrgId("");
      parentOrgDO.setCohParentOrgName("");
      parentOrgDO.setCohDatagateId(1010101010);
      this.orgs.put(parentOrgDO.getCohOrgName(),parentOrgDO);


      ParentOrgDO parentOrgDO1 = new ParentOrgDO();
      parentOrgDO1.setCohId(2);
      parentOrgDO1.setCohType(1);
      parentOrgDO1.setCohOrgId("102");
      parentOrgDO1.setCohOrgName("Microsoft2");
      parentOrgDO1.setCohParentOrgId("101");
      parentOrgDO1.setCohParentOrgName("Microsoft");
      parentOrgDO1.setCohDatagateId(1010101010);
      this.orgs.put(parentOrgDO1.getCohOrgName(), parentOrgDO1);


      ParentOrgDO parentOrgDO2 = new ParentOrgDO();
      parentOrgDO2.setCohId(3);
      parentOrgDO2.setCohType(1);
      parentOrgDO2.setCohOrgId("103");
      parentOrgDO2.setCohOrgName("Microsoft3");
      parentOrgDO2.setCohParentOrgId("101");
      parentOrgDO2.setCohParentOrgName("Microsoft");
      parentOrgDO2.setCohDatagateId(1010101010);
      this.orgs.put(parentOrgDO2.getCohOrgName(), parentOrgDO2);


      ParentOrgDO parentOrgDO11 = new ParentOrgDO();
      parentOrgDO11.setCohId(4);
      parentOrgDO11.setCohType(1);
      parentOrgDO11.setCohOrgId("104");
      parentOrgDO11.setCohOrgName("Microsoft4");
      parentOrgDO11.setCohParentOrgId("101");
      parentOrgDO11.setCohParentOrgName("Microsoft");
      parentOrgDO11.setCohDatagateId(1010101010);
      this.orgs.put(parentOrgDO11.getCohOrgName(), parentOrgDO11);


      ParentOrgDO parentOrgDO21 = new ParentOrgDO();
      parentOrgDO21.setCohId(5);
      parentOrgDO21.setCohType(1);
      parentOrgDO21.setCohOrgId("105");
      parentOrgDO21.setCohOrgName("Microsoft5");
      parentOrgDO21.setCohParentOrgId("101");
      parentOrgDO21.setCohParentOrgName("Microsoft");
      parentOrgDO21.setCohDatagateId(1010101010);
      this.orgs.put(parentOrgDO21.getCohOrgName(), parentOrgDO21);

      }


      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#addChild(java.lang.Object, org.richfaces.component.TreeNode)
      */
      public void addChild(Object arg0, TreeNode arg1)
      {
      orgs.put(arg0, arg1);
      arg1.setParent(this);
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#getChild(java.lang.Object)
      */
      public TreeNode getChild(Object arg0)
      {
      return (TreeNode)orgs.get(arg0);
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#getChildren()
      */
      public Iterator getChildren()
      {
      return orgs.entrySet().iterator();
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#getData()
      */
      public Object getData()
      {
      return this;
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#getParent()
      */
      public TreeNode getParent()
      {
      return null;
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#isLeaf()
      */
      public boolean isLeaf()
      {
      return orgs.isEmpty();
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#removeChild(java.lang.Object)
      */
      public void removeChild(Object arg0)
      {
      orgs.remove(arg0);
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#setData(java.lang.Object)
      */
      public void setData(Object arg0)
      {
      }

      /* (non-Javadoc)
      * @see org.richfaces.component.TreeNode#setParent(org.richfaces.component.TreeNode)
      */
      public void setParent(TreeNode arg0)
      {
      }

      public String getType()
      {
      return "metadata";
      }

      /**
      * @return the cdId
      */
      public int getCdId()
      {
      return cdId;
      }

      /**
      * @param cdId the cdId to set
      */
      public void setCdId(int cdId)
      {
      this.cdId = cdId;
      }

      /**
      * @return the cohId
      */
      public int getCohId()
      {
      return cohId;
      }

      /**
      * @param cohId the cohId to set
      */
      public void setCohId(int cohId)
      {
      this.cohId = cohId;
      }

      /**
      * @return the cohOrgId
      */
      public String getCohOrgId()
      {
      return cohOrgId;
      }

      /**
      * @param cohOrgId the cohOrgId to set
      */
      public void setCohOrgId(String cohOrgId)
      {
      this.cohOrgId = cohOrgId;
      }

      /**
      * @return the cohOrgName
      */
      public String getCohOrgName()
      {
      return cohOrgName;
      }

      /**
      * @param cohOrgName the cohOrgName to set
      */
      public void setCohOrgName(String cohOrgName)
      {
      this.cohOrgName = cohOrgName;
      }

      /**
      * @return the cohParentOrgId
      */
      public String getCohParentOrgId()
      {
      return cohParentOrgId;
      }

      /**
      * @param cohParentOrgId the cohParentOrgId to set
      */
      public void setCohParentOrgId(String cohParentOrgId)
      {
      this.cohParentOrgId = cohParentOrgId;
      }

      /**
      * @return the cohParentOrgName
      */
      public String getCohParentOrgName()
      {
      return cohParentOrgName;
      }

      /**
      * @param cohParentOrgName the cohParentOrgName to set
      */
      public void setCohParentOrgName(String cohParentOrgName)
      {
      this.cohParentOrgName = cohParentOrgName;
      }

      /**
      * @return the cohType
      */
      public int getCohType()
      {
      return cohType;
      }

      /**
      * @param cohType the cohType to set
      */
      public void setCohType(int cohType)
      {
      this.cohType = cohType;
      }

      /**
      * @return the datagateId
      */
      public int getCohDatagateId()
      {
      return cohDatagateId;
      }

      /**
      * @param pcohDatagateId the datagateId to set
      */
      public void setCohDatagateId(int pcohDatagateId)
      {
      this.cohDatagateId = pcohDatagateId;
      }

      /**
      * @return the id
      */
      public Integer getId() {
      return id;
      }

      }