1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Collections;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Xml;
|
---|
7 | using System.Globalization;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.DataImporter.Data.Model {
|
---|
11 | [StorableClass]
|
---|
12 | public class ProgrammableColumn : ColumnBase {
|
---|
13 | private DynamicValueList dynamicValues;
|
---|
14 | [Storable]
|
---|
15 | private int myIndexInColumnGroup;
|
---|
16 |
|
---|
17 | private ProgrammableColumn()
|
---|
18 | : base(string.Empty) {
|
---|
19 | this.DataType = typeof(double?);
|
---|
20 | }
|
---|
21 |
|
---|
22 | public ProgrammableColumn(string columnName, ColumnGroup columnGroup)
|
---|
23 | : base(columnName) {
|
---|
24 | this.DataType = typeof(double?);
|
---|
25 | this.ColumnGroup = columnGroup;
|
---|
26 | Expression = string.Empty;
|
---|
27 | }
|
---|
28 |
|
---|
29 | private string expression;
|
---|
30 | [Storable]
|
---|
31 | public string Expression {
|
---|
32 | get { return expression; }
|
---|
33 | set {
|
---|
34 | expression = value;
|
---|
35 | dynamicValues = new DynamicValueList(expression, columnGroup);
|
---|
36 | dynamicValues.RecursiveIndex = myIndexInColumnGroup;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | private ColumnGroup columnGroup;
|
---|
41 | [Storable]
|
---|
42 | private ColumnGroup ColumnGroup {
|
---|
43 | get { return this.columnGroup; }
|
---|
44 | set {
|
---|
45 | if (this.columnGroup != null)
|
---|
46 | this.columnGroup.Changed -= new EventHandler(columnGroup_Changed);
|
---|
47 | this.columnGroup = value;
|
---|
48 | RefreshMyIndex();
|
---|
49 | if (this.columnGroup != null)
|
---|
50 | columnGroup.Changed += new EventHandler(columnGroup_Changed);
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public void columnGroup_Changed(object sender, EventArgs e) {
|
---|
55 | RefreshMyIndex();
|
---|
56 | dynamicValues.RecursiveIndex = myIndexInColumnGroup;
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void RefreshMyIndex() {
|
---|
60 | // find the index of this column to prevent recursive expressions
|
---|
61 | for (int i = 0; i < columnGroup.Columns.Count(); i++) {
|
---|
62 | if (columnGroup.GetColumn(i) == this) {
|
---|
63 | myIndexInColumnGroup = i;
|
---|
64 | return;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | myIndexInColumnGroup = columnGroup.Columns.Count();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override string ToString() {
|
---|
71 | return base.ToString() + " <Programmable>\n" + expression;
|
---|
72 | }
|
---|
73 |
|
---|
74 | protected override IList Values {
|
---|
75 | get { return (IList)dynamicValues; }
|
---|
76 | }
|
---|
77 |
|
---|
78 | public override void AddValue(IComparable value) {
|
---|
79 | dynamicValues.IncreaseLength();
|
---|
80 | }
|
---|
81 |
|
---|
82 | public override void AddValueOrNull(IComparable value) {
|
---|
83 | dynamicValues.IncreaseLength();
|
---|
84 | }
|
---|
85 |
|
---|
86 | public override void InsertValue(int position, IComparable value) {
|
---|
87 | dynamicValues.IncreaseLength();
|
---|
88 | }
|
---|
89 |
|
---|
90 | public override void ChangeValue(int position, IComparable value) {
|
---|
91 | throw new NotSupportedException("Can't change values of a programmable column");
|
---|
92 | }
|
---|
93 |
|
---|
94 | public override void ChangeValueOrNull(int position, IComparable value) {
|
---|
95 | throw new NotSupportedException("Can't change values of a programmable column");
|
---|
96 | }
|
---|
97 |
|
---|
98 | public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
|
---|
99 | throw new NotSupportedException("Can't change values of a programmable column");
|
---|
100 | }
|
---|
101 |
|
---|
102 | public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
|
---|
103 | return CreateCopyOfColumnWithoutValues();
|
---|
104 | }
|
---|
105 |
|
---|
106 | public override ColumnBase CreateCopyOfColumnWithoutValues() {
|
---|
107 | ProgrammableColumn clone = new ProgrammableColumn(this.Name, this.columnGroup);
|
---|
108 | clone.Expression = expression;
|
---|
109 | return clone;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|