1. #1
    Sencha User francescoNemesi's Avatar
    Join Date
    Apr 2007
    Location
    London (UK), Milan (ITA)
    Posts
    148
    Vote Rating
    0
    francescoNemesi is on a distinguished road

      0  

    Default Fully Loaded Tree from Server

    Fully Loaded Tree from Server


    Hi all,

    I am trying to create a tree with fully loaded data from the server. The idea is to call the remote service on the server only at application startup. The service will then return a List<TreeFolder> with fully loaded children.

    The "problem" is that it all works well, but every time I expand a tree node a new request to the server is made even on nodes whose children have already been sent to the client and hence I end up always seeing the first nodes of the tree.

    Is there a way to avoid a call to the server if a node already has children in its local model? From the code below in the BeforeExpand event of the tree, you can see that the client knows that the model for the item already has children loaded...

    Thanks all in advance!

    Client Code
    Code:
    public class gxtTree extends LayoutContainer implements EntryPoint{
    
        public void onModuleLoad() {
            RootPanel.get().add(this);
        }
    
        @Override
        protected void onRender(Element parent, int pos) {
          super.onRender(parent, pos);
    
          setLayout(new FlowLayout(10));
    
          final TreeServiceAsync service = (TreeServiceAsync) GWT.create(TreeService.class);
          ServiceDefTarget endpoint = (ServiceDefTarget) service;
          String moduleRelativeURL = GWT.getModuleBaseURL() + "biptreeservice";
          endpoint.setServiceEntryPoint(moduleRelativeURL);
    
          final Tree tree = new Tree();
    
          tree.addListener(Events.BeforeExpand, new Listener<TreeEvent>() {
              public void handleEvent(TreeEvent te) {
    
                  TreeItem item = te.item;
                  if (item != null) {
    
                      TreeFolder model = (TreeFolder)item.getModel();
                      System.out.println("Number of already available children : "+model.getChildCount());
    
                  }
              }
          });
    
          // data proxy
          RpcProxy<TreeFolder, List<TreeFolder>> proxy = new RpcProxy<TreeFolder, List<TreeFolder>>() {
              @Override
              protected void load(TreeFolder loadConfig, AsyncCallback<List<TreeFolder>> callback) {
                  service.getTreeAsync(loadConfig, callback);
              }
          };
    
          // tree loader
    
          TreeLoader<TreeFolder> loader = new BaseTreeLoader<TreeFolder>(proxy) {
          };
    
          // tree store
          TreeStore<TreeFolder> store = new TreeStore<TreeFolder>(loader);
    
          TreeBinder<TreeFolder> binder = new TreeBinder<TreeFolder>(tree, store);
          binder.setDisplayProperty("label");
    
          binder.setIconProvider(new ModelStringProvider<TreeFolder>() {
    
              public String getStringValue(TreeFolder model, String property) {
                  if (model instanceof TreeLeaf) return "leaf-icon";
                  else return "tree-folder";
              }
    
          });
    
          loader.load();
          add(tree);
    
        }
    
    }
    Service Implementation with test fully loaded Tree
    Code:
    public class TreeServiceImpl extends RemoteServiceServlet implements TreeService {
    
        private static final long serialVersionUID = 7738855532175557082L;
    
        public List<TreeFolder> geTreeAsync(TreeFolder inNode) {
    
            List<TreeFolder> subChild1 = new ArrayList<TreeFolder>();
            subChild1.add(new TreeLeaf("a4.a4","Child 11 Of Child 1"));
            subChild1.add(new TreeLeaf("a5.a5","Child 12 Of Child 1"));
    
            List<TreeFolder> children = new ArrayList<TreeFolder>();
            children.add(new TreeFolder("a2.a2","Child 1",subChild1));
    
            children.add(new TreeFolder("a3.a3","Child 2"));
            children.add(new TreeLeaf("a3.a3","Child 3"));
    
            return children;
        }
    
    }
    TreeFolder Model
    Code:
    public class TreeFolder extends BaseTreeModel<TreeFolder>{
    
        private static final long serialVersionUID = 626670354093708647L;
    
        protected TreeFolder() {
        }
    
        public TreeFolder(String Id,String label) {
            setId(Id);
            setLabel(label);
        }
    
        public TreeFolder(String Id,String label,List<TreeFolder> c) {
            setId(Id);
            setLabel(label);
            setChildren(c);
        }
    
        public void setId(String Id) {
            set("Id",Id);
        }
    
        public void setLabel(String label) {
            set("label",label);
        }
    
        public String getId() {
            return get("Id");
        }
    
        public String getLabel() {
            return get("label");
        }
    
    }
    TreeLeaf Model
    Code:
    public class TreeLeaf extends TreeFolder{
    
        private static final long serialVersionUID = 1018344480224926174L;
    
        protected TreeLeaf() {
        }
    
        public TreeLeaf(String Id, String label) {
            super(Id,label);
        }
    
    }

  2. #2
    Sencha - GXT Dev Team darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242
    Vote Rating
    2
    darrellmeyer is on a distinguished road

      0  

    Default


    One option would be to use retrieve the data first either directly or using a loader. Then add the root model to the TreeStore passing true in the second parameter so that all of the children are loaded into the store. The store will then work locally without a loader.

  3. #3
    Sencha User francescoNemesi's Avatar
    Join Date
    Apr 2007
    Location
    London (UK), Milan (ITA)
    Posts
    148
    Vote Rating
    0
    francescoNemesi is on a distinguished road

      0  

    Default


    Hi Darrell,

    thanks for your quick reply. (I think) I have implemented your suggestion... My remote service now returns a TreeFolder bean, not List<TreeFolder> as before and I call it directly though RPC. Everything seems to be working ok, but the tree only shows the root node without the possibility to expand, although it knows it has 3 children, as reported by the getChildCount() method in the onSuccess of the AsyncCallback.

    What am I missing?

    Thanks again

    Code:
          service.getTreeAsync(new TreeFolder("","") , new AsyncCallback<TreeFolder>() {
    
              public void onFailure(Throwable caught) {
                  // TODO Auto-generated method stub            
              }
    
              public void onSuccess(TreeFolder treeRoot) {
                  
                  System.out.println(treeRoot.getChildCount());
                  
                  store.add(treeRoot, true);
                  
              }        
          });

  4. #4
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default


    I think Darrell was suggesting that you pull down the entire treefolder independent of the tree and add that model to the tree - ie what you would do if you were building the model locally, except don't build it locally, load it from RPC 1st and then add to tree as if the tree was not RPC based... make sense?

  5. #5
    Sencha User francescoNemesi's Avatar
    Join Date
    Apr 2007
    Location
    London (UK), Milan (ITA)
    Posts
    148
    Vote Rating
    0
    francescoNemesi is on a distinguished road

      0  

    Default Done!

    Done!


    Hi there,

    yes it does make sense, thanks. I got the principle but my implementation was wrong... anyway I think I have it all working now

    Thanks both for your help and time

    Francesco

    Code:
    public class gxtTree extends LayoutContainer implements EntryPoint{
    
        public void onModuleLoad() {
            RootPanel.get().add(this);
        }
    
        @Override
        protected void onRender(Element parent, int pos) {
            super.onRender(parent, pos);
    
            setLayout(new FlowLayout(10));
    
            final TreeServiceAsync service = (TreeServiceAsync) GWT.create(TreeService.class);        
            ServiceDefTarget endpoint = (ServiceDefTarget) service;  
            String moduleRelativeURL = GWT.getModuleBaseURL() + "treeservice";  
            endpoint.setServiceEntryPoint(moduleRelativeURL);      
          
            final Tree tree = new Tree();      
            final TreeLoader<TreeFolder> loader = new BaseTreeLoader<TreeFolder>(new TreeModelReader());        
            final TreeStore<TreeFolder> store = new TreeStore<TreeFolder>(loader);
          
            TreeBinder<TreeFolder> binder = new TreeBinder<TreeFolder>(tree, store);
            binder.setDisplayProperty("label");      
            binder.setIconProvider(new ModelStringProvider<TreeFolder>() {
    
                public String getStringValue(TreeFolder model, String property) {
                    if (model instanceof TreeLeaf) return "leaf-icon";
                    else return "tree-folder";
                }
    
            });
          
            tree.addListener(Events.BeforeExpand, new Listener<TreeEvent>() {          
                public void handleEvent(TreeEvent te) {
                    //System.out.println("BeforeExpand!");
                    TreeItem item = te.item;                            
                    if (item != null) {
                        
                        TreeFolder model = (TreeFolder)item.getModel();
                        System.out.println(model.getId()+" - Children:"+model.getChildCount());
                        
                    }  
                }          
            });
          
    
            add(tree);      
          
            service.getTreeAsync(new TreeFolder("","") , new AsyncCallback<TreeFolder>() {
    
                public void onFailure(Throwable caught) {            
                }
    
                public void onSuccess(TreeFolder treeRoot) {
                    loader.load(treeRoot);
                }        
            });            
        }
    
    }

  6. #6
    Sencha - GXT Dev Team darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242
    Vote Rating
    2
    darrellmeyer is on a distinguished road

      0  

    Default


    I typed up an example before seeing the last posts. You still find the code helpful:

    Code:
    public void onModuleLoad() {
        final TreeStore<TreeModel> store = new TreeStore<TreeModel>();
        final Tree tree = new Tree();
    
        TreeBinder binder = new TreeBinder<TreeModel>(tree, store);
        binder.setDisplayProperty("name");
        binder.init();
    
        RootPanel.get().add(tree);
    
        // simulate rpc call
        Timer t = new Timer() {
    
          @Override
          public void run() {
            TreeModel<TreeModel> root = new BaseTreeModel<TreeModel>();
            root.set("name", "root");
            TreeModel<TreeModel> child = new BaseTreeModel<TreeModel>();
            child.set("name", "child");
            root.add(child);
            store.add(root, true);
            tree.expandAll();
          }
        };
        t.schedule(2000);
      }

  7. #7
    Sencha User francescoNemesi's Avatar
    Join Date
    Apr 2007
    Location
    London (UK), Milan (ITA)
    Posts
    148
    Vote Rating
    0
    francescoNemesi is on a distinguished road

      0  

    Default


    Thanks

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi