Ejemplo n.º 1
0
        public bool Add(int index, AbstractFieldNode newChild)
        {
            bool isAllowed = false;

            foreach (Type type in AllowedChildTypes)
            {
                if (type.IsInstanceOfType(newChild))
                {
                    isAllowed = true;
                    break;
                }
            }

            if (!isAllowed)
            {
                return(false);
            }

            if (AddChild(index, newChild))
            {
                newChild.m_parent = this;
                newChild.m_index  = index;

                InvokeChildAdded(newChild);

                return(true);
            }

            return(false);
        }
        protected override bool AddChild(int index, AbstractFieldNode newChild)
        {
            if (index < 0 || index > m_children.Count)
                return false;

            m_children.Insert(index, newChild);

            return true;
        }
        protected override bool AddChild(int index, AbstractFieldNode newChild)
        {
            if (index < 0 || index > m_children.Count)
            {
                return(false);
            }

            m_children.Insert(index, newChild);

            return(true);
        }
Ejemplo n.º 4
0
        private void AddChildType(object sender, EventArgs eventArgs)
        {
            MenuItem menuItem = sender as MenuItem;

            Debug.Assert(menuItem != null, "menuItem != null");

            Type type = menuItem.Tag as Type;

            AbstractFieldNode filedNode = Activator.CreateInstance(type) as AbstractFieldNode;

            Add(Count, filedNode);
        }
Ejemplo n.º 5
0
        public void NodeChanged(AbstractFieldNode node)
        {
            TreeNode treeNode = GetTreeNode(node);
            if(treeNode == null)
                return;

            treeNode.Text = node.ToString();

            for (int i = 0; i < node.Count; i++)
            {
                NodeChanged(node.GetChild(i));
            }
        }
Ejemplo n.º 6
0
        public bool Remove()
        {
            if (m_parent != null && m_parent.RemoveChild(m_index))
            {
                AbstractFieldNode parent = m_parent;

                m_parent = null;
                m_index  = -1;

                parent.InvokeChildRemoved(this);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        public static AbstractFieldNode Deserialize(BinaryReader reader)
        {
            string qualifiedName = reader.ReadString();
            Type   type          = Type.GetType(qualifiedName);

            AbstractFieldNode node = Activator.CreateInstance(type) as AbstractFieldNode;

            node.OnDeserialize(reader);

            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                AbstractFieldNode child = Deserialize(reader);
                node.Add(i, child);
            }

            return(node);
        }
Ejemplo n.º 8
0
        public void AddNode(AbstractFieldNode node)
        {
            AbstractFieldNode parent = node.Parent;
            if (parent == null)
            {
                if (m_nodeLookup.Count != 0)
                    throw new InvalidOperationException("Cannot add a root node, a root already exists.");

                LinkedList<MenuItem> menuItems = new LinkedList<MenuItem>();
                node.GetMenuCommands(menuItems);

                TreeNode treeNode = new TreeNode(node.ToString());
                treeNode.ContextMenu = new ContextMenu(menuItems.ToArray());
                treeNode.Tag = node;

                m_treeView.Nodes.Add(treeNode);

                m_treeNodeLookup.Add(node, treeNode);
                m_nodeLookup.Add(treeNode, node);
            }
            else
            {
                LinkedList<MenuItem> menuItems = new LinkedList<MenuItem>();
                node.GetMenuCommands(menuItems);

                TreeNode treeNode = new TreeNode(node.ToString());
                treeNode.ContextMenu = new ContextMenu(menuItems.ToArray());
                treeNode.Tag = node;

                TreeNode parentTreeNode = GetTreeNode(parent);
                parentTreeNode.Nodes.Add(treeNode);
                parentTreeNode.Expand();

                m_treeNodeLookup.Add(node, treeNode);
                m_nodeLookup.Add(treeNode, node);
            }
        }
 protected abstract bool AddChild(int index, AbstractFieldNode newChild);
        public bool Remove()
        {
            if (m_parent != null && m_parent.RemoveChild(m_index))
            {
                AbstractFieldNode parent = m_parent;

                m_parent = null;
                m_index = -1;

                parent.InvokeChildRemoved(this);

                return true;
            }

            return false;
        }
Ejemplo n.º 11
0
        public void ChildNodeRemoved(AbstractFieldNode parent, AbstractFieldNode child)
        {
            TreeNode childTreeNode = GetTreeNode(child);

            childTreeNode.Remove();
        }
        public bool Add(int index, AbstractFieldNode newChild)
        {
            bool isAllowed = false;
            foreach (Type type in AllowedChildTypes)
            {
                if (type.IsInstanceOfType(newChild))
                {
                    isAllowed = true;
                    break;
                }
            }

            if (!isAllowed)
                return false;

            if (AddChild(index, newChild))
            {
                newChild.m_parent = this;
                newChild.m_index = index;

                InvokeChildAdded(newChild);

                return true;
            }

            return false;
        }
 private void OnNodeRemoved(AbstractFieldNode parent, AbstractFieldNode child)
 {
     m_winForm.ChildNodeRemoved(parent, child);
 }
Ejemplo n.º 14
0
 protected abstract bool AddChild(int index, AbstractFieldNode newChild);
Ejemplo n.º 15
0
 protected virtual void InvokeChildRemoved(AbstractFieldNode removedchild)
 {
     OnChildRemoved?.Invoke(this, removedchild);
 }
Ejemplo n.º 16
0
 protected virtual void InvokeChildAdded(AbstractFieldNode newchild)
 {
     OnChildAdded?.Invoke(this, newchild);
 }
 protected virtual void InvokeChildAdded(AbstractFieldNode newchild)
 {
     OnChildAdded?.Invoke(this, newchild);
 }
 private void OnNodeChanged(AbstractFieldNode node)
 {
     m_winForm.NodeChanged(node);
 }
 protected virtual void InvokeChildRemoved(AbstractFieldNode removedchild)
 {
     OnChildRemoved?.Invoke(this, removedchild);
 }
Ejemplo n.º 20
0
 private TreeNode GetTreeNode(AbstractFieldNode node)
 {
     TreeNode treeNode;
     m_treeNodeLookup.TryGetValue(node, out treeNode);
     return treeNode;
 }
 private void OnNodeAdded(AbstractFieldNode parent, AbstractFieldNode child)
 {
     SetupNode(child);
 }
        private void SetupNode(AbstractFieldNode node)
        {
            node.OnChildAdded += OnNodeAdded;
            node.OnChanged += OnNodeChanged;
            node.OnChildRemoved += OnNodeRemoved;
            m_winForm.AddNode(node);

            int childCount = node.Count;
            for (int i = 0; i < childCount; i++)
            {
                SetupNode(node.GetChild(i));
            }
        }