moel@345: using System; moel@345: using System.Collections.Generic; moel@345: using System.Text; moel@345: using System.Collections; moel@345: moel@345: namespace Aga.Controls.Tree moel@345: { moel@345: public class SortedTreeModel: TreeModelBase moel@345: { moel@345: private ITreeModel _innerModel; moel@345: public ITreeModel InnerModel moel@345: { moel@345: get { return _innerModel; } moel@345: } moel@345: moel@345: private IComparer _comparer; moel@345: public IComparer Comparer moel@345: { moel@345: get { return _comparer; } moel@345: set moel@345: { moel@345: _comparer = value; moel@345: OnStructureChanged(new TreePathEventArgs(TreePath.Empty)); moel@345: } moel@345: } moel@345: moel@345: public SortedTreeModel(ITreeModel innerModel) moel@345: { moel@345: _innerModel = innerModel; moel@345: _innerModel.NodesChanged += new EventHandler(_innerModel_NodesChanged); moel@345: _innerModel.NodesInserted += new EventHandler(_innerModel_NodesInserted); moel@345: _innerModel.NodesRemoved += new EventHandler(_innerModel_NodesRemoved); moel@345: _innerModel.StructureChanged += new EventHandler(_innerModel_StructureChanged); moel@345: } moel@345: moel@345: void _innerModel_StructureChanged(object sender, TreePathEventArgs e) moel@345: { moel@345: OnStructureChanged(e); moel@345: } moel@345: moel@345: void _innerModel_NodesRemoved(object sender, TreeModelEventArgs e) moel@345: { moel@345: OnStructureChanged(new TreePathEventArgs(e.Path)); moel@345: } moel@345: moel@345: void _innerModel_NodesInserted(object sender, TreeModelEventArgs e) moel@345: { moel@345: OnStructureChanged(new TreePathEventArgs(e.Path)); moel@345: } moel@345: moel@345: void _innerModel_NodesChanged(object sender, TreeModelEventArgs e) moel@345: { moel@345: OnStructureChanged(new TreePathEventArgs(e.Path)); moel@345: } moel@345: moel@345: public override IEnumerable GetChildren(TreePath treePath) moel@345: { moel@345: if (Comparer != null) moel@345: { moel@345: ArrayList list = new ArrayList(); moel@345: IEnumerable res = InnerModel.GetChildren(treePath); moel@345: if (res != null) moel@345: { moel@345: foreach (object obj in res) moel@345: list.Add(obj); moel@345: list.Sort(Comparer); moel@345: return list; moel@345: } moel@345: else moel@345: return null; moel@345: } moel@345: else moel@345: return InnerModel.GetChildren(treePath); moel@345: } moel@345: moel@345: public override bool IsLeaf(TreePath treePath) moel@345: { moel@345: return InnerModel.IsLeaf(treePath); moel@345: } moel@345: } moel@345: }