using System; using System.Collections.Generic; using System.Text; using Volian.CSLA.Library; using System.Windows.Forms; using Csla; using System.Collections; namespace Volian.CSLA.Library { public abstract class VETreeNode : TreeNode { #region Business Methods protected IVEReadOnlyItem _VEObject; public IVEReadOnlyItem VEObject { get { return _VEObject; } set { _VEObject = value; base.Text = _VEObject.ToString(); ResetNode(); } } public void Refresh() { if (_VEObject != null) Text = _VEObject.ToString(); } // Only load the Children Once protected bool _ChildrenLoaded = false; public bool ChildrenLoaded { get { return _ChildrenLoaded; } } // Reset Node public void CloseNode() { ResetNode(); } private void ResetNode() { if (_VEObject!=null && _VEObject.HasChildren()) { _ChildrenLoaded = false;// Reset the children loaded flag this.Nodes.Add("Dummy");// Add a Dummy Node so that the item will appear to be expanable. } else { _ChildrenLoaded = true;// Reset the children loaded flag } // ToDo: Need to reset object as well } public void RefreshNode() { ResetNode();// Drop Children LoadChildren();// Load Children } public abstract void LoadChildren(); //public IVEReadOnlyItem GetCsla() //{ // return _VEObject; //} #endregion #region Factory Methods // Constructors public VETreeNode() : base("NoText") { ; } public VETreeNode(IVEReadOnlyItem o) : base(o.ToString()) { _VEObject = o;// Save the BusinessObject ResetNode(); } public VETreeNode(string s) : base(s) { _VEObject = null;// Save the BusinessObject ResetNode(); } #endregion } public class VETreeNodeBase : VETreeNode where T : VETreeNode, new() { #region Factory Methods public VETreeNodeBase(string s) : base(s) { ;} public VETreeNodeBase(IVEReadOnlyItem o) : base(o) { ;} protected VETreeNodeBase() : base() { ;} public override void LoadChildren() { if (!_ChildrenLoaded) { this.Nodes.Clear(); IList ol = _VEObject.GetChildren(); if (ol != null) { foreach (IVEReadOnlyItem o in ol) { try { T tmp = new T(); tmp.VEObject = o; this.Nodes.Add(tmp); } catch (Exception ex) { Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); } } } _ChildrenLoaded = true; } } #endregion } public class VEFolder : VETreeNodeBase { public static VEFolder LoadTree() { VEFolder root = null; FolderInfoList fil = FolderInfoList.Get(); Dictionary dicMissing = new Dictionary(); Dictionary dicExists = new Dictionary(); foreach (FolderInfo fi in fil) { VEFolder ftp = null; if (dicExists.ContainsKey(fi.ParentID)) { ftp = dicExists[fi.ParentID]; } else { if (fi.ParentID != 0) { ftp = new VEFolder(fi.ParentID.ToString()); dicMissing.Add(fi.ParentID, ftp); dicExists.Add(fi.ParentID, ftp); } } VEFolder ft = null; if (dicMissing.ContainsKey(fi.FolderID)) { ft = dicMissing[fi.FolderID]; ft.VEObject = fi; dicMissing.Remove(fi.FolderID); } else { ft = new VEFolder(fi); dicExists.Add(fi.FolderID, ft); } if (fi.ParentID == 0) root = ft; else ftp.Nodes.Add(ft); } //root.FindTree = dicExists; return root; } private VEFolder(string s) : base(s) { ;} public VEFolder(IVEReadOnlyItem o) : base(o) { ;} } public class VEVersion : VETreeNodeBase { } public class VEProcedure : VETreeNodeBase { public override void LoadChildren() { if (!_ChildrenLoaded) { this.Nodes.Clear(); Dictionary dicSect = new Dictionary(); SectionInfoList ol = (SectionInfoList)_VEObject.GetChildren(); if (ol != null) { foreach (SectionInfo o in ol) { try { VESection tmp = new VESection(); tmp.VEObject = o; if (dicSect.ContainsKey(o.PPath)) dicSect[o.PPath].Nodes.Add(tmp); else this.Nodes.Add(tmp); dicSect[o.Path] = tmp; } catch (Exception ex) { Console.WriteLine("{0}\r\n{1}", ex.Message, ex.InnerException); } } } _ChildrenLoaded = true; } } } public class VESection : VETreeNodeBase { } public class VEStep : VETreeNodeBase { } }