Files
spark/src/DataStreamSuite/DataStreamCore/BlueData/SimpleBindableCollection.cs
T
2023-09-04 16:25:40 -04:00

122 lines
3.2 KiB
C#

using System;
using System.ComponentModel;
using System.Collections;
namespace BCG
{
public class SimpleBindableCollection : IBlueRowCollection, ITypedList, IList
{
private ArrayList myRows;
private IBlueTableSchema mySchema;
private PropertyDescriptorCollection myPDColl;
public SimpleBindableCollection (IBlueTableSchema schema, ICollection rows)
{
mySchema = schema;
ArrayList temp = new ArrayList ();
foreach (ColumnInfo ci in mySchema.columnInfo)
temp.Add (new BlueDataPropertyDescriptor (ci));
myPDColl = new PropertyDescriptorCollection (temp.ToArray (typeof(PropertyDescriptor)) as PropertyDescriptor[]);
myRows = new ArrayList (rows);
}
public SimpleBindableCollection (IBlueTableSchema schema)
: this (schema, new ArrayList ())
{}
#region IBlueRowCollection Members
public IBlueRow this[int id]
{
get
{
foreach (IBlueRow r in this)
if (r["id"].Equals (id))
return r;
throw new ApplicationException ("ID + " + id.ToString () + " not found");
}
}
public bool containsID(int id)
{
try
{
return this[id] != null;
}
catch (ApplicationException)
{
return false;
}
}
public IBlueTableSchema schema {get {return mySchema;}}
#endregion
#region ICollection Members
public bool IsSynchronized {get {return false;}}
public int Count {get {return myRows.Count;}}
public void CopyTo(Array array, int index) {myRows.CopyTo (array, index);}
public object SyncRoot { get {return null;}}
#endregion
#region IEnumerable Members
public System.Collections.IEnumerator GetEnumerator()
{
return myRows.GetEnumerator ();
}
#endregion
#region ITypedList Members
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
{
return myPDColl;
}
public string GetListName(PropertyDescriptor[] listAccessors)
{
return "SimpleBindableCollection";
}
#endregion
#region IList Members
public bool IsReadOnly {get {return true;}}
object System.Collections.IList.this[int index]
{
get {return myRows[index];}
set {throw new ApplicationException ("Collection is read only");}
}
public void RemoveAt(int index) {throw new ApplicationException ("Collection is read only");}
public void Insert(int index, object value) {throw new ApplicationException ("Collection is read only");}
public void Remove(object value) {throw new ApplicationException ("Collection is read only");}
public bool Contains(object value) {return myRows.Contains (value);}
public void Clear() {throw new ApplicationException ("Collection is read only");}
public int IndexOf(object value) {return myRows.IndexOf (value);}
public int Add(object value) {throw new ApplicationException ("Collection is read only");}
public bool IsFixedSize {get {return true;}}
#endregion
public void reset (ICollection rows) {myRows = new ArrayList(rows);}
}
}