[6134] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2011 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;
|
---|
[6133] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.DataImporter.Data;
|
---|
| 27 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
| 28 | using HeuristicLab.DataImporter.Data.Model;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 | using System.Windows.Forms;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.DataImporter.Command {
|
---|
| 33 | [StorableClass]
|
---|
| 34 | [ViewableCommandInfo("Merge ColumnGroups", 2, ColumnGroupState.Active, "ColumnGroup Commands", Position = 5, MinActiveColumnGroups = 2)]
|
---|
| 35 | public class MergeColumnGroupsCommand : DataSetCommandWithAffectedColumnGroupsBase {
|
---|
| 36 | private SortedDictionary<int, ColumnGroup> oldColumnGroups;
|
---|
| 37 | private List<int> oldRowCounts;
|
---|
| 38 | private ColumnGroup newColumnGroup;
|
---|
| 39 |
|
---|
| 40 | private MergeColumnGroupsCommand()
|
---|
| 41 | : base(null, null) {
|
---|
| 42 | oldColumnGroups = new SortedDictionary<int, ColumnGroup>();
|
---|
| 43 | oldRowCounts = new List<int>();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public MergeColumnGroupsCommand(DataSet dataSet, List<string> affectedColumnGroupNames)
|
---|
| 47 | : base(dataSet, affectedColumnGroupNames) {
|
---|
| 48 | oldColumnGroups = new SortedDictionary<int, ColumnGroup>();
|
---|
| 49 | oldRowCounts = new List<int>();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public override void Execute() {
|
---|
| 53 | base.Execute();
|
---|
| 54 | string name = "";
|
---|
| 55 | ColumnGroup columnGroup;
|
---|
| 56 | foreach (string columnGroupName in AffectedColumnGroupNames) {
|
---|
| 57 | columnGroup = this.DataSet.GetColumnGroup(columnGroupName);
|
---|
| 58 | oldColumnGroups.Add(this.DataSet.IndexOfColumnGroup(columnGroup), columnGroup);
|
---|
| 59 | oldRowCounts.Add(columnGroup.RowCount);
|
---|
| 60 | name = name + " & " + columnGroup.Name;
|
---|
| 61 | }
|
---|
| 62 | name = name.Remove(0, 3);
|
---|
| 63 | this.newColumnGroup = new ColumnGroup(name);
|
---|
| 64 | foreach (ColumnGroup grp in oldColumnGroups.Values) {
|
---|
| 65 | newColumnGroup.AddColumns(grp.Columns);
|
---|
| 66 | DataSet.RemoveColumnGroup(grp);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | foreach (ColumnBase col in this.newColumnGroup.Columns) {
|
---|
| 70 | col.Resize(oldRowCounts.Max());
|
---|
| 71 | col.SortOrder = SortOrder.None;
|
---|
| 72 | }
|
---|
| 73 | DataSet.InsertColumnGroup(oldColumnGroups.Keys.ElementAt(0), this.newColumnGroup);
|
---|
| 74 | DataSet.FireChanged();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public override void UndoExecute() {
|
---|
| 78 | base.UndoExecute();
|
---|
| 79 | DataSet.RemoveColumnGroup(newColumnGroup);
|
---|
| 80 | int col;
|
---|
| 81 | for (int i = 0; i < oldColumnGroups.Count; i++) {
|
---|
| 82 | col = oldColumnGroups.Keys.ElementAt(i);
|
---|
| 83 | DataSet.InsertColumnGroup(col, oldColumnGroups[col]);
|
---|
| 84 | foreach (ColumnBase column in oldColumnGroups[col].Columns)
|
---|
| 85 | column.Resize(oldRowCounts[i]);
|
---|
| 86 | }
|
---|
| 87 | oldColumnGroups.Clear();
|
---|
| 88 | newColumnGroup = null;
|
---|
| 89 | oldRowCounts.Clear();
|
---|
| 90 | DataSet.FireChanged();
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public override string Description {
|
---|
| 94 | get { return "Merge column groups"; }
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|