public NodeTreeViewManager(TreeView treeView, NodeClasses nodeClasses)
        {
            m_TreeView    = treeView;
            m_NodeClasses = nodeClasses;

            treeView.Nodes.Clear();
            m_CompositeItem              = new NodeTypeItem();
            m_CompositeItem.NodeType     = NodeType.Composite;
            m_CompositeItem.TreeNode     = m_TreeView.Nodes.Add("组合节点");
            m_CompositeItem.TreeNode.Tag = m_CompositeItem;

            m_DecoratorItem              = new NodeTypeItem();
            m_DecoratorItem.NodeType     = NodeType.Decorator;
            m_DecoratorItem.TreeNode     = m_TreeView.Nodes.Add("装饰节点");
            m_DecoratorItem.TreeNode.Tag = m_DecoratorItem;

            m_ConditionItem              = new NodeTypeItem();
            m_ConditionItem.NodeType     = NodeType.Condition;
            m_ConditionItem.TreeNode     = m_TreeView.Nodes.Add("条件节点");
            m_ConditionItem.TreeNode.Tag = m_ConditionItem;

            m_ActionItem              = new NodeTypeItem();
            m_ActionItem.NodeType     = NodeType.Action;
            m_ActionItem.TreeNode     = m_TreeView.Nodes.Add("动作节点");
            m_ActionItem.TreeNode.Tag = m_ActionItem;
        }
        public CategoryItem FindCategoryItem(NodeType nodeType, string categoryStr)
        {
            NodeTypeItem nodeTypeItem = GetNodeTypeItem(nodeType);

            for (int i = 0; i < nodeTypeItem.TreeNode.Nodes.Count; i++)
            {
                TreeNode     treeNode     = nodeTypeItem.TreeNode.Nodes[i];
                CategoryItem categoryItem = FindCategoryItem(treeNode, categoryStr);
                if (categoryItem != null)
                {
                    return(categoryItem);
                }
            }

            return(null);
        }
        private void 添加类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NodeType nodeType = NodeType.Composite;

            if (treeView1.SelectedNode != null)
            {
                TreeNode treeNode = treeView1.SelectedNode;
                while (treeNode.Parent != null)
                {
                    treeNode = treeNode.Parent;
                }

                if (treeNode.Tag is NodeTypeItem)
                {
                    NodeTypeItem nodeTypeItem = treeNode.Tag as NodeTypeItem;
                    nodeType = nodeTypeItem.NodeType;
                }
            }

            AddDefineForm addDefineForm = new AddDefineForm(nodeType, this);

            addDefineForm.ShowDialog();
        }
        public NodeItem BindNodeClass(NodeClass nodeClass)
        {
            NodeTypeItem nodeTypeItem = GetNodeTypeItem(nodeClass.NodeType);

            if (nodeTypeItem == null)
            {
                return(null);
            }

            NodeItem nodeItem = FindNodeItem(nodeClass);

            //刷新
            if (nodeItem != null)
            {
                if (nodeItem.OldNodeType == nodeClass.NodeType && nodeItem.OldCategory == nodeClass.Category)
                {
                    nodeItem.TreeNode.Text = nodeClass.ClassType;
                    return(nodeItem);
                }
                else
                {
                    nodeItem.TreeNode.Remove();
                }

                if (nodeItem.OldCategory != nodeClass.Category)
                {
                    CheckRemoveCategory(nodeItem.OldNodeType, nodeItem.OldCategory);
                }
            }

            if (nodeItem == null)
            {
                nodeItem = new NodeItem();
            }

            if (string.IsNullOrEmpty(nodeClass.Category))
            {
                TreeNode treeNode = nodeTypeItem.TreeNode.Nodes.Add(nodeClass.ClassType);
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = null;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeClass    = nodeClass;

                nodeItem.OldCategory = nodeClass.Category;
                nodeItem.OldNodeType = nodeClass.NodeType;
            }
            else
            {
                CategoryItem categoryItem = FindCategoryItem(nodeClass.NodeType, nodeClass.Category);

                if (categoryItem == null)
                {
                    categoryItem = BindCategory(nodeTypeItem.TreeNode, nodeClass.Category);
                }

                TreeNode treeNode = categoryItem.TreeNode.Nodes.Add(nodeClass.ClassType);
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = categoryItem;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeClass    = nodeClass;

                nodeItem.OldCategory = nodeClass.Category;
                nodeItem.OldNodeType = nodeClass.NodeType;
            }

            return(nodeItem);
        }
        public NodeItem BindNodeDefine(NodeDefine nodeDefine)
        {
            NodeTypeItem nodeTypeItem = GetNodeTypeItem(nodeDefine.NodeType);

            if (nodeTypeItem == null)
            {
                return(null);
            }

            NodeItem nodeItem = FindNodeItem(nodeDefine);

            //刷新
            if (nodeItem != null)
            {
                if (nodeItem.OldNodeType == nodeDefine.NodeType && nodeItem.OldCategory == nodeDefine.Category)
                {
                    nodeItem.TreeNode.Text = nodeDefine.ClassType + (string.IsNullOrEmpty(nodeDefine.Label) ? string.Empty : " (" + nodeDefine.Label + ")");
                    return(nodeItem);
                }
                else
                {
                    nodeItem.TreeNode.Remove();
                }

                if (nodeItem.OldCategory != nodeDefine.Category)
                {
                    CheckRemoveCategory(nodeItem.OldNodeType, nodeItem.OldCategory);
                }
            }

            if (nodeItem == null)
            {
                nodeItem = new NodeItem();
            }

            if (string.IsNullOrEmpty(nodeDefine.Category))
            {
                TreeNode treeNode = nodeTypeItem.TreeNode.Nodes.Add(nodeDefine.ClassType + (string.IsNullOrEmpty(nodeDefine.Label) ? string.Empty : " (" + nodeDefine.Label + ")"));
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = null;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeDefine   = nodeDefine;

                nodeItem.OldCategory = nodeDefine.Category;
                nodeItem.OldNodeType = nodeDefine.NodeType;
            }
            else
            {
                CategoryItem categoryItem = FindCategoryItem(nodeDefine.NodeType, nodeDefine.Category);

                if (categoryItem == null)
                {
                    categoryItem = BindCategory(nodeTypeItem.TreeNode, nodeDefine.Category);
                }

                TreeNode treeNode = categoryItem.TreeNode.Nodes.Add(nodeDefine.ClassType + (string.IsNullOrEmpty(nodeDefine.Label) ? string.Empty : " (" + nodeDefine.Label + ")"));
                treeNode.Tag          = nodeItem;
                nodeItem.TreeNode     = treeNode;
                nodeItem.CategoryItem = categoryItem;
                nodeItem.NodeTypeItem = nodeTypeItem;
                nodeItem.NodeDefine   = nodeDefine;

                nodeItem.OldCategory = nodeDefine.Category;
                nodeItem.OldNodeType = nodeDefine.NodeType;
            }

            return(nodeItem);
        }