5 Replies Latest reply on Nov 25, 2008 9:16 AM by nbelaevski

    The role of child identifier in TreeNode

    koloale1

      I don't understand the role of a child identifier that is used when adding a node as a child, but that is not reachable form the TreeNode model of this node(I mean a particular node knows nothing about its id). How can I retrieve a child id form nodeSelectListener, e.g. to delete it subsequently by calling removeChild(id)?

      Thanks in advance, Alexey.

        • 1. Re: The role of child identifier in TreeNode
          ilya_shaikovsky

          you could iterate through the childs using getChildren() in your listener and remove the node you need.

          • 2. Re: The role of child identifier in TreeNode
            koloale1

            Thank you for your answer, it can help. But how about removing by identifier. When adding children I have to provide a not arbitrary id (e.g. it should be unique on a particular level), but is there any way to reuse that id?

            "ilya_shaikovsky" wrote:
            you could iterate through the childs using getChildren() in your listener and remove the node you need.


            • 3. Re: The role of child identifier in TreeNode
              ilya_shaikovsky

              please paste your current code.. I'll paste some additions according to the code if need.

              • 4. Re: The role of child identifier in TreeNode
                koloale1

                 

                void createTree() {
                 root = new TreeNodeImpl<String>();
                 int ind = 0;
                 for (Object child : children) {
                 TreeNodeImpl<String> node = new TreeNodeImpl<String>();
                 node.setData(child);
                 root.addChild(ind++, node);
                }
                
                public void processSelection(NodeSelectedEvent event) {
                 UITree tree = (UITree) event.getComponent();
                 curObject = tree.getTreeNode().getData();
                 // how here I can get identifier that I passed into addChild method during tree creation
                }
                public void doDelete() {
                 // where does identifier go from
                 curNode.getParent().removeChild(identifier);
                }
                


                I already understood that method doDelete() can be implemented by iterating through all children and finding current object to delete, but I'd like to use more convenient method removeChild(). If there is no way to get identifier of the current node then who calls removeChild method at all?

                • 5. Re: The role of child identifier in TreeNode
                  nbelaevski

                  Hi,

                  Child identifier is used to create so called row keys for each model node. Tree component uses them to process submitted data and render tree structure.

                  Just extend TreeNodeImpl the way you like.