Exemplo n.º 1
0
        public void RemoveElements(IList <T> elements)
        {
            foreach (var element in elements)
            {
                if (element == root)
                {
                    throw new ArgumentException(Maintainer.ConstructError("It is not allowed to remove the root element!"));
                }
            }

            var commonAncestors = TreeElementUtility.FindCommonAncestorsWithinList(elements);

            foreach (var element in commonAncestors)
            {
                element.parent.children.Remove(element);
                element.parent = null;
            }

            TreeElementUtility.TreeToList(root, data);

            Changed();
        }
Exemplo n.º 2
0
        public void AddElement(T element, TreeElement parent, int insertPosition)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", Maintainer.ConstructError("element is null!"));
            }
            if (parent == null)
            {
                throw new ArgumentNullException("parent", Maintainer.ConstructError("parent is null!"));
            }

            if (parent.children == null)
            {
                parent.children = new List <TreeElement> ();
            }

            parent.children.Insert(insertPosition, element);
            element.parent = parent;

            TreeElementUtility.UpdateDepthValues(parent);
            TreeElementUtility.TreeToList(root, data);

            Changed();
        }