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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.DataImporter.Data;
|
---|
24 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
25 | using HeuristicLab.DataImporter.Data.Model;
|
---|
26 | using HEAL.Attic;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.DataImporter.Command {
|
---|
29 | [StorableType("BAE4C6C2-980A-45CB-B172-BAEF880A66A6")]
|
---|
30 | [ViewableCommandInfoAttribute("New ColumnGroup", 0, ColumnGroupState.None, "ColumnGroup Commands", Position = 0)]
|
---|
31 | public class AddNewColumnGroupCommand : DataSetCommandBase {
|
---|
32 | [Storable]
|
---|
33 | private string newColumnGroupName;
|
---|
34 |
|
---|
35 | private ColumnGroup newColumnGroup;
|
---|
36 |
|
---|
37 | [StorableConstructor]
|
---|
38 | protected AddNewColumnGroupCommand(StorableConstructorFlag _) : base(_) { }
|
---|
39 |
|
---|
40 | public AddNewColumnGroupCommand(DataSet dataSet)
|
---|
41 | : base(dataSet) {
|
---|
42 | int i = 0;
|
---|
43 | string columnGroupName = "New ColumnGroup " + i;
|
---|
44 | while (dataSet.ColumnGroups.Any(cg => cg.Name == columnGroupName)) {
|
---|
45 | i++;
|
---|
46 | columnGroupName = "New ColumnGroup " + i;
|
---|
47 | }
|
---|
48 | this.newColumnGroupName = columnGroupName;
|
---|
49 | }
|
---|
50 |
|
---|
51 | private AddNewColumnGroupCommand(DataSet dataSet, string name)
|
---|
52 | : base(dataSet) {
|
---|
53 | this.newColumnGroupName = name;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public override string Description {
|
---|
57 | get { return "New column group"; }
|
---|
58 | }
|
---|
59 |
|
---|
60 | public override void Execute() {
|
---|
61 | base.Execute();
|
---|
62 | this.newColumnGroup = new ColumnGroup(newColumnGroupName);
|
---|
63 | this.DataSet.AddColumnGroup(newColumnGroup);
|
---|
64 | this.newColumnGroup.Active = true;
|
---|
65 | this.DataSet.FireChanged();
|
---|
66 | }
|
---|
67 |
|
---|
68 | public override void UndoExecute() {
|
---|
69 | base.UndoExecute();
|
---|
70 | this.DataSet.RemoveColumnGroup(newColumnGroup);
|
---|
71 | this.newColumnGroup = null;
|
---|
72 | this.DataSet.FireChanged();
|
---|
73 | }
|
---|
74 | }
|
---|
75 | } |
---|