[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] | 22 | using System.Linq;
|
---|
[8676] | 23 | using HeuristicLab.DataImporter.Command.View;
|
---|
| 24 | using HeuristicLab.DataImporter.Data;
|
---|
[6133] | 25 | using HeuristicLab.DataImporter.Data.CommandBase;
|
---|
| 26 | using HeuristicLab.DataImporter.Data.Model;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace 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 {
|
---|
[9614] | 34 | [StorableConstructor]
|
---|
| 35 | protected AddNewProgrammableColumnCommand(bool deserializing) : base(deserializing) { }
|
---|
[6133] | 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 |
|
---|
[9595] | 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);
|
---|
[8676] | 73 | } else {
|
---|
| 74 | ColumnGroup.AddColumn(NewColumn);
|
---|
| 75 | }
|
---|
[6133] | 76 | ColumnGroup.FireChanged();
|
---|
| 77 | ColumnGroup = null;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|