External/Aga.Controls/Tree/ListModel.cs
author moel.mich
Sat, 08 Jun 2013 17:06:00 +0000
changeset 392 4b43228a9894
permissions -rw-r--r--
Some modifications to the OxyPlot library to back-port to .NET 2.0. Added the LINQBridge library for the LINQ based code in OxyPlot (the original .NET LINQ is not available in .NET 2.0).
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Text;
     4 using System.Collections;
     5 
     6 namespace Aga.Controls.Tree
     7 {
     8 	public class ListModel : TreeModelBase
     9 	{
    10 		private IList _list;
    11 
    12 		public int Count
    13 		{
    14 			get { return _list.Count; }
    15 		}
    16 
    17 		public ListModel()
    18 		{
    19 			_list = new List<object>();
    20 		}
    21 
    22 		public ListModel(IList list)
    23 		{
    24 			_list = list;
    25 		}
    26 
    27 		public override IEnumerable GetChildren(TreePath treePath)
    28 		{
    29 			return _list;
    30 		}
    31 
    32 		public override bool IsLeaf(TreePath treePath)
    33 		{
    34 			return true;
    35 		}
    36 
    37 		public void AddRange(IEnumerable items)
    38 		{
    39 			foreach (object obj in items)
    40 				_list.Add(obj);
    41 			OnStructureChanged(new TreePathEventArgs(TreePath.Empty));
    42 		}
    43 
    44 		public void Add(object item)
    45 		{
    46 			_list.Add(item);
    47 			OnNodesInserted(new TreeModelEventArgs(TreePath.Empty, new int[] { _list.Count - 1 }, new object[] { item }));
    48 		}
    49 
    50 		public void Clear()
    51 		{
    52 			_list.Clear();
    53 			OnStructureChanged(new TreePathEventArgs(TreePath.Empty));
    54 		}
    55 	}
    56 }