Ejemplo n.º 1
0
        /// <summary>
        /// Get the visible node which matches the given data.
        /// </summary>
        /// <param name="nodes">nodes collection</param>
        /// <param name="data">data.</param>
        /// <returns>visible node.</returns>
        internal TreeNode GetVisibleNode(TreeNodes nodes, object data)
        {
            TreeNode treeNode = null;

            foreach (var node in nodes)
            {
                if (node.Item == data)
                {
                    if (!node.IsFiltered)
                    {
                        treeNode = node;
                    }
                    break;
                }
                else
                {
                    if (!node.IsFiltered && node.IsExpanded)
                    {
                        treeNode = GetVisibleNode(node.ChildNodes, data);
                    }
                    if (treeNode != null)
                    {
                        break;
                    }
                }
            }
            return(treeNode);
        }
        /// <summary>
        /// Validates the CheckBoxProperty value by considering selection mode.
        /// </summary>
        /// <param name="nodes">specifies the tree node collection.</param>
        internal void ValidateCheckBoxPropertyValue(TreeNodes nodes)
        {
            if (string.IsNullOrEmpty(treeGrid.CheckBoxMappingName))
            {
                return;
            }
            if (treeGrid.CheckBoxSelectionMode == CheckBoxSelectionMode.Default)
            {
                return;
            }

            var list = nodes.Where(i => i.IsChecked == true);

            if (treeGrid.SelectionMode == GridSelectionMode.Single)
            {
                if (list.Count() > 1)
                {
                    throw new Exception("Not possible to have IsChecked as true for more than one item when selection mode is single");
                }
                if (list.Any() && treeGrid.SelectionController.SelectedRows.Any(r => r.Node != list.FirstOrDefault()))
                {
                    throw new Exception("Not possible to have IsChecked as true for more than one item when selection mode is single");
                }
            }
            else if (treeGrid.SelectionMode == GridSelectionMode.None)
            {
                if (list.Any())
                {
                    throw new Exception("Not possible to have IsChecked as true for more than one item when selection mode is None");
                }
            }
        }
        internal TreeNode FindParentNode(TreeNodes nodes, TreeNode tempNode)
        {
            TreeNode parentNode = null;

            var index = nodes.nodeList.BinarySearch(tempNode, SortComparer);

            if (index < 0)
            {
                foreach (var node in nodes)
                {
                    if (node.IsExpanded || node.ChildNodes.Any())
                    {
                        parentNode = FindParentNode(node.ChildNodes, tempNode);
                        if (parentNode != null)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                parentNode = nodes[index];
            }

            return(parentNode);
        }
        internal TreeNode FindParentNode(TreeNodes nodes, object childValue)
        {
            TreeNode parentNode = null;

            foreach (var node in nodes)
            {
                var    record      = node.Item;
                object parentValue = propertyAccessProvider.GetValue(record, parentPropertyName);
                //  if (IsEqual(parentValue, childValue))
                if (!IsEqual(SelfRelationRootValue, childValue, true) && IsEqual(parentValue, childValue))
                {
                    parentNode = node;
                    break;
                }
            }
            if (parentNode == null)
            {
                foreach (var node in nodes)
                {
                    if (node.IsExpanded || node.ChildNodes.Any())
                    {
                        parentNode = FindParentNode(node.ChildNodes, childValue);
                        if (parentNode != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(parentNode);
        }
 internal void AddTreeNodes(TreeNode parentNode, TreeNodes nodes)
 {
     foreach (var node in nodes)
     {
         AddNode(parentNode, node, parentNode == null ? Nodes.RootNodes.Count : parentNode.ChildNodes.Count);
     }
 }
        private TreeNodes CopyTreeNodes(TreeNodes treeNodes)
        {
            var nodes = new TreeNodes();

            nodes.nodeList   = treeNodes.nodeList.ToList();
            nodes.sourceList = treeNodes.sourceList.ToList();
            return(nodes);
        }
Ejemplo n.º 7
0
 internal TreeNode(object item, int level, bool isExpanded, TreeNode parentNode, Func <TreeGridView> getView)
 {
     Level           = level;
     Item            = item;
     ParentNode      = parentNode;
     ChildNodes      = new TreeNodes();
     this.isExpanded = isExpanded;
     isDirty         = false;
     maxLevel        = level;
     GetView         = getView;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Finds the next visible node.
        /// </summary>
        /// <param name="nodes">nodes collection.</param>
        /// <param name="node">specific node.</param>
        /// <returns>visible node.</returns>
        private TreeNode FindNode(TreeNodes nodes, TreeNode node)
        {
            int nodeIndex = nodes.IndexOf(node);

            for (int i = nodeIndex + 1; i < nodes.Count; i++)
            {
                if (!nodes[i].IsFiltered)
                {
                    return(nodes[i]);
                }
            }
            return(null);
        }
Ejemplo n.º 9
0
        public TreeNodesEnumerator(TreeNodes nodes)
        {
            this.RootNodes = nodes;
            this.Helper    = new TreeNodesTraversalHelper(RootNodes);

            if (nodes.Count == 0)
            {
                this.next = null;
            }
            else
            {
                next = nodes.FirstOrDefault(n => !n.IsFiltered);
            }
        }
        private TreeNodes GetNodeCollection(object parentValue)
        {
            var nodes = new TreeNodes();

            foreach (object record in SourceCollection)
            {
                object childValue = propertyAccessProvider.GetValue(record, childPropertyName);
                if (IsEqual(parentValue, childValue))
                {
                    var node = FindNodefromData(null, record, true);
                    if (node != null)
                    {
                        nodes.Add(node);
                    }
                }
            }
            return(nodes);
        }
Ejemplo n.º 11
0
 private bool FindNode(TreeNode node, TreeNodes nodes)
 {
     foreach (var treeNode in nodes)
     {
         if (treeNode.Equals(node))
         {
             return(true);
         }
         if (treeNode.IsExpanded)
         {
             var found = FindNode(node, treeNode.ChildNodes);
             if (found)
             {
                 return(true);
             }
             else
             {
                 continue;
             }
         }
     }
     return(false);
 }
Ejemplo n.º 12
0
        public TreeNode GetNode(TreeNodes treeNodes, int index)
        {
            TreeNode node        = null;
            var      nodes       = treeNodes.Where(n => !n.IsFiltered);
            var      actualIndex = index;

            foreach (TreeNode rootNode in nodes)
            {
                if (index <= 0)
                {
                    node = rootNode;
                    break;
                }
                else
                {
                    if (rootNode != null && rootNode.IsExpanded)
                    {
                        var nodeCount = rootNode.GetYAmountCache();
                        if (index <= nodeCount - 1)
                        {
                            index--;
                            node = GetNode(rootNode.ChildNodes, index);
                            break;
                        }
                        else
                        {
                            index -= nodeCount;
                        }
                    }
                    else
                    {
                        index--;
                    }
                }
            }
            return(node);
        }
Ejemplo n.º 13
0
 internal override void ValidateCheckBoxPropertyValue(TreeNodes nodes)
 {
     TreeGrid.NodeCheckBoxController.ValidateCheckBoxPropertyValue(nodes);
 }
Ejemplo n.º 14
0
 public TreeNode()
 {
     ChildNodes = new TreeNodes();
     isDirty    = false;
     maxLevel   = level;
 }
Ejemplo n.º 15
0
 public void Dispose()
 {
     this.RootNodes = null;
 }
Ejemplo n.º 16
0
 public TreeNodeCollection()
 {
     RootNodes = new TreeNodes();
     helper    = new TreeNodesTraversalHelper(this.RootNodes);
 }
        private void UpdateNodesOnParentPropertyChange(object sender, TreeNode treeNode, PropertyChangedEventArgs e)
        {
            if (SelfRelationUpdateMode.HasFlag(SelfRelationUpdateMode.None))
            {
                return;
            }

            var parentValue = propertyAccessProvider.GetValue(sender, parentPropertyName);

            if (treeNode != null && treeNode.ChildNodes.Any())
            {
                object childValue = propertyAccessProvider.GetValue(treeNode.ChildNodes[0].Item, childPropertyName);
                // checking parent property is changed or not (by comparing child and parent property values)
                if (IsEqual(parentValue, childValue))
                {
                    return;
                }
            }
            if ((e == null && SelfRelationUpdateMode.HasFlag(SelfRelationUpdateMode.MoveOnEdit)) || (e != null && SelfRelationUpdateMode.HasFlag(SelfRelationUpdateMode.MoveOnPropertyChange)))
            {
                TreeNodes nodeCollection = null;
                object    childValue     = propertyAccessProvider.GetValue(sender, childPropertyName);
                // if (!IsEqual(parentValue, childValue) || (IsEqual(parentValue, childValue) && SelfRelationRootValue == DependencyProperty.UnsetValue))
                if (!IsEqual(parentValue, childValue) || SelfRelationRootValue == DependencyProperty.UnsetValue)
                {
                    // Root value not set case. Remove root nodes if it has child property value equals to parent property value.
                    nodeCollection = RemoveNodesHavingChildPropertyEqualsToNewParentProperty(parentValue, treeNode);
                }

                // For property change case only

                if (treeNode == null)
                {
                    var childItems = GetChildSourceFromParentID(SelfRelationRootValue, null, true);

                    foreach (var childItem in childItems)
                    {
                        CanAddRootNode(childItem, true);
                    }
                }
                else
                {
                    if (SelfRelationRootValue == DependencyProperty.UnsetValue)
                    {
                        AddRootNodesFromRemovedParent(treeNode);
                        // When parent and child value both are same, need to add the child nodes(removed from root nodes) having child property equal to parent property.
                        if (nodeCollection != null && nodeCollection.Any() && IsEqual(parentValue, childValue) && SelfRelationRootValue == DependencyProperty.UnsetValue)
                        {
                            nodeCollection.Remove(treeNode);
                            if (treeNode.IsExpanded || treeNode.ChildNodes.Any())
                            {
                                AddTreeNodes(treeNode, nodeCollection);
                            }
                        }
                    }
                    else
                    {
                        ResetNodes(treeNode, true);
                    }

                    // After parent property name is changed, if node is expanded and dont have child node, need to populate child nodes based on new parent property value.
                    if (treeNode.IsExpanded && !treeNode.ChildNodes.Any())
                    {
                        TreeGrid.TreeGridModel.ExpandNode(treeNode, true);
                    }
                    else
                    {
                        IsChildNodeAvailable(treeNode);
                        var rowIndex = TreeGrid.ResolveToRowIndex(treeNode);
                        TreeGrid.UpdateDataRow(rowIndex);
                    }
                }
            }
        }
Ejemplo n.º 18
0
 public TreeNodesTraversalHelper(TreeNodes Nodes)
 {
     this.RootNodes = Nodes;
 }