Пример #1
0
 /// <summary>
 /// Exception handling error mechanism in place.
 /// </summary>
 /// <param name="child"></param>
 private void AddChild(AManaged child)
 {
     OnPreAddChild(child);
     _children.Add(child);
 }
Пример #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="child"></param>
 private void RemoveChild(AManaged child)
 {
     OnPreRemoveChild(child);
     _children.Remove(child);
 }
Пример #3
0
 protected virtual void OnPreRemoveChild(AManaged child)
 {
 }
Пример #4
0
 protected virtual void OnPreAddChild(AManaged child)
 {
 }
Пример #5
0
        // This needs to be a separate call so that the children can define precisely when to attach to parent.
        protected void Initialize(AManaged parent, string name)
        {
            // Keep this order, the _parent assigned first, then the _parent.AddChild.
            _parent = parent;
            _name = name;

            if (_parent != null)
            {
                _parent.AddChild(this);
            }
        }
Пример #6
0
        /// <summary>
        /// When cloning, new item is not assigned to original item's parent.
        /// New created item is left to exist freely.
        /// </summary>
        /// <param name="managed"></param>
        protected void CloneTo(AManaged managed)
        {
            managed._name = _name;
            managed._closed = _closed;

            //    foreach(AManaged child in this.Children)
            //    {
            //        AManaged newChild = (AManaged)child.Clone();
            //        newChild._parent = managed;
            //        managed.AddChild(newChild);
            //    }
        }
        private void SynchronizeCollectionWithNode(TreeNode parentNode, int startingIndex, AManaged[] items)
        {
            for (int i = startingIndex; i < items.Length + startingIndex; i++)
            {
                AManaged item = items[i - startingIndex];

                if (parentNode.Nodes.Count > i && parentNode.Nodes[i].Tag == item)
                {// Node with this index exists and is proper one.
                    parentNode.Nodes[i].ImageIndex = item.ImageIndex;
                    parentNode.Nodes[i].SelectedImageIndex = item.ImageIndex;
                    parentNode.Nodes[i].Text = item.Name;
                }
                else
                {// No existing node or improper one.

                    if (parentNode.Nodes.Count > i)
                    {// This is invalid existing node, remove.
                        parentNode.Nodes.RemoveAt(i);
                    }

                    TreeNode newNode = new TreeNode(item.Name, item.ImageIndex, item.ImageIndex);
                    newNode.Tag = item;

                    parentNode.Nodes.Add(newNode);
                }

                // Recursively synchronize the children.
                SynchronizeCollectionWithNode(parentNode.Nodes[i], 0, item.ChildrenArray);
            }

            for (int j = items.Length + startingIndex; j < parentNode.Nodes.Count; j++)
            {// Clean up the remaining nodes that are no longer valid.
                parentNode.Nodes.RemoveAt(j);
            }
        }