author | moel.mich |
Sun, 27 May 2012 15:16:19 +0000 | |
changeset 345 | 0c551e8818e0 |
permissions | -rw-r--r-- |
moel@345 | 1 |
using System; |
moel@345 | 2 |
using System.Collections.Generic; |
moel@345 | 3 |
using System.Text; |
moel@345 | 4 |
using System.Collections; |
moel@345 | 5 |
|
moel@345 | 6 |
namespace Aga.Controls.Tree |
moel@345 | 7 |
{ |
moel@345 | 8 |
public class SortedTreeModel: TreeModelBase |
moel@345 | 9 |
{ |
moel@345 | 10 |
private ITreeModel _innerModel; |
moel@345 | 11 |
public ITreeModel InnerModel |
moel@345 | 12 |
{ |
moel@345 | 13 |
get { return _innerModel; } |
moel@345 | 14 |
} |
moel@345 | 15 |
|
moel@345 | 16 |
private IComparer _comparer; |
moel@345 | 17 |
public IComparer Comparer |
moel@345 | 18 |
{ |
moel@345 | 19 |
get { return _comparer; } |
moel@345 | 20 |
set |
moel@345 | 21 |
{ |
moel@345 | 22 |
_comparer = value; |
moel@345 | 23 |
OnStructureChanged(new TreePathEventArgs(TreePath.Empty)); |
moel@345 | 24 |
} |
moel@345 | 25 |
} |
moel@345 | 26 |
|
moel@345 | 27 |
public SortedTreeModel(ITreeModel innerModel) |
moel@345 | 28 |
{ |
moel@345 | 29 |
_innerModel = innerModel; |
moel@345 | 30 |
_innerModel.NodesChanged += new EventHandler<TreeModelEventArgs>(_innerModel_NodesChanged); |
moel@345 | 31 |
_innerModel.NodesInserted += new EventHandler<TreeModelEventArgs>(_innerModel_NodesInserted); |
moel@345 | 32 |
_innerModel.NodesRemoved += new EventHandler<TreeModelEventArgs>(_innerModel_NodesRemoved); |
moel@345 | 33 |
_innerModel.StructureChanged += new EventHandler<TreePathEventArgs>(_innerModel_StructureChanged); |
moel@345 | 34 |
} |
moel@345 | 35 |
|
moel@345 | 36 |
void _innerModel_StructureChanged(object sender, TreePathEventArgs e) |
moel@345 | 37 |
{ |
moel@345 | 38 |
OnStructureChanged(e); |
moel@345 | 39 |
} |
moel@345 | 40 |
|
moel@345 | 41 |
void _innerModel_NodesRemoved(object sender, TreeModelEventArgs e) |
moel@345 | 42 |
{ |
moel@345 | 43 |
OnStructureChanged(new TreePathEventArgs(e.Path)); |
moel@345 | 44 |
} |
moel@345 | 45 |
|
moel@345 | 46 |
void _innerModel_NodesInserted(object sender, TreeModelEventArgs e) |
moel@345 | 47 |
{ |
moel@345 | 48 |
OnStructureChanged(new TreePathEventArgs(e.Path)); |
moel@345 | 49 |
} |
moel@345 | 50 |
|
moel@345 | 51 |
void _innerModel_NodesChanged(object sender, TreeModelEventArgs e) |
moel@345 | 52 |
{ |
moel@345 | 53 |
OnStructureChanged(new TreePathEventArgs(e.Path)); |
moel@345 | 54 |
} |
moel@345 | 55 |
|
moel@345 | 56 |
public override IEnumerable GetChildren(TreePath treePath) |
moel@345 | 57 |
{ |
moel@345 | 58 |
if (Comparer != null) |
moel@345 | 59 |
{ |
moel@345 | 60 |
ArrayList list = new ArrayList(); |
moel@345 | 61 |
IEnumerable res = InnerModel.GetChildren(treePath); |
moel@345 | 62 |
if (res != null) |
moel@345 | 63 |
{ |
moel@345 | 64 |
foreach (object obj in res) |
moel@345 | 65 |
list.Add(obj); |
moel@345 | 66 |
list.Sort(Comparer); |
moel@345 | 67 |
return list; |
moel@345 | 68 |
} |
moel@345 | 69 |
else |
moel@345 | 70 |
return null; |
moel@345 | 71 |
} |
moel@345 | 72 |
else |
moel@345 | 73 |
return InnerModel.GetChildren(treePath); |
moel@345 | 74 |
} |
moel@345 | 75 |
|
moel@345 | 76 |
public override bool IsLeaf(TreePath treePath) |
moel@345 | 77 |
{ |
moel@345 | 78 |
return InnerModel.IsLeaf(treePath); |
moel@345 | 79 |
} |
moel@345 | 80 |
} |
moel@345 | 81 |
} |