/// <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); } } }
/// <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); }
/// <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); }