External/Aga.Controls/Tree/ListModel.cs
changeset 345 0c551e8818e0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/External/Aga.Controls/Tree/ListModel.cs	Sun May 27 15:16:19 2012 +0000
     1.3 @@ -0,0 +1,56 @@
     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 ListModel : TreeModelBase
    1.12 +	{
    1.13 +		private IList _list;
    1.14 +
    1.15 +		public int Count
    1.16 +		{
    1.17 +			get { return _list.Count; }
    1.18 +		}
    1.19 +
    1.20 +		public ListModel()
    1.21 +		{
    1.22 +			_list = new List<object>();
    1.23 +		}
    1.24 +
    1.25 +		public ListModel(IList list)
    1.26 +		{
    1.27 +			_list = list;
    1.28 +		}
    1.29 +
    1.30 +		public override IEnumerable GetChildren(TreePath treePath)
    1.31 +		{
    1.32 +			return _list;
    1.33 +		}
    1.34 +
    1.35 +		public override bool IsLeaf(TreePath treePath)
    1.36 +		{
    1.37 +			return true;
    1.38 +		}
    1.39 +
    1.40 +		public void AddRange(IEnumerable items)
    1.41 +		{
    1.42 +			foreach (object obj in items)
    1.43 +				_list.Add(obj);
    1.44 +			OnStructureChanged(new TreePathEventArgs(TreePath.Empty));
    1.45 +		}
    1.46 +
    1.47 +		public void Add(object item)
    1.48 +		{
    1.49 +			_list.Add(item);
    1.50 +			OnNodesInserted(new TreeModelEventArgs(TreePath.Empty, new int[] { _list.Count - 1 }, new object[] { item }));
    1.51 +		}
    1.52 +
    1.53 +		public void Clear()
    1.54 +		{
    1.55 +			_list.Clear();
    1.56 +			OnStructureChanged(new TreePathEventArgs(TreePath.Empty));
    1.57 +		}
    1.58 +	}
    1.59 +}