private void UpdateChildren(KTreeNodes newChildren) { Children.Owner?.BeginUpdate(); try { Children.Clear(); _placeholder = CreatePlaceholder(State, newChildren); if (_placeholder != null) { Children.Add(_placeholder); } if (newChildren != null) { foreach (KTreeNode child in newChildren) { Children.Add(child); } } } finally { Children.Owner?.EndUpdate(); } }
protected virtual string GetPlaceholderText(LoadingState state, KTreeNodes children) { if (PlaceholderText == null) { return(null); } return(PlaceholderText(Children.Parent, state, children)); }
public KTree() { SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.Selectable, true); BackColor = SystemColors.Window; _rootNodes = new KTreeNodes(this); SetupRenderer(); InitScrollBars(); }
protected virtual KTreeNode CreatePlaceholder(LoadingState state, KTreeNodes children) { string text = GetPlaceholderText(state, children); if (string.IsNullOrEmpty(text)) { return(null); } KTreeNode node = new KTreeNode(text); node.HasCheckBox = false; node.IsSelectable = false; return(node); }
private void StartLoadChildren() { // Set the loading placeholder State = LoadingState.Loading; UpdateChildren(null); // Load children asynchronously KTreeNode node = Children.Parent; OnBeginLoading(node); KUITask .New(() => { return(DoLoadChildren(node)); }) // Continuation in UI thread .OnSuccess(result => { // Loaded successfully, render KTreeNodes childrenTemp = new KTreeNodes(node); DoRenderChildren(node, result, childrenTemp); State = LoadingState.Loaded; return(childrenTemp); }, true) .OnError(error => { Logger.Instance.Error(this, "Exception while fetching child nodes: {0}", error); // On error return an empty node list State = LoadingState.Error; return(new KTreeNodes(node)); }, true) .OnCompletion(children => { // Update nodes (or plaaceholder) and notify we're done UpdateChildren(children); OnEndLoading(node); }, true) .Start(); }
public KTreeNodeLoader(KTreeNode parent) { Children = new KTreeNodes(parent); }
virtual protected void DoRenderChildren(KTreeNode node, object loaded, KTreeNodes children) { RenderChildren(node, loaded, children); }