1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 | using HEAL.Attic;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.DataImporter.Data.Model {
|
---|
29 | [StorableType("92C9DDC3-8C5D-4496-9C72-E7F9E8624D5B")]
|
---|
30 | public class DataSet {
|
---|
31 |
|
---|
32 | [Storable]
|
---|
33 | private List<ColumnGroup> columnGroups;
|
---|
34 | public IEnumerable<ColumnGroup> ColumnGroups {
|
---|
35 | get { return this.columnGroups; }
|
---|
36 | }
|
---|
37 | [StorableConstructor]
|
---|
38 | protected DataSet(StorableConstructorFlag _) { }
|
---|
39 | public DataSet() {
|
---|
40 | this.columnGroups = new List<ColumnGroup>();
|
---|
41 | }
|
---|
42 |
|
---|
43 | public event EventHandler Changed;
|
---|
44 | protected virtual void OnChanged() {
|
---|
45 | if (this.Changed != null)
|
---|
46 | this.Changed(this, EventArgs.Empty);
|
---|
47 | }
|
---|
48 | public void FireChanged() {
|
---|
49 | this.OnChanged();
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void AddColumnGroup(ColumnGroup columnGroup) {
|
---|
53 | this.CheckColumnGroupName(columnGroup);
|
---|
54 | this.columnGroups.Add(columnGroup);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void AddColumnGroups(IEnumerable<ColumnGroup> columnGroups) {
|
---|
58 | foreach (ColumnGroup columnGroup in columnGroups) {
|
---|
59 | this.CheckColumnGroupName(columnGroup);
|
---|
60 | }
|
---|
61 | this.columnGroups.AddRange(columnGroups);
|
---|
62 | }
|
---|
63 |
|
---|
64 | private void CheckColumnGroupName(ColumnGroup columnGroup) {
|
---|
65 | int i = 0;
|
---|
66 | string columnGroupName = columnGroup.Name;
|
---|
67 | while (this.ColumnGroups.Any(cg => cg.Name == columnGroupName && cg != columnGroup)) {
|
---|
68 | i++;
|
---|
69 | columnGroupName = columnGroup.Name + " " + i;
|
---|
70 | }
|
---|
71 | columnGroup.Name = columnGroupName;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public void InsertColumnGroup(int position, ColumnGroup columnGroup) {
|
---|
75 | this.CheckColumnGroupName(columnGroup);
|
---|
76 | this.columnGroups.Insert(position, columnGroup);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public void ReplaceColumnGroup(int position, ColumnGroup columnGroup) {
|
---|
80 | this.columnGroups[position] = columnGroup;
|
---|
81 | this.CheckColumnGroupName(columnGroup);
|
---|
82 | }
|
---|
83 |
|
---|
84 | public void RemoveColumnGroup(ColumnGroup columnGroup) {
|
---|
85 | this.columnGroups.Remove(columnGroup);
|
---|
86 | }
|
---|
87 |
|
---|
88 | public int IndexOfColumnGroup(ColumnGroup columnGroup) {
|
---|
89 | return this.columnGroups.IndexOf(columnGroup);
|
---|
90 | }
|
---|
91 |
|
---|
92 | public ColumnGroup GetColumnGroup(string columnGroupName) {
|
---|
93 | IEnumerable<ColumnGroup> groups = this.columnGroups.Where(g => g.Name == columnGroupName);
|
---|
94 | if (groups.Count() != 1)
|
---|
95 | throw new InvalidOperationException("Found 0 or more than 1 column group with the name \"" + columnGroupName + "\".");
|
---|
96 | return groups.First();
|
---|
97 |
|
---|
98 | }
|
---|
99 |
|
---|
100 | public IEnumerable<ColumnGroup> ActiveColumnGroups {
|
---|
101 | get {
|
---|
102 | return this.columnGroups.Where(cg => cg.Active);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|