Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/DataSources/OneDimensional/EnumerableDataSourceBase.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.6 KB
Line 
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Collections.Specialized;
5using System.Diagnostics;
6using System.Windows;
7
8namespace Microsoft.Research.DynamicDataDisplay.DataSources
9{
10    /// <summary>Base class for all sources who receive data for charting
11    /// from any IEnumerable of T</summary>
12    /// <typeparam name="T">Type of items in IEnumerable</typeparam>
13  public abstract class EnumerableDataSourceBase<T> : IPointDataSource {
14        private IEnumerable data;
15
16    /// <summary>
17    /// Gets or sets the data.
18    /// </summary>
19    /// <value>The data.</value>
20        public IEnumerable Data {
21      get { return data; }
22      set {
23        if (value == null)
24          throw new ArgumentNullException("value");
25
26        data = value;
27
28        var observableCollection = data as INotifyCollectionChanged;
29        if (observableCollection != null) {
30          observableCollection.CollectionChanged += observableCollection_CollectionChanged;
31        }
32      }
33    }
34
35    protected EnumerableDataSourceBase(IEnumerable<T> data) : this((IEnumerable)data) { }
36
37    protected EnumerableDataSourceBase(IEnumerable data) {
38      if (data == null)
39        throw new ArgumentNullException("data");
40      Data = data;
41    }
42
43    private void observableCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
44      RaiseDataChanged();
45    }
46
47    public event EventHandler DataChanged;
48    public void RaiseDataChanged() {
49      if (DataChanged != null) {
50        DataChanged(this, EventArgs.Empty);
51      }
52    }
53
54    public abstract IPointEnumerator GetEnumerator(DependencyObject context);
55  }
56}
Note: See TracBrowser for help on using the repository browser.