Example #1
0
        public void RefreshTree()
        {
            // turn off visual updating
            BeginUpdate();
            // clear tree
            Nodes.Clear();
            try
            {
                // insert root nodes
                List <DocTreeNode> rootNodes = DocTreeNode.getRootNodes();
                if (0 == rootNodes.Count)
                {
                    FormCreateBranch form = new FormCreateBranch();
                    if (DialogResult.OK == form.ShowDialog())
                    {
                        DocTreeNodeBranch.AddNewRootNode(form.BranchName, form.BranchDescription, form.BranchImage);
                        rootNodes = DocTreeNode.getRootNodes();
                    }
                    else
                    {
                        return;
                    }
                }

                foreach (DocTreeNode docNode in rootNodes)
                {
                    TreeNode tnRoot = new TreeNode(docNode.Name, GetImageIndex(docNode), GetSelectedImageIndex(docNode));
                    Nodes.Add(tnRoot);
                    if (docNode.IsBranch)
                    {
                        // add menu
                        tnRoot.ContextMenuStrip = GetBranchMenu();
                    }

                    tnRoot.Tag = docNode;
                    LoadChildrens(tnRoot);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                Logger.Write(ex.ToString(), Category.General, Priority.High);
            }

            // turn on visual updating
            EndUpdate();
        }
Example #2
0
 static private void ProcessNode(XmlNode node, string offset, DocTreeNodeBranch parentBranch)
 {
     if ("xml" == node.Name)
     {   // parent node -> do nothing
     }
     else if ("Branch" == node.Name)
     {
         // create new branch
         string name = node.Attributes["Name"].Value;
         Console.WriteLine(offset + string.Format("Branch : {0}", name));
         string            description = node.Attributes["Description"].Value;
         string            bmpFileName = node.Attributes["BmpFileName"].Value;
         string            filePath    = bmpFileName.Length == 0 ? string.Empty : Path.Combine(_dstDirectory, bmpFileName);
         DocTreeNodeBranch newBranch   = null;
         if (null == parentBranch)
         {
             newBranch = DocTreeNodeBranch.AddNewRootNode(name, description, filePath);
         }
         else
         {
             newBranch = parentBranch.AddChildBranch(name, description, filePath);
         }
         // recursively create child nodes
         foreach (XmlNode childNode in node.ChildNodes)
         {
             try
             {
                 ProcessNode(childNode, offset + "    ", newBranch);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.ToString());
             }
         }
     }
     else if ("Leaf" == node.Name)
     {
         // create new leaf
         string name = node.Attributes["Name"].Value;
         Console.WriteLine(offset + string.Format("Leaf : {0}", name));
         string   description   = node.Attributes["Description"].Value;
         string   filePath      = Path.Combine(_dstDirectory, node.Attributes["FileName"].Value);
         Document childDocument = Document.create(DocumentType.getByName("ParametricComponent"), name, description, filePath);
         parentBranch.AddChildDocument(childDocument);
     }
 }