Example #1
0
        /// <summary>
        /// Creates the XML node recursive.
        /// </summary>
        /// <param name="xmlParentNode">The XML parent node.</param>
        /// <param name="treeNode">The tree node.</param>
        protected void CreateXMLNodeRecursive(XmlNode xmlParentNode, ASTreeViewNode treeNode)
        {
            XmlNode xmlNode = XmlHelper.AddElement(xmlParentNode, "astreeview-node", null);

            XmlHelper.AddAttribute(xmlNode, "node-text", treeNode.NodeText);
            XmlHelper.AddAttribute(xmlNode, "node-value", treeNode.NodeValue);
            #region nodeType
            ASTreeViewNodeType nodeType = treeNode.NodeType;
            XmlHelper.AddAttribute(xmlNode, "node-type", ((int)nodeType).ToString());
            #endregion
            XmlHelper.AddAttribute(xmlNode, "checked-state", ((int)treeNode.CheckedState).ToString());
            XmlHelper.AddAttribute(xmlNode, "open-state", ((int)treeNode.OpenState).ToString());
            XmlHelper.AddAttribute(xmlNode, "selected", treeNode.Selected.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-edit-context-menu", treeNode.EnableEditContextMenu.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-delete-context-menu", treeNode.EnableDeleteContextMenu.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-add-context-menu", treeNode.EnableAddContextMenu.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "node-icon", treeNode.NodeIcon);
            XmlHelper.AddAttribute(xmlNode, "enable-drag-drop", treeNode.EnableDragDrop.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-siblings", treeNode.EnableSiblings.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-children", treeNode.EnableChildren.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-checkbox", treeNode.EnableCheckbox.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-selection", treeNode.EnableSelection.ToString().ToLower());
            XmlHelper.AddAttribute(xmlNode, "enable-open-close", treeNode.EnableOpenClose.ToString().ToLower());


            if (nodeType == ASTreeViewNodeType.HyperLink)
            {
                ASTreeViewLinkNode linkNode = (ASTreeViewLinkNode)treeNode;
                XmlHelper.AddAttribute(xmlNode, "navigate-url", linkNode.NavigateUrl);
                XmlHelper.AddAttribute(xmlNode, "target", linkNode.Target);
                XmlHelper.AddAttribute(xmlNode, "tooltip", linkNode.Tooltip);
            }

            if (treeNode.ChildNodes.Count > 0)
            {
                XmlNode astreeviewNodes = XmlHelper.AddElement(xmlNode, "astreeview-nodes", null);
                foreach (ASTreeViewNode node in treeNode.ChildNodes)
                {
                    CreateXMLNodeRecursive(astreeviewNodes, node);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Converts the node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public HtmlGenericControl ConvertNode(ASTreeViewNode node)
        {
            #region manage li

            HtmlGenericControl li = new HtmlGenericControl();
            li.TagName = "li";
            li.Attributes.Add("treeNodeType", ((int)node.NodeType).ToString());

            #endregion

            #region manage selection

            li.Attributes.Add("treeNodeValue", node.NodeValue);
            if (node.Selected)
            {
                li.Attributes.Add("selected", "true");
            }

            #endregion

            #region manage treelines

            if (this.currentTreeView.EnableTreeLines)
            {
                //if the current node is the last node of parent's childnodes.
                if (node.ParentNode != null && node.ParentNode.ChildNodes.IndexOf(node) == (node.ParentNode.ChildNodes.Count - 1))
                {
                    if ((this.currentTreeView.EnableRoot && node == this.currentTreeView.RootNode)
                        ||
                        (!this.currentTreeView.EnableRoot &&
                         this.currentTreeView.RootNode.ChildNodes.Count == 1 &&
                         node == this.currentTreeView.RootNode.ChildNodes[0])
                        )
                    {
                        //if the current node is root node.
                        li.Attributes.Add("class", this.currentTreeView.CssClassLineRoot /* "line-root"*/);
                    }
                    else
                    {
                        li.Attributes.Add("class", this.currentTreeView.CssClassLineBottom /* "line-bottom"*/);
                    }
                }
                // if the current is the root node and has siblings.
                else if (!this.currentTreeView.EnableRoot &&
                         this.currentTreeView.RootNode.ChildNodes.Count > 1 &&
                         node == this.currentTreeView.RootNode.ChildNodes[0]
                         )
                {
                    li.Attributes.Add("class", this.currentTreeView.CssClassLineTop /* "line-top"*/);
                }
                else
                {
                    li.Attributes.Add("class", this.currentTreeView.CssClassLineMiddle /*"line-middle"*/);
                }
            }

            #endregion

            #region manage open close

            li.Attributes.Add("openState", ((int)node.OpenState).ToString());

            #endregion

            #region manage node icon

            //set li attribute for save viewstate
            if (!string.IsNullOrEmpty(node.NodeIcon))
            {
                li.Attributes.Add("treeNodeIcon", node.NodeIcon);
            }

            #endregion

            #region manage context menu attributes

            li.Attributes.Add("enable-edit-context-menu", node.EnableEditContextMenu ? "true" : "false");
            li.Attributes.Add("enable-delete-context-menu", node.EnableDeleteContextMenu ? "true" : "false");
            li.Attributes.Add("enable-add-context-menu", node.EnableAddContextMenu ? "true" : "false");

            #endregion

            #region manage node drag drop
            if (!node.EnableDragDrop)
            {
                li.Attributes.Add("enable-drag-drop", "false");
            }
            #endregion

            #region manage node siblings
            if (!node.EnableSiblings)
            {
                li.Attributes.Add("enable-siblings", "false");
            }
            #endregion

            #region manage node children
            if (!node.EnableChildren)
            {
                li.Attributes.Add("enable-children", "false");
            }
            #endregion

            #region manage enable checkbox
            if (!node.EnableCheckbox)
            {
                li.Attributes.Add("enable-checkbox", "false");
            }
            #endregion

            #region manage enable selection
            if (!node.EnableSelection)
            {
                li.Attributes.Add("enable-selection", "false");
            }
            #endregion


            #region manage enable open close
            if (!node.EnableOpenClose)
            {
                li.Attributes.Add("enable-open-close", "false");
            }
            #endregion

            #region manage line (not implemented)

            /*
             * HtmlGenericControl divLine = new HtmlGenericControl();
             * divLine.TagName = "div";
             * divLine.InnerHtml = "&nbsp;";
             * divLine.Attributes.Add( "class", "line" );
             *
             * //HtmlImage imgLine = new HtmlImage();
             * //imgLine.Src = "javascript/astreeview/images/astreeview-vertical-line.gif";
             * li.Controls.Add( divLine );
             */
            #endregion

            #region manage plus minus icon

            HtmlImage imgPlusMinus = new HtmlImage();
            imgPlusMinus.Attributes.Add("icon-type", ((int)ASTreeViewIconType.OpenClose).ToString());
            imgPlusMinus.Attributes.Add("class", this.currentTreeView.CssClassPlusMinusIcon);

            switch (node.OpenState)
            {
            case ASTreeViewNodeOpenState.Open:
                imgPlusMinus.Src = this.currentTreeView.ImgMinusIcon;
                break;

            case ASTreeViewNodeOpenState.Close:
                imgPlusMinus.Src = this.currentTreeView.ImgPlusIcon;
                break;

            default:
                imgPlusMinus.Src = this.currentTreeView.ImgMinusIcon;
                break;
            }


            if (node.ChildNodes.Count == 0 || !node.EnableOpenClose)
            {
                imgPlusMinus.Style.Add("visibility", "hidden");
            }

            li.Controls.Add(imgPlusMinus);

            #endregion

            #region manage checkbox

            HtmlImage imgCheckbox = null;
            if (this.currentTreeView.EnableCheckbox)
            {
                imgCheckbox = this.ConvertCheckbox(node);
                imgCheckbox.Attributes.Add("icon-type", ((int)ASTreeViewIconType.Checkbox).ToString());

                #region handle postback

                if (this.currentTreeView.AutoPostBack)
                {
                    imgCheckbox.Attributes.Add("postbackscript", this.CurrentTreeView.Page.ClientScript.GetPostBackEventReference(this.CurrentTreeView, node.NodeValue));
                }

                #endregion

                li.Controls.Add(imgCheckbox);

                #region manage checkbox for single node

                if (!node.EnableCheckbox)
                {
                    imgCheckbox.Style.Add(HtmlTextWriterStyle.Display, "none");
                }

                #endregion
            }

            li.Attributes.Add("checkedState", ((int)node.CheckedState).ToString());

            #endregion

            #region manage folder icon
            if (this.currentTreeView.EnableNodeIcon)
            {
                HtmlImage imgIcon = new HtmlImage();
                imgIcon.Attributes.Add("icon-type", ((int)ASTreeViewIconType.NodeIcon).ToString());

                imgIcon.Attributes.Add("class", this.currentTreeView.CssClassIcon);

                if (this.currentTreeView.EnableCustomizedNodeIcon && !string.IsNullOrEmpty(node.NodeIcon))
                {
                    //if node has custom icon
                    imgIcon.Src = node.NodeIcon;
                }
                else
                {
                    //use default icons
                    if (node.ChildNodes.Count > 0)
                    {
                        if (node.OpenState == ASTreeViewNodeOpenState.Open)
                        {
                            imgIcon.Src = this.currentTreeView.DefaultFolderOpenIcon;
                        }
                        else
                        {
                            imgIcon.Src = this.currentTreeView.DefaultFolderIcon;
                        }
                    }
                    else
                    {
                        imgIcon.Src = this.currentTreeView.DefaultNodeIcon;
                    }

                    //if node is virtual node
                    if (node.IsVirtualNode && node.VirtualNodesCount > 0)
                    {
                        imgIcon.Src = this.currentTreeView.DefaultFolderIcon;
                    }
                }

                //add drag & drap ability
                if (this.currentTreeView.EnableDragDropOnIcon)
                {
                    imgIcon.Attributes.Add("is-astreeview-node", "true");
                }

                li.Controls.Add(imgIcon);
            }

            #endregion

            #region manage link

            int counter = liCounter + 1;

            if (node.NodeType == ASTreeViewNodeType.LinkButton)
            {
                LinkButton lb = new LinkButton();
                lb.ID   = "lbASTreeNode" + counter.ToString();
                lb.Text = node.NodeText;
                string disableClickScript = "return false;";
                if (!this.currentTreeView.AutoPostBack)
                {
                    lb.Attributes.Add("onclick", disableClickScript);
                }
                if (node.Selected)
                {
                    lb.CssClass += " astreeview-node-selected";
                }

                if (this.currentTreeView.EnableContextMenu)
                {
                    lb.CssClass += (" " + this.currentTreeView.ContextMenuTargetCssClass);

                    if (!node.EnableAddContextMenu || !this.currentTreeView.EnableContextMenuAdd)
                    {
                        lb.Attributes.Add("disable" + this.currentTreeView.ContextMenuAddCommandName, "true");
                    }

                    if (!node.EnableEditContextMenu || !this.currentTreeView.EnableContextMenuEdit)
                    {
                        lb.Attributes.Add("disable" + this.currentTreeView.ContextMenuEditCommandName, "true");
                    }

                    if (!node.EnableDeleteContextMenu || !this.currentTreeView.EnableContextMenuDelete)
                    {
                        lb.Attributes.Add("disable" + this.currentTreeView.ContextMenuDeleteCommandName, "true");
                    }
                }

                this.AddAdditionalAttributes(lb, node.AdditionalAttributes);

                //add astreeviewnode tag
                lb.Attributes.Add("is-astreeview-node", "true");
                li.Controls.Add(lb);
            }
            else if (node.NodeType == ASTreeViewNodeType.HyperLink)
            {
                ASTreeViewLinkNode linkNode = (ASTreeViewLinkNode)node;
                HyperLink          hl       = new HyperLink();

                hl.ID   = "hlASTreeNode" + counter.ToString();
                hl.Text = linkNode.NodeText;
                if (linkNode.Selected)
                {
                    hl.CssClass += " astreeview-node-selected";
                }

                if (this.currentTreeView.EnableContextMenu)
                {
                    hl.CssClass += (" " + this.currentTreeView.ContextMenuTargetCssClass);
                    if (!linkNode.EnableAddContextMenu || !this.currentTreeView.EnableContextMenuAdd)
                    {
                        hl.Attributes.Add("disable" + this.currentTreeView.ContextMenuAddCommandName, "true");
                    }

                    if (!linkNode.EnableEditContextMenu || !this.currentTreeView.EnableContextMenuEdit)
                    {
                        hl.Attributes.Add("disable" + this.currentTreeView.ContextMenuEditCommandName, "true");
                    }

                    if (!linkNode.EnableDeleteContextMenu || !this.currentTreeView.EnableContextMenuDelete)
                    {
                        hl.Attributes.Add("disable" + this.currentTreeView.ContextMenuDeleteCommandName, "true");
                    }
                }

                hl.NavigateUrl = linkNode.NavigateUrl;
                hl.Target      = linkNode.Target;
                hl.ToolTip     = linkNode.Tooltip;


                this.AddAdditionalAttributes(hl, linkNode.AdditionalAttributes);

                //add astreeviewnode tag
                hl.Attributes.Add("is-astreeview-node", "true");
                li.Controls.Add(hl);
            }
            else if (node.NodeType == ASTreeViewNodeType.Text)
            {
                ASTreeViewTextNode textNode = (ASTreeViewTextNode)node;

                HtmlGenericControl div = new HtmlGenericControl("div");
                div.InnerHtml = textNode.NodeText;
                div.Attributes.Add("class", this.currentTreeView.CssClassTextNodeContainer /* "astreeview-text-node"*/);
                div.Attributes.Add("is-astreeview-node", "true");
                div.Attributes.Add("isTreeNodeChild", "true");
                li.Controls.Add(div);

                //for li
                string strLiCss   = li.Attributes["class"];
                string strLiToAdd = this.currentTreeView.CssClassTextNode;
                li.Attributes["class"] = string.IsNullOrEmpty(strLiToAdd) ? strLiToAdd : strLiCss + " " + strLiToAdd;

                //for plus minus
                string strPlusMinusCss   = imgPlusMinus.Attributes["class"];
                string strPlusMinusToAdd = this.currentTreeView.CssClassPlusMinusTextNode;//"astreeview-plus-minus-text";
                imgPlusMinus.Attributes["class"] = string.IsNullOrEmpty(strPlusMinusCss) ? strPlusMinusToAdd : strPlusMinusCss + " " + strPlusMinusToAdd;

                //for checkbox
                if (imgCheckbox != null)
                {
                    string strCheckboxCss   = imgCheckbox.Attributes["class"];
                    string strCheckboxToAdd = this.currentTreeView.CssClassCheckboxTextNode;//"astreeview-checkbox-text";
                    imgCheckbox.Attributes["class"] = string.IsNullOrEmpty(strCheckboxCss) ? strCheckboxToAdd : strCheckboxCss + " " + strCheckboxToAdd;
                }
            }

            #endregion

            #region manage virtual node

            if (node.IsVirtualNode)
            {
                li.Attributes.Add("is-virtual-node", "true");
                li.Attributes.Add("virtual-nodes-count", node.VirtualNodesCount.ToString());
                li.Attributes.Add("virtual-parent-key", node.VirtualParentKey);

                li.Attributes["openState"]       = ((int)ASTreeViewNodeOpenState.Close).ToString();
                imgPlusMinus.Style["visibility"] = "visible";
                imgPlusMinus.Src = this.currentTreeView.ImgPlusIcon;

                HtmlGenericControl ulVirtualNodesContainer = new HtmlGenericControl("ul");
                HtmlGenericControl liVirtualNodesContainer = new HtmlGenericControl("li");
                HtmlGenericControl divTextContainer        = new HtmlGenericControl("div");
                liVirtualNodesContainer.Attributes.Add("virtial-node-placeholder-li", "true");
                ulVirtualNodesContainer.Attributes.Add("virtial-node-placeholder-ul", "true");

                ulVirtualNodesContainer.Controls.Add(liVirtualNodesContainer);
                ulVirtualNodesContainer.Style.Add("display", "none");
                divTextContainer.InnerHtml = string.Format(this.currentTreeView.VirtualNodePlaceHolderText, node.VirtualNodesCount);   //"loading..." + node.VirtualNodesCount.ToString();
                divTextContainer.Attributes.Add("class", "astreeview-loading-placeholder");
                liVirtualNodesContainer.Controls.Add(divTextContainer);
                li.Controls.Add(ulVirtualNodesContainer);

                /*
                 * HtmlGenericControl divVirtualNodesContainer = new HtmlGenericControl( "div" );
                 * divVirtualNodesContainer.InnerHtml = "loading..." + node.VirtualNodesCount.ToString();
                 * li.Controls.Add( divVirtualNodesContainer );
                 */
            }

            #endregion

            #region manage additional attributes

            if (node.AdditionalAttributes.Count > 0)
            {
                JsonObject joAdditionalAttr = new JsonObject();

                foreach (KeyValuePair <string, string> attr in node.AdditionalAttributes)
                {
                    if (!joAdditionalAttr.ContainsKey(attr.Key))
                    {
                        joAdditionalAttr.Add(attr.Key, attr.Value);
                    }
                }

                string attrString = string.Empty;
                using (JsonWriter writer = new JsonWriter())
                {
                    joAdditionalAttr.Write(writer);
                    attrString = writer.ToString();
                }

                li.Attributes.Add("additional-attributes", attrString);
            }

            #endregion

            #region manage right to left render

            if (this.currentTreeView.EnableRightToLeftRender)
            {
                //reverse child controls of li
                ArrayList al = new ArrayList();
                foreach (Control c in li.Controls)
                {
                    al.Add(c);
                }

                while (li.Controls.Count > 0)
                {
                    li.Controls.RemoveAt(0);
                }

                al.Reverse();

                foreach (Control con in al)
                {
                    li.Controls.Add(con);
                }
            }

            #endregion

            #region manage node depth

            if (this.currentTreeView.EnableFixedDepthDragDrop)
            {
                li.Attributes.Add("tree-node-depth", node.NodeDepth.ToString());
            }

            #endregion

            return(li);
        }
Example #3
0
        /// <summary>
        /// Gets the node json.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public IJsonType GetNodeJson(ASTreeViewNode node)
        {
            JsonArray  jaNode = new JsonArray();
            JsonObject joNode = new JsonObject();

            joNode.Add(this.GetObfuscatedString("node_treeNodeText"), this.currentTreeView.EnableEscapeInput ? HttpUtility.UrlEncode(node.NodeText) : node.NodeText);
            joNode.Add(this.GetObfuscatedString("node_treeNodeValue"), node.NodeValue);
            joNode.Add(this.GetObfuscatedString("node_checkedState"), (int)node.CheckedState);
            joNode.Add(this.GetObfuscatedString("node_openState"), (int)node.OpenState);
            joNode.Add(this.GetObfuscatedString("node_selected"), node.Selected);
            joNode.Add(this.GetObfuscatedString("node_enableEditContextMenu"), node.EnableEditContextMenu);
            joNode.Add(this.GetObfuscatedString("node_enableDeleteContextMenu"), node.EnableDeleteContextMenu);
            joNode.Add(this.GetObfuscatedString("node_enableAddContextMenu"), node.EnableAddContextMenu);
            joNode.Add(this.GetObfuscatedString("node_treeNodeType"), (int)node.NodeType);
            joNode.Add(this.GetObfuscatedString("node_treeNodeIcon"), node.NodeIcon);

            joNode.Add(this.GetObfuscatedString("node_enableDragDrop"), node.EnableDragDrop);
            joNode.Add(this.GetObfuscatedString("node_enableSiblings"), node.EnableSiblings);
            joNode.Add(this.GetObfuscatedString("node_enableChildren"), node.EnableChildren);
            joNode.Add(this.GetObfuscatedString("node_enableCheckbox"), node.EnableCheckbox);
            joNode.Add(this.GetObfuscatedString("node_enableSelection"), node.EnableSelection);
            joNode.Add(this.GetObfuscatedString("node_enableOpenClose"), node.EnableOpenClose);

            #region additionalAttributes

            string attrString = string.Empty;
            if (node.AdditionalAttributes.Count > 0)
            {
                JsonObject joAdditionalAttr = new JsonObject();

                foreach (KeyValuePair <string, string> attr in node.AdditionalAttributes)
                {
                    joAdditionalAttr.Add(attr.Key, attr.Value);
                }


                using (JsonWriter writer = new JsonWriter())
                {
                    joAdditionalAttr.Write(writer);
                    attrString = writer.ToString();
                }
            }
            joNode.Add(this.GetObfuscatedString("node_additionalAttributes"), attrString);

            #endregion

            joNode.Add(this.GetObfuscatedString("node_isVirtualNode"), node.IsVirtualNode);
            joNode.Add(this.GetObfuscatedString("node_virtualNodesCount"), node.VirtualNodesCount);
            joNode.Add(this.GetObfuscatedString("node_virtualParentKey"), node.VirtualParentKey);

            joNode.Add(this.GetObfuscatedString("node_treeNodeDepth"), node.NodeDepth);

            /*
             *
             * this.enableDragDrop = true;//
             * this.enableSiblings = true;//
             * this.enableChildren = true;//
             *
             * this.additionalAttributes = "";
             *
             * this.isVirtualNode = false;
             * this.virtualNodesCount = 0;
             * this.virtualParentKey = "";
             * this.treeNodeDepth = -1;
             *
             */

            if (node.NodeType == ASTreeViewNodeType.HyperLink)
            {
                ASTreeViewLinkNode linkNode = (ASTreeViewLinkNode)node;
                joNode.Add(this.GetObfuscatedString("node_href"), linkNode.NavigateUrl);
                joNode.Add(this.GetObfuscatedString("node_target"), linkNode.Target);
                joNode.Add(this.GetObfuscatedString("node_tooltip"), linkNode.Tooltip);
            }

            if (node.ChildNodes.Count == 0)
            {
                //handle root, speical
                if (node.ParentNode == null)  //handle root, speical
                {
                    JsonArray jaRoot = new JsonArray();
                    jaRoot.Add(joNode);
                    jaRoot.Add(jaNode);


                    if (!this.currentTreeView.EnableRoot)
                    {
                        return(jaRoot[1]);
                    }

                    return(jaRoot);
                }

                return(joNode);
            }

            if (node.ParentNode != null)  //handle root, speical
            {
                jaNode.Add(joNode);
            }

            JsonArray jaChildren = new JsonArray();
            foreach (ASTreeViewNode child in node.ChildNodes)
            {
                jaChildren.Add(this.GetNodeJson(child));
            }

            foreach (IJsonType childJson in jaChildren)
            {
                //get the first object from child to current
                if (childJson is JsonObject)
                {
                    jaNode.Add(childJson);
                }
                else if (childJson is JsonArray && ((JsonArray)childJson).Count > 0)
                {
                    jaNode.Add(((JsonArray)childJson)[0]);
                    ((JsonArray)childJson).RemoveAt(0);
                    jaNode.Add(childJson);
                }
            }

            //handle root, speical
            if (node.ParentNode == null)  //handle root, speical
            {
                JsonArray jaRoot = new JsonArray();
                jaRoot.Add(joNode);
                jaRoot.Add(jaNode);


                if (!this.currentTreeView.EnableRoot)
                {
                    return(jaRoot[1]);
                }

                return(jaRoot);
            }



            return(jaNode);
        }
Example #4
0
        /// <summary>
        /// Parses the json to node.
        /// </summary>
        /// <param name="joTreeNode">The jo tree node.</param>
        /// <returns></returns>
        public ASTreeViewNode ParseJsonToNode(JsonObject joTreeNode)
        {
            JsonString  nodeText                = (JsonString)joTreeNode[this.GetObfuscatedString("node_treeNodeText")];
            JsonString  nodeValue               = (JsonString)joTreeNode[this.GetObfuscatedString("node_treeNodeValue")];
            JsonNumber  checkedState            = (JsonNumber)joTreeNode[this.GetObfuscatedString("node_checkedState")];
            JsonNumber  openState               = (JsonNumber)joTreeNode[this.GetObfuscatedString("node_openState")];
            JsonBoolean selected                = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_selected")];
            JsonBoolean enableEditContextMenu   = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableEditContextMenu")];
            JsonBoolean enableDeleteContextMenu = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableDeleteContextMenu")];
            JsonBoolean enableAddContextMenu    = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableAddContextMenu")];
            JsonNumber  treeNodeType            = (JsonNumber)joTreeNode[this.GetObfuscatedString("node_treeNodeType")];
            JsonString  treeNodeIcon            = null;

            if (joTreeNode.ContainsKey(this.GetObfuscatedString("node_treeNodeIcon")))
            {
                treeNodeIcon = (JsonString)joTreeNode[this.GetObfuscatedString("node_treeNodeIcon")];
            }

            ASTreeViewNodeType astNodeType = (ASTreeViewNodeType)((int)treeNodeType.Value);

            JsonBoolean enableDragDrop  = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableDragDrop")];
            JsonBoolean enableSiblings  = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableSiblings")];
            JsonBoolean enableChildren  = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableChildren")];
            JsonBoolean enableCheckbox  = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableCheckbox")];
            JsonBoolean enableSelection = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableSelection")];
            JsonBoolean enableOpenClose = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_enableOpenClose")];

            ASTreeViewNode node;// = new ASTreeViewNode();

            switch (astNodeType)
            {
            case ASTreeViewNodeType.LinkButton:
                node = new ASTreeViewNode();
                break;

            case ASTreeViewNodeType.HyperLink:
                node = new ASTreeViewLinkNode();
                break;

            case ASTreeViewNodeType.Text:
                node = new ASTreeViewTextNode();
                break;

            default:
                node = new ASTreeViewNode();
                break;
            }

            node.NodeText                = HttpUtility.UrlDecode(nodeText.Value);
            node.NodeValue               = HttpUtility.UrlDecode(nodeValue.Value);
            node.CheckedState            = (ASTreeViewCheckboxState)((int)checkedState.Value);
            node.OpenState               = (ASTreeViewNodeOpenState)((int)openState.Value);
            node.Selected                = selected.Value;
            node.EnableEditContextMenu   = enableEditContextMenu.Value;
            node.EnableDeleteContextMenu = enableDeleteContextMenu.Value;
            node.EnableAddContextMenu    = enableAddContextMenu.Value;

            node.EnableDragDrop  = enableDragDrop.Value;
            node.EnableSiblings  = enableSiblings.Value;
            node.EnableChildren  = enableChildren.Value;
            node.EnableCheckbox  = enableCheckbox.Value;
            node.EnableSelection = enableSelection.Value;
            node.EnableOpenClose = enableOpenClose.Value;

            #region handle tree node depth

            if (this.currentTreeView.EnableFixedDepthDragDrop)
            {
                JsonNumber treeNodeDepth = null;
                if (joTreeNode.ContainsKey(this.GetObfuscatedString("node_treeNodeDepth")))
                {
                    treeNodeDepth  = (JsonNumber)joTreeNode[this.GetObfuscatedString("node_treeNodeDepth")];
                    node.NodeDepth = (int)treeNodeDepth.Value;
                }
            }

            #endregion

            #region handle virtual node
            JsonBoolean isVirtualNode = null;
            if (joTreeNode.ContainsKey(this.GetObfuscatedString("node_isVirtualNode")))
            {
                isVirtualNode      = (JsonBoolean)joTreeNode[this.GetObfuscatedString("node_isVirtualNode")];
                node.IsVirtualNode = isVirtualNode.Value;
            }

            JsonNumber virtualNodesCount = null;
            if (joTreeNode.ContainsKey(this.GetObfuscatedString("node_virtualNodesCount")))
            {
                virtualNodesCount      = (JsonNumber)joTreeNode[this.GetObfuscatedString("node_virtualNodesCount")];
                node.VirtualNodesCount = (int)virtualNodesCount.Value;
            }

            JsonString virtualParentKey = null;
            if (joTreeNode.ContainsKey(this.GetObfuscatedString("node_virtualParentKey")))
            {
                virtualParentKey      = (JsonString)joTreeNode[this.GetObfuscatedString("node_virtualParentKey")];
                node.VirtualParentKey = virtualParentKey.Value;
            }

            JsonString jsAttr = null;
            if (joTreeNode.ContainsKey(this.GetObfuscatedString("node_additionalAttributes")))
            {
                jsAttr = (JsonString)joTreeNode[this.GetObfuscatedString("node_additionalAttributes")];
                string attrString = jsAttr.Value;

                if (!string.IsNullOrEmpty(attrString))
                {
                    try
                    {
                        StringReader rdr    = new StringReader(attrString);
                        JsonParser   parser = new JsonParser(rdr, true);
                        JsonObject   jo     = (JsonObject)parser.ParseObject();
                        List <KeyValuePair <string, string> > additionalAttributes = new List <KeyValuePair <string, string> >();
                        foreach (string key in jo.Keys)
                        {
                            additionalAttributes.Add(new KeyValuePair <string, string>(key, ((JsonString)jo[key]).Value));
                        }

                        node.AdditionalAttributes = additionalAttributes;
                    }
                    catch { }
                }
            }


            #endregion


            //handle hyperlink
            if (astNodeType == ASTreeViewNodeType.HyperLink)
            {
                ASTreeViewLinkNode hlNode  = (ASTreeViewLinkNode)node;
                JsonString         href    = (JsonString)joTreeNode[this.GetObfuscatedString("node_href")];
                JsonString         target  = (JsonString)joTreeNode[this.GetObfuscatedString("node_target")];
                JsonString         tooltip = (JsonString)joTreeNode[this.GetObfuscatedString("node_tooltip")];

                hlNode.NavigateUrl = href.Value;
                hlNode.Target      = target.Value;
                hlNode.Tooltip     = tooltip.Value;
            }

            if (treeNodeIcon != null)
            {
                node.NodeIcon = treeNodeIcon.Value;
            }

            return(node);
        }
Example #5
0
        /// <summary>
        /// Converts the XML node to tree node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        private ASTreeViewNode ConvertXmlNodeToTreeNode(XmlNode node)
        {
            ASTreeViewNode     treeNode = new ASTreeViewNode();
            ASTreeViewNodeType nodeType = (ASTreeViewNodeType)int.Parse(node.Attributes["node-type"].Value);

            //handle linkbutton
            if (nodeType == ASTreeViewNodeType.HyperLink)
            {
                ASTreeViewLinkNode treeLinkNode = new ASTreeViewLinkNode();

                if (node.Attributes["navigate-url"].Value != null)
                {
                    treeLinkNode.NavigateUrl = node.Attributes["navigate-url"].Value;
                }
                if (node.Attributes["target"].Value != null)
                {
                    treeLinkNode.Target = node.Attributes["target"].Value;
                }
                if (node.Attributes["tooltip"].Value != null)
                {
                    treeLinkNode.Tooltip = node.Attributes["tooltip"].Value;
                }

                treeNode = treeLinkNode;
            }


            treeNode.NodeText  = node.Attributes["node-text"].Value;
            treeNode.NodeValue = node.Attributes["node-value"].Value;

            if (node.Attributes["checked-state"].Value != null)
            {
                treeNode.CheckedState = (ASTreeViewCheckboxState)int.Parse(node.Attributes["checked-state"].Value);
            }

            if (node.Attributes["open-state"].Value != null)
            {
                treeNode.OpenState = (ASTreeViewNodeOpenState)int.Parse(node.Attributes["open-state"].Value);
            }

            if (node.Attributes["selected"].Value != null)
            {
                treeNode.Selected = bool.Parse(node.Attributes["selected"].Value);
            }

            if (node.Attributes["enable-edit-context-menu"].Value != null)
            {
                treeNode.EnableEditContextMenu = bool.Parse(node.Attributes["enable-edit-context-menu"].Value);
            }

            if (node.Attributes["enable-delete-context-menu"].Value != null)
            {
                treeNode.EnableDeleteContextMenu = bool.Parse(node.Attributes["enable-delete-context-menu"].Value);
            }

            if (node.Attributes["enable-add-context-menu"] != null)
            {
                treeNode.EnableAddContextMenu = bool.Parse(node.Attributes["enable-add-context-menu"].Value);
            }

            if (node.Attributes["node-icon"].Value != null)
            {
                treeNode.NodeIcon = node.Attributes["node-icon"].Value;
            }

            if (node.Attributes["enable-drag-drop"] != null)
            {
                treeNode.EnableDragDrop = bool.Parse(node.Attributes["enable-drag-drop"].Value);
            }

            if (node.Attributes["enable-siblings"] != null)
            {
                treeNode.EnableSiblings = bool.Parse(node.Attributes["enable-siblings"].Value);
            }

            if (node.Attributes["enable-children"] != null)
            {
                treeNode.EnableChildren = bool.Parse(node.Attributes["enable-children"].Value);
            }

            if (node.Attributes["enable-checkbox"] != null)
            {
                treeNode.EnableCheckbox = bool.Parse(node.Attributes["enable-checkbox"].Value);
            }

            if (node.Attributes["enable-selection"] != null)
            {
                treeNode.EnableSelection = bool.Parse(node.Attributes["enable-selection"].Value);
            }

            if (node.Attributes["enable-open-close"] != null)
            {
                treeNode.EnableOpenClose = bool.Parse(node.Attributes["enable-open-close"].Value);
            }

            return(treeNode);
        }