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
Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4
Files:
4 edited

Legend:

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

    r10693 r10947  
    9191      this.cbAttr.Location = new System.Drawing.Point(92, 12);
    9292      this.cbAttr.Name = "cbAttr";
    93       this.cbAttr.Size = new System.Drawing.Size(247, 21);
     93      this.cbAttr.Size = new System.Drawing.Size(235, 21);
    9494      this.cbAttr.TabIndex = 3;
    9595      this.cbAttr.SelectedIndexChanged += new System.EventHandler(this.cbAttr_SelectedIndexChanged);
     
    103103      this.cbFilterOperation.Location = new System.Drawing.Point(92, 39);
    104104      this.cbFilterOperation.Name = "cbFilterOperation";
    105       this.cbFilterOperation.Size = new System.Drawing.Size(247, 21);
     105      this.cbFilterOperation.Size = new System.Drawing.Size(235, 21);
    106106      this.cbFilterOperation.TabIndex = 4;
    107107      this.cbFilterOperation.SelectedIndexChanged += new System.EventHandler(this.cbFilterOperation_SelectedIndexChanged);
     
    113113      this.tbFilterData.Location = new System.Drawing.Point(92, 67);
    114114      this.tbFilterData.Name = "tbFilterData";
    115       this.tbFilterData.Size = new System.Drawing.Size(247, 20);
     115      this.tbFilterData.Size = new System.Drawing.Size(235, 20);
    116116      this.tbFilterData.TabIndex = 5;
    117117      this.tbFilterData.Validating += new System.ComponentModel.CancelEventHandler(this.tbFilterData_Validating);
  • 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
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/CopyOfStringConvertibleMatrixView.cs

    r10916 r10947  
    104104    }
    105105
     106    // Was private before
     107    protected void Sort() {
     108      virtualRowIndices = Sort(sortedColumnIndices);
     109      UpdateSortGlyph();
     110      UpdateRowHeaders();
     111      dataGridView.Invalidate();
     112    }
     113
     114    // Was private before
     115    protected List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
     116
    106117    #region unchanged copied from original - see  HeuristicLab.Data.Views.StringConvertibleMatrix
    107118
    108119    protected int[] virtualRowIndices;
    109     private List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
    110120    private RowComparer rowComparer;
    111121
     
    293303    private Point[] GetSelectedCellsAsPoints() {
    294304      Point[] points = new Point[dataGridView.SelectedCells.Count];
    295       for (int i = 0; i < dataGridView.SelectedCells.Count; i++)
    296       {
     305      for (int i = 0; i < dataGridView.SelectedCells.Count; i++) {
    297306        points[i].X = dataGridView.SelectedCells[i].ColumnIndex;
    298307        points[i].Y = dataGridView.SelectedCells[i].RowIndex;
     
    487496    }
    488497
    489     private void Sort() {
    490       virtualRowIndices = Sort(sortedColumnIndices);
    491       UpdateSortGlyph();
    492       UpdateRowHeaders();
    493       dataGridView.Invalidate();
    494     }
    495498    protected virtual int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
    496499      int[] newSortedIndex = Enumerable.Range(0, Content.Rows).ToArray();
     
    597600    }
    598601
    599    
     602
    600603  }
    601604    #endregion
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r10946 r10947  
    7373      dataGridView.KeyDown += dataGridView_KeyDown;
    7474      dataGridView.MouseUp += dataGridView_MouseUp;
     75      dataGridView.ColumnHeaderMouseClick += dataGridView_ColumnHeaderMouseClick;
    7576      contextMenuCell.Items.Add(ShowHideColumns);
    7677      _highlightedRowIndices = new List<int>();
     
    7980    }
    8081
     82    private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
     83      searchIterator = null;
     84    }
     85
    8186    protected override void dataGridView_SelectionChanged(object sender, EventArgs e) {
    8287      if (Content != null) {
     
    8792            return;
    8893          }
    89            
     94
    9095          base.dataGridView_SelectionChanged(sender, e);
    91        
     96
    9297          Content.DataGridLogic.SetSelection(GetSelectedCells());
    9398        }
     
    96101
    97102    private void dataGridView_MouseUp(object sender, MouseEventArgs e) {
    98       if (!updateOnMouseUp) 
     103      if (!updateOnMouseUp)
    99104        return;
    100105
    101106      updateOnMouseUp = false;
    102107      dataGridView_SelectionChanged(sender, e);
    103     }                                     
     108    }
    104109
    105110    protected override void OnContentChanged() {
     
    250255
    251256    void findAndReplaceDialog_FindNextEvent(object sender, EventArgs e) {
    252       if (searchIterator == null ||
    253         currentSearchText != findAndReplaceDialog.GetSearchText() ||
    254         currentComparisonOperation != findAndReplaceDialog.GetComparisonOperation()) {
     257      if (searchIterator == null
     258        || currentSearchText != findAndReplaceDialog.GetSearchText()
     259        || currentComparisonOperation != findAndReplaceDialog.GetComparisonOperation()) {
     260
    255261        searchIterator = new FindPreprocessingItemsIterator(FindAll(findAndReplaceDialog.GetSearchText()));
    256262        currentSearchText = findAndReplaceDialog.GetSearchText();
     
    349355      bool searchInSelection = HightlightedCellsBackground.Values.Sum(list => list.Count) > 1;
    350356      ComparisonOperation comparisonOperation = findAndReplaceDialog.GetComparisonOperation();
    351       var comparisonFilter = new ComparisonFilter(Content.FilterLogic.PreprocessingData, GetConstraintOperation(comparisonOperation), new StringValue(match), true);
    352       var filters = new List<Filter.IFilter>() { comparisonFilter };
    353357      var foundCells = new Dictionary<int, IList<int>>();
    354358      for (int i = 0; i < Content.FilterLogic.PreprocessingData.Columns; i++) {
    355         comparisonFilter.ConstraintColumn = i;
     359        var filters = CreateFilters(match, comparisonOperation, i);
     360
    356361        bool[] filteredRows = Content.FilterLogic.GetFilterResult(filters, true);
    357362        var foundIndices = new List<int>();
     
    370375        }
    371376      }
    372       return foundCells;
     377      return MapToSorting(foundCells);
     378    }
     379
     380    private List<IFilter> CreateFilters(string match, ComparisonOperation comparisonOperation, int columnIndex) {
     381      IPreprocessingData preprocessingData = Content.FilterLogic.PreprocessingData;
     382      IStringConvertibleValue value;
     383      if (preprocessingData.IsType<double>(columnIndex)) {
     384        value = new DoubleValue();
     385      } else if (preprocessingData.IsType<String>(columnIndex)) {
     386        value = new StringValue();
     387      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
     388        value = new DateTimeValue();
     389      } else {
     390        throw new ArgumentException("unsupported type");
     391      }
     392      value.SetValue(match);
     393      var comparisonFilter = new ComparisonFilter(preprocessingData, GetConstraintOperation(comparisonOperation), value, true);
     394      comparisonFilter.ConstraintColumn = columnIndex;
     395      return new List<Filter.IFilter>() { comparisonFilter };
     396    }
     397
     398    private IDictionary<int, IList<int>> MapToSorting(Dictionary<int, IList<int>> foundCells) {
     399      if (sortedColumnIndices.Count == 0) {
     400        return foundCells;
     401      } else {
     402        var sortedFoundCells = new Dictionary<int, IList<int>>();
     403
     404        var indicesToVirtual = new Dictionary<int, int>();
     405        for (int i = 0; i < virtualRowIndices.Length; ++i) {
     406          indicesToVirtual.Add(virtualRowIndices[i], i);
     407        }
     408
     409        foreach (var entry in foundCells) {
     410          var cells = new List<int>();
     411          foreach (var cell in entry.Value) {
     412            cells.Add(indicesToVirtual[cell]);
     413          }
     414          cells.Sort();
     415          sortedFoundCells.Add(entry.Key, cells);
     416        }
     417        return sortedFoundCells;
     418      }
    373419    }
    374420
     
    533579    private void StopReplacing() {
    534580      isReplacing = false;
    535       ResumeRepaint(true); 
     581      ResumeRepaint(true);
    536582    }
    537583
Note: See TracChangeset for help on using the changeset viewer.