Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/21/14 12:22:38 (10 years ago)
Author:
sbreuer
Message:
  • offer search comparison options
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataGridContentView.cs

    r10863 r10870  
    3535
    3636    private bool notOwnEvent = true;
     37    private bool isSearching = false;
    3738    private SearchAndReplaceDialog findAndReplaceDialog;
    3839    private IFindPreprocessingItemsIterator searchIterator;
    3940    private string currentSearchText;
     41    private ComparisonOperation currentComparisonOperation;
    4042    private Tuple<int, int> currentCell;
    4143
     
    5456    }
    5557
    56     private IDictionary<int, IList<int>> _highlightedCells;
    57     public IDictionary<int, IList<int>> HightlightedCells {
    58       get { return _highlightedCells; }
    59       set {
    60         _highlightedCells = value;
    61         Refresh();
    62       }
    63     }
    64 
    6558    private IDictionary<int, IList<int>> _highlightedCellsBackground;
    6659    public IDictionary<int, IList<int>> HightlightedCellsBackground {
     
    7871      dataGridView.KeyDown += dataGridView_KeyDown;
    7972      contextMenuCell.Items.Add(ShowHideColumns);
    80       _highlightedCells = new Dictionary<int, IList<int>>();
    8173      _highlightedRowIndices = new List<int>();
    8274      _highlightedCellsBackground = new Dictionary<int, IList<int>>();
     
    8678
    8779    void DataGridView_SelectionChanged(object sender, EventArgs e) {
    88       Content.DataGridLogic.SetSelection(GetSelectedCells());
     80      if (!isSearching) {
     81        Content.DataGridLogic.SetSelection(GetSelectedCells());
     82      }
    8983    }
    9084
     
    179173    void DataGridView_SelectionChanged_FindAndReplace(object sender, EventArgs e) {
    180174      if (Content != null) {
    181         if (AreMultipleCellsSelected()) {
     175        if (!isSearching && AreMultipleCellsSelected()) {
    182176          ResetHighlightedCellsBackground();
    183177          HightlightedCellsBackground = GetSelectedCells();
     
    188182
    189183    void findAndReplaceDialog_FormClosing(object sender, FormClosingEventArgs e) {
    190       ResetHighlightedCells();
    191184      ResetHighlightedCellsBackground();
    192185      searchIterator = null;
     
    205198
    206199    void findAndReplaceDialog_FindNextEvent(object sender, EventArgs e) {
    207       if (searchIterator == null || currentSearchText != findAndReplaceDialog.GetSearchText()) {
     200      if (searchIterator == null ||
     201        currentSearchText != findAndReplaceDialog.GetSearchText() ||
     202        currentComparisonOperation != findAndReplaceDialog.GetComparisonOperation()) {
    208203        searchIterator = new FindPreprocessingItemsIterator(FindAll(findAndReplaceDialog.GetSearchText()));
    209204        currentSearchText = findAndReplaceDialog.GetSearchText();
    210       }
     205        currentComparisonOperation = findAndReplaceDialog.GetComparisonOperation();
     206      }
     207
    211208      if (IsOneCellSelected()) {
    212209        var first = GetSelectedCells().First();
     
    214211      }
    215212
    216 
    217213      bool moreOccurences = false;
    218       do {
    219         currentCell = searchIterator.GetCurrent();
    220         moreOccurences = searchIterator.MoveNext();
    221         if (IsOneCellSelected()) {
    222           var first = GetSelectedCells().First();
    223           if (currentCell.Item1 == first.Key && currentCell.Item2 == first.Value[0]) {
    224             if (!moreOccurences) {
    225               searchIterator.Reset();
    226             }
    227             currentCell = searchIterator.GetCurrent();
    228             moreOccurences = searchIterator.MoveNext();
    229 
     214      currentCell = searchIterator.GetCurrent();
     215      moreOccurences = searchIterator.MoveNext();
     216      if (IsOneCellSelected() && currentCell != null) {
     217        var first = GetSelectedCells().First();
     218        if (currentCell.Item1 == first.Key && currentCell.Item2 == first.Value[0]) {
     219          if (!moreOccurences) {
     220            searchIterator.Reset();
    230221          }
    231         }
    232       } while (moreOccurences && (currentCell == null || !Content.GetValue(currentCell.Item2, currentCell.Item1).Equals(currentSearchText)));
     222          currentCell = searchIterator.GetCurrent();
     223          moreOccurences = searchIterator.MoveNext();
     224          if (!moreOccurences) {
     225            searchIterator.Reset();
     226          }
     227        }
     228      }
     229
     230      dataGridView.ClearSelection();
    233231
    234232      if (currentCell != null) {
    235         dataGridView.ClearSelection();
    236233        dataGridView[currentCell.Item1, currentCell.Item2].Selected = true;
    237       } else {
    238         ResetHighlightedCells();
    239       }
    240 
    241       //if (!moreOccurences) {
    242       //  searchIterator.Reset();
    243       //  dataGridView.ClearSelection();
    244       //  currentCell = searchIterator.GetCurrent();
    245       //  dataGridView[currentCell.Item1, currentCell.Item2].Selected = true;
    246       //}
     234      }
    247235    }
    248236
     
    264252
    265253    void findAndReplaceDialog_FindAllEvent(object sender, EventArgs e) {
    266       HightlightedCells = FindAll(findAndReplaceDialog.GetSearchText());
     254      dataGridView.ClearSelection();
     255      isSearching = true;
     256      foreach (var column in FindAll(findAndReplaceDialog.GetSearchText())) {
     257        foreach (var cell in column.Value) {
     258          dataGridView[column.Key, cell].Selected = true;
     259        }
     260      }
     261      isSearching = false;
     262      DataGridView_SelectionChanged(null, null);
     263    }
     264
     265    private Core.ConstraintOperation GetConstraintOperation(ComparisonOperation comparisonOperation) {
     266      Core.ConstraintOperation constraintOperation = Core.ConstraintOperation.Equal;
     267      switch (comparisonOperation) {
     268        case ComparisonOperation.Equal:
     269          constraintOperation = Core.ConstraintOperation.Equal;
     270          break;
     271        case ComparisonOperation.Greater:
     272          constraintOperation = Core.ConstraintOperation.Greater;
     273          break;
     274        case ComparisonOperation.GreaterOrEqual:
     275          constraintOperation = Core.ConstraintOperation.GreaterOrEqual;
     276          break;
     277        case ComparisonOperation.Less:
     278          constraintOperation = Core.ConstraintOperation.Less;
     279          break;
     280        case ComparisonOperation.LessOrEqual:
     281          constraintOperation = Core.ConstraintOperation.LessOrEqual;
     282          break;
     283        case ComparisonOperation.NotEqual:
     284          constraintOperation = Core.ConstraintOperation.NotEqual;
     285          break;
     286      }
     287      return constraintOperation;
    267288    }
    268289
    269290    private IDictionary<int, IList<int>> FindAll(string match) {
    270291      bool searchInSelection = HightlightedCellsBackground.Values.Sum(list => list.Count) > 1;
    271       var comparisonFilter = new ComparisonFilter(Content.FilterLogic.PreprocessingData, Core.ConstraintOperation.Equal, new StringValue(match), true);
     292      ComparisonOperation comparisonOperation = findAndReplaceDialog.GetComparisonOperation();
     293      var comparisonFilter = new ComparisonFilter(Content.FilterLogic.PreprocessingData, GetConstraintOperation(comparisonOperation), new StringValue(match), true);
    272294      var filters = new List<Filter.IFilter>() { comparisonFilter };
    273295      var foundCells = new Dictionary<int, IList<int>>();
     
    324346    }
    325347
    326     private void ResetHighlightedCells() {
    327       HightlightedCells = new Dictionary<int, IList<int>>();
    328     }
    329 
    330348    private void ResetHighlightedCellsBackground() {
    331349      HightlightedCellsBackground = new Dictionary<int, IList<int>>();
     
    374392      if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
    375393      if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
    376       if (HighlightedRowIndices == null && HightlightedCells == null) return;
     394      if (HighlightedRowIndices == null) return;
    377395
    378396      int rowIndex = virtualRowIndices[e.RowIndex];
     
    382400      if (HightlightedCellsBackground.ContainsKey(e.ColumnIndex) && HightlightedCellsBackground[e.ColumnIndex].Contains(e.RowIndex)) {
    383401        backColor = Color.LightGray;
    384       }
    385       if (HighlightedRowIndices.Contains(rowIndex) || HightlightedCells.ContainsKey(e.ColumnIndex) && HightlightedCells[e.ColumnIndex].Contains(e.RowIndex)) {
    386         backColor = Color.LightGreen;
    387402      }
    388403
Note: See TracChangeset for help on using the changeset viewer.