#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using HeuristicLab.DataImporter.Data.View; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.DataImporter.Data.Model { [StorableClass] public class DataSet { [Storable] private List columnGroups; public IEnumerable ColumnGroups { get { return this.columnGroups; } } public DataSet() { this.columnGroups = new List(); } public event EventHandler Changed; protected virtual void OnChanged() { if (this.Changed != null) this.Changed(this, EventArgs.Empty); } public void FireChanged() { this.OnChanged(); } public void AddColumnGroup(ColumnGroup columnGroup) { this.CheckColumnGroupName(columnGroup); this.columnGroups.Add(columnGroup); } public void AddColumnGroups(IEnumerable columnGroups) { foreach (ColumnGroup columnGroup in columnGroups) { this.CheckColumnGroupName(columnGroup); } this.columnGroups.AddRange(columnGroups); } private void CheckColumnGroupName(ColumnGroup columnGroup) { int i = 0; string columnGroupName = columnGroup.Name; while (this.ColumnGroups.Any(cg => cg.Name == columnGroupName && cg != columnGroup)) { i++; columnGroupName = columnGroup.Name + " " + i; } columnGroup.Name = columnGroupName; } public void InsertColumnGroup(int position, ColumnGroup columnGroup) { this.CheckColumnGroupName(columnGroup); this.columnGroups.Insert(position, columnGroup); } public void ReplaceColumnGroup(int position, ColumnGroup columnGroup) { this.columnGroups[position] = columnGroup; this.CheckColumnGroupName(columnGroup); } public void RemoveColumnGroup(ColumnGroup columnGroup) { this.columnGroups.Remove(columnGroup); } public int IndexOfColumnGroup(ColumnGroup columnGroup) { return this.columnGroups.IndexOf(columnGroup); } public ColumnGroup GetColumnGroup(string columnGroupName) { IEnumerable groups = this.columnGroups.Where(g => g.Name == columnGroupName); if (groups.Count() != 1) throw new InvalidOperationException("Found 0 or more than 1 column group with the name \"" + columnGroupName + "\"."); return groups.First(); } public IEnumerable ActiveColumnGroups { get { return this.columnGroups.Where(cg => cg.Active); } } } }