1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    17
    Vote Rating
    0
    Kathie is on a distinguished road

      0  

    Default Unable to move tree node(s) properly

    Unable to move tree node(s) properly


    I have a tree which I want to move the nodes from one folder to another manually. However, it seems to appear to moved successfully on the screen, but not updated in the store/tree. Although this can be done via DnD, but I want to give user an option to do it manually with a menu button. After selecting a node to move follow by the button click, a popup of the same tree will appear. The treestore is being passed into the secondary panel to display the same tree as the primary panel. User will then need to select the new location. Group will move upon confirmation.

    My structure looks like this
    Root
    -> Parent 1
    ----> Child 1
    ----> Child 2
    --------> Grandchild 1
    --------> Grandchild 2
    ---->Child 3
    -> Parent 2

    When I tried to move Child 2 to Child 3, it works and reflects well on the screen. But after which, when I tried to move Child 3 (together with its new child and grandchildren) to Child 1, only Child 3 is there. Child 2 and its 2 children are gone. So my guess is the store did not get updated at all!

    My move codes:
    Code:
    store.remove(sel);
    store.add(targetGroup, sel);
    processFolder(store, (GroupDto) sel);
    tree.refresh(targetGroup);
    store.update(targetGroup);
    tree.setExpanded(targetGroup, true);
    How can I get it to work as intended?
    Last edited by Kathie; 13 Dec 2012 at 12:46 AM. Reason: add more info

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,634
    Vote Rating
    79
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    First, to clarify - do you not want to use DnD? The drag and drop code in GXT works well for trees, which can be tested here: http://www.sencha.com/examples/#Exam...reorderingtree

    Next, even if you don't want to use the DnD feature, consider reading at least how it works - you'd notice an important difference between your code and it. Instead of calling store.remove(M) and store.add(M,M), it uses the store.getSubTree method to get the full structure, removes that structure with store.remove (as you do), then insert it again with store.addSubTree. These *SubTree methods are designed to allow describing the children, grandchildren, etc of the node in question.

    The processFolder method you are invoking probably looks likes the ones we use in some examples. This helper method is really only there to help *build* the tree with sample data - after the tree structure has changed within the store, you can't simply continue to use that method. The point was to tell the store about the structure, not to be the authoritative source of the structure after the store was finished.

  3. #3
    Sencha User
    Join Date
    Dec 2012
    Posts
    17
    Vote Rating
    0
    Kathie is on a distinguished road

      0  

    Default


    Thanks for you reply
    I'm using DnD at the same time wishes to allow the tree nodes to be moved "manually".

    I did try using store.addSubTree, but it gave me IndexOutOfBoundException which I am unable to determine why, thus I used the processFolder method which I thought works (initially).

  4. #4
    Sencha User
    Join Date
    Dec 2012
    Posts
    17
    Vote Rating
    0
    Kathie is on a distinguished road

      0  

    Default


    Alright. It works after I start the index from 0.
    May I know why is that the case since it is an existing non-empty tree?

  5. #5
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,634
    Vote Rating
    79
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    Without seeing an example, I can't tell you a lot. Here is a unit test for the TreeStore that uses addSubTree with an index of other than zero, and it passes.

    Code:
      public void testAddSubTreeEvents() {
        DataTree a = new DataTree("a", 
            new DataTree("aa", 
                new DataTree("aaa"), 
                new DataTree("aac")),
                new DataTree("ab", 
                    new DataTree("aba"),
                    new DataTree("abc")));
        TreeStore<DataTree> store = new TreeStore<DataTree>(new DataKeyProvider());
        ReportingStoreAddHandler<DataTree> reportingAddHandler = new ReportingStoreAddHandler<DataTree>();
        store.addStoreAddHandler(reportingAddHandler);
    
        // Add to the root unfiltered
        store.addSubTree(0, Arrays.asList(a));
        assertEquals(1, reportingAddHandler.getLatestItems().size());
    
        // Enable a filter
        store.addFilter(new StoreFilter<DataTree>() {
          @Override
          public boolean select(Store<DataTree> store, DataTree parent, DataTree item) {
            return item.getName().endsWith("c");
          }
        });
        store.setEnableFilters(true);
        DataTree b = new DataTree("b", new DataTree("ba"));
        DataTree c = new DataTree("c", new DataTree("ca"), new DataTree("cb"));
        DataTree d = new DataTree("d", new DataTree("da"), new DataTree("dc"));
    
        // Add Filtered Items to the root
        store.addSubTree(1, Arrays.asList(b,c,d));
        assertEquals(2, reportingAddHandler.getLatestItems().size());
    
        DataTree de = new DataTree("de", 
            new DataTree("dea"),
            new DataTree("dec"));
        DataTree df = new DataTree("df");
    
        // Add filtered items to an existing node
        store.addSubTree(d, 1, Arrays.asList(de, df));
        assertEquals(1, reportingAddHandler.getLatestItems().size());
    
        // Enable a sort (reverse all existing sort)
        store.addSortInfo(new StoreSortInfo<DataTree>(new NameValueProvider(), SortDir.DESC));
    
        DataTree ac = new DataTree("ac", new DataTree("aca"));
        DataTree ad = new DataTree("ad", new DataTree("ada"));
        store.addSubTree(a, 0, Arrays.asList(ad, ac));
        assertEquals(1, reportingAddHandler.getLatestItems().size());
    
        // Disable filter, just add items sorted
        store.setEnableFilters(false);
        DataTree ae = new DataTree("ae");
        DataTree af = new DataTree("af");
        store.addSubTree(a, 0, Arrays.asList(af, ae));
        assertEquals(2, reportingAddHandler.getLatestItems().size());
      }
    This isn't the full case (missing test classes), but is meant to demonstrate only that the idea should work. Without more details from you (version, failing code with setup), I can't suggest a lot.

  6. #6
    Sencha User
    Join Date
    Dec 2012
    Posts
    17
    Vote Rating
    0
    Kathie is on a distinguished road

      0  

    Default


    Not sure if it is because the nodes were added to the store with the add(p, c) during initiation, instead of addSubTree when it was created. So when the first addSubTree was called, the IndexOutOfBound happened..

    Code:
    TreeNode<BaseDto> toMove = store.getSubTree(sel);
    store.remove(sel);
    store.add(targetGroup, toMove.getData());	    
    store.addSubTree(toMove.getData(), 0, toMove.getChildren());
    Seems to be something to do with toMove being empty at this point of time?
    Last edited by Kathie; 16 Dec 2012 at 10:34 PM. Reason: add code

Thread Participants: 1

Tags for this Thread

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