Exemple #1
0
        /// <summary>
        /// Removes a child from this object.
        /// </summary>
        /// <param name="child">The child to be removed from this parent.</param>
        public void RemoveChild(object child)
        {
            ITreeNode node = CreateNodeWrapper(child);             // TODO: This might not remove correctly.

            if (!IsReadOnly)
            {
                if (m_children == null || (!m_children.Contains(node)))
                {
                    return;
                }
                OnAboutToLoseChild?.Invoke(this, node);
                ((TreeNodeHelper)node).AboutToBeRemoved(((TreeNodeHelper)node));
                m_children.Remove(node);
                if (m_autoIndex)
                {
                    ITreeNodeProxy       tnp = (ITreeNodeProxy)node;
                    SimCore.IHasIdentity ihi = (SimCore.IHasIdentity)tnp.Ward;
                    m_childFinder.Remove(ihi.Guid);
                }
                OnLostChild?.Invoke(this, node);
                ((TreeNodeHelper)node).WasRemoved(((TreeNodeHelper)node));
            }
            else
            {
                ReadOnlyAccessViolation("RemoveChild");
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds a child to this object. If the TreeNodeHelper is set to autoIndex, the new child
        /// must be an implementer of IHasIdentity, and will be indexed into the list of children.
        /// </summary>
        /// <param name="newChild">The child to be added to this parent.</param>
        /// <returns>The TreeNodeHelper that wraps the new child.</returns>
        public ITreeNode AddChild(object newChild)
        {
            ITreeNode node = CreateNodeWrapper(newChild);

            if (!IsReadOnly)
            {
                OnAboutToGainChild?.Invoke(this, node);
                if (m_children == null)
                {
                    m_children = new ArrayList();
                }
                m_children.Add(node);
                node.Parent = this;
                if (m_autoIndex)
                {
                    if (m_childFinder == null)
                    {
                        m_childFinder = new Hashtable();
                    }
                    ITreeNodeProxy       tnp = (ITreeNodeProxy)node;
                    SimCore.IHasIdentity ihi = (SimCore.IHasIdentity)tnp.Ward;

                    //if ( m_childFinder.Contains(ihi.Guid) ) Console.WriteLine();

                    m_childFinder.Add(ihi.Guid, tnp);
                }
                OnGainedChild?.Invoke(this, node);
            }
            else
            {
                ReadOnlyAccessViolation("AddChild");
            }
            return(node);
        }