Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/14 14:57:45 (10 years ago)
Author:
rstoll
Message:
  • Changed ComparisonFilter, using DoubleValue and DateTime rather than just StringValue
  • Included better input validation for ComparisonFilterView
  • Bug "Search and Sorted DataGridContentView" fixed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ComparisonFilterView.cs

    r10735 r10947  
    2020#endregion
    2121
     22using System;
    2223using System.Linq;
     24using HeuristicLab.Core;
    2325using HeuristicLab.Core.Views;
    24 using HeuristicLab.Core;
    2526using HeuristicLab.Data;
    2627using HeuristicLab.DataPreprocessing.Filter;
    2728using HeuristicLab.MainForm;
    28 using System.Collections;
    29 using System;
    30 using System.Collections.Generic;
    3129
    3230namespace HeuristicLab.DataPreprocessing.Views {
     
    4442
    4543
    46     protected override void OnContentChanged()
    47     {
     44    protected override void OnContentChanged() {
    4845      base.OnContentChanged();
    4946      cbAttr.Items.Clear(); //cmbConstraintColumn.Items.Clear();
    5047      cbFilterOperation.Items.Clear(); //cmbConstraintOperation.Items.Clear();
    5148      tbFilterData.Text = string.Empty;
    52       if (Content != null)
    53       {
     49      if (Content != null) {
    5450        cbFilterOperation.Items.AddRange(Content.AllowedConstraintOperations.ToArray());
    5551        if (Content.ConstraintOperation != null)
     
    5955        UpdateColumnComboBox();
    6056        ReadOnly = Content.Active;
    61         if (Content.ConstraintData != null)
    62         {
     57        if (Content.ConstraintData != null) {
    6358          tbFilterData.Text = Content.ConstraintData.GetValue();
    64         }
    65         else
    66         {
     59        } else {
    6760          this.Content_ConstraintColumnChanged(cbAttr, EventArgs.Empty); // TODO
    6861        }
    6962      }
    70       if (Content == null || Content.ConstraintData == null)
    71       {
     63      if (Content == null || Content.ConstraintData == null) {
    7264        tbFilterData.Text = string.Empty;
    73       }
    74       else
    75       {
     65      } else {
    7666        tbFilterData.Text = Content.ConstraintData.GetValue();
    7767      }
    7868    }
    7969
    80     protected virtual void UpdateColumnComboBox()
    81     {
     70    protected virtual void UpdateColumnComboBox() {
    8271      this.cbAttr.Items.Clear();
    83       if (Content.ConstrainedValue != null)
    84       {
     72      if (Content.ConstrainedValue != null) {
    8573        this.cbAttr.Items.AddRange(Content.ConstrainedValue.VariableNames.ToArray<string>());
    8674        //if (!string.IsNullOrEmpty(Content.ConstraintColumn))
     
    8977        //if (Content.ConstraintColumn != null)
    9078        //{
    91           cbAttr.SelectedItem = Content.ConstraintColumn;
    92           if (Content.ConstraintData != null)
    93             tbFilterData.Text = Content.ConstraintData.GetValue();
    94           else
    95             this.Content_ConstraintColumnChanged(cbAttr, EventArgs.Empty);
     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);
    9684        //}
    9785      }
    9886    }
    9987
    100     protected override void RegisterContentEvents()
    101     {
     88    protected override void RegisterContentEvents() {
    10289      base.RegisterContentEvents();
    10390      this.Content.ActiveChanged += new EventHandler(Content_ActiveChanged);
     
    10895    }
    10996
    110     protected override void DeregisterContentEvents()
    111     {
     97    protected override void DeregisterContentEvents() {
    11298      base.DeregisterContentEvents();
    11399      this.Content.ActiveChanged -= new EventHandler(Content_ActiveChanged);
     
    118104    }
    119105
    120     protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e)
    121     {
     106    protected virtual void Content_ConstrainedValueChanged(object sender, EventArgs e) {
    122107      this.UpdateColumnComboBox();
    123108    }
    124109
    125     private void Content_ConstrainedDataChanged(object sender, EventArgs e)
    126     {
     110    private void Content_ConstrainedDataChanged(object sender, EventArgs e) {
    127111      if (Content.ConstraintData != null)
    128112        tbFilterData.Text = Content.ConstraintData.GetValue();
     
    131115    }
    132116
    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) {
    139120          cbAttr.SelectedItem = this.cbAttr.Items[Content.ConstraintColumn];
    140121        }
    141122      }
    142       if (Content.ConstraintData == null)
    143         this.Content.ConstraintData = new StringValue();
     123      if (Content.ConstraintData == null) {
     124        this.Content.ConstraintData = CreateStringConvertibleValue(cbAttr.SelectedIndex);
     125      }
    144126    }
    145127
    146128
    147     protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e)
    148     {
     129    protected virtual void Content_ComparisonOperationChanged(object sender, EventArgs e) {
    149130      if (Content.ConstraintOperation != (ConstraintOperation)this.cbFilterOperation.SelectedItem)
    150131        this.cbFilterOperation.SelectedItem = Content.ConstraintOperation;
    151132    }
    152133
    153     protected override void SetEnabledStateOfControls()
    154     {
     134    protected override void SetEnabledStateOfControls() {
    155135      base.SetEnabledStateOfControls();
    156136      /*
     
    165145    }
    166146
    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) {
    171149        Content.ConstraintColumn = Content.ConstrainedValue.GetColumnIndex(cbAttr.SelectedItem.ToString());
    172150      }
    173151    }
    174152
    175     private void cbFilterOperation_SelectedIndexChanged(object sender, EventArgs e)
    176     {
     153    private void cbFilterOperation_SelectedIndexChanged(object sender, EventArgs e) {
    177154      Content.ConstraintOperation = (ConstraintOperation)this.cbFilterOperation.SelectedItem;
    178155    }
    179156
    180     protected virtual void Content_ActiveChanged(object sender, EventArgs e)
    181     {
     157    protected virtual void Content_ActiveChanged(object sender, EventArgs e) {
    182158      this.ReadOnly = !Content.Active;
    183159      SetEnabledStateOfControls();
     
    185161    }
    186162
    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;
    192167    }
    193168
    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();
    204190    }
    205191
Note: See TracChangeset for help on using the changeset viewer.