External/Aga.Controls/Tree/SortedTreeModel.cs
changeset 345 0c551e8818e0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/External/Aga.Controls/Tree/SortedTreeModel.cs	Sun May 27 15:16:19 2012 +0000
     1.3 @@ -0,0 +1,81 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Text;
     1.7 +using System.Collections;
     1.8 +
     1.9 +namespace Aga.Controls.Tree
    1.10 +{
    1.11 +	public class SortedTreeModel: TreeModelBase
    1.12 +	{
    1.13 +		private ITreeModel _innerModel;
    1.14 +		public ITreeModel InnerModel
    1.15 +		{
    1.16 +			get { return _innerModel; }
    1.17 +		}
    1.18 +
    1.19 +		private IComparer _comparer;
    1.20 +		public IComparer Comparer
    1.21 +		{
    1.22 +			get { return _comparer; }
    1.23 +			set 
    1.24 +			{ 
    1.25 +				_comparer = value;
    1.26 +				OnStructureChanged(new TreePathEventArgs(TreePath.Empty));
    1.27 +			}
    1.28 +		}
    1.29 +
    1.30 +		public SortedTreeModel(ITreeModel innerModel)
    1.31 +		{
    1.32 +			_innerModel = innerModel;
    1.33 +			_innerModel.NodesChanged += new EventHandler<TreeModelEventArgs>(_innerModel_NodesChanged);
    1.34 +			_innerModel.NodesInserted += new EventHandler<TreeModelEventArgs>(_innerModel_NodesInserted);
    1.35 +			_innerModel.NodesRemoved += new EventHandler<TreeModelEventArgs>(_innerModel_NodesRemoved);
    1.36 +			_innerModel.StructureChanged += new EventHandler<TreePathEventArgs>(_innerModel_StructureChanged);
    1.37 +		}
    1.38 +
    1.39 +		void _innerModel_StructureChanged(object sender, TreePathEventArgs e)
    1.40 +		{
    1.41 +			OnStructureChanged(e);
    1.42 +		}
    1.43 +
    1.44 +		void _innerModel_NodesRemoved(object sender, TreeModelEventArgs e)
    1.45 +		{
    1.46 +			OnStructureChanged(new TreePathEventArgs(e.Path));
    1.47 +		}
    1.48 +
    1.49 +		void _innerModel_NodesInserted(object sender, TreeModelEventArgs e)
    1.50 +		{
    1.51 +			OnStructureChanged(new TreePathEventArgs(e.Path));
    1.52 +		}
    1.53 +
    1.54 +		void _innerModel_NodesChanged(object sender, TreeModelEventArgs e)
    1.55 +		{
    1.56 +			OnStructureChanged(new TreePathEventArgs(e.Path));
    1.57 +		}
    1.58 +
    1.59 +		public override IEnumerable GetChildren(TreePath treePath)
    1.60 +		{
    1.61 +			if (Comparer != null)
    1.62 +			{
    1.63 +				ArrayList list = new ArrayList();
    1.64 +				IEnumerable res = InnerModel.GetChildren(treePath);
    1.65 +				if (res != null)
    1.66 +				{
    1.67 +					foreach (object obj in res)
    1.68 +						list.Add(obj);
    1.69 +					list.Sort(Comparer);
    1.70 +					return list;
    1.71 +				}
    1.72 +				else
    1.73 +					return null;
    1.74 +			}
    1.75 +			else
    1.76 +				return InnerModel.GetChildren(treePath);
    1.77 +		}
    1.78 +
    1.79 +		public override bool IsLeaf(TreePath treePath)
    1.80 +		{
    1.81 +			return InnerModel.IsLeaf(treePath);
    1.82 +		}
    1.83 +	}
    1.84 +}