예제 #1
0
        private void InitController()
        {
            _navigationTreeController = new TypeBinderTreeViewController(this.dataEntityTree);

            #region ImageList

            //节点的小图标ImageList
            ImageList _imageList = new ImageList();
            _imageList.Images.Add(IconsLibrary.Folder);      //0
            _imageList.Images.Add(IconsLibrary.DataEntity3); //1
            _imageList.Images.Add(IconsLibrary.Cube2);       //2
            _navigationTreeController.ImageList = _imageList;

            #endregion

            #region Codon

            _navigationTreeController.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                                       typeof(DataEntityFolder), typeof(DataEntityDev),
                                                       DataEntityFolder.Property_Text, DataEntityFolder.Property_Items)
            {
                ImageIndex       = TreeImages.Folder,
                ContextMenuStrip = _treeMenuDataEntityFolder.View
            });

            _navigationTreeController.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                                       typeof(DataEntityDev), typeof(DataItemEntityDev),
                                                       DataEntityDev.Property_Name, DataEntityDev.Property_Items)
            {
                ImageIndex       = TreeImages.DataEntity,
                ContextMenuStrip = _treeMenuDataEntity.View
            });

            _navigationTreeController.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                                       typeof(DataItemEntityDev), DataItemEntityDev.Property_Name)
            {
                ImageIndex       = TreeImages.DataItemEntity,
                ContextMenuStrip = _treeMenuDataItemEntity.View
            });

            #endregion

            _navigationTreeController.AfterSelect +=
                new TypeBinderTreeViewController.OnAfterSelectHandler(_navigationTreeController_AfterSelect);
        }
        private void InitController()
        {
            _controller = new TypeBinderTreeViewController(this.treeView);

            #region ImageList

            //节点的小图标ImageList
            ImageList _imageList = new ImageList();
            _imageList.Images.Add(IconsLibrary.Folder); //0
            _imageList.Images.Add(IconsLibrary.Menu);   //1
            _controller.ImageList = _imageList;

            #endregion

            #region Codon

            _controller.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                         typeof(MenuEntityFolder), typeof(MenuEntity),
                                         MenuEntityFolder.Property_Text, MenuEntityFolder.Property_Items)
            {
                ImageIndex       = TreeImages.Folder,
                ContextMenuStrip = _treeMenuMenuEntityFolder.View
            });

            _controller.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                         typeof(MenuEntity), typeof(MenuEntity), MenuEntity.Property_Name, MenuEntity.Property_Menus)
            {
                ActOnSubClass    = true,//因为实际运行是Dev结尾的类型
                ImageIndex       = TreeImages.MenuEntity,
                ContextMenuStrip = _treeMenuMenuEntity.View
            });

            #endregion

            _controller.AfterSelect += new TypeBinderTreeViewController.OnAfterSelectHandler(_controller_AfterSelect);
        }
예제 #3
0
        private void InitController()
        {
            _controller = new TypeBinderTreeViewController(this.treeView);

            #region ImageList

            //节点的小图标ImageList
            ImageList _imageList = new ImageList();
            _imageList.Images.Add(IconsLibrary.Folder);        //0
            _imageList.Images.Add(IconsLibrary.ActiveTabItem); //1
            _imageList.Images.Add(IconsLibrary.GroupItem);     //2
            _imageList.Images.Add(IconsLibrary.Menu);          //3
            _controller.ImageList = _imageList;

            #endregion

            #region Codon

            _controller.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                         typeof(ToolStripItemFolder), typeof(ToolStripPageEntity),
                                         ToolStripItemFolder.Property_Text, ToolStripItemFolder.Property_Items)
            {
                ImageIndex       = TreeImages.Folder,
                ContextMenuStrip = _treeMenuToolStripItemFolder.View
            });

            TypeBinderTreeViewNodeCodon pageCodon = new TypeBinderTreeViewNodeCodon(
                typeof(ToolStripPageEntity), typeof(ToolStripGroupEntity),
                ToolStripItemAbstract.Property_Name)
            {
                ImageIndex          = TreeImages.ToolStripPageEntity,
                ActOnSubClass       = true,
                ContextMenuStrip    = _treeMenuToolStripPage.View,
                RelationChildMember = ToolStripPageEntity.Property_Id
            };
            pageCodon.GetItemsFunc = (pageEntity) =>
            {
                return(ToolStripArchive.Instance.GetGroupCollection(((ToolStripPageEntity)pageEntity).Id));
            };
            _controller.AddNodeCodon(pageCodon);

            TypeBinderTreeViewNodeCodon groupCodon = new TypeBinderTreeViewNodeCodon(
                typeof(ToolStripGroupEntity), typeof(ToolStripItemAbstract),
                ToolStripItemAbstract.Property_Name)
            {
                ImageIndex           = TreeImages.ToolStripGroupEntity,
                ActOnSubClass        = true,
                ContextMenuStrip     = _treeMenuToolStripGroup.View,
                RelationParentMember = ToolStripGroupEntity.Property_PageId,
                RelationChildMember  = ToolStripGroupEntity.Property_Id
            };
            groupCodon.GetItemsFunc = (groupEntity) =>
            {
                return(ToolStripArchive.Instance.GetEntityList(((ToolStripGroupEntity)groupEntity).Id));
            };
            _controller.AddNodeCodon(groupCodon);

            _controller.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                         typeof(ToolStripItemAbstract), ToolStripItemAbstract.Property_Name)
            {
                ActOnSubClass        = true,//因为实际运行是Dev结尾的类型
                ImageIndex           = TreeImages.ToolStripItemAbstract,
                ContextMenuStrip     = _treeMenuToolStripItem.View,
                RelationParentMember = ToolStripItemAbstract.Property_GroupId
            });

            #endregion

            _controller.AfterSelect += new TypeBinderTreeViewController.OnAfterSelectHandler(_controller_AfterSelect);

            #region 处理拖放

            treeView.AllowDrop = true;

            #region CanDragFunc

            treeView.CanDragFunc = (dragNode) =>
            {
                //总文件夹不允许拖动
                ITypeBinderTreeViewNode binderDragNode = (ITypeBinderTreeViewNode)dragNode;
                if (binderDragNode.Codon.DataBoundType == typeof(ToolStripItemFolder))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            };

            #endregion

            #region CanDropFunc

            treeView.CanDropFunc = (dragNode, dropNode) =>
            {
                ITypeBinderTreeViewNode binderDragNode = (ITypeBinderTreeViewNode)dragNode;
                ITypeBinderTreeViewNode binderDropNode = (ITypeBinderTreeViewNode)dropNode;

                //如果拖的是页,那只允许放在页上
                if (binderDragNode.Codon.DataBoundType == typeof(ToolStripPageEntity))
                {
                    if (binderDropNode.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        return(true);
                    }
                }

                //如果拖的是分组,允许放在页和分组上
                if (binderDragNode.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                {
                    if (binderDropNode.Codon.DataBoundType == typeof(ToolStripPageEntity) ||
                        binderDropNode.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        return(true);
                    }
                }

                //如果拖的是项,允许放在分组和项上
                if (binderDragNode.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                {
                    if (binderDropNode.Codon.DataBoundType == typeof(ToolStripGroupEntity) ||
                        binderDropNode.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                    {
                        return(true);
                    }
                }

                return(false);
            };

            #endregion

            #region DragDropAction

            treeView.DragDropAction = (dragNode, dropNode) =>
            {
                ITypeBinderTreeViewNode binderDragNode = (ITypeBinderTreeViewNode)dragNode;
                ITypeBinderTreeViewNode binderDropNode = (ITypeBinderTreeViewNode)dropNode;

                #region 如果拖的是页

                //如果拖的是页,那只允许放在页上
                //移动拖动的页到放置的页后面
                if (binderDragNode.Codon.DataBoundType == typeof(ToolStripPageEntity))
                {
                    if (binderDropNode.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        //只要调用 _toolStripArchive.MovePageAfter 就行了
                        //树节点的移动会由相关事件引发
                        ToolStripPageEntity dragPage = (ToolStripPageEntity)binderDragNode.DataBoundItem;
                        ToolStripPageEntity dropPage = (ToolStripPageEntity)binderDropNode.DataBoundItem;
                        _toolStripArchive.MovePageAfter(dragPage.Id, dropPage.Id);
                    }
                }

                #endregion

                #region 如果拖的是分组

                //如果拖的是分组,允许放在页和分组上
                if (binderDragNode.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                {
                    ToolStripGroupEntity dragGroup = (ToolStripGroupEntity)binderDragNode.DataBoundItem;

                    //放在放置页的最后面
                    if (binderDropNode.Codon.DataBoundType == typeof(ToolStripPageEntity))
                    {
                        ToolStripPageEntity dropPage = (ToolStripPageEntity)binderDropNode.DataBoundItem;
                        dragGroup.PageId = dropPage.Id;

                        //确保拖的分组在放的页的最后一项
                        if (binderDropNode.Items.Count > 0)
                        {
                            ToolStripGroupEntity lastGroup = (ToolStripGroupEntity)binderDropNode.Items[binderDropNode.Items.Count - 1];
                            _toolStripArchive.MoveGroupAfter(dragGroup.Id, lastGroup.Id);
                        }

                        _toolStripArchive.UpdateGroup(dragGroup);
                    }
                    //放在放置分组的后面,同时注意修改拖动分组所属页到放置分组所属的页上
                    else if (binderDropNode.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        ToolStripGroupEntity dropGroup = (ToolStripGroupEntity)binderDropNode.DataBoundItem;
                        _toolStripArchive.MoveGroupAfter(dragGroup.Id, dropGroup.Id);

                        if (dragGroup.PageId != dropGroup.PageId)
                        {
                            dragGroup.PageId = dropGroup.PageId;
                            _toolStripArchive.UpdateGroup(dragGroup);
                        }
                    }
                }

                #endregion

                #region 如果拖的是项

                //如果拖的是项,允许放在分组和项上
                if (binderDragNode.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                {
                    ToolStripItemAbstract dragItem = (ToolStripItemAbstract)binderDragNode.DataBoundItem;

                    //放在放置分组的最后面,同时修改拖动项所属分组
                    //放置分组肯定不是项原来的分组,因为如果把树子节点拖到自己的父节点上什么也不会发生,SETreeView里不允许这种操作
                    if (binderDropNode.Codon.DataBoundType == typeof(ToolStripGroupEntity))
                    {
                        ToolStripGroupEntity dropGroup = (ToolStripGroupEntity)binderDropNode.DataBoundItem;
                        dragItem.GroupId = dropGroup.Id;

                        //确保拖的分组在放的页的最后一项
                        if (binderDropNode.Items.Count > 0)
                        {
                            ToolStripItemAbstract lastItem = (ToolStripItemAbstract)binderDropNode.Items[binderDropNode.Items.Count - 1];
                            _toolStripArchive.MoveAfter(dragItem.Id, lastItem.Id);
                        }

                        _toolStripArchive.Update(dragItem);
                    }
                    //放在放置项的后面,同时修改拖动项所属分组为放置项所属的分组,如果他们不在一个分组
                    if (binderDropNode.Codon.DataBoundType == typeof(ToolStripItemAbstract))
                    {
                        ToolStripItemAbstract dropItem = (ToolStripItemAbstract)binderDropNode.DataBoundItem;
                        _toolStripArchive.MoveAfter(dragItem.Id, dropItem.Id);

                        if (dragItem.GroupId != dropItem.GroupId)
                        {
                            dragItem.GroupId = dropItem.GroupId;
                            _toolStripArchive.Update(dragItem);
                        }
                    }
                }

                #endregion
            };

            #endregion

            #endregion
        }
예제 #4
0
        private void InitController()
        {
            _navigationTreeController = new TypeBinderTreeViewController(this.navigationTree);

            #region ImageList

            //节点的小图标ImageList
            ImageList _imageList = new ImageList();
            _imageList.Images.Add(IconsLibrary.Folder); //0
            _imageList.Images.Add(IconsLibrary.Form);   //1
            _navigationTreeController.ImageList = _imageList;

            #endregion

            #region Codon



            _navigationTreeController.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                                       typeof(FolderEntityIndex), typeof(WindowEntityIndex),
                                                       FolderEntityIndex.Property_Name, FolderEntityIndex.Property_Items)
            {
                ImageIndex       = TreeImages.Folder,
                ContextMenuStrip = _treeMenuFolder.View
                                   //GetItemsFunc = (folderEntity) =>
                                   //{
                                   //    return WindowArchive.Instance.GetIndexList(((FolderEntityIndex)folderEntity).Id);
                                   //}
            });

            _navigationTreeController.AddNodeCodon(new TypeBinderTreeViewNodeCodon(
                                                       typeof(WindowEntityIndex), WindowEntityIndex.Property_Name)
            {
                ImageIndex       = TreeImages.Form,
                ContextMenuStrip = _treeMenuWindowEntity.View
            });

            #endregion

            _navigationTreeController.AfterSelect +=
                new TypeBinderTreeViewController.OnAfterSelectHandler(_navigationTreeController_AfterSelect);

            #region 处理拖放

            navigationTree.AllowDrop = true;

            navigationTree.CanDropFunc = (dragNode, dropNode) =>
            {
                //只有在放置节点为目录时,才允许放置
                ITypeBinderTreeViewNode binderDropNode = (ITypeBinderTreeViewNode)dropNode;
                if (binderDropNode.Codon.DataBoundType == typeof(FolderEntityIndex))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };

            navigationTree.DragDropAction = (dragNode, dropNode) =>
            {
                ITypeBinderTreeViewNode binderDragNode = (ITypeBinderTreeViewNode)dragNode;
                ITypeBinderTreeViewNode binderDropNode = (ITypeBinderTreeViewNode)dropNode;
                FolderEntityIndex       dropFolder     = (FolderEntityIndex)binderDropNode.DataBoundItem;

                if (binderDragNode.Codon.DataBoundType == typeof(FolderEntityIndex))
                {
                    FolderEntityIndex dragFolder = (FolderEntityIndex)binderDragNode.DataBoundItem;
                    _windowArchive.MoveFolder(dragFolder.Id, dropFolder.Id);
                }
                else if (binderDragNode.Codon.DataBoundType == typeof(WindowEntityIndex))
                {
                    WindowEntityIndex dragWindow = (WindowEntityIndex)binderDragNode.DataBoundItem;
                    _windowArchive.MoveWindow(dragWindow.Id, dropFolder.Id);
                }
                else
                {
                    Debug.Assert(false, "未处理的节点类型");
                }

                binderDragNode.Parent.Items.Remove(binderDragNode.DataBoundItem);
                binderDropNode.Items.Add(binderDragNode.DataBoundItem);

                navigationTree.MoveNode(dragNode, dropNode);
            };

            #endregion
        }