Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10870


Ignore:
Timestamp:
05/21/14 12:22:38 (11 years ago)
Author:
sbreuer
Message:
  • offer search comparison options
Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3
Files:
4 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
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/SearchAndReplaceDialog.Designer.cs

    r10762 r10870  
    3737      this.txtValue = new System.Windows.Forms.TextBox();
    3838      this.label1 = new System.Windows.Forms.Label();
     39      this.cmbComparisonOperator = new System.Windows.Forms.ComboBox();
    3940      this.tabSearchReplace.SuspendLayout();
    4041      this.tabReplace.SuspendLayout();
     
    6768      // tabReplace
    6869      //
     70      this.tabReplace.Controls.Add(this.cmbComparisonOperator);
    6971      this.tabReplace.Controls.Add(this.txtSearchString);
    7072      this.tabReplace.Controls.Add(this.lblSearch);
     
    8789      // txtSearchString
    8890      //
    89       this.txtSearchString.Location = new System.Drawing.Point(103, 20);
     91      this.txtSearchString.Location = new System.Drawing.Point(154, 20);
    9092      this.txtSearchString.Name = "txtSearchString";
    91       this.txtSearchString.Size = new System.Drawing.Size(254, 20);
     93      this.txtSearchString.Size = new System.Drawing.Size(203, 20);
    9294      this.txtSearchString.TabIndex = 23;
    9395      //
     
    171173      this.label1.TabIndex = 14;
    172174      this.label1.Text = "Replace with";
     175      //
     176      // cmbComparisonOperator
     177      //
     178      this.cmbComparisonOperator.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     179      this.cmbComparisonOperator.FormattingEnabled = true;
     180      this.cmbComparisonOperator.Location = new System.Drawing.Point(103, 19);
     181      this.cmbComparisonOperator.Name = "cmbComparisonOperator";
     182      this.cmbComparisonOperator.Size = new System.Drawing.Size(45, 21);
     183      this.cmbComparisonOperator.TabIndex = 24;
    173184      //
    174185      // SearchAndReplaceDialog
     
    206217    private System.Windows.Forms.TextBox txtValue;
    207218    private System.Windows.Forms.Label label1;
     219    private System.Windows.Forms.ComboBox cmbComparisonOperator;
    208220  }
    209221}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/SearchAndReplaceDialog.cs

    r10762 r10870  
    1313  }
    1414
     15  public enum ComparisonOperation {
     16    Equal,
     17    Less,
     18    LessOrEqual,
     19    Greater,
     20    GreaterOrEqual,
     21    NotEqual
     22  }
     23
    1524  public partial class SearchAndReplaceDialog : Form {
    1625    private string[] cmbItemsText = { "Value", "Average", "Median", "Random", "Most Common", "Interpolation" };
     26    private string[] cmbComparisonOperatorText = { "==", "<", "<=", ">", ">=", "!=" };
    1727
    1828    public SearchAndReplaceDialog() {
     
    2030      cmbReplaceWith.Items.AddRange(cmbItemsText);
    2131      cmbReplaceWith.SelectedIndex = (int)ReplaceAction.Value;
     32      cmbComparisonOperator.Items.AddRange(cmbComparisonOperatorText);
     33      cmbComparisonOperator.SelectedIndex = (int)ComparisonOperation.Equal;
    2234    }
    2335
     
    4557      tabSearchReplace.SelectedTab.Controls.Add(lblSearch);
    4658      tabSearchReplace.SelectedTab.Controls.Add(txtSearchString);
     59      tabSearchReplace.SelectedTab.Controls.Add(cmbComparisonOperator);
    4760      ActiveControl = txtSearchString;
    4861      AcceptButton = btnFindNext;
     
    5972    public ReplaceAction GetReplaceAction() {
    6073      return (ReplaceAction)cmbReplaceWith.SelectedIndex;
     74    }
     75
     76    public ComparisonOperation GetComparisonOperation() {
     77      return (ComparisonOperation)cmbComparisonOperator.SelectedIndex;
    6178    }
    6279
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/Utils/FindPreprocessingItemsIterator.cs

    r10852 r10870  
    4545        ++tmpColumnIndex;
    4646      }
     47      if (startCell == null && tmpColumnIndex == columnIndex && rowIndex != 0) {
     48        startCell = GetNextFoundCell(columnIndex, 0);
     49      }
    4750      currentCell = startCell;
    4851    }
     
    6265      bool result = false;
    6366      bool endReached = false;
    64       if (items != null) {
     67      if (CurrentCellExists()) {
    6568        do {
    6669          if (currentCell.Item2 < items[currentCell.Item1].Count - 1) {
     
    9598    private bool CurrentCellExists() {
    9699      bool result = false;
    97       if (items != null) {
     100      if (currentCell != null && items != null) {
    98101        result = items.ContainsKey(currentCell.Item1) && currentCell.Item2 < items[currentCell.Item1].Count;
    99102      }
Note: See TracChangeset for help on using the changeset viewer.