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