Kevincosme / flexlib

Automatically exported from code.google.com/p/flexlib
0 stars 0 forks source link

leaf nodes appear in wrong branch after close/reopen the higher level node #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. create a tree with multiple 2nd level node
2. open all 2nd node
3. close rootNode node
4. re-open rootNode, leaf nodes appear in wrong branch.

What is the expected output? What do you see instead?

Original and Expected output:
rootNode
--1st level A
  -2nd level 1A
       1A_Child_1
       1A_Child_2
  -2nd level 1B
       1B_Child_1
       1B_Child_2

What I see instead:
after closing rootNode and reopen rootNode tree appears as follow

rootNode
--1st level A
  -2nd level 1A
       1A_Child_1
       1A_Child_2
       1B_Child_1
       1B_Child_2
  -2nd level 1B

What version of the product are you using? On what operating system?
1.4, windows, flex 2.0.1

Original issue reported on code.google.com by tica...@gmail.com on 4 Apr 2007 at 10:25

GoogleCodeExporter commented 8 years ago
for module TreeGrid

Original comment by tica...@gmail.com on 4 Apr 2007 at 10:26

GoogleCodeExporter commented 8 years ago

Original comment by darron.schall on 5 Apr 2007 at 10:36

GoogleCodeExporter commented 8 years ago
There is a bug in the "openItemAt" method. The index used to insert rows does 
not
take into account the sub children.

This code seems to work fine :

    /**
     * @return the number of rows added to the display model
     */
    public function openItemAt( rowNum : Number, item : Object = null ) : Number
    {
        var uid : String = itemToUID( item );
        _openItems[ uid ] = item;

        this.selectedIndex = -1;

        if ( item == null )
            item = ListCollectionView( _displayedModel ).getItemAt( rowNum );

        // add the rows for the children at this level
        for ( var i : int = 0; i < _dataDescriptor.getChildren( item ).length; i++ )
        {
            ListCollectionView( _displayedModel ).addItemAt( _dataDescriptor.getChildren( item
)[i], rowNum + i + 1 );
        }

        var offset:Number = 0;

        for ( i = 0; i < _dataDescriptor.getChildren( item ).length; i++ )
        {
            var vChild:Object = _dataDescriptor.getChildren( item )[ i ];

            if ( isItemOpen( vChild ) )
            {
                offset += openItemAt( rowNum + i + 1 + offset, vChild );
            }
        }
        return _dataDescriptor.getChildren( item ).length + offset;
    }

Original comment by sro...@gmail.com on 7 May 2007 at 12:41

GoogleCodeExporter commented 8 years ago
thank you for this solution.
I replaced it in the source and recompiled the .swc and now its fixed :)

Original comment by g.kr.gu...@gmail.com on 25 May 2007 at 6:47

GoogleCodeExporter commented 8 years ago

Original comment by dmcc...@gmail.com on 26 Dec 2007 at 11:44

GoogleCodeExporter commented 8 years ago
obrigado pela solução!!! ajudou muito!!!
abraços Clayton

Original comment by clayton....@gmail.com on 14 Mar 2008 at 8:13

GoogleCodeExporter commented 8 years ago
Even better:

/**
     * This method opens up an item at the row # passed in
     * 
     * @return the number of rows added to the display model
     * or return 0 if there were no children to open up (and thus no rows were added)
     */
    public function openItemAt( rowNum : Number, item : Object = null ) : Number
    {
        //if there was no item passed in then retrieve it via row number
        if ( item == null )
            item = ListCollectionView( _displayedModel ).getItemAt( rowNum );

        //if the item is not already open
        if (!isItemOpen(item))
        {
            //add the item to the list of open items
            var uid : String = itemToUID( item );
            _openItems[ uid ] = item;

            this.selectedIndex = -1;

            //if there are childrent then go and open them up, otherwise skip to the bottom
and return 0
            if ( _dataDescriptor.getChildren( item ) )
            {
                // add the rows for the children at this level
                for ( var i : int = 0; i < _dataDescriptor.getChildren( item ).length; i++ )
                {
                    ListCollectionView( _displayedModel ).addItemAt( _dataDescriptor.getChildren(
item )[i], rowNum + i + 1 );
                }

                var offset:Number = 0;

                for ( i = 0; i < _dataDescriptor.getChildren( item ).length; i++ )
                {
                    var vChild:Object = _dataDescriptor.getChildren( item )[ i ];

                    if ( isItemOpen( vChild ) )
                    {
                        offset += openItemAt( rowNum + i + 1 + offset, vChild );
                    }
                }
                //return the number of children that were opened
                return _dataDescriptor.getChildren( item ).length + offset;
            }
        }
        //if the item was already open then return 0 as well
        return 0;
    }

Original comment by bdub...@gmail.com on 19 Feb 2009 at 8:24