BoundComboBoxSource.cs :  » Persistence-Frameworks » Ubik » StoresAndStockPricing » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » Ubik 
Ubik » StoresAndStockPricing » Controls » BoundComboBoxSource.cs
using System;
using System.Collections.Generic;
using System.Text;
using Ubik.Engine.Client;

namespace StoresAndStockPricing.Controls{
  public class BoundComboBoxSource<T> : IList<BoundComboBoxItem<T>>,
    System.Collections.IList where T : Individual
  {
    public delegate string DisplayDelegate(Session session, T t);

    private Session _session;
    private DisplayDelegate _displayDelegate;
    private string _filter;
    private List<BoundComboBoxItem<T>> _items = new List<BoundComboBoxItem<T>>();

    public BoundComboBoxSource(Session session, DisplayDelegate displayDelegate)
    {
      if (session == null)
        throw new ArgumentNullException("session");

      if (displayDelegate == null)
        throw new ArgumentNullException("displayDelegate");

      _session = session;
      _displayDelegate = displayDelegate;
    }

    public string Filter
    {
      get
      {
        return _filter;
      }
      set
      {
        string oldValue = _filter;
        try
        {
          _filter = value;
          Load();
        }
        catch (Exception)
        {
          _filter = oldValue;
          throw;
        }
      }
    }

    private string UPathFilter
    {
      get
      {
        if (string.IsNullOrEmpty(_filter))
          return typeof(T).Name;
        else
          return typeof(T).Name + "[" + _filter + "]";
      }
    }

    private void Load()
    {
      List<BoundComboBoxItem<T>> oldItems = _items;

      try
      {
        _items = new List<BoundComboBoxItem<T>>();

        IList<Individual> newItems = _session.Select(UPathFilter);

        foreach (T item in newItems)
        {
          _items.Add(new BoundComboBoxItem<T>(_session, _displayDelegate, item));
        }

      }
      catch (Exception)
      {
        _items = oldItems;
        throw;
      }
    }

    #region IEnumerable<BindingProxy<T>> Members

    public IEnumerator<BoundComboBoxItem<T>> GetEnumerator()
    {
      return _items.GetEnumerator();
    }

    #endregion

    #region IEnumerable Members

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
      return GetEnumerator();
    }

    #endregion

    #region IList<BoundComboBoxItem<T>> Members

    public int IndexOf(BoundComboBoxItem<T> item)
    {
      return _items.IndexOf(item);
    }

    public void Insert(int index, BoundComboBoxItem<T> item)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    public void RemoveAt(int index)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    public BoundComboBoxItem<T> this[int index]
    {
      get
      {
        return _items[index];
      }
      set
      {
        throw new Exception("The method or operation is not implemented.");
      }
    }

    #endregion

    #region ICollection<BoundComboBoxItem<T>> Members

    public void Add(BoundComboBoxItem<T> item)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    public void Clear()
    {
      throw new Exception("The method or operation is not implemented.");
    }

    public bool Contains(BoundComboBoxItem<T> item)
    {
      return _items.Contains(item);
    }

    public void CopyTo(BoundComboBoxItem<T>[] array, int arrayIndex)
    {
      _items.CopyTo(array, arrayIndex);
    }

    public int Count
    {
      get
      {
        return _items.Count;
      }
    }

    public bool IsReadOnly
    {
      get
      {
        return true;
      }
    }

    public bool Remove(BoundComboBoxItem<T> item)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    #endregion

    #region IList Members

    int System.Collections.IList.Add(object value)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    void System.Collections.IList.Clear()
    {
      throw new Exception("The method or operation is not implemented.");
    }

    bool System.Collections.IList.Contains(object value)
    {
      return Contains((BoundComboBoxItem<T>)value);
    }

    int System.Collections.IList.IndexOf(object value)
    {
      return IndexOf((BoundComboBoxItem<T>)value);
    }

    void System.Collections.IList.Insert(int index, object value)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    bool System.Collections.IList.IsFixedSize
    {
      get
      {
        return true;
      }
    }

    bool System.Collections.IList.IsReadOnly
    {
      get
      {
        return true;
      }
    }

    void System.Collections.IList.Remove(object value)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    void System.Collections.IList.RemoveAt(int index)
    {
      throw new Exception("The method or operation is not implemented.");
    }

    object System.Collections.IList.this[int index]
    {
      get
      {
        return this[index];
      }
      set
      {
        throw new Exception("The method or operation is not implemented.");
      }
    }

    #endregion

    #region ICollection Members

    void System.Collections.ICollection.CopyTo(Array array, int index)
    {
      for (int i = index; i < _items.Count; i++)
        array.SetValue(_items[i], i);
    }

    int System.Collections.ICollection.Count
    {
      get
      {
        return Count;
      }
    }

    bool System.Collections.ICollection.IsSynchronized
    {
      get
      {
        return false;
      }
    }

    object System.Collections.ICollection.SyncRoot
    {
      get
      {
        return this;
      }
    }

    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.