1. #1
    Sencha User
    Join Date
    Oct 2010
    Location
    Philadelphia, PA
    Posts
    10
    Vote Rating
    0
    mdomingo is on a distinguished road

      0  

    Default Tree Grid DND reordering does not update logical TreeModel

    Tree Grid DND reordering does not update logical TreeModel


    I was attempting to perform a mass update on an editortreegrid. Basically the update is, if you change the indent # of a parent, it should increment the indent of all its children. When the tree is first created, and I performed the indent changing, the children would update accordingly. Once I drag and drop a child to a new node, If i tried to perform the indent change on the new parent, the newly dropped child would not update. However, if you changed the original parent then the child would update its indent. I removed all my custom Models and Gridview and tried it again in this watered down test and then debugged through and I still see the same results. If you drag a child to a new parent and then inspect the tree's treedatastore, you will see the parent will not contain the dragged child in its child list. Below is a Test application which will build up a static list and display it in a EditorTreeGrid. Just to give a little more info, I did try to override the onDragDrop method, but I ended up having duplicates, or it would work, except if you tried to drop the child on its direct parent, in which case would make the child disappear from the list altogether.
    - 2.2.0
    - both
    - IE7
    - Windows XP
    - Sample code
    Code:
    public class TestProject implements EntryPoint {
        /**
         * This is the entry point method.
         */
        private static Stack<BaseTreeModel> parents = new Stack<BaseTreeModel>();
        private static List<BaseTreeModel> treeModels;
        
        public void onModuleLoad() {
            final LayoutContainer container = new LayoutContainer();
            container.setSize(800, 600);
            container.setBorders(true);
            container.setScrollMode(Scroll.AUTOY);
            
            // tree source setup
            TreeStore<BaseTreeModel> store = new TreeStore<BaseTreeModel>();
            store.add(createTreeData(), true);
            ColumnModel cm = createColumnModel();
            
            // grid
            EditorTreeGrid editorTreeGrid = new EditorTreeGrid<BaseTreeModel>(store, cm);
            editorTreeGrid.setAutoExpand(true);
            editorTreeGrid.setSelectionModel(new TreeGridSelectionModel<BaseTreeModel>());
            editorTreeGrid.setClicksToEdit(ClicksToEdit.TWO);
            editorTreeGrid.setLoadMask(true);
            editorTreeGrid.setBorders(true);
            editorTreeGrid.getView().setShowDirtyCells(true);
            editorTreeGrid.setTrackMouseOver(false);
            editorTreeGrid.setHeight(500);
            editorTreeGrid.setWidth(500);
                    
            editorTreeGrid.expandAll();
            // drag drop stuff
            new TreeGridDragSource(editorTreeGrid);
            TreeGridDropTarget target = new TreeGridDropTarget(editorTreeGrid){
                 @Override
                protected void onDragDrop(DNDEvent event) {
                    super.onDragDrop(event);
                }
            };
            target.setAllowSelfAsSource(true);
            target.setAllowDropOnLeaf(true);
            target.setFeedback(Feedback.INSERT);
            
            container.add(editorTreeGrid);
            RootPanel.get("sendButtonContainer").add(container);
    
        }
    
        public static List<BaseTreeModel> createTreeData() {
            treeModels = new ArrayList<BaseTreeModel>();
    
            createTreeDataModel("test1", "1");
            createTreeDataModel("test1-2", "2");
            createTreeDataModel("test1-3", "3");
            createTreeDataModel("test2", "1");
            createTreeDataModel("test2-2a", "2");
            createTreeDataModel("test2-2b", "2");
            createTreeDataModel("test2-2b5", "5");
            createTreeDataModel("test2-2b3", "3");
            clearParents();
    
            return treeModels;
        }
    
        private static BaseTreeModel createTreeDataModel(String name, String indent) {
            BaseTreeModel treeModel = new BaseTreeModel();
            treeModel.set("name", name);
            treeModel.set("indent", indent);
            findParent(indent);
            parents.push(treeModel);
    
            return treeModel;
        }
    
        private static void clearParents() {
            if (!parents.empty()) {
                BaseTreeModel parent = parents.pop();
                if (!parents.empty()) {
                    parents.peek().add(parent);
                } else {
                    treeModels.add(parent);
                }
                clearParents();
            }
            return;
        }
    
        /**
         * Recursively finds the parent of the current element being processed.
         * 
         * @param childIndent
         * @return
         */
        private static BaseTreeModel findParent(String childIndent) {
            BaseTreeModel parent;
            if (!parents.empty()) {
                parent = parents.peek();
                int parentIndent = Integer.parseInt((String)parent.get("indent"));
                int childIndex = Integer.parseInt(childIndent);
                if (childIndex > parentIndent) {
                    return parent;
                } else {
                    parent = parents.pop();
                    if (parents.isEmpty()) {
                        treeModels.add(parent);
                    } else {
                        parents.peek().add(parent);
                    }
                    return findParent(childIndent);
                }
            } else {
                return null;
            }
        }
    
        public static ColumnModel createColumnModel() {
            ColumnConfig name = new ColumnConfig("name", "Name", 250);
    
            TreeGridCellRenderer<BaseTreeModel> gridCellRenderer = new TreeGridCellRenderer<BaseTreeModel>();
            name.setRenderer(gridCellRenderer);
            TextField<String> text = new TextField<String>();
            text.setAllowBlank(false);
            name.setEditor(new CellEditor(text));
            List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
            configs.add(name);
            configs.add(getColumnConfig("indent", "indent", 100));
            ColumnModel edaOrKeyedColumnModel = new ColumnModel(configs);
            return edaOrKeyedColumnModel;
        }
    
        public static ColumnConfig getColumnConfig(String id, String header,
                int width) {
            ColumnConfig column = new ColumnConfig();
            column.setId(id);
            column.setHeader(header);
            column.setWidth(width);
            column.setEditor(new CellEditor(new TextField<String>()));
    
            return column;
        }
    }
    Hopefully it is just that I'm performing this type of task incorrectly but I thought this would be fairly straight forward.

    Thanks!
    Max Domingo

  2. #2
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    The parent <-> child relationship is not handled in the model. The treestore keeps track of this.

    What is your testcode showing us? I run that testcode against GXT 2.2.1 and i can reorder the nodes.

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Location
    Philadelphia, PA
    Posts
    10
    Vote Rating
    0
    mdomingo is on a distinguished road

      0  

    Default


    Yes, visually the nodes reorder. I was checking through inspecting the model (debugging) that the treestore does not get an updated. So say you drag, test2-1b3 onto test1-3. It will visually show up under 1-3, however in the treestore, 1-3 will still not contain any children in its child list.

  4. #4
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    How have you checked the treestore?

    You need to call
    Code:
    tree.getChildren(myparent);

  5. #5
    Sencha User
    Join Date
    Oct 2010
    Location
    Philadelphia, PA
    Posts
    10
    Vote Rating
    0
    mdomingo is on a distinguished road

      0  

    Default


    Ah ok, I think I see what I'm doing wrong. Instead of using the selected node out of the event. I need to use the selected item to get the correct node out of the editorTreeGrid's tree store. I was hoping it was something easy like this which is why I put it in the Bug area. Thanks for the help.

  6. #6
    Sencha User
    Join Date
    Oct 2010
    Location
    Philadelphia, PA
    Posts
    10
    Vote Rating
    0
    mdomingo is on a distinguished road

      0  

    Default


    Thank you for the help, I updated my code and started accessing data through the treeGrid's treestore. Everything is working much better now.

Similar Threads

  1. Replies: 12
    Last Post: 11 Jun 2010, 2:21 PM
  2. Update tree on updating the treemodel
    By smiletolead in forum Ext GWT: Discussion
    Replies: 1
    Last Post: 18 Feb 2010, 6:27 AM
  3. Replies: 2
    Last Post: 5 Jun 2008, 1:34 PM

Thread Participants: 1

Tags for this Thread