1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    LA
    Posts
    25
    Answers
    1
    Vote Rating
    1
    ByReaL is on a distinguished road

      0  

    Default Unanswered: GXT3 Tree very simple example

    Unanswered: GXT3 Tree very simple example


    I'm looking at the tree example and i have a question, what will be the easiest and the most simple way to create a structure for a tree (BaseDto, FolderDto, MusicDto...... looks like too many things witch are not necessary)

    so we have
    Code:
    public class BaseDto implements Serializable, TreeStore.TreeNode<BaseDto> {
    .......... the code from the example
    }
    according to my understanding at this point we have an object witch is a tree node

    so only by using the BaseDto it is possible to create a root with 2 children that we add to a store ?

    Code:
    BaseDto root = new BaseDto(0,"Root");
    ??????
    also it is possible to handle the increment of the ID directly in BaseDto ?

    PS: i know those are very basic questions but i'm trying to understand how all this things work.

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    The objects in the TreeStore need not implement TreeNode, this was done so that the models could describe their own structure, as opposed to just allowing the TreeStore to manage the relationshipts.

    If you create a TreeStore and Tree that handle some base class, that class may have multiple subclasses as BaseDto does. The TreeNode inheritance is only required to allow each model to outline its own children and use the addSubTree methods instead of the add methods.

    It could be possible to build an object that creates its own IDs, but you'll need to consider how that object will be sent over RPC, and how that might affect the creation of new items on the client or on the server, or on multiple clients talking to the same server. In most server setups, this is the responsibility of the persistence mechanism like the database, but if the client isn't sharing these objects with the server, it could be sufficient to just have a static counter to keep track of IDs.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Location
    LA
    Posts
    25
    Answers
    1
    Vote Rating
    1
    ByReaL is on a distinguished road

      0  

    Default


    An example will be grate.

    Code:
    import com.sencha.gxt.data.shared.TreeStore.TreeNode;
    
    @SuppressWarnings("serial")
    public class Folder implements Serializable, TreeNode<Folder> {
    
    
        private Integer id;
        private String name;
    
    
        private List<Folder> children;
    
    
        protected Folder() {
    
    
        }
    
    
        public Folder(Integer id, String name) {
            this.id = id;
            this.name = name;
            this.children = null;
        }
    
    
        public Integer getId() {
            return id;
        }
    
    
        public void setId(Integer id) {
            this.id = id;
        }
    
    
        public String getName() {
            return name;
        }
    
    
        public void setName(String name) {
            this.name = name;
        }
    
    
        @Override
        public String toString() {
            return name != null ? name : super.toString();
        }
    
    
        @Override
        public List<? extends TreeNode<Folder>> getChildren() {
            return children;
        }
    
    
        @Override
        public Folder getData() {
            return this;
        }
    
    
        public void setChildren(List<Folder> children) {
            this.children = children;
        }
    
    
        public void addChild(Folder child) {
            this.children.add(child);
        }
    
    
    }
    Code:
    myTreeStore = new TreeStore<Folder>(new KeyProvider());
    
    List<Folder> treeData = new ArrayList<Folder>();
            
    treeData.add(new Folder(0, "AAAAAA1"));
    treeData.add(new Folder(1, "AAAAAA2"));
            
    List<Folder> treeData2 = new ArrayList<Folder>();
    treeData2.add(new Folder(2, "AAAAAA3"));
    treeData2.add(new Folder(3, "AAAAAA4"));
    treeData.get(1).setChildren(treeData2);
    treeData.get(1).addChild(new Folder(4, "AAAAAA5"));
            
    myTreeStore.clear();
    myTreeStore.add(treeData);
    is showing AAAA1 and AAAA2 but not 3 4 and 5

    the part witch i think that i'm missing is that "TreeStore.TreeNode<BaseDto>" should be able to have a parent but also kids but i'm not able somehow to get to add the kids (treeData2)

Thread Participants: 1