1. #1
    Ext User
    Join Date
    Aug 2009
    Posts
    14
    Vote Rating
    0
    cnestor is on a distinguished road

      0  

    Cool Question about TreeStore update

    Question about TreeStore update


    I have the following issue. When I insert a new node in my treePanel, the tree is updated in the UI, (see code snippet below)

    Code:
    	private TreeStore<ModelData> store = new TreeStore<ModelData>();
    	private TreePanel<ModelData> aoiTree;
            .....
    	 insert.addSelectionListener(new SelectionListener<MenuEvent>() {
    	 public void componentSelected(MenuEvent ce) {
    
    				ModelData folder = aoiTree.getSelectionModel().getSelectedItem();
    				if (folder != null && !(folder instanceof Folder)) {
    					Category child = new Category("Add Child" +  count++);
    					store.add(folder, child, false);
    					store.update(folder);
    					aoiTree.setExpanded(folder, true);
    				}
    			}
    		});
    
    public class Folder extends BaseTreeModel
    ....
    but when I retrieve all the nodes from the TreeStore, it doesn't contain the new relationship related to the insert or drag and drop action. It still refers to the 'old' store.

    Code:
    		    List<ModelData> itemlist = aoiTree.getStore().getAllItems();
    		    for (ModelData modelData : itemlist) {
    			System.out.println("Modeldata: " + modelData.get("name"));
    				if (modelData instanceof Folder) {
    					Folder folder = (Folder) modelData;
    					System.out.println("ModeldataParent: " + folder.getParent().get("name"));
    				}
    		    }
    In the API doc for TreeStore, I can see:
    The parent child relationships are handled internally by the store. It is important to note that the store does not use the the parent and children of any TreeModel instances added to the store.

    So my question is: How do I update the treestore or how do I retrieve the relationship (parent/child) for the new node? I need this information to update the store on the server side.

    Thanks a lot.
    C

  2. #2
    Ext User
    Join Date
    Mar 2008
    Location
    Berlin, Germany
    Posts
    58
    Vote Rating
    0
    HerrB is on a distinguished road

      0  

    Default


    Err, just a question: Are you sure, that it should be !(folder instanceof Folder) in:
    Code:
    if (folder != null && !(folder instanceof Folder)) {
    					Category child = new Category("Add Child" +  count++);
    					store.add(folder, child, false);
    					store.update(folder);
    					aoiTree.setExpanded(folder, true);
    				}
    So, you are adding a child to a child - not a folder. If this should make the parent child to become a folder, then the object has to be changed, I think.

    But maybe I'm completely wrong on what you are trying to do.

    Regards,

    HerrB

  3. #3
    Ext User
    Join Date
    Aug 2009
    Posts
    14
    Vote Rating
    0
    cnestor is on a distinguished road

      0  

    Default


    Thanks HerrB.
    Poor naming convention on my part, the folder is really an item, therefore I am checking if it's a child or a parent. In my tree, Folder.class is a child, and Category is a parent. I can only create a new category under an existing category.
    Code:
    ||Category
               ||_ Folder
               ||_ Folder
    Code:
    	    aoiTree = new TreePanel<ModelData>(store){
    	    @Override  
    	      public boolean hasChildren(ModelData parent) {  
    	    	if(parent instanceof Category){
    	          return true;  
    	        }  
    	        return super.hasChildren(parent);  
    	      }  
    	    };
    Apparently when I insert a new category, the wrapper around the treestore is updated since I can see the new node on the screen, but the real store is not. How do I tie these two together?

  4. #4
    Ext User
    Join Date
    Mar 2008
    Location
    Berlin, Germany
    Posts
    58
    Vote Rating
    0
    HerrB is on a distinguished road

      0  

    Default


    Ok, thanks for the clarification. I think you can ask the store:

    Code:
    List<ModelData> itemlist = aoiTree.getStore().getAllItems();
    		    for (ModelData modelData : itemlist) {
    			System.out.println("Modeldata: " + modelData.get("name"));
    				if (modelData instanceof Folder) {
    					Folder folder = (Folder) modelData;
    					System.out.println("ModeldataParent: " + aoiTree.getStore().getParent(folder).get("name"));
    				}
    		    }
    Regards,

    HerrB

  5. #5
    Ext User
    Join Date
    Aug 2009
    Posts
    14
    Vote Rating
    0
    cnestor is on a distinguished road

      0  

    Thumbs up Solved

    Solved


    Thanks HerrB, it worked!

    But I am definitely missing something in term of basic understanding.
    I don't understand why when I use:
    aoiTree.getStore().getParent(folder).get("name"));
    it returns the correct parent (the target directory where the item has been inserted or dragged and dropped).

    but when I use the following snippet:
    Code:
    List<ModelData> itemlist = aoiTree.getStore().getAllItems();
    for (ModelData modelData : itemlist) {
    	System.out.println("Modeldata: " + modelData.get("name"));
    	if (modelData instanceof Folder) {
    		Folder folder = (Folder) modelData;
    		System.out.println("ModeldataParent: " + folder.getParent().get("name"));
    The same item will return the parent before the drag & drop.
    Ex:
    ParentA - FileA
    ParentB
    action: Move FileA to ParentB
    ParentA
    ParentB - FileA

    aoiTree.getStore().getParent(folder).get("name"));=> ParentB // correct.
    List<ModelData> itemlist = aoiTree.getStore().getAllItems()... => ParentA for fileA //Incorrect.
    Why is that?

    Thanks a lot
    C

  6. #6
    Ext User
    Join Date
    Mar 2008
    Location
    Berlin, Germany
    Posts
    58
    Vote Rating
    0
    HerrB is on a distinguished road

      0  

    Default


    Actually, I think, you said it by yourself:
    The parent child relationships are handled internally by the store. It is important to note that the store does not use the the parent and children of any TreeModel instances added to the store.
    aoiTree.getStore().getAllItems(); gets you all objects. They do have a getParent method (as they are TreeModel objects), but the information is just "nice" and is ignored by the store. Say, you generate an object Z with Z.setParent(A). You can add this object to every parent - Z.getParent gets you always A, asking the Store with store.getParent(Z) will get you the real parent.

    Maybe this will be changed in the future...

    Regards,

    HerrB

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar