コード例 #1
0
        private void RefreshTreeEditor()
        {
            this.selectedEditor.leftTreeView.Nodes.Clear();
            XmlNode root = GetSelectedXMLDocumentElement();
            if (root == null)
                return;
            XMLEditorTreeNode[] children = this.PopulateTree(root);
            XMLEditorTreeNode[] attrroot = this.PopulateAttributes(root);
            XMLEditorTreeNode[] rootchildren = new XMLEditorTreeNode[children.Length + attrroot.Length];
            System.Array.Copy(attrroot, rootchildren, attrroot.Length);
            System.Array.Copy(children, 0, rootchildren, attrroot.Length, children.Length);
            XMLEditorTreeNode rootNode = new XMLEditorTreeNode("<" + root.Name + ">", rootchildren, root);
            this.BuildImageList(root);
            this.SetTreeNodeImageAndToolTip(rootNode, root);
            rootNode.SelectedImageKey = rootNode.StateImageKey =
                rootNode.ImageKey="DEFAULTVXD";
            this.selectedEditor.leftTreeView.Nodes.Add(rootNode);
            rootNode.Expand();
            this.selectedEditor.leftTreeView.Invalidate();

            this.selectedEditor.rightTreeView.Nodes.Clear();
            if (this.xmlValidated)
            {
                XmlNode rroot = GetSelectedXSDDocumentElement();
                XMLEditorTreeNode[] rchildren = this.PopulateTree(rroot);
                XMLEditorTreeNode[] rattrroot = this.PopulateAttributes(rroot);
                XMLEditorTreeNode[] rrootchildren = new XMLEditorTreeNode[rchildren.Length + rattrroot.Length];
                System.Array.Copy(rattrroot, rrootchildren, rattrroot.Length);
                System.Array.Copy(rchildren, 0, rrootchildren, rattrroot.Length, rchildren.Length);
                XMLEditorTreeNode rrootNode = new XMLEditorTreeNode("<" + rroot.Name + ">", rrootchildren, rroot);
                this.BuildImageList(rroot);
                this.SetTreeNodeImageAndToolTip(rrootNode, rroot);
                rrootNode.SelectedImageKey = rrootNode.StateImageKey =
                    rrootNode.ImageKey = "DEFAULTVXD";
                this.selectedEditor.rightTreeView.Nodes.Add(rrootNode);
                rrootNode.Expand();
                this.selectedEditor.rightTreeView.Invalidate();
            }

            this.selectedEditor.Invalidate();
        }
コード例 #2
0
 protected XMLEditorTreeNode[] PopulateTree(XmlNode parent)
 {
     if (parent == null || parent.ChildNodes == null)
         return new XMLEditorTreeNode[0];
     XMLEditorTreeNode treend = null;
     ArrayList arr = new ArrayList();
     foreach (XmlNode nd in parent.ChildNodes)
     {
         this.BuildImageList(nd);
         if (nd.HasChildNodes)
         {
             XMLEditorTreeNode[] attrroot = this.PopulateAttributes(nd);
             XMLEditorTreeNode[] children = this.PopulateTree(nd);
             XMLEditorTreeNode[] rootchildren = new XMLEditorTreeNode[children.Length + attrroot.Length];
             System.Array.Copy(attrroot, rootchildren, attrroot.Length);
             System.Array.Copy(children, 0, rootchildren, attrroot.Length, children.Length);
             string nameattr = string.Empty;
             if (nd.Attributes != null)
             {
                 XmlAttribute id = nd.Attributes["ID"];
                 if (id == null)
                     id = nd.Attributes["id"];
                 if (id != null && id.Value != null)
                     nameattr += " ID=\"" + id.Value.ToString() + "\" ";
                 foreach (string nmatt in new string[] { "Name", "NAME", "name" })
                 {
                     XmlAttribute nm = nd.Attributes[nmatt];
                     if (nm != null && nm.Value != null)
                     {
                         nameattr += " name=\"" + nm.Value.ToString() + "\"";
                         break;
                     }
                 }
             }
             treend = new XMLEditorTreeNode("<" + nd.Name + nameattr + ">", rootchildren, nd);
             this.SetTreeNodeImageAndToolTip(treend, nd);
             arr.Add(treend);
             treend.Expand();
         }
         else
         {
             XMLEditorTreeNode[] att = PopulateAttributes(nd);
             string nameattr = string.Empty;
             if (nd.Attributes != null)
             {
                 XmlAttribute id = nd.Attributes["ID"];
                 if (id == null)
                     id = nd.Attributes["id"];
                 if (id != null && id.Value != null)
                     nameattr += " ID=\"" + id.Value.ToString() + "\" ";
                 foreach (string nmatt in new string[] { "Name", "NAME", "name" })
                 {
                     XmlAttribute nm = nd.Attributes[nmatt];
                     if (nm != null && nm.Value != null)
                     {
                         nameattr += " name=\"" + nm.Value.ToString() + "\"";
                         break;
                     }
                 }
             }
             if (att == null)
                 treend = new XMLEditorTreeNode("<" + nd.Name + nameattr + ">", nd);
             else
                 treend = new XMLEditorTreeNode("<" + nd.Name + nameattr + ">", att, nd);
             this.SetTreeNodeImageAndToolTip(treend, nd);
             arr.Add(treend);
             treend.Collapse();
             if (treend.Parent != null)
                 treend.Parent.Collapse();
         }
     }
     int i = 0;
     XMLEditorTreeNode[] nds = new XMLEditorTreeNode[arr.Count];
     foreach (XMLEditorTreeNode t in arr)
     {
         nds[i] = t; ++i;
     }
     return nds;
 }