[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 |
|
---|
| 22 | using System;
|
---|
[6133] | 23 | using System.Collections;
|
---|
| 24 | using System.Linq;
|
---|
[16566] | 25 | using HEAL.Attic;
|
---|
[6133] | 26 |
|
---|
| 27 | namespace HeuristicLab.DataImporter.Data.Model {
|
---|
[16566] | 28 | [StorableType("5FAE0F69-2400-4DB9-AA1B-C80298C77A77")]
|
---|
[6133] | 29 | public class ProgrammableColumn : ColumnBase {
|
---|
| 30 | private DynamicValueList dynamicValues;
|
---|
| 31 | [Storable]
|
---|
| 32 | private int myIndexInColumnGroup;
|
---|
| 33 |
|
---|
[9614] | 34 | [StorableConstructor]
|
---|
[16567] | 35 | protected ProgrammableColumn(StorableConstructorFlag _) : base(_) { }
|
---|
[6133] | 36 |
|
---|
| 37 | public ProgrammableColumn(string columnName, ColumnGroup columnGroup)
|
---|
| 38 | : base(columnName) {
|
---|
| 39 | this.ColumnGroup = columnGroup;
|
---|
| 40 | Expression = string.Empty;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[9614] | 43 | public override Type DataType {
|
---|
| 44 | get { return typeof(double?); }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[6133] | 47 | private string expression;
|
---|
| 48 | [Storable]
|
---|
| 49 | public string Expression {
|
---|
| 50 | get { return expression; }
|
---|
| 51 | set {
|
---|
| 52 | expression = value;
|
---|
| 53 | dynamicValues = new DynamicValueList(expression, columnGroup);
|
---|
| 54 | dynamicValues.RecursiveIndex = myIndexInColumnGroup;
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | private ColumnGroup columnGroup;
|
---|
| 59 | [Storable]
|
---|
| 60 | private ColumnGroup ColumnGroup {
|
---|
| 61 | get { return this.columnGroup; }
|
---|
| 62 | set {
|
---|
| 63 | if (this.columnGroup != null)
|
---|
| 64 | this.columnGroup.Changed -= new EventHandler(columnGroup_Changed);
|
---|
| 65 | this.columnGroup = value;
|
---|
| 66 | RefreshMyIndex();
|
---|
| 67 | if (this.columnGroup != null)
|
---|
| 68 | columnGroup.Changed += new EventHandler(columnGroup_Changed);
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public void columnGroup_Changed(object sender, EventArgs e) {
|
---|
| 73 | RefreshMyIndex();
|
---|
| 74 | dynamicValues.RecursiveIndex = myIndexInColumnGroup;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | private void RefreshMyIndex() {
|
---|
| 78 | // find the index of this column to prevent recursive expressions
|
---|
| 79 | for (int i = 0; i < columnGroup.Columns.Count(); i++) {
|
---|
| 80 | if (columnGroup.GetColumn(i) == this) {
|
---|
| 81 | myIndexInColumnGroup = i;
|
---|
| 82 | return;
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | myIndexInColumnGroup = columnGroup.Columns.Count();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public override string ToString() {
|
---|
| 89 | return base.ToString() + " <Programmable>\n" + expression;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | protected override IList Values {
|
---|
| 93 | get { return (IList)dynamicValues; }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public override void AddValue(IComparable value) {
|
---|
| 97 | dynamicValues.IncreaseLength();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | public override void AddValueOrNull(IComparable value) {
|
---|
| 101 | dynamicValues.IncreaseLength();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public override void InsertValue(int position, IComparable value) {
|
---|
| 105 | dynamicValues.IncreaseLength();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public override void ChangeValue(int position, IComparable value) {
|
---|
| 109 | throw new NotSupportedException("Can't change values of a programmable column");
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | public override void ChangeValueOrNull(int position, IComparable value) {
|
---|
| 113 | throw new NotSupportedException("Can't change values of a programmable column");
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
|
---|
| 117 | throw new NotSupportedException("Can't change values of a programmable column");
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
|
---|
| 121 | return CreateCopyOfColumnWithoutValues();
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | public override ColumnBase CreateCopyOfColumnWithoutValues() {
|
---|
| 125 | ProgrammableColumn clone = new ProgrammableColumn(this.Name, this.columnGroup);
|
---|
| 126 | clone.Expression = expression;
|
---|
| 127 | return clone;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|