/// <summary>
 /// Adds any child HCUnits to the given node.
 /// </summary>
 /// <param name="parentNode">The node under which to add items.</param>
 /// <param name="parentUnit">The HCUnit containing child units.</param>
 private void PopulateNode(Node parentNode, HCUnit parentUnit)
 {
     foreach (HCUnit childUnit in parentUnit.ChildUnits)
     {
         Node childNode = new OrbatNode(childUnit);
         parentNode.Nodes.Add(childNode);
         PopulateNode(childNode, childUnit);
     }
 }
        /// <summary>
        /// Populates the tree with the given countries and hcunit hierarchy.
        /// </summary>
        /// <param name="countrys">An array of Country's.</param>
        /// <param name="topHCUnit">The top-level HCUnit that contains all other hcunits.</param>
        private void PopulateTree(IEnumerable <Country> countrys, HCUnit topHCUnit)
        {
            tvwOrbat.BeginUpdate();

            ((TreeModel)tvwOrbat.Model).Nodes.Clear();

            foreach (Country country in countrys)
            {
                if (!country.IsActive)
                {
                    continue;
                }

                Node countryNode = new OrbatNode(country.Name);
                ((TreeModel)tvwOrbat.Model).Nodes.Add(countryNode);

                foreach (int branch in Enum.GetValues(typeof(Branch)))
                {
                    if (branch == (int)Branch.None)
                    {
                        continue;
                    }

                    Node branchNode = new OrbatNode(Misc.EnumString((Branch)branch));
                    countryNode.Nodes.Add(branchNode);

                    if (topHCUnit != null)
                    {
                        foreach (HCUnit hcunit in topHCUnit.ChildUnits) // top levels
                        {
                            if (hcunit.Country != country || hcunit.Branch != (Branch)branch)
                            {
                                continue;
                            }

                            Node hcunitNode = new OrbatNode(hcunit);
                            branchNode.Nodes.Add(hcunitNode);
                            PopulateNode(hcunitNode, hcunit);
                        }
                    }
                }
            }

            RestoreTree();
            tvwOrbat.EndUpdate();
            ResizeWidget();
        }