#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Linq; using HeuristicLab.DataImporter.Command.View; using HeuristicLab.DataImporter.Data; using HeuristicLab.DataImporter.Data.CommandBase; using HeuristicLab.DataImporter.Data.Model; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.DataImporter.Command { [StorableClass] [ViewableCommandInfoAttribute("New ProgrammableColumn", 1, ColumnGroupState.Active, "Column Commands", Position = 10, OptionsView = typeof(ProgrammableColumnCommandView))] public class AddNewProgrammableColumnCommand : AddNewColumnCommandBase { [StorableConstructor] protected AddNewProgrammableColumnCommand(bool deserializing) : base(deserializing) { } public AddNewProgrammableColumnCommand(DataSet dataSet, string columnGroupName) : this(dataSet, columnGroupName, "New ProgrammableColumn") { } public AddNewProgrammableColumnCommand(DataSet dataSet, string columnGroupName, string columnName) : base(dataSet, columnGroupName, columnName, typeof(ProgrammableColumn)) { } public override string Description { get { return "New programmable column"; } } [Storable] private string expression; public string Expression { get { return expression; } set { expression = value; } } public override void Execute() { this.UpdateColumnGroup(); NewColumn = new ProgrammableColumn(ColumnName, ColumnGroup); NewColumn.Resize(ColumnGroup.RowCount); try { ((ProgrammableColumn)NewColumn).Expression = expression; } catch (ParseException ex) { throw new CommandExecutionException("Error occured during parsing of expression.", ex, this); } if (ColumnIndex == -1) { ColumnBase cb = ColumnGroup.Columns.FirstOrDefault(x => x.Selected); if (cb != null) ColumnIndex = ColumnGroup.IndexOfColumn(cb); } if (ColumnIndex != -1) { ColumnGroup.InsertColumn(ColumnIndex + 1, NewColumn); } else { ColumnGroup.AddColumn(NewColumn); } ColumnGroup.FireChanged(); ColumnGroup = null; } } }