Exemple #1
0
            public int Compare(object x, object y)
            {
                TreeNodeHelper tnhx = (TreeNodeHelper)x;
                TreeNodeHelper tnhy = (TreeNodeHelper)y;

                return(m_comparer.Compare(tnhx.Ward, tnhy.Ward));
            }
        public void TestTreeNodeHelperBasics()
        {
            string ja0 = "Joseph Adams 1654-1736";
            string ja1 = "John Adams Sr, 1690-1761";
            string ja2 = "John Adams, Jr 1735-1826";
            string aa1 = "Abigail Adams 1765-1813";
            string jqa = "John Quincy Adams 1767-1848";
            string gwa = "George Washington Adams b. 1801";
            string ja3 = "John Adams, III b. 1803";
            string cfa = "Charles Francis Adams b. 1807";
            string lca = "Louisa Catherine Adams b. 1811";
            string sa  = "Susanna Adams 1768-1770";
            string ca  = "Charles Adams b. 1770";
            string tba = "Thomas Boylston Adams b. 1772";

            TreeNodeHelper root   = new TreeNodeHelper(ja0, false, false);
            TreeNodeHelper child  = (TreeNodeHelper)root.AddChild(ja1);
            TreeNodeHelper gchild = (TreeNodeHelper)child.AddChild(ja2);

            gchild.AddChild(aa1);
            gchild.AddChild(sa);
            gchild.AddChild(ca);
            gchild.AddChild(tba);
            TreeNodeHelper ggchild = (TreeNodeHelper)gchild.AddChild(jqa);

            ggchild.AddChild(gwa);
            ggchild.AddChild(ja3);
            ggchild.AddChild(cfa);
            ggchild.AddChild(lca);


            string result = root.ToStringDeep();

            _Debug.Assert(AdamsResult.Equals(result), "TestTreeNodeHelperBasics");
        }
Exemple #3
0
 /// <summary>
 /// Creates a TreeNodeHelper with the indicated object as its ward. It is read-only or auto-indexed according to the
 /// </summary>
 /// <param name="ward">The object that this TreeNodeHelper is helping. If the ward is derived from TreeNodeHelper, use 'this'.</param>
 /// <param name="readOnly">True if this TreeNodeHelper cannot change the tree structure.</param>
 /// <param name="autoIndex">True if all children will be implementers of IHasIdentity, and should be indexed for the GetChild(Guid childID) API.</param>
 public TreeNodeHelper(object ward, bool readOnly, bool autoIndex)
 {
     Ward          = ward;
     m_parent      = null;
     m_children    = null;
     m_childFinder = null;
     IsReadOnly    = readOnly;
     m_autoIndex   = autoIndex;
 }
        public void TestReadOnlyTreeNodeHelperBasics()
        {
            string ja0 = "Joseph Adams 1654-1736";
            string ja1 = "John Adams Sr, 1690-1761";
            string ja2 = "John Adams, Jr 1735-1826";
            string aa1 = "Abigail Adams 1765-1813";
            string jqa = "John Quincy Adams 1767-1848";
            string gwa = "George Washington Adams b. 1801";
            string ja3 = "John Adams, III b. 1803";
            string cfa = "Charles Francis Adams b. 1807";
            string lca = "Louisa Catherine Adams b. 1811";
            string sa  = "Susanna Adams 1768-1770";
            string ca  = "Charles Adams b. 1770";
            string tba = "Thomas Boylston Adams b. 1772";

            TreeNodeHelper root  = new TreeNodeHelper(ja0, false, false);
            TreeNodeHelper child = (TreeNodeHelper)root.AddChild(ja1);

            child = (TreeNodeHelper)child.AddChild(ja2);
            child.AddChild(aa1);
            child.AddChild(sa);
            child.AddChild(ca);
            child.AddChild(tba);
            TreeNodeHelper jqaNode = (TreeNodeHelper)child.AddChild(jqa);

            jqaNode.AddChild(gwa);
            jqaNode.AddChild(ja3);
            jqaNode.AddChild(cfa);
            jqaNode.AddChild(lca);

            jqaNode.SetReadOnly(true);

            bool blewUp = false;

            try {
                jqaNode.AddChild("Alfred E. Neuman 1971-1977");
            } catch (ArgumentException) {
                blewUp = true;
            }
            _Debug.Assert(blewUp, "TestReadOnlyTreeNodeHelperBasics");


            string result = jqaNode.GetRoot().ToStringDeep();

            Console.WriteLine(result);
            _Debug.Assert(AdamsResult.Equals(result), "TestReadOnlyTreeNodeHelperBasics");
        }
Exemple #5
0
        private void Dump(ref System.Text.StringBuilder sb, int levels, ITreeNode parent)
        {
            for (int i = 0; i < levels; i++)
            {
                sb.Append("\t");
            }
            TreeNodeHelper helper = parent as TreeNodeHelper;

            if (helper != null)
            {
                sb.Append(helper.Ward + "\r\n");
            }
            else
            {
                sb.Append(parent + "\r\n");
            }
            foreach (ITreeNode child in parent.Children)
            {
                Dump(ref sb, levels + 1, child);
            }
        }
        public void TestTreeNodeHelperChildSequencing()
        {
            string ja0 = "Joseph Adams 1654-1736";
            string ja1 = "John Adams Sr, 1690-1761";
            string ja2 = "John Adams, Jr 1735-1826";
            string aa1 = "Abigail Adams 1765-1813";
            string jqa = "John Quincy Adams 1767-1848";
            string gwa = "George Washington Adams b. 1801";
            string ja3 = "John Adams, III b. 1803";
            string cfa = "Charles Francis Adams b. 1807";
            string lca = "Louisa Catherine Adams b. 1811";
            string sa  = "Susanna Adams 1768-1770";
            string ca  = "Charles Adams b. 1770";
            string tba = "Thomas Boylston Adams b. 1772";

            TreeNodeHelper root  = new TreeNodeHelper(ja0, false, false);
            TreeNodeHelper child = (TreeNodeHelper)root.AddChild(ja1);

            child = (TreeNodeHelper)child.AddChild(ja2);
            child.AddChild(aa1);
            child.AddChild(sa);
            child.AddChild(ca);
            child.AddChild(tba);
            TreeNodeHelper jqaNode = (TreeNodeHelper)child.AddChild(jqa);

            jqaNode.AddChild(gwa);
            jqaNode.AddChild(ja3);
            jqaNode.AddChild(cfa);
            jqaNode.AddChild(lca);

            jqaNode.ResequenceChildren(Comparer.Default);
            string result = jqaNode.GetRoot().ToStringDeep();

            Console.WriteLine(result);
            _Debug.Assert(AdamsResultJQAChildrenSequenced.Equals(result), "TestTreeNodeHelperChildSequencing");
        }
Exemple #7
0
 protected void WasRemoved(TreeNodeHelper newOrphan)
 {
     OnWasRemoved?.Invoke(this, newOrphan);
 }
Exemple #8
0
 protected void AboutToBeRemoved(TreeNodeHelper childInTheCrosshairs)
 {
     OnAboutToBeRemoved?.Invoke(this, childInTheCrosshairs);
 }
Exemple #9
0
 protected void _OnLostChild(TreeNodeHelper newChild)
 {
     OnLostChild?.Invoke(this, newChild);
 }
Exemple #10
0
 protected void _OnAboutToLoseChild(TreeNodeHelper newChild)
 {
     OnAboutToLoseChild?.Invoke(this, newChild);
 }