private void RenderNodes(KeyCatalog catalog, NodeCollection nodes, int restoreLevel)
        {
            restoreLevel--;
            foreach (KeyCatalog sub in catalog.Subcatalogs.SortedValues)
            {
                KeyNode n = new KeyNode(sub.ToString())
                {
                    Catalog = sub
                };
                nodes.Add(n);

                if (restoreLevel < 0)
                {
                    if (SelectionNodeName == sub.Name)
                    {
                        ATree.SelectedNode = n;
                    }
                }

                if (!sub.IsLeaf)
                {
                    RenderNodes(sub, n.Nodes, restoreLevel);
                }
            }
        }
        public KeyCatalog this[string name]
        {
            get
            {
                if (!_catalogs.ContainsKey(name))
                {
                    KeyCatalog kc = null;

                    kc = Factory.Create(name);

                    _catalogs.Add(name, kc);
                }
                return(_catalogs[name]);
            }
        }
        /// <summary>
        /// 產生資料到畫面上,請透過 GenerateDataModel 產生資料結構。
        /// </summary>
        protected void RenderTreeView(bool reserveSelection)
        {
            if (reserveSelection)
            {
                ReserveTreeSelection();
            }

            KeyCatalog userroot = new KeyCatalog(RootCaption, KCFactory);
            Task       task     = Task.Factory.StartNew((x) =>
            {
                GenerateTreeStruct(x as KeyCatalog);
            }, userroot);

            task.ContinueWith(x =>
            {
                if (x.Exception != null)
                {
                    ErrorBox.Show(x.Exception.Message, x.Exception);
                }

                ATree.Nodes.Clear();

                KeyCatalog rkc = x.AsyncState as KeyCatalog;

                if (ShowRoot)
                {
                    KeyCatalog root = new KeyCatalog("", KCFactory);
                    root.Subcatalogs.Add(rkc);
                    RenderNodes(root, ATree.Nodes, RestoreLevel);
                }
                else
                {
                    RenderNodes(rkc, ATree.Nodes, RestoreLevel);
                }

                foreach (Node n in ATree.Nodes)
                {
                    n.Expand();
                }
            }, UISyncContext);
        }
 /// <summary>
 /// 排序 KeyCatalog,如果不改寫則使用 Name 屬性排序。
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 protected virtual int KeyCatalogComparer(KeyCatalog x, KeyCatalog y)
 {
     return(NameComparer.Compare(x.Name, y.Name));
 }
 /// <summary>
 /// 產生資料模型,將資料產生在 Root 屬性上。
 /// </summary>
 protected virtual void GenerateTreeStruct(KeyCatalog root)
 {
     throw new NotImplementedException("您應該實作此方法。");
 }
 /// <summary>
 /// 提供 KeyCatalog 標題的格式化方法。
 /// </summary>
 /// <param name="catalog"></param>
 /// <returns></returns>
 protected virtual string KeyCatalogTitleFormat(KeyCatalog catalog)
 {
     return(string.Format("{0}({1})", catalog.Name, catalog.TotalKeyCount));
 }
 public void Add(KeyCatalog catalog)
 {
     _catalogs.Add(catalog.Name, catalog);
 }