#region License Information /* HeuristicLab * Copyright (C) 2002-2013 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.Collections.Generic; using HeuristicLab.DataImporter.Data.CommandBase; using HeuristicLab.DataImporter.Data.Model; using HeuristicLab.DataImporter.DbExplorer.Interfaces; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.DataImporter.DataProcessor.Command { [StorableClass] public class LoadColumnGroupsFromDBCommand : DatabaseCommandBase { [Storable] private List tables; private List newColumnGroups; [StorableConstructor] protected LoadColumnGroupsFromDBCommand(bool deserializing) : base(deserializing) { this.newColumnGroups = new List(); } public LoadColumnGroupsFromDBCommand(DataSet dataSet, IDbExplorer dbExplorer, IEnumerable tables) : base(dataSet, dbExplorer) { this.tables = new List(tables); this.newColumnGroups = new List(); } public override string Description { get { return "Load ColumnGroups from database"; } } public override void Execute() { base.Execute(); if (DbExplorer == null || !DbExplorer.IsConnected) throw new CommandExecutionException("Could not load data because no connection to the database exists", this); ColumnGroup columnGroup; foreach (DbTable table in tables) { columnGroup = DbExplorer.CreateColumnGroup(table); this.DataSet.AddColumnGroup(columnGroup); newColumnGroups.Add(columnGroup); } this.DataSet.FireChanged(); } public override void UndoExecute() { base.UndoExecute(); foreach (ColumnGroup columnGroup in newColumnGroups) this.DataSet.RemoveColumnGroup(columnGroup); newColumnGroups.Clear(); this.DataSet.FireChanged(); } } }