Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/14 14:57:45 (8 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/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.