#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;
using HeuristicLab.DataImporter.Data.CommandBase;
using HeuristicLab.DataImporter.Data.Model;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.DataImporter.Command {
[StorableClass]
[ViewableCommandInfoAttribute("Delete ColumnGroup", 1, ColumnGroupState.Active, "ColumnGroup Commands", Position = 1, MinActiveColumnGroups = 1)]
public class DeleteColumnGroupCommand : DataSetCommandWithAffectedColumnGroupsBase {
private List> deletedColumnGroups;
[StorableConstructor]
protected DeleteColumnGroupCommand(bool deserializing)
: base(deserializing) {
deletedColumnGroups = new List>();
}
public DeleteColumnGroupCommand(DataSet dataSet, List affectedColumnGroupNames)
: base(dataSet, affectedColumnGroupNames) {
deletedColumnGroups = new List>();
}
public override string Description {
get { return "Delete ColumnGroup"; }
}
public override void Execute() {
base.Execute();
ColumnGroup columnGroup;
foreach (string columnGroupName in AffectedColumnGroupNames) {
columnGroup = this.DataSet.GetColumnGroup(columnGroupName);
deletedColumnGroups.Add(new KeyValuePair(this.DataSet.IndexOfColumnGroup(columnGroup), columnGroup));
this.DataSet.RemoveColumnGroup(columnGroup);
}
this.DataSet.FireChanged();
}
public override void UndoExecute() {
base.UndoExecute();
deletedColumnGroups.Reverse();
for (int i = 0; i < deletedColumnGroups.Count; i++)
this.DataSet.InsertColumnGroup(deletedColumnGroups[i].Key, deletedColumnGroups[i].Value);
deletedColumnGroups.Clear();
this.DataSet.FireChanged();
}
}
}