Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

DataStorage: Store settings type-safe

, 8 Aug 2012
Shows how to use the DataStorage classes to generate type-safe settings classes.
DataStorage.zip
DataStorage
Aga.Controls
Aga.Controls.csproj.user
key.snk
Properties
Resources
check.bmp
DVSplit.cur
Folder.bmp
FolderClosed.bmp
Leaf.bmp
loading_icon
minus.bmp
plus.bmp
Thumbs.db
uncheck.bmp
unknown.bmp
Threading
Tree
ClassDiagram.cd
Input
NodeControls
ClassDiagram.cd
CommandLineGenerator
Properties
DataStorage
Properties
DataStorageGenerator
DataGeneration
Images
Add.png
AddClass.png
AddProperty.pdn
AddProperty.png
Class.png
Delete.png
FileOpen.png
FileSave.png
FileSaveAs.png
GenerateAll.png
Property.png
PropertyBool.png
PropertyColor.png
PropertyDateTime.png
PropertyDouble.png
PropertyEnum.png
PropertyFloat.png
PropertyInt.png
PropertyLong.png
PropertyString.png
PropertyVersion.png
Properties
Settings.settings
StorageTester
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Aga.Controls.Tree
{
	public class SortedTreeModel: TreeModelBase
	{
		private ITreeModel _innerModel;
		public ITreeModel InnerModel
		{
			get { return _innerModel; }
		}

		private IComparer _comparer;
		public IComparer Comparer
		{
			get { return _comparer; }
			set 
			{ 
				_comparer = value;
				OnStructureChanged(new TreePathEventArgs(TreePath.Empty));
			}
		}

		public SortedTreeModel(ITreeModel innerModel)
		{
			_innerModel = innerModel;
			_innerModel.NodesChanged += new EventHandler<TreeModelEventArgs>(_innerModel_NodesChanged);
			_innerModel.NodesInserted += new EventHandler<TreeModelEventArgs>(_innerModel_NodesInserted);
			_innerModel.NodesRemoved += new EventHandler<TreeModelEventArgs>(_innerModel_NodesRemoved);
			_innerModel.StructureChanged += new EventHandler<TreePathEventArgs>(_innerModel_StructureChanged);
		}

		void _innerModel_StructureChanged(object sender, TreePathEventArgs e)
		{
			OnStructureChanged(e);
		}

		void _innerModel_NodesRemoved(object sender, TreeModelEventArgs e)
		{
			OnStructureChanged(new TreePathEventArgs(e.Path));
		}

		void _innerModel_NodesInserted(object sender, TreeModelEventArgs e)
		{
			OnStructureChanged(new TreePathEventArgs(e.Path));
		}

		void _innerModel_NodesChanged(object sender, TreeModelEventArgs e)
		{
			OnStructureChanged(new TreePathEventArgs(e.Path));
		}

		public override IEnumerable GetChildren(TreePath treePath)
		{
			if (Comparer != null)
			{
				ArrayList list = new ArrayList();
				IEnumerable res = InnerModel.GetChildren(treePath);
				if (res != null)
				{
					foreach (object obj in res)
						list.Add(obj);
					list.Sort(Comparer);
					return list;
				}
				else
					return null;
			}
			else
				return InnerModel.GetChildren(treePath);
		}

		public override bool IsLeaf(TreePath treePath)
		{
			return InnerModel.IsLeaf(treePath);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

pchinery
pdfforge GbR
Germany Germany
Philip is a Software Architect with severaly years of experience. He studied business IT in the University of Wedel, Germany, and has reached his Masters degree in 2010. Back in 2002, he started his so far best-known software PDFCreator. The second developer joined two years later and since then, both constantly improve this piece of open source software.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 8 Aug 2012
Article Copyright 2012 by pchinery
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid