Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeDataset/SplitColumnGroupCommand.cs @ 16567

Last change on this file since 16567 was 16567, checked in by gkronber, 6 years ago

#2520: changed StorableConstructors and added StorableType attributes in HeuristicLab.DataImporter addon

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
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;
29using HEAL.Attic;
30
31namespace HeuristicLab.DataImporter.Command {
32  [StorableType("C619464C-C98C-4A14-92BF-C318041390E6")]
33  [ViewableCommandInfo("Split ColumnGroup", 1, ColumnGroupState.ColumnSelected, "ColumnGroup Commands", Position = 6, SelectedColumns = 2)]
34  public class SplitColumnGroupsCommand : ColumnGroupCommandWithAffectedColumnsBase {
35    private IEnumerable<SortOrder> oldSortOrder;
36    private ColumnGroup oldColumnGroup;
37    private int oldColumnGroupIndex;
38    private ColumnGroup newColumnGroup1;
39    private ColumnGroup newColumnGroup2;
40
41    [StorableConstructor]
42    protected SplitColumnGroupsCommand(StorableConstructorFlag _) : base(_) { }
43    public SplitColumnGroupsCommand(DataSet dataSet, string columnGroupName, int[] affectedColumns)
44      : base(dataSet, columnGroupName, affectedColumns) {
45    }
46
47    public override void Execute() {
48      base.Execute();
49      int splitPosition = AffectedColumns[0] + 1;
50      oldColumnGroup = this.ColumnGroup;
51      oldColumnGroupIndex = this.DataSet.IndexOfColumnGroup(oldColumnGroup);
52      oldSortOrder = oldColumnGroup.SortOrdersForColumns.ToList();
53      newColumnGroup1 = new ColumnGroup(oldColumnGroup.Name);
54      newColumnGroup2 = new ColumnGroup(oldColumnGroup.Name);
55
56      for (int i = 0; i < splitPosition; i++)
57        newColumnGroup1.AddColumn(oldColumnGroup.Columns.ElementAt(i));
58      for (int i = splitPosition; i < oldColumnGroup.Columns.Count(); i++)
59        newColumnGroup2.AddColumn(oldColumnGroup.Columns.ElementAt(i));
60
61      newColumnGroup1.ResetSorting();
62      newColumnGroup2.ResetSorting();
63      this.DataSet.RemoveColumnGroup(oldColumnGroup);
64      this.DataSet.InsertColumnGroup(oldColumnGroupIndex, newColumnGroup1);
65      this.DataSet.InsertColumnGroup(oldColumnGroupIndex + 1, newColumnGroup2);
66      this.DataSet.FireChanged();
67    }
68
69    public override void UndoExecute() {
70      base.UndoExecute();
71      this.DataSet.RemoveColumnGroup(newColumnGroup1);
72      this.DataSet.RemoveColumnGroup(newColumnGroup2);
73      this.DataSet.InsertColumnGroup(oldColumnGroupIndex, oldColumnGroup);
74      oldColumnGroup.SortOrdersForColumns = oldSortOrder;
75      newColumnGroup1 = null;
76      newColumnGroup2 = null;
77      oldSortOrder = null;
78      oldColumnGroup = null;
79      this.DataSet.FireChanged();
80    }
81
82    public override string Description {
83      get { return "Split column group"; }
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.