Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeColumnGroup/AddNewProgrammableColumnCommand.cs @ 9760

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

#1734: Updated copyright information in all DataImporter classes.

File size: 3.0 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.Linq;
23using HeuristicLab.DataImporter.Command.View;
24using HeuristicLab.DataImporter.Data;
25using HeuristicLab.DataImporter.Data.CommandBase;
26using HeuristicLab.DataImporter.Data.Model;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.DataImporter.Command {
30  [StorableClass]
31  [ViewableCommandInfoAttribute("New ProgrammableColumn", 1, ColumnGroupState.Active, "Column Commands", Position = 10,
32  OptionsView = typeof(ProgrammableColumnCommandView))]
33  public class AddNewProgrammableColumnCommand : AddNewColumnCommandBase {
34    [StorableConstructor]
35    protected AddNewProgrammableColumnCommand(bool deserializing) : base(deserializing) { }
36
37    public AddNewProgrammableColumnCommand(DataSet dataSet, string columnGroupName)
38      : this(dataSet, columnGroupName, "New ProgrammableColumn") {
39    }
40
41    public AddNewProgrammableColumnCommand(DataSet dataSet, string columnGroupName, string columnName)
42      : base(dataSet, columnGroupName, columnName, typeof(ProgrammableColumn)) {
43    }
44
45    public override string Description {
46      get { return "New programmable column"; }
47    }
48
49    [Storable]
50    private string expression;
51    public string Expression {
52      get { return expression; }
53      set { expression = value; }
54    }
55
56    public override void Execute() {
57      this.UpdateColumnGroup();
58      NewColumn = new ProgrammableColumn(ColumnName, ColumnGroup);
59      NewColumn.Resize(ColumnGroup.RowCount);
60      try {
61        ((ProgrammableColumn)NewColumn).Expression = expression;
62      }
63      catch (ParseException ex) {
64        throw new CommandExecutionException("Error occured during parsing of expression.", ex, this);
65      }
66
67      if (ColumnIndex == -1) {
68        ColumnBase cb = ColumnGroup.Columns.FirstOrDefault(x => x.Selected);
69        if (cb != null) ColumnIndex = ColumnGroup.IndexOfColumn(cb);
70      }
71      if (ColumnIndex != -1) {
72        ColumnGroup.InsertColumn(ColumnIndex + 1, NewColumn);
73      } else {
74        ColumnGroup.AddColumn(NewColumn);
75      }
76      ColumnGroup.FireChanged();
77      ColumnGroup = null;
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.