コード例 #1
0
 public object Clone()
 {
     Tree newValue = new Tree();
     newValue.Name = (string)this.Name.Clone();
     newValue.IsTemplate = this.IsTemplate;
     newValue.TemplateName = (string)this.TemplateName.Clone();
     newValue.Root = (Node)this.Root.Clone();
     return newValue;
 }
コード例 #2
0
 public Page(Tree t)
 {
     if (t != null)
     {
         this.treeHandler = new TreeHandler();
         this.treeHandler.Tree = t;
         this.name = t.Name;
         this.isTemplate = true;
     }
     this.InitPage();
 }
コード例 #3
0
        /// <summary>
        /// 从json文件读取
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool Read(string path)
        {
            if (path == null || path == string.Empty)
            {
                return false;
            }

            string jsonString = this.Load(path);

            if (jsonString == null || jsonString == string.Empty)
            {
                return false;
            }

            Tree tree = (Tree)JsonConvert.DeserializeObject(jsonString, typeof(Tree));
            if (tree == null || tree.Root == null)
            {
                return false;
            }

            this.Tree = tree;
            return true;
        }
コード例 #4
0
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            Point p = this.treeView.PointToClient(new Point(e.X, e.Y));
            ZDLTreeNode node = (ZDLTreeNode)this.treeView.GetNodeAt(p.X, p.Y);//拖拽到的节点
            Node objNode = null;//拖拽到的节点对应的行为树节点
            if (node != null)
            {
                objNode = node.ObjNode;
            }

            object treeNodeData = e.Data.GetData(typeof(ZDLTreeNode));
            object stringData = e.Data.GetData(DataFormats.Text);

            #region 是从左边列表拖进来的
            if (stringData != null)
            {
                string stringDataValue = e.Data.GetData(DataFormats.Text).ToString();

                bool isRoot = false;
                if (this.treeHandler == null || this.treeHandler.Tree.Root == null)
                {
                    isRoot = true;
                }

                if (stringDataValue == "Node")
                {
                    #region 节点
                    if (this.dragNode != null)
                    {
                        if (isRoot)
                        {
                            //创建树
                            Node root = (Node)this.dragNode.Clone();

                            if (this.treeHandler == null)
                            {
                                this.treeHandler = new TreeHandler();
                            }

                            Tree tree = this.treeHandler.Tree;
                            if (tree == null)
                            {
                                tree = new Tree();
                                tree.Name = "untitled";
                                tree.IsTemplate = false;
                                tree.TemplateName = null;
                                this.treeHandler.Tree = tree;
                            }
                            tree.Root = root;
                            this.AddMemento();

                            //添加根节点视图
                            ZDLTreeNode rootNodeView = new ZDLTreeNode(this.dragNode.name + "(" + this.dragNode.type + ")");
                            rootNodeView.ObjNode = root;
                            rootNodeView.ToolTipText = "没有设置进入条件";
                            rootNodeView.ForeColor = Color.Red;
                            this.treeView.Nodes.Add(rootNodeView);
                            this.treeView.ExpandAll();

                            //为编辑状态
                            this.state = PageState.Edit;

                        }
                        else if (node != null && objNode != null)
                        {
                            if (objNode.isVirtual)
                            {
                                //添加对象
                                Node dragNodeClone = (Node)this.dragNode.Clone();
                                objNode.child.Add(dragNodeClone);
                                this.AddMemento();

                                //添加视图
                                ZDLTreeNode nodeView = new ZDLTreeNode(this.dragNode.name + "(" + this.dragNode.type + ")");
                                nodeView.ObjNode = dragNodeClone;
                                nodeView.ToolTipText = "没有设置进入条件";
                                nodeView.ForeColor = Color.Red;
                                node.Nodes.Add(nodeView);
                                node.ExpandAll();

                                //为编辑状态
                                this.state = PageState.Edit;
                            }
                        }
                    }
                    #endregion
                }
                else if (stringDataValue == "Tree")
                {
                    #region 树

                    //如果是拖拽模板创建模板是不允许的
                    if (this.isTemplate)
                    {
                        MessageBox.Show("暂不支持模板拖拽到模板", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    if (this.isTemplate == false && this.dragTree != null && this.dragTree.Root != null)
                    {
                        if (isRoot)
                        {
                            //创建树
                            if (this.treeHandler == null)
                            {
                                this.treeHandler = new TreeHandler();
                            }

                            if (this.treeHandler.Tree == null)
                            {
                                //这种是拖拽模板创建普通树的情况
                                this.treeHandler.Tree = new Tree();
                                this.treeHandler.Tree.TemplateName = this.dragTree.Name;
                                this.treeHandler.Tree.Name = "untitled";
                                this.treeHandler.Tree.IsTemplate = false;
                            }

                            this.treeHandler.Tree.Root = (Node)this.dragTree.Root.Clone();
                            this.AddMemento();

                            //添加根节点视图
                            this.BandIngTreeView(null, null);

                            //为编辑状态
                            this.state = PageState.Edit;
                        }
                        else if (node != null && objNode != null)
                        {
                            if (objNode.isVirtual)
                            {
                                //添加对象
                                Node dragNodeClone = (Node)this.dragTree.Root.Clone();
                                objNode.child.Add(dragNodeClone);
                                this.AddMemento();

                                //添加根节点视图
                                this.BandIngTreeView(null, null);

                                //为编辑状态
                                this.state = PageState.Edit;
                            }
                        }
                    }
                    #endregion
                }
                else if (stringDataValue == "Precondition")
                {
                    #region 条件
                    if (this.dragPrecondition != null)
                    {
                        if (node != null && objNode != null)
                        {
                            Precondition dragPreconditionClone = (Precondition)this.dragPrecondition.Clone();
                            objNode.precondition = dragPreconditionClone;
                            this.AddMemento();

                            node.ExpandAll();
                            node.ToolTipText = dragPreconditionClone.name;
                            node.ForeColor = Color.Black;

                            //为编辑状态
                            this.state = PageState.Edit;
                        }
                    }
                    #endregion
                }
            }
            #endregion

            #region 树本身节点拖拽
            if (treeNodeData != null)
            {
                ZDLTreeNode dNode = treeNodeData as ZDLTreeNode;
                if (dNode != null && node != null && objNode != null && dNode != node)
                {
                    Node dObjNode = dNode.ObjNode;
                    if (dObjNode != null && dObjNode != objNode)
                    {
                        //如果拖拽的节点不是目标节点父亲
                        if (!this.isHasTreeNode(dObjNode.child, objNode))
                        {
                            //如果目标节点不是虚节点,那么只有交换顺序的情况
                            if (!objNode.isVirtual)
                            {
                                #region 交换顺序
                                ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                if (dParentNode != null)
                                {
                                    Node dObjParentNode = dParentNode.ObjNode;
                                    if (dObjParentNode != null)
                                    {
                                        ZDLTreeNode parentNode = (ZDLTreeNode)node.Parent;
                                        if (parentNode != null)
                                        {
                                            Node objParentNode = parentNode.ObjNode;

                                            if (objParentNode != null)
                                            {
                                                if (dParentNode == parentNode)//调整顺序
                                                {
                                                    //数据
                                                    dObjParentNode.child.Remove(dObjNode);
                                                    int index = dObjParentNode.child.IndexOf(objNode);
                                                    dObjParentNode.child.Insert(index, dObjNode);
                                                    this.AddMemento();

                                                    //视图
                                                    dParentNode.Nodes.Remove(dNode);
                                                    index = dParentNode.Nodes.IndexOf(node);
                                                    dParentNode.Nodes.Insert(index, dNode);
                                                    dParentNode.ExpandAll();

                                                    //为编辑状态
                                                    this.state = PageState.Edit;

                                                }

                                            }
                                        }
                                    }
                                }
                                #endregion
                            }
                            else//移动到另一个父亲节点
                            {
                                if (node != dNode.Parent && MessageBox.Show("插入到该节点吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                                {
                                    #region 插入到该节点
                                    ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                    Node dObjParentNode = dParentNode.ObjNode;

                                    if (dParentNode != null && dObjParentNode != null)
                                    {
                                        //数据
                                        dObjParentNode.child.Remove(dObjNode);
                                        objNode.child.Add(dObjNode);
                                        this.AddMemento();

                                        //视图
                                        dParentNode.Nodes.Remove(dNode);
                                        node.Nodes.Add(dNode);
                                        node.ExpandAll();

                                        //为编辑状态
                                        this.state = PageState.Edit;
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 交换顺序
                                    ZDLTreeNode dParentNode = (ZDLTreeNode)dNode.Parent;
                                    if (dParentNode != null)
                                    {
                                        Node dObjParentNode = dParentNode.ObjNode;
                                        if (dObjParentNode != null)
                                        {
                                            ZDLTreeNode parentNode = (ZDLTreeNode)node.Parent;
                                            if (parentNode != null)
                                            {
                                                Node objParentNode = parentNode.ObjNode;

                                                if (objParentNode != null)
                                                {
                                                    if (dParentNode == parentNode)//调整顺序
                                                    {
                                                        //数据
                                                        dObjParentNode.child.Remove(dObjNode);
                                                        int index = dObjParentNode.child.IndexOf(objNode);
                                                        dObjParentNode.child.Insert(index, dObjNode);
                                                        this.AddMemento();

                                                        //视图
                                                        dParentNode.Nodes.Remove(dNode);
                                                        index = dParentNode.Nodes.IndexOf(node);
                                                        dParentNode.Nodes.Insert(index, dNode);
                                                        dParentNode.ExpandAll();

                                                        //为编辑状态
                                                        this.state = PageState.Edit;

                                                    }

                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }
            }
            #endregion
        }
コード例 #5
0
        /// <summary>
        /// 确认按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sureButton_Click(object sender, EventArgs e)
        {
            string error = null;
            if (!this.checkData(ref error))
            {
                MessageBox.Show(error, "错误", MessageBoxButtons.OK);
                return;
            }

            if(this.editTree != null)
            {
                Tree tmpP = new Tree();
                tmpP.Name = this.editTree.Name;

                this.editTree.Name = this.nameTextBox.Text.Trim();

                List<Tree> parms = new List<Tree>();
                parms.Add(tmpP);
                parms.Add(this.editTree);
                NotificationCenter.DefaultCenter().postNotification("TreeUpdate", parms);
            }
            else
            {
                Tree newTree = new Tree();
                newTree.Name = this.nameTextBox.Text.Trim();
                newTree.IsTemplate = true;
                newTree.TemplateName = null;
                this.treeDatas.Add(newTree);
            }

            if (this.m_delegate != null)
            {
                this.m_delegate.RefreshTemplateForm();
            }

            this.Close();
        }