Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeDataset/SplitColumnGroupCommand.cs @ 13792

Last change on this file since 13792 was 9615, checked in by mkommend, 12 years ago

#1734: Updated copyright information in all DataImporter classes.

File size: 3.5 KB
RevLine 
[6134]1#region License Information
2/* HeuristicLab
[9615]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6134]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
[6133]22using System.Collections.Generic;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.DataImporter.Data;
26using HeuristicLab.DataImporter.Data.CommandBase;
27using HeuristicLab.DataImporter.Data.Model;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.DataImporter.Command {
31  [StorableClass]
32  [ViewableCommandInfo("Split ColumnGroup", 1, ColumnGroupState.ColumnSelected, "ColumnGroup Commands", Position = 6, SelectedColumns = 2)]
33  public class SplitColumnGroupsCommand : ColumnGroupCommandWithAffectedColumnsBase {
34    private IEnumerable<SortOrder> oldSortOrder;
35    private ColumnGroup oldColumnGroup;
36    private int oldColumnGroupIndex;
37    private ColumnGroup newColumnGroup1;
38    private ColumnGroup newColumnGroup2;
39
[9614]40    [StorableConstructor]
41    protected SplitColumnGroupsCommand(bool deserializing) : base(deserializing) { }
[6133]42    public SplitColumnGroupsCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
43      : base(dataSet, columnGroupName, affectedColumns) {
44    }
45
46    public override void Execute() {
47      base.Execute();
48      int splitPosition = AffectedColumns[0] + 1;
49      oldColumnGroup = this.ColumnGroup;
50      oldColumnGroupIndex = this.DataSet.IndexOfColumnGroup(oldColumnGroup);
51      oldSortOrder = oldColumnGroup.SortOrdersForColumns.ToList();
52      newColumnGroup1 = new ColumnGroup(oldColumnGroup.Name);
53      newColumnGroup2 = new ColumnGroup(oldColumnGroup.Name);
54
55      for (int i = 0; i < splitPosition; i++)
56        newColumnGroup1.AddColumn(oldColumnGroup.Columns.ElementAt(i));
57      for (int i = splitPosition; i < oldColumnGroup.Columns.Count(); i++)
58        newColumnGroup2.AddColumn(oldColumnGroup.Columns.ElementAt(i));
59
60      newColumnGroup1.ResetSorting();
61      newColumnGroup2.ResetSorting();
62      this.DataSet.RemoveColumnGroup(oldColumnGroup);
63      this.DataSet.InsertColumnGroup(oldColumnGroupIndex, newColumnGroup1);
64      this.DataSet.InsertColumnGroup(oldColumnGroupIndex + 1, newColumnGroup2);
65      this.DataSet.FireChanged();
66    }
67
68    public override void UndoExecute() {
69      base.UndoExecute();
70      this.DataSet.RemoveColumnGroup(newColumnGroup1);
71      this.DataSet.RemoveColumnGroup(newColumnGroup2);
72      this.DataSet.InsertColumnGroup(oldColumnGroupIndex, oldColumnGroup);
73      oldColumnGroup.SortOrdersForColumns = oldSortOrder;
74      newColumnGroup1 = null;
75      newColumnGroup2 = null;
76      oldSortOrder = null;
77      oldColumnGroup = null;
78      this.DataSet.FireChanged();
79    }
80
81    public override string Description {
82      get { return "Split column group"; }
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.