Changeset 10628 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/LineChartView.cs
- Timestamp:
- 03/19/14 14:24:40 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/LineChartView.cs
r10573 r10628 21 21 22 22 using System.Windows.Forms; 23 using HeuristicLab.Analysis; 24 using HeuristicLab.Collections; 25 using HeuristicLab.Core; 23 26 using HeuristicLab.Core.Views; 27 using HeuristicLab.Data; 24 28 using HeuristicLab.MainForm; 25 29 … … 30 34 public partial class LineChartView : ItemView { 31 35 36 private ILineChartLogic logic; 37 private DataTable dataTable; 38 private ICheckedItemList<StringValue> itemList; 39 private const string LINE_CHART_TITLE = "LineChart"; 40 32 41 public LineChartView() { 33 42 InitializeComponent(); 34 43 } 35 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 36 66 private void InitDataTable() { 37 ILineChartLogic logic = Content.LineChartLogic; 38 viewHost.Content = logic.GetDataTable(); 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; 39 74 } 40 75 … … 61 96 base.OnContentChanged(); 62 97 if (Content != null) { 98 logic = Content.LineChartLogic; 63 99 InitDataTable(); 64 100 InitVariablesListBox(); 101 itemList.CheckedItemsChanged += CheckedItemsChanged; 102 logic.Changed += PreprocessingData_Changed; 65 103 } 66 104 } 67 105 68 private void InitVariablesListBox() { 69 ILineChartLogic logic = Content.LineChartLogic; 70 71 foreach (var variableName in logic.GetVariableNames()) { 72 variablesListBox.Items.Add(variableName, true); 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; 73 124 } 74 125 } 75 126 76 private void variablesListBox_ItemCheck(object sender, ItemCheckEventArgs e) { 77 string item = variablesListBox.Items[e.Index] as string; 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 } 78 150 79 151 80 if (e.NewValue == CheckState.Checked && !Content.LineChartLogic.VariableIsDisplayed(item))81 Content.LineChartLogic.AddVariable(item);82 else if (e.NewValue == CheckState.Unchecked && Content.LineChartLogic.VariableIsDisplayed(item))83 Content.LineChartLogic.RemoveVariable(item);84 }85 152 } 86 153 }
Note: See TracChangeset
for help on using the changeset viewer.