using System;
using System.Collections;
using System.ComponentModel;
namespace DevComponents.Tree
{
///
/// A strongly-typed collection of objects.
///
public class CellCollection:CollectionBase
{
#region Private Variables
private Node m_ParentNode=null;
#endregion
#region Internal Implementation
/// Creates new instance of the class.
public CellCollection()
{
}
///
/// Adds new object to the collection.
///
/// Object to add.
/// Index of newly added object.
public int Add(Cell cell)
{
return List.Add(cell);
}
///
/// Returns reference to the object in collection based on it's index.
///
public Cell this[int index]
{
get {return (Cell)(List[index]);}
set {List[index] = value;}
}
///
/// Inserts new object into the collection.
///
/// Position of the object.
/// Object to insert.
public void Insert(int index, Cell value)
{
List.Insert(index, value);
}
///
/// Returns index of the object inside of the collection.
///
/// Reference to the object.
/// Index of the object.
public int IndexOf(Cell value)
{
return List.IndexOf(value);
}
///
/// Returns whether collection contains specified object.
///
/// Object to look for.
/// true if object is part of the collection, otherwise false.
public bool Contains(Cell value)
{
return List.Contains(value);
}
///
/// Removes specified object from the collection.
///
///
public void Remove(Cell value)
{
List.Remove(value);
}
protected override void OnRemoveComplete(int index,object value)
{
base.OnRemoveComplete(index,value);
Cell cell=value as Cell;
cell.SetParent(null);
if(m_ParentNode!=null)
m_ParentNode.OnCellRemoved(cell);
}
protected override void OnInsertComplete(int index,object value)
{
base.OnInsertComplete(index,value);
Cell cell=value as Cell;
if(cell.Parent!=null && cell.Parent!=m_ParentNode)
cell.Parent.Cells.Remove(cell);
cell.SetParent(m_ParentNode);
if(m_ParentNode!=null)
m_ParentNode.OnCellInserted(cell);
}
///
/// Copies collection into the specified array.
///
/// Array to copy collection to.
/// Starting index.
public void CopyTo(Cell[] array, int index)
{
List.CopyTo(array, index);
}
///
/// Copies contained items to the Cell array.
///
/// Array to copy to.
internal void CopyTo(Cell[] array)
{
List.CopyTo(array,0);
}
protected override void OnClear()
{
base.OnClear();
}
///
/// Gets or sets the node this collection is associated with.
///
[Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Node ParentNode
{
get {return m_ParentNode;}
}
///
/// Sets the node collection belongs to.
///
/// Cell that is parent of this collection.
internal void SetParentNode(Node parent)
{
m_ParentNode=parent;
}
#endregion
}
#region CellCollectionEditor
///
/// Support for Cell tabs design-time editor.
///
public class CellCollectionEditor:System.ComponentModel.Design.CollectionEditor
{
/// Creates new instance of cell collection editor.
/// Type to initialize editor with.
public CellCollectionEditor(Type type):base(type)
{
}
protected override Type CreateCollectionItemType()
{
return typeof(Cell);
}
protected override Type[] CreateNewItemTypes()
{
return new Type[] {typeof(Cell)};
}
protected override object CreateInstance(Type itemType)
{
object item=base.CreateInstance(itemType);
if(item is Cell)
{
Cell cell=item as Cell;
cell.Text=cell.Name;
}
return item;
}
}
#endregion
}