src/Misc/EFTools/DesignXmlCore/Base/Shell/TreeGridDesignerTreeControl.cs
/// <summary>
///     Populates the tree via attributes specifed on th root object.  This object usually corresponds to
///     the selection made in a designer.
/// </summary>
/// <returns>True if the tree was populated.  False if the object passed in doesn't specify any branches.</returns>
Populates the tree via attributes specifed on th root object.  This object usually corresponds to
the selection made in a designer.
Populates the tree via attributes specifed on th root object . This object usually corresponds to the selection made in a designer .
internal bool PopulateTree(object root)
        {
            object attributeOwner;
            ArrayList rootBranches = null;
            var tree = Tree;
            if (tree != null
                && root != null)
            {
                var attributes = FindAttributes(root, typeof(TreeGridDesignerColumnAttribute), out attributeOwner);
                TreeGridDesignerColumnDescriptor[] newColumns = null;
                if (attributes != null
                    && attributes.Length > 0)
                {
                    var currentColumn = 0;
                    newColumns = new TreeGridDesignerColumnDescriptor[attributes.Length];
                    Array.Sort(attributes);
                    foreach (TreeGridDesignerColumnAttribute attribute in attributes)
                    {
                        newColumns[currentColumn++] = FindOrCreateColumn(attribute.ColumnType);
                    }
                }
                if (newColumns == null
                    && _defaultColumns != null)
                {
                    newColumns = _defaultColumns;
                }
                if (newColumns != null)
                {
                    attributes = FindAttributes(root, typeof(TreeGridDesignerRootBranchAttribute), out attributeOwner);
                    if (attributes.Length > 0)
                    {
                        Array.Sort(attributes);
                        rootBranches = new ArrayList(attributes.Length);
                        foreach (TreeGridDesignerRootBranchAttribute attribute in attributes)
                        {
                            var branchType = attribute.BranchType;
                            var rootBranch = Activator.CreateInstance(branchType) 
                                as ITreeGridDesignerInitializeBranch;
                            if (rootBranch != null)
                            {
                                if (rootBranch.Initialize(attributeOwner, newColumns))
                                {
                                    rootBranches.Add(rootBranch);
                                }
                            }
                        }
                        if (rootBranches.Count > 0)
                        {
                            var refreshColumns = (_currentColumns == null) || (newColumns.Length != _currentColumns.Length);
                            if (!refreshColumns)
                            {
                                for (var i = 0; i < _currentColumns.Length && !refreshColumns; i++)
                                {
                                    refreshColumns = _currentColumns[i] != newColumns[i];
                                }
                            }
                            if (refreshColumns)
                            {
                                _currentColumns = newColumns;
                                var variableColumnTree = tree as VariableColumnTree;
                                Debug.Assert(variableColumnTree != null, "unable to change column count.");
                                if (variableColumnTree != null)
                                {
                                    variableColumnTree.ChangeColumnCount(_currentColumns.Length);
                                    SetColumns(_currentColumns);
                                }
                            }
                            tree.Root = rootBranches.Count == 1 ? (IBranch)rootBranches[0] : new AggregateBranch(rootBranches, 0);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
internal bool PopulateTree ( object root ) { object attributeOwner ; ArrayList rootBranches = null ; var tree = Tree ; if ( tree != null && root != null ) { var attributes = FindAttributes ( root , typeof ( TreeGridDesignerColumnAttribute ) , out attributeOwner ) ; TreeGridDesignerColumnDescriptor [ ] newColumns = null ; if ( attributes != null && attributes . Length > 0 ) { var currentColumn = 0 ; newColumns = new TreeGridDesignerColumnDescriptor [ attributes . Length ] ; Array . Sort ( attributes ) ; foreach ( TreeGridDesignerColumnAttribute attribute in attributes ) { newColumns [ currentColumn ++ ] = FindOrCreateColumn ( attribute . ColumnType ) ; } } if ( newColumns == null && _defaultColumns != null ) { newColumns = _defaultColumns ; } if ( newColumns != null ) { attributes = FindAttributes ( root , typeof ( TreeGridDesignerRootBranchAttribute ) , out attributeOwner ) ; if ( attributes . Length > 0 ) { Array . Sort ( attributes ) ; rootBranches = new ArrayList ( attributes . Length ) ; foreach ( TreeGridDesignerRootBranchAttribute attribute in attributes ) { var branchType = attribute . BranchType ; var rootBranch = Activator . CreateInstance ( branchType ) as ITreeGridDesignerInitializeBranch ; if ( rootBranch != null ) { if ( rootBranch . Initialize ( attributeOwner , newColumns ) ) { rootBranches . Add ( rootBranch ) ; } } } if ( rootBranches . Count > 0 ) { var refreshColumns = ( _currentColumns == null ) || ( newColumns . Length != _currentColumns . Length ) ; if ( ! refreshColumns ) { for ( var i = 0 ; i < _currentColumns . Length && ! refreshColumns ; i ++ ) { refreshColumns = _currentColumns [ i ] != newColumns [ i ] ; } } if ( refreshColumns ) { _currentColumns = newColumns ; var variableColumnTree = tree as VariableColumnTree ; Debug . Assert ( variableColumnTree != null , " " ) ; if ( variableColumnTree != null ) { variableColumnTree . ChangeColumnCount ( _currentColumns . Length ) ; SetColumns ( _currentColumns ) ; } } tree . Root = rootBranches . Count == 1 ? ( IBranch ) rootBranches [ 0 ] : new AggregateBranch ( rootBranches , 0 ) ; return true ; } } } } return false ; }
Populates the tree via attributes specifed on th root object.
Populates the tree via attributes specifed on th root object .
// determine which columns should be shown // find the column descriptor in the cache or create it // determine which root nodes should be shown // support types that implement IBranch with a default constructor // Only add in the branch if it can be successfully initialized. (Orphaned PELs can't) // we have at least one root branch, now adjust columns accordingly // refresh columns if necessary // root tree at branch
True if the tree was populated.  False if the object passed in doesn't specify any branches.
True if the tree was populated . False if the object passed in doesn ' t specify any branches .
root
object