Free cookie consent management tool by TermsFeed Policy Generator

source: branches/NET40/sources/HeuristicLab.Analysis/3.3/DataVisualization/DataRow.cs @ 5138

Last change on this file since 5138 was 5097, checked in by epitzer, 14 years ago

DataTable, DataRow and DataTableView have been unsealed. (#1338)

A possible persistence problem has also been fixed by directly persisting the visualProperties property otherwise an ArgumentException might break backwards compatibility.

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using HeuristicLab.Collections;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Analysis {
31  /// <summary>
32  /// A row of data values.
33  /// </summary>
34  [Item("DataRow", "A row of data values.")]
35  [StorableClass]
36  public class DataRow : NamedItem {
37    [Storable(Name = "VisualProperties")]
38    private DataRowVisualProperties visualProperties;
39    public DataRowVisualProperties VisualProperties {
40      get { return visualProperties; }
41      set {
42        if (visualProperties != value) {
43          if (value == null) throw new ArgumentNullException("VisualProperties");
44          if (visualProperties != null) visualProperties.PropertyChanged -= new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
45          visualProperties = value;
46          visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
47          OnVisualPropertiesChanged();
48        }
49      }
50    }
51    private ObservableList<double> values;
52    public ObservableList<double> Values {
53      get { return values; }
54    }
55
56    #region Persistence Properties
57    [Storable(Name = "values")]
58    private IEnumerable<double> StorableValues {
59      get { return values; }
60      set { values = new ObservableList<double>(value); }
61    }
62    #endregion
63
64    [StorableConstructor]
65    protected DataRow(bool deserializing) : base(deserializing) { }
66    protected DataRow(DataRow original, Cloner cloner)
67      : base(original, cloner) {
68      this.VisualProperties = (DataRowVisualProperties)cloner.Clone(original.visualProperties);
69      this.values = new ObservableList<double>(original.values);
70    }
71    public DataRow()
72      : base() {
73      VisualProperties = new DataRowVisualProperties();
74      values = new ObservableList<double>();
75    }
76    public DataRow(string name)
77      : base(name) {
78      VisualProperties = new DataRowVisualProperties();
79      values = new ObservableList<double>();
80    }
81    public DataRow(string name, string description)
82      : base(name, description) {
83      VisualProperties = new DataRowVisualProperties();
84      values = new ObservableList<double>();
85    }
86    public DataRow(string name, string description, IEnumerable<double> values)
87      : base(name, description) {
88      VisualProperties = new DataRowVisualProperties();
89      this.values = new ObservableList<double>(values);
90    }
91
92    // BackwardsCompatibility3.3
93    #region Backwards compatible code, remove with 3.4
94    [StorableHook(HookType.AfterDeserialization)]
95    private void AfterDeserialization() {
96      if (VisualProperties == null) VisualProperties = new DataRowVisualProperties();
97    }
98    #endregion
99
100    public override IDeepCloneable Clone(Cloner cloner) {
101      return new DataRow(this, cloner);
102    }
103
104    public event EventHandler VisualPropertiesChanged;
105    protected virtual void OnVisualPropertiesChanged() {
106      EventHandler handler = VisualPropertiesChanged;
107      if (handler != null) handler(this, EventArgs.Empty);
108    }
109
110    private void VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) {
111      OnVisualPropertiesChanged();
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.