Changeset 10947 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ComparisonFilterView.cs
- Timestamp:
- 06/04/14 14:57:45 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ComparisonFilterView.cs
r10735 r10947 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 24 using HeuristicLab.Core; 23 25 using HeuristicLab.Core.Views; 24 using HeuristicLab.Core;25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.DataPreprocessing.Filter; 27 28 using HeuristicLab.MainForm; 28 using System.Collections;29 using System;30 using System.Collections.Generic;31 29 32 30 namespace HeuristicLab.DataPreprocessing.Views { … … 44 42 45 43 46 protected override void OnContentChanged() 47 { 44 protected override void OnContentChanged() { 48 45 base.OnContentChanged(); 49 46 cbAttr.Items.Clear(); //cmbConstraintColumn.Items.Clear(); 50 47 cbFilterOperation.Items.Clear(); //cmbConstraintOperation.Items.Clear(); 51 48 tbFilterData.Text = string.Empty; 52 if (Content != null) 53 { 49 if (Content != null) { 54 50 cbFilterOperation.Items.AddRange(Content.AllowedConstraintOperations.ToArray()); 55 51 if (Content.ConstraintOperation != null) … … 59 55 UpdateColumnComboBox(); 60 56 ReadOnly = Content.Active; 61 if (Content.ConstraintData != null) 62 { 57 if (Content.ConstraintData != null) { 63 58 tbFilterData.Text = Content.ConstraintData.GetValue(); 64 } 65 else 66 { 59 } else { 67 60 this.Content_ConstraintColumnChanged(cbAttr, EventArgs.Empty); // TODO 68 61 } 69 62 } 70 if (Content == null || Content.ConstraintData == null) 71 { 63 if (Content == null || Content.ConstraintData == null) { 72 64 tbFilterData.Text = string.Empty; 73 } 74 else 75 { 65 } else { 76 66 tbFilterData.Text = Content.ConstraintData.GetValue(); 77 67 } 78 68 } 79 69 80 protected virtual void UpdateColumnComboBox() 81 { 70 protected virtual void UpdateColumnComboBox() { 82 71 this.cbAttr.Items.Clear(); 83 if (Content.ConstrainedValue != null) 84 { 72 if (Content.ConstrainedValue != null) { 85 73 this.cbAttr.Items.AddRange(Content.ConstrainedValue.VariableNames.ToArray<string>()); 86 74 //if (!string.IsNullOrEmpty(Content.ConstraintColumn)) … … 89 77 //if (Content.ConstraintColumn != null) 90 78 //{ 91 92 93 94 95 79 cbAttr.SelectedItem = Content.ConstraintColumn; 80 if (Content.ConstraintData != null) 81 tbFilterData.Text = Content.ConstraintData.GetValue(); 82 else 83 this.Content_ConstraintColumnChanged(cbAttr, EventArgs.Empty); 96 84 //} 97 85 } 98 86 } 99 87 100 protected override void RegisterContentEvents() 101 { 88 protected override void RegisterContentEvents() { 102 89 base.RegisterContentEvents(); 103 90 this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged); … … 108 95 } 109 96 110 protected override void DeregisterContentEvents() 111 { 97 protected override void DeregisterContentEvents() { 112 98 base.DeregisterContentEvents(); 113 99 this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged); … … 118 104 } 119 105 120 protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e) 121 { 106 protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e) { 122 107 this.UpdateColumnComboBox(); 123 108 } 124 109 125 private void Content_ConstrainedDataChanged(object sender, EventArgs e) 126 { 110 private void Content_ConstrainedDataChanged(object sender, EventArgs e) { 127 111 if (Content.ConstraintData != null) 128 112 tbFilterData.Text = Content.ConstraintData.GetValue(); … … 131 115 } 132 116 133 protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e) 134 { 135 if (Content.ConstrainedValue != null) 136 { 137 if (cbAttr.Items.IndexOf(cbAttr.SelectedItem) != Content.ConstraintColumn) 138 { 117 protected virtual void Content_ConstraintColumnChanged(object sender, EventArgs e) { 118 if (Content.ConstrainedValue != null) { 119 if (cbAttr.Items.IndexOf(cbAttr.SelectedItem) != Content.ConstraintColumn) { 139 120 cbAttr.SelectedItem = this.cbAttr.Items[Content.ConstraintColumn]; 140 121 } 141 122 } 142 if (Content.ConstraintData == null) 143 this.Content.ConstraintData = new StringValue(); 123 if (Content.ConstraintData == null) { 124 this.Content.ConstraintData = CreateStringConvertibleValue(cbAttr.SelectedIndex); 125 } 144 126 } 145 127 146 128 147 protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e) 148 { 129 protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e) { 149 130 if (Content.ConstraintOperation != (ConstraintOperation)this.cbFilterOperation.SelectedItem) 150 131 this.cbFilterOperation.SelectedItem = Content.ConstraintOperation; 151 132 } 152 133 153 protected override void SetEnabledStateOfControls() 154 { 134 protected override void SetEnabledStateOfControls() { 155 135 base.SetEnabledStateOfControls(); 156 136 /* … … 165 145 } 166 146 167 private void cbAttr_SelectedIndexChanged(object sender, EventArgs e) 168 { 169 if (Content.ConstrainedValue != null) 170 { 147 private void cbAttr_SelectedIndexChanged(object sender, EventArgs e) { 148 if (Content.ConstrainedValue != null) { 171 149 Content.ConstraintColumn = Content.ConstrainedValue.GetColumnIndex(cbAttr.SelectedItem.ToString()); 172 150 } 173 151 } 174 152 175 private void cbFilterOperation_SelectedIndexChanged(object sender, EventArgs e) 176 { 153 private void cbFilterOperation_SelectedIndexChanged(object sender, EventArgs e) { 177 154 Content.ConstraintOperation = (ConstraintOperation)this.cbFilterOperation.SelectedItem; 178 155 } 179 156 180 protected virtual void Content_ActiveChanged(object sender, EventArgs e) 181 { 157 protected virtual void Content_ActiveChanged(object sender, EventArgs e) { 182 158 this.ReadOnly = !Content.Active; 183 159 SetEnabledStateOfControls(); … … 185 161 } 186 162 187 private void tbFilterData_Validated(object sender, EventArgs e) 188 { 189 IStringConvertibleValue value = new StringValue(); 190 value.SetValue(tbFilterData.Text); 191 Content.ConstraintData = value; 163 private void tbFilterData_Validated(object sender, EventArgs e) { 164 IStringConvertibleValue value = CreateStringConvertibleValue(cbAttr.SelectedIndex); 165 value.SetValue(tbFilterData.Text); 166 Content.ConstraintData = value; 192 167 } 193 168 194 private void tbFilterData_Validating(object sender, System.ComponentModel.CancelEventArgs e) 195 { 196 string errorMessage = string.Empty; 197 if (!Content.ConstraintData.Validate(tbFilterData.Text, out errorMessage)) 198 { 199 errorProvider.SetError(tbFilterData, errorMessage); 200 e.Cancel = true; 201 } 202 else 203 errorProvider.Clear(); 169 private IStringConvertibleValue CreateStringConvertibleValue(int columnIndex) { 170 IStringConvertibleValue value; 171 if (Content.ConstrainedValue.IsType<double>(columnIndex)) { 172 value = new DoubleValue(); 173 } else if (Content.ConstrainedValue.IsType<String>(columnIndex)) { 174 value = new StringValue(); 175 } else if (Content.ConstrainedValue.IsType<DateTime>(columnIndex)) { 176 value = new DateTimeValue(); 177 } else { 178 throw new ArgumentException("unsupported type"); 179 } 180 return value; 181 } 182 183 private void tbFilterData_Validating(object sender, System.ComponentModel.CancelEventArgs e) { 184 string errorMessage = string.Empty; 185 if (!Content.ConstraintData.Validate(tbFilterData.Text, out errorMessage)) { 186 errorProvider.SetError(tbFilterData, errorMessage); 187 e.Cancel = true; 188 } else 189 errorProvider.Clear(); 204 190 } 205 191
Note: See TracChangeset
for help on using the changeset viewer.