Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis/3.3/DataVisualization/DataRow.cs @ 11158

Last change on this file since 11158 was 9740, checked in by gkronber, 11 years ago

#1483: removed parameterless constructor from DataRow and added a check for IsNullOrEmpty.

File size: 4.6 KB
RevLine 
[2908]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2908]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
[4644]22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
[2908]25using HeuristicLab.Collections;
[3376]26using HeuristicLab.Common;
[2908]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.")]
[3017]35  [StorableClass]
[5097]36  public class DataRow : NamedItem {
[4644]37    private DataRowVisualProperties visualProperties;
38    public DataRowVisualProperties VisualProperties {
39      get { return visualProperties; }
40      set {
41        if (visualProperties != value) {
42          if (value == null) throw new ArgumentNullException("VisualProperties");
43          if (visualProperties != null) visualProperties.PropertyChanged -= new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
44          visualProperties = value;
45          visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
46          OnVisualPropertiesChanged();
47        }
48      }
49    }
[2908]50    private ObservableList<double> values;
[4703]51    public ObservableList<double> Values {
[2908]52      get { return values; }
53    }
54
[4644]55    #region Persistence Properties
[5261]56    [Storable(Name = "VisualProperties")]
57    private DataRowVisualProperties StorableVisualProperties {
58      get { return visualProperties; }
59      set {
60        visualProperties = value;
61        visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
62      }
63    }
[4644]64    [Storable(Name = "values")]
65    private IEnumerable<double> StorableValues {
66      get { return values; }
67      set { values = new ObservableList<double>(value); }
68    }
69    #endregion
70
[4722]71    [StorableConstructor]
[5097]72    protected DataRow(bool deserializing) : base(deserializing) { }
73    protected DataRow(DataRow original, Cloner cloner)
[4722]74      : base(original, cloner) {
75      this.VisualProperties = (DataRowVisualProperties)cloner.Clone(original.visualProperties);
76      this.values = new ObservableList<double>(original.values);
77    }
[2908]78    public DataRow(string name)
79      : base(name) {
[9740]80      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataRow cannot be empty", name);
[6628]81      VisualProperties = new DataRowVisualProperties(name);
[2908]82      values = new ObservableList<double>();
83    }
84    public DataRow(string name, string description)
85      : base(name, description) {
[9740]86      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataRow cannot be empty", name);
[6628]87      VisualProperties = new DataRowVisualProperties(name);
[2908]88      values = new ObservableList<double>();
89    }
[4777]90    public DataRow(string name, string description, IEnumerable<double> values)
[4644]91      : base(name, description) {
[9740]92      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataRow cannot be empty", name);
[6628]93      VisualProperties = new DataRowVisualProperties(name);
[4777]94      this.values = new ObservableList<double>(values);
[4644]95    }
[2908]96
[4644]97    // BackwardsCompatibility3.3
98    #region Backwards compatible code, remove with 3.4
99    [StorableHook(HookType.AfterDeserialization)]
100    private void AfterDeserialization() {
101      if (VisualProperties == null) VisualProperties = new DataRowVisualProperties();
102    }
103    #endregion
104
[4777]105    public override IDeepCloneable Clone(Cloner cloner) {
106      return new DataRow(this, cloner);
107    }
108
[4644]109    public event EventHandler VisualPropertiesChanged;
[5097]110    protected virtual void OnVisualPropertiesChanged() {
[4644]111      EventHandler handler = VisualPropertiesChanged;
112      if (handler != null) handler(this, EventArgs.Empty);
113    }
114
115    private void VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) {
116      OnVisualPropertiesChanged();
117    }
[2908]118  }
119}
Note: See TracBrowser for help on using the repository browser.