Example #1
0
        /// <summary>
        /// 通过element添加ElementNode节点,并添加到树中
        /// </summary>
        public virtual ElementNode AddElementNode(SimpleExIndexXmlElement element)
        {
            ///IsDeleted为true的,表示已经被删除,不显示
            if (element.IsDeleted)
            {
                return(null);
            }

            ElementNode elementNode = null;

            switch (element.DataType)
            {
            case DataType.Channel:
                //右侧树或选择频道才加载频道
                if (TreeView.TreeMode == TreeMode.General || TreeView.TreeMode == TreeMode.SelectChannel)
                {
                    elementNode = new ChannelNode(element as ChannelSimpleExXmlElement);
                }
                break;

            case DataType.Tmplt:
                //选择模板文件夹的树不加载模板文件
                if (TreeView.TreeMode == TreeMode.SelectTmplt || TreeView.TreeMode == TreeMode.General)
                {
                    elementNode = new TmpltNode(element as TmpltSimpleExXmlElement);
                }
                break;

            case DataType.Page:
                //只有在右侧树中才显示页面
                if (TreeView.TreeMode == TreeMode.General)
                {
                    elementNode = new PageNode(element as PageSimpleExXmlElement);
                }
                break;

            case DataType.Resources:
                //只有在右侧树中才显示资源文件夹
                if (TreeView.TreeMode == TreeMode.General)
                {
                    elementNode = new ResourceRootNode(element as ResourcesXmlElement);
                }
                break;

            case DataType.Folder:
            {
                switch (((FolderXmlElement)element).FolderType)
                {
                case FolderType.ChannelFolder:
                    //选择模板和选择模板文件夹的树不加载子频道
                    if (TreeView.TreeMode != TreeMode.SelectTmplt && TreeView.TreeMode != TreeMode.SelectTmpltFolder)
                    {
                        elementNode = new ChannelFolderNode(element as FolderXmlElement);
                    }
                    break;

                case FolderType.TmpltFolder:
                    elementNode = new TmpltFolderNode(element as FolderXmlElement);
                    break;

                case FolderType.ResourcesFolder:
                    elementNode = new ResourceFolderNode(element as FolderXmlElement);
                    break;

                default:
                    Debug.Fail("未处理的FolderType类型:" + ((FolderXmlElement)element).FolderType);
                    break;
                }

                break;
            }

            case DataType.File:
                elementNode = new ResourceFileNode(element as FileSimpleExXmlElement);
                break;

            case DataType.TmpltFolder:
                //选择频道的树不加载模板
                if (TreeView.TreeMode != TreeMode.SelectChannel)
                {
                    elementNode = new TmpltRootNode(element as TmpltFolderXmlElement);
                }
                break;

            default:
                Debug.Fail("未处理的Element的DataType:" + element.DataType);
                break;
            }

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

            ///添加到树中
            if (elementNode is ResourceRootNode)
            {
                ///资源文件夹的根,添加到第一个
                this.AddChildNode(0, elementNode);

                ((RootChannelNode)this).ResourceRootNode = (ResourceRootNode)elementNode;
            }
            else if (elementNode is TmpltRootNode)
            {
                ///模板文件夹的根,添加到第二个
                this.AddChildNode(1, elementNode);

                ((RootChannelNode)this).TmpltRootNode = (TmpltRootNode)elementNode;
            }
            else
            {
                this.AddChildNode(elementNode);
            }

            ///调用LoadData()加载本身的数据
            elementNode.LoadData();

            ///添加到收藏夹
            if (elementNode.Element.IsFavorite)
            {
                if (TreeView.TreeMode == TreeMode.General)
                {
                    TreeView.AddLinkNodeToFavorite(elementNode);
                }
            }

            return(elementNode);
        }
Example #2
0
        public virtual int AddChildNode(int index, BaseTreeNode node)
        {
            int result = index;

            ///先添加到节点中
            if (index == -1)
            {
                result = this.Nodes.Add(node);
            }
            else
            {
                this.Nodes.Insert(index, node);
            }

            ///设置图标
            node.SelectedImageKey = node.ImageKey = node.FactImageKey;

            ///初始化节点状态
            TreeView.InitNode(node);

            ///检查文件是否正常
            if (node is ElementNode)
            {
                ElementNode elementNode = (ElementNode)node;

                ///添加到TreeNode的dic容器里去
                if (TreeView.TreeMode == TreeMode.General && elementNode.NodeType != TreeNodeType.Link)
                {
                    TreeView.SetElementNode(elementNode);
                }

                ///检查文件是否存在:不存在,则在图标上画一个感叹号
                if (!Utility.File.Exists(elementNode.Element.AbsoluteFilePath))
                {
                    string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.ExcalmatoryPoint);
                    if (!this.TreeView.ImageList.Images.ContainsKey(signKey))
                    {
                        ///若是资源文件节点,则先确定图标已经存在
                        if (elementNode is ResourceFileNode)
                        {
                            ResourceFileNode fileNode = (ResourceFileNode)elementNode;
                            fileNode.InsureIcon();
                        }

                        ///画标记
                        Image signImage = this.TreeView.ImageList.Images[node.FactImageKey];
                        Service.Draw.DrawSign(signImage, SignType.ExcalmatoryPoint);
                        this.TreeView.ImageList.Images.Add(signKey, signImage);
                    }

                    node.SelectedImageKey = node.ImageKey = signKey;

                    if (elementNode.IsFolder)
                    {
                        node.ToolTipText = "此文件夹不存在!";
                    }
                    else
                    {
                        node.ToolTipText = "此文件不存在!";
                    }
                }
                else
                {
                    bool isHealthy = true;
                    switch (elementNode.Element.DataType)
                    {
                    ///检查非首页型模板是否有正文型页面片
                    case DataType.Tmplt:
                    {
                        TmpltSimpleExXmlElement tmpltEle = elementNode.Element as TmpltSimpleExXmlElement;
                        if (tmpltEle.TmpltType != TmpltType.Home && !tmpltEle.HasContentSnip)
                        {
                            isHealthy = false;
                            elementNode.ToolTipText = "此模板没有正文型页面片。属于不完整模板。\r\n请为此模板创建正文型页面片,否则关联到它的页面无法正常生成。";
                        }
                        break;
                    }

                    ///检查页面是否正确关联了模板
                    case DataType.Page:
                    {
                        PageSimpleExXmlElement pageEle = elementNode.Element as PageSimpleExXmlElement;
                        if (string.IsNullOrEmpty(pageEle.TmpltId))
                        {
                            isHealthy = false;
                            elementNode.ToolTipText = "此页面没有设置关联模板,属于不完整页面。\r\n请重新选择关联模板,否则将无法生成最终页面。";
                        }
                        else
                        {
                            TmpltSimpleExXmlElement tmpltEle = Service.Sdsite.CurrentDocument.GetTmpltElementById(pageEle.TmpltId);
                            if (tmpltEle == null ||
                                !File.Exists(tmpltEle.AbsoluteFilePath))
                            {
                                isHealthy = false;
                                elementNode.ToolTipText = "此页面关联的模板未能找到,属于不完整页面。\r\n请重新选择关联模板,否则无法生成最终页面。";
                            }
                            else
                            {
                                isHealthy = true;
                                //ElementNode tmpltNode = TreeView.GetElementNode(tmpltEle.Id);
                                //if (tmpltNode != null)
                                //{
                                //    elementNode.ToolTipText = "此页面完整,关联的模板是:" + tmpltNode.FullPath + "。\r\n可生成最终页面。";
                                //}
                            }
                        }
                        break;
                    }
                    }

                    ///不健康节点,在图标上添加标记
                    if (!isHealthy)
                    {
                        string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.QuestionPoint);
                        if (!this.TreeView.ImageList.Images.ContainsKey(signKey))
                        {
                            Image signImage = this.TreeView.ImageList.Images[node.FactImageKey];
                            Service.Draw.DrawSign(signImage, SignType.QuestionPoint);
                            this.TreeView.ImageList.Images.Add(signKey, signImage);
                        }

                        node.SelectedImageKey = node.ImageKey = signKey;
                    }
                }
            }

            return(result);
        }