Example #1
0
        /// <summary>
        /// Create and add child nodes for subtables of this node and direct greater columns.
        /// </summary>
        public void ExpandTree(bool recursively = true)
        {
            if (Input == null) // We cannot expand the set but try to expand the existing children
            {
                if (!recursively)
                {
                    return;
                }
                foreach (ColumnNode c in this)
                {
                    if (!(c is SubtableTree))
                    {
                        continue;
                    }
                    ((SubtableTree)c).ExpandTree(recursively);
                }
                return;
            }

            foreach (DcColumn sd in Input.SubColumns)
            {
                if (ExistsChild(sd))
                {
                    continue;
                }

                // New child instances need to have the type of this instance (this instance can be an extension of this class so we do not know it)
                ColumnNode child = (ColumnNode)Activator.CreateInstance(this.GetType(), new Object[] { sd, null });
                this.AddChild(child);

                if (recursively && (child is SubtableTree))
                {
                    ((SubtableTree)child).ExpandTree(recursively);
                }
            }

            // Add child nodes for greater column (no recursion)
            foreach (DcColumn gd in Input.Columns)
            {
                if (gd.IsSuper)
                {
                    continue;
                }
                if (ExistsChild(gd))
                {
                    continue;
                }

                // New child instances need to have the type of this instance (this instance can be an extension of this class so we do not know it)
                ColumnNode child = (ColumnNode)Activator.CreateInstance(this.GetType(), new Object[] { gd, null });
                this.AddChild(child);
            }
        }
Example #2
0
 public SubtableTree(DcColumn col, ColumnNode parent = null)
     : base(col, parent)
 {
     // Register for events from the schema (or inside constructor?)
 }
Example #3
0
        protected override void Input_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) // Changes in our lesser set
        {
            if (!IsSubsetNode)
            {
                return;                // Child nodes are added/deleted for only super-columns (for subset trees)
            }
            DcColumn col = null;

            if (e.Action == NotifyCollectionChangedAction.Add) // Decide if this node has to add a new child node
            {
                col = e.NewItems != null && e.NewItems.Count > 0 ? (Column)e.NewItems[0] : null;
                if (col == null)
                {
                    return;
                }

                if (col.IsSuper)                    // Inclusion
                {
                    if (col.Output == Column.Input) // Add a subset child node (recursively)
                    {
                        if (!ExistsChild(col))
                        {
                            // New child instances need to have the type of this instance (this instance can be an extension of this class so we do not know it)
                            ColumnNode child = (ColumnNode)Activator.CreateInstance(this.GetType(), new Object[] { col, null });
                            AddChild(child);

                            if (child is SubtableTree)
                            {
                                ((SubtableTree)child).ExpandTree(true);
                            }
                        }
                    }
                }
                else // Poset
                {
                    if (col.Input == Column.Input) // Add an attribute child node (non-recursively)
                    {
                        if (!ExistsChild(col))
                        {
                            // New child instances need to have the type of this instance (this instance can be an extension of this class so we do not know it)
                            ColumnNode child = (ColumnNode)Activator.CreateInstance(this.GetType(), new Object[] { col, null });
                            AddChild(child);
                        }
                    }
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                col = e.OldItems != null && e.OldItems.Count > 0 ? (Column)e.OldItems[0] : null;
                if (col == null)
                {
                    return;
                }

                if (col.IsSuper)                    // Inclusion
                {
                    if (col.Output == Column.Input) // Remove a subset child node (recursively)
                    {
                        ColumnNode child = GetChild(col);
                        if (child != null)
                        {
                            RemoveChild(child);
                        }
                    }
                }
                else // Poset
                {
                    if (col.Input == Column.Input) // Add an attribute child node (non-recursively)
                    {
                        ColumnNode child = GetChild(col);
                        if (child != null)
                        {
                            RemoveChild(child);
                        }
                    }
                }
            }
        }