#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 System.Linq;
using System.Windows.Forms;
using HeuristicLab.DataImporter.Data;
using HeuristicLab.DataImporter.Data.CommandBase;
using HeuristicLab.DataImporter.Data.Model;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HEAL.Attic;
namespace HeuristicLab.DataImporter.Command {
[StorableType("C619464C-C98C-4A14-92BF-C318041390E6")]
[ViewableCommandInfo("Split ColumnGroup", 1, ColumnGroupState.ColumnSelected, "ColumnGroup Commands", Position = 6, SelectedColumns = 2)]
public class SplitColumnGroupsCommand : ColumnGroupCommandWithAffectedColumnsBase {
private IEnumerable oldSortOrder;
private ColumnGroup oldColumnGroup;
private int oldColumnGroupIndex;
private ColumnGroup newColumnGroup1;
private ColumnGroup newColumnGroup2;
[StorableConstructor]
protected SplitColumnGroupsCommand(StorableConstructorFlag _) : base(_) { }
public SplitColumnGroupsCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
: base(dataSet, columnGroupName, affectedColumns) {
}
public override void Execute() {
base.Execute();
int splitPosition = AffectedColumns[0] + 1;
oldColumnGroup = this.ColumnGroup;
oldColumnGroupIndex = this.DataSet.IndexOfColumnGroup(oldColumnGroup);
oldSortOrder = oldColumnGroup.SortOrdersForColumns.ToList();
newColumnGroup1 = new ColumnGroup(oldColumnGroup.Name);
newColumnGroup2 = new ColumnGroup(oldColumnGroup.Name);
for (int i = 0; i < splitPosition; i++)
newColumnGroup1.AddColumn(oldColumnGroup.Columns.ElementAt(i));
for (int i = splitPosition; i < oldColumnGroup.Columns.Count(); i++)
newColumnGroup2.AddColumn(oldColumnGroup.Columns.ElementAt(i));
newColumnGroup1.ResetSorting();
newColumnGroup2.ResetSorting();
this.DataSet.RemoveColumnGroup(oldColumnGroup);
this.DataSet.InsertColumnGroup(oldColumnGroupIndex, newColumnGroup1);
this.DataSet.InsertColumnGroup(oldColumnGroupIndex + 1, newColumnGroup2);
this.DataSet.FireChanged();
}
public override void UndoExecute() {
base.UndoExecute();
this.DataSet.RemoveColumnGroup(newColumnGroup1);
this.DataSet.RemoveColumnGroup(newColumnGroup2);
this.DataSet.InsertColumnGroup(oldColumnGroupIndex, oldColumnGroup);
oldColumnGroup.SortOrdersForColumns = oldSortOrder;
newColumnGroup1 = null;
newColumnGroup2 = null;
oldSortOrder = null;
oldColumnGroup = null;
this.DataSet.FireChanged();
}
public override string Description {
get { return "Split column group"; }
}
}
}