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 |
|
---|
22 | using System.Windows.Forms;
|
---|
23 | using HeuristicLab.Analysis;
|
---|
24 | using HeuristicLab.Collections;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
31 |
|
---|
32 | [View("Line Chart View")]
|
---|
33 | [Content(typeof(LineChartContent), false)]
|
---|
34 | public partial class LineChartView : ItemView {
|
---|
35 |
|
---|
36 | private ILineChartLogic logic;
|
---|
37 | private DataTable dataTable;
|
---|
38 | private ICheckedItemList<StringValue> itemList;
|
---|
39 | private const string LINE_CHART_TITLE = "LineChart";
|
---|
40 |
|
---|
41 | public LineChartView() {
|
---|
42 | InitializeComponent();
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
|
---|
46 | foreach(IndexedItem<StringValue> item in checkedItems.Items)
|
---|
47 | {
|
---|
48 | string variableName = item.Value.Value;
|
---|
49 | if (VariableIsDisplayed(variableName)) {
|
---|
50 | dataTable.Rows.Remove(variableName);
|
---|
51 | } else {
|
---|
52 | dataTable.Rows.Add(logic.CreateDataRow(variableName));
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | public bool VariableIsDisplayed(string name) {
|
---|
58 |
|
---|
59 | foreach (var item in dataTable.Rows) {
|
---|
60 | if (item.Name == name)
|
---|
61 | return true;
|
---|
62 | }
|
---|
63 | return false;
|
---|
64 | }
|
---|
65 |
|
---|
66 | private void InitDataTable() {
|
---|
67 | dataTable = logic.CreateDataTable(LINE_CHART_TITLE);
|
---|
68 | viewHost.Content = dataTable;
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void InitVariablesListBox() {
|
---|
72 | itemList = logic.CreateVariableItemList();
|
---|
73 | checkedItemList.Content = itemList;
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void RegisterContentEvents() {
|
---|
77 | base.RegisterContentEvents();
|
---|
78 | Content.Changed += Content_Changed;
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected override void DeregisterContentEvents() {
|
---|
82 | base.DeregisterContentEvents();
|
---|
83 | Content.Changed -= Content_Changed;
|
---|
84 | }
|
---|
85 |
|
---|
86 | void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
|
---|
87 | viewHost.Refresh();
|
---|
88 | }
|
---|
89 |
|
---|
90 | public new LineChartContent Content {
|
---|
91 | get { return (LineChartContent)base.Content; }
|
---|
92 | set { base.Content = value; }
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected override void OnContentChanged() {
|
---|
96 | base.OnContentChanged();
|
---|
97 | if (Content != null) {
|
---|
98 | logic = Content.LineChartLogic;
|
---|
99 | InitDataTable();
|
---|
100 | InitVariablesListBox();
|
---|
101 | itemList.CheckedItemsChanged += CheckedItemsChanged;
|
---|
102 | logic.Changed += PreprocessingData_Changed;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | //TODO: refactor: possible code duplication with HistogramLogic
|
---|
107 | void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
|
---|
108 | switch (e.Type) {
|
---|
109 | case DataPreprocessingChangedEventType.DeleteColumn:
|
---|
110 | RemoveVariable(logic.GetVariableNameByIndex(e.Column));
|
---|
111 | break;
|
---|
112 | case DataPreprocessingChangedEventType.AddColumn:
|
---|
113 | AddVariable(logic.GetVariableNameByIndex(e.Column));
|
---|
114 | break;
|
---|
115 | case DataPreprocessingChangedEventType.ChangeColumn:
|
---|
116 | case DataPreprocessingChangedEventType.ChangeItem:
|
---|
117 | dataTable.Rows.Remove(logic.GetVariableNameByIndex(e.Column));
|
---|
118 | dataTable.Rows.Add(logic.CreateDataRow((logic.GetVariableNameByIndex(e.Column))));
|
---|
119 | break;
|
---|
120 | case DataPreprocessingChangedEventType.DeleteRow:
|
---|
121 | case DataPreprocessingChangedEventType.AddRow:
|
---|
122 | InitDataTable();
|
---|
123 | break;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | // add variable to data table and item list
|
---|
128 | private void AddVariable(string name) {
|
---|
129 | dataTable.Rows.Add(logic.CreateDataRow(name));
|
---|
130 | itemList.Add(new StringValue(name));
|
---|
131 | }
|
---|
132 |
|
---|
133 | // remove variable from data table and item list
|
---|
134 | private void RemoveVariable(string name) {
|
---|
135 | dataTable.Rows.Remove(name);
|
---|
136 |
|
---|
137 | StringValue stringValue = FindVariableItemList(name);
|
---|
138 | if (stringValue != null)
|
---|
139 | itemList.Remove(stringValue);
|
---|
140 |
|
---|
141 | }
|
---|
142 |
|
---|
143 | private StringValue FindVariableItemList(string name) {
|
---|
144 | foreach (StringValue stringValue in itemList) {
|
---|
145 | if (stringValue.Value == name)
|
---|
146 | return stringValue;
|
---|
147 | }
|
---|
148 | return null;
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|