Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs @ 10949

Last change on this file since 10949 was 10949, checked in by mleitner, 10 years ago

Keep sorting when content changes

File size: 25.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using System.Windows.Forms;
27using HeuristicLab.Data;
28using HeuristicLab.DataPreprocessing.Filter;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.DataPreprocessing.Views {
32  [View("Data Grid Content View")]
33  [Content(typeof(IDataGridContent), true)]
34  public partial class DataGridContentView : CopyOfStringConvertibleMatrixView {
35
36    private bool notOwnEvent = true;
37    private bool isSearching = false;
38    private bool isReplacing = false;
39    private bool updateOnMouseUp = false;
40    private SearchAndReplaceDialog findAndReplaceDialog;
41    private IFindPreprocessingItemsIterator searchIterator;
42    private string currentSearchText;
43    private ComparisonOperation currentComparisonOperation;
44    private Tuple<int, int> currentCell;
45
46    public new IDataGridContent Content {
47      get { return (IDataGridContent)base.Content; }
48      set { base.Content = value; }
49    }
50
51    private IList<int> _highlightedRowIndices;
52    public IList<int> HighlightedRowIndices {
53      get { return _highlightedRowIndices; }
54      set {
55        _highlightedRowIndices = value;
56        Refresh();
57      }
58    }
59
60    private IDictionary<int, IList<int>> _highlightedCellsBackground;
61    public IDictionary<int, IList<int>> HightlightedCellsBackground {
62      get { return _highlightedCellsBackground; }
63      set {
64        _highlightedCellsBackground = value;
65        Refresh();
66      }
67    }
68
69    public DataGridContentView() {
70      InitializeComponent();
71      dataGridView.CellMouseClick += dataGridView_CellMouseClick;
72      dataGridView.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(dataGridView_CellPainting);
73      dataGridView.KeyDown += dataGridView_KeyDown;
74      dataGridView.MouseUp += dataGridView_MouseUp;
75      dataGridView.ColumnHeaderMouseClick += dataGridView_ColumnHeaderMouseClick;
76      contextMenuCell.Items.Add(ShowHideColumns);
77      _highlightedRowIndices = new List<int>();
78      _highlightedCellsBackground = new Dictionary<int, IList<int>>();
79      currentCell = null;
80    }
81
82    private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
83      searchIterator = null;
84    }
85
86    protected override void dataGridView_SelectionChanged(object sender, EventArgs e) {
87      if (Content != null) {
88        if (!isSearching && !isReplacing) {
89
90          if (Control.MouseButtons == MouseButtons.Left) {
91            updateOnMouseUp = true;
92            return;
93          }
94
95          base.dataGridView_SelectionChanged(sender, e);
96
97          Content.DataGridLogic.SetSelection(GetSelectedCells());
98        }
99      }
100    }
101
102    private void dataGridView_MouseUp(object sender, MouseEventArgs e) {
103      if (!updateOnMouseUp)
104        return;
105
106      updateOnMouseUp = false;
107      dataGridView_SelectionChanged(sender, e);
108    }
109
110    protected override void OnContentChanged() {
111      List<KeyValuePair<int, SortOrder>> order = new List<KeyValuePair<int, SortOrder>>(base.sortedColumnIndices);
112      base.OnContentChanged();
113      // ToDo: Temporarily disabled because needs to much performance
114      // DataGridView.AutoResizeColumns();
115      // DataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
116     
117      DataGridView.RowHeadersWidth = 70;
118
119      if (Content == null && findAndReplaceDialog != null) {
120        findAndReplaceDialog.Close();
121      }
122
123      if (Content != null) {
124        base.sortedColumnIndices = order;
125        base.Sort();
126      }
127
128    }
129
130    protected override void RegisterContentEvents() {
131      base.RegisterContentEvents();
132      Content.Changed += Content_Changed;
133      Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
134    }
135
136    protected override void DeregisterContentEvents() {
137      base.DeregisterContentEvents();
138      Content.Changed -= Content_Changed;
139      Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
140    }
141
142    void FilterLogic_FilterChanged(object sender, EventArgs e) {
143      OnContentChanged();
144      searchIterator = null;
145      if (findAndReplaceDialog != null && !findAndReplaceDialog.IsDisposed) {
146        if (Content.FilterLogic.IsFiltered) {
147          findAndReplaceDialog.DisableReplace();
148        } else {
149          findAndReplaceDialog.EnableReplace();
150        }
151      }
152      btnReplace.Enabled = !Content.FilterLogic.IsFiltered;
153    }
154
155    void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
156      if (notOwnEvent) {
157        switch (e.Type) {
158          case DataPreprocessingChangedEventType.ChangeColumn:
159          case DataPreprocessingChangedEventType.ChangeItem:
160            dataGridView.Refresh();
161            break;
162          default:
163            OnContentChanged();
164            break;
165        }
166       }
167      searchIterator = null;
168    }
169
170    protected override void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
171      if (!dataGridView.ReadOnly) {
172        string errorMessage;
173        if (Content != null) {
174          if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered) {
175            errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
176          } else {
177            Content.DataGridLogic.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex);
178          }
179
180          if (!String.IsNullOrEmpty(errorMessage)) {
181            e.Cancel = true;
182            dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
183          }
184        }
185      }
186    }
187
188    protected override void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
189      triggersOwnEvent(() => base.dataGridView_CellParsing(sender, e));
190    }
191
192    protected override void PasteValuesToDataGridView() {
193      triggersOwnEvent(() => base.PasteValuesToDataGridView());
194    }
195
196    protected override void SetEnabledStateOfControls() {
197      base.SetEnabledStateOfControls();
198      rowsTextBox.ReadOnly = true;
199      columnsTextBox.ReadOnly = true;
200    }
201
202    private void btnApplySort_Click(object sender, System.EventArgs e) {
203      triggersOwnEvent(() => {
204        Content.ManipulationLogic.ReOrderToIndices(virtualRowIndices);
205        OnContentChanged();
206      });
207    }
208
209    private void triggersOwnEvent(Action action) {
210      notOwnEvent = false;
211      action();
212      notOwnEvent = true;
213    }
214
215    #region FindAndReplaceDialog
216
217    private void CreateFindAndReplaceDialog() {
218      if (findAndReplaceDialog == null || findAndReplaceDialog.IsDisposed) {
219        findAndReplaceDialog = new SearchAndReplaceDialog();
220        findAndReplaceDialog.Show(this);
221        if (AreMultipleCellsSelected()) {
222          ResetHighlightedCellsBackground();
223          HightlightedCellsBackground = GetSelectedCells();
224          dataGridView.ClearSelection();
225        }
226        findAndReplaceDialog.FindAllEvent += findAndReplaceDialog_FindAllEvent;
227        findAndReplaceDialog.FindNextEvent += findAndReplaceDialog_FindNextEvent;
228        findAndReplaceDialog.ReplaceAllEvent += findAndReplaceDialog_ReplaceAllEvent;
229        findAndReplaceDialog.ReplaceNextEvent += findAndReplaceDialog_ReplaceEvent;
230        findAndReplaceDialog.FormClosing += findAndReplaceDialog_FormClosing;
231        searchIterator = null;
232        DataGridView.SelectionChanged += DataGridView_SelectionChanged_FindAndReplace;
233        if (Content.FilterLogic.IsFiltered) {
234          findAndReplaceDialog.DisableReplace();
235        }
236      }
237    }
238
239    private void DataGridView_SelectionChanged_FindAndReplace(object sender, EventArgs e) {
240      if (Content != null) {
241        if (!isSearching && AreMultipleCellsSelected()) {
242          ResetHighlightedCellsBackground();
243          HightlightedCellsBackground = GetSelectedCells();
244          searchIterator = null;
245        }
246      }
247    }
248
249    void findAndReplaceDialog_FormClosing(object sender, FormClosingEventArgs e) {
250      ResetHighlightedCellsBackground();
251      searchIterator = null;
252      DataGridView.SelectionChanged -= DataGridView_SelectionChanged_FindAndReplace;
253    }
254
255    void findAndReplaceDialog_ReplaceEvent(object sender, EventArgs e) {
256      if (searchIterator != null && searchIterator.GetCurrent() != null) {
257        Replace(TransformToDictionary(currentCell));
258      }
259    }
260
261    void findAndReplaceDialog_ReplaceAllEvent(object sender, EventArgs e) {
262      Replace(FindAll(findAndReplaceDialog.GetSearchText()));
263    }
264
265    void findAndReplaceDialog_FindNextEvent(object sender, EventArgs e) {
266      if (searchIterator == null
267        || currentSearchText != findAndReplaceDialog.GetSearchText()
268        || currentComparisonOperation != findAndReplaceDialog.GetComparisonOperation()) {
269
270        searchIterator = new FindPreprocessingItemsIterator(FindAll(findAndReplaceDialog.GetSearchText()));
271        currentSearchText = findAndReplaceDialog.GetSearchText();
272        currentComparisonOperation = findAndReplaceDialog.GetComparisonOperation();
273      }
274
275      if (IsOneCellSelected()) {
276        var first = GetSelectedCells().First();
277        searchIterator.SetStartCell(first.Key, first.Value[0]);
278      }
279
280      bool moreOccurences = false;
281      currentCell = searchIterator.GetCurrent();
282      moreOccurences = searchIterator.MoveNext();
283      if (IsOneCellSelected() && currentCell != null) {
284        var first = GetSelectedCells().First();
285        if (currentCell.Item1 == first.Key && currentCell.Item2 == first.Value[0]) {
286          if (!moreOccurences) {
287            searchIterator.Reset();
288          }
289          currentCell = searchIterator.GetCurrent();
290          moreOccurences = searchIterator.MoveNext();
291          if (!moreOccurences) {
292            searchIterator.Reset();
293          }
294        }
295      }
296
297      dataGridView.ClearSelection();
298
299      if (currentCell != null) {
300        dataGridView[currentCell.Item1, currentCell.Item2].Selected = true;
301        dataGridView.CurrentCell = dataGridView[currentCell.Item1, currentCell.Item2];
302      }
303    }
304
305    private bool AreMultipleCellsSelected() {
306      return GetSelectedCellCount() > 1;
307    }
308
309    private bool IsOneCellSelected() {
310      return GetSelectedCellCount() == 1;
311    }
312
313    private int GetSelectedCellCount() {
314      int count = 0;
315      foreach (var column in GetSelectedCells()) {
316        count += column.Value.Count();
317      }
318      return count;
319    }
320
321    void findAndReplaceDialog_FindAllEvent(object sender, EventArgs e) {
322      dataGridView.ClearSelection();
323      isSearching = true;
324      SuspendRepaint();
325      var selectedCells = FindAll(findAndReplaceDialog.GetSearchText());
326      foreach (var column in selectedCells) {
327        foreach (var cell in column.Value) {
328          dataGridView[column.Key, cell].Selected = true;
329        }
330      }
331      ResumeRepaint(true);
332      isSearching = false;
333      Content.DataGridLogic.SetSelection(selectedCells);
334      //update statistic in base
335      base.dataGridView_SelectionChanged(sender, e);
336    }
337
338    private Core.ConstraintOperation GetConstraintOperation(ComparisonOperation comparisonOperation) {
339      Core.ConstraintOperation constraintOperation = Core.ConstraintOperation.Equal;
340      switch (comparisonOperation) {
341        case ComparisonOperation.Equal:
342          constraintOperation = Core.ConstraintOperation.Equal;
343          break;
344        case ComparisonOperation.Greater:
345          constraintOperation = Core.ConstraintOperation.Greater;
346          break;
347        case ComparisonOperation.GreaterOrEqual:
348          constraintOperation = Core.ConstraintOperation.GreaterOrEqual;
349          break;
350        case ComparisonOperation.Less:
351          constraintOperation = Core.ConstraintOperation.Less;
352          break;
353        case ComparisonOperation.LessOrEqual:
354          constraintOperation = Core.ConstraintOperation.LessOrEqual;
355          break;
356        case ComparisonOperation.NotEqual:
357          constraintOperation = Core.ConstraintOperation.NotEqual;
358          break;
359      }
360      return constraintOperation;
361    }
362
363    private IDictionary<int, IList<int>> FindAll(string match) {
364      bool searchInSelection = HightlightedCellsBackground.Values.Sum(list => list.Count) > 1;
365      ComparisonOperation comparisonOperation = findAndReplaceDialog.GetComparisonOperation();
366      var foundCells = new Dictionary<int, IList<int>>();
367      for (int i = 0; i < Content.FilterLogic.PreprocessingData.Columns; i++) {
368        var filters = CreateFilters(match, comparisonOperation, i);
369
370        bool[] filteredRows = Content.FilterLogic.GetFilterResult(filters, true);
371        var foundIndices = new List<int>();
372        for (int idx = 0; idx < filteredRows.Length; ++idx) {
373          var notFilteredThusFound = !filteredRows[idx];
374          if (notFilteredThusFound) {
375            foundIndices.Add(idx);
376          }
377        }
378        foundCells[i] = foundIndices;
379        IList<int> selectedList;
380        if (searchInSelection && HightlightedCellsBackground.TryGetValue(i, out selectedList)) {
381          foundCells[i] = foundCells[i].Intersect(selectedList).ToList<int>();
382        } else if (searchInSelection) {
383          foundCells[i].Clear();
384        }
385      }
386      return MapToSorting(foundCells);
387    }
388
389    private List<IFilter> CreateFilters(string match, ComparisonOperation comparisonOperation, int columnIndex) {
390      IPreprocessingData preprocessingData = Content.FilterLogic.PreprocessingData;
391      IStringConvertibleValue value;
392      if (preprocessingData.IsType<double>(columnIndex)) {
393        value = new DoubleValue();
394      } else if (preprocessingData.IsType<String>(columnIndex)) {
395        value = new StringValue();
396      } else if (preprocessingData.IsType<DateTime>(columnIndex)) {
397        value = new DateTimeValue();
398      } else {
399        throw new ArgumentException("unsupported type");
400      }
401      value.SetValue(match);
402      var comparisonFilter = new ComparisonFilter(preprocessingData, GetConstraintOperation(comparisonOperation), value, true);
403      comparisonFilter.ConstraintColumn = columnIndex;
404      return new List<Filter.IFilter>() { comparisonFilter };
405    }
406
407    private IDictionary<int, IList<int>> MapToSorting(Dictionary<int, IList<int>> foundCells) {
408      if (sortedColumnIndices.Count == 0) {
409        return foundCells;
410      } else {
411        var sortedFoundCells = new Dictionary<int, IList<int>>();
412
413        var indicesToVirtual = new Dictionary<int, int>();
414        for (int i = 0; i < virtualRowIndices.Length; ++i) {
415          indicesToVirtual.Add(virtualRowIndices[i], i);
416        }
417
418        foreach (var entry in foundCells) {
419          var cells = new List<int>();
420          foreach (var cell in entry.Value) {
421            cells.Add(indicesToVirtual[cell]);
422          }
423          cells.Sort();
424          sortedFoundCells.Add(entry.Key, cells);
425        }
426        return sortedFoundCells;
427      }
428    }
429
430    private void Replace(IDictionary<int, IList<int>> cells) {
431      if (findAndReplaceDialog != null) {
432        ReplaceTransaction(() => {
433          switch (findAndReplaceDialog.GetReplaceAction()) {
434            case ReplaceAction.Value:
435              Content.ManipulationLogic.ReplaceIndicesByValue(cells, findAndReplaceDialog.GetReplaceText());
436              break;
437            case ReplaceAction.Average:
438              Content.ManipulationLogic.ReplaceIndicesByAverageValue(cells, false);
439              break;
440            case ReplaceAction.Median:
441              Content.ManipulationLogic.ReplaceIndicesByMedianValue(cells, false);
442              break;
443            case ReplaceAction.Random:
444              Content.ManipulationLogic.ReplaceIndicesByRandomValue(cells, false);
445              break;
446            case ReplaceAction.MostCommon:
447              Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(cells, false);
448              break;
449            case ReplaceAction.Interpolation:
450              Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
451              break;
452          }
453        });
454      }
455    }
456
457    private IDictionary<int, IList<int>> TransformToDictionary(Tuple<int, int> tuple) {
458      var highlightCells = new Dictionary<int, IList<int>>();
459      highlightCells.Add(tuple.Item1, new List<int>() { tuple.Item2 });
460      return highlightCells;
461    }
462
463    private void ResetHighlightedCellsBackground() {
464      HightlightedCellsBackground = new Dictionary<int, IList<int>>();
465    }
466
467    #endregion FindAndReplaceDialog
468
469    private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
470      if (Content == null) return;
471      if (e.Button == System.Windows.Forms.MouseButtons.Right) {
472        if (e.ColumnIndex == -1 || e.RowIndex == -1) {
473          replaceValueOverColumnToolStripMenuItem.Visible = false;
474          contextMenuCell.Show(MousePosition);
475        } else {
476          if (!dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, e.RowIndex])) {
477            dataGridView.ClearSelection();
478            dataGridView[e.ColumnIndex, e.RowIndex].Selected = true;
479          }
480
481          var columnIndices = new HashSet<int>();
482          for (int i = 0; i < dataGridView.SelectedCells.Count; i++) {
483            columnIndices.Add(dataGridView.SelectedCells[i].ColumnIndex);
484          }
485
486          replaceValueOverSelectionToolStripMenuItem.Enabled = AreMultipleCellsSelected();
487
488          averageToolStripMenuItem_Column.Enabled =
489            averageToolStripMenuItem_Selection.Enabled =
490            medianToolStripMenuItem_Column.Enabled =
491            medianToolStripMenuItem_Selection.Enabled =
492            randomToolStripMenuItem_Column.Enabled =
493            randomToolStripMenuItem_Selection.Enabled = !Content.DataGridLogic.AreAllStringColumns(columnIndices);
494
495          smoothingToolStripMenuItem_Column.Enabled =
496            interpolationToolStripMenuItem_Column.Enabled = !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, 0])
497            && !dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, Content.Rows - 1])
498            && !Content.DataGridLogic.AreAllStringColumns(columnIndices);
499
500          replaceValueOverColumnToolStripMenuItem.Visible = true;
501          contextMenuCell.Show(MousePosition);
502        }
503      }
504    }
505
506    protected void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
507      if (Content == null) return;
508      if (e.RowIndex < 0) return;
509      if (e.ColumnIndex < 0) return;
510      if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
511      if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
512      if (HighlightedRowIndices == null) return;
513
514      int rowIndex = virtualRowIndices[e.RowIndex];
515
516      Color backColor = e.CellStyle.BackColor;
517
518      if (HightlightedCellsBackground.ContainsKey(e.ColumnIndex) && HightlightedCellsBackground[e.ColumnIndex].Contains(e.RowIndex)) {
519        backColor = Color.LightGray;
520      }
521
522      using (Brush backColorBrush = new SolidBrush(backColor)) {
523        Rectangle bounds = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height);
524        e.Graphics.FillRectangle(backColorBrush, bounds);
525      }
526
527      using (Brush gridBrush = new SolidBrush(Color.LightGray)) {
528        Pen gridLinePen = new Pen(gridBrush);
529        e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
530               e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
531               e.CellBounds.Bottom - 1);
532        e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
533            e.CellBounds.Top, e.CellBounds.Right - 1,
534            e.CellBounds.Bottom);
535      }
536
537      e.PaintContent(e.CellBounds);
538      e.Handled = true;
539    }
540
541    void dataGridView_KeyDown(object sender, KeyEventArgs e) {
542      var selectedRows = dataGridView.SelectedRows;
543      if (e.KeyCode == Keys.Delete && selectedRows.Count > 0) {
544        List<int> rows = new List<int>();
545        for (int i = 0; i < selectedRows.Count; ++i) {
546          rows.Add(selectedRows[i].Index);
547        }
548        triggersOwnEvent(() => {
549          Content.DataGridLogic.DeleteRow(rows);
550          OnContentChanged();
551        });
552      } else if (e.Control && e.KeyCode == Keys.F) {
553        CreateFindAndReplaceDialog();
554        findAndReplaceDialog.ActivateSearch();
555      } else if (e.Control && e.KeyCode == Keys.R) {
556        CreateFindAndReplaceDialog();
557        findAndReplaceDialog.ActivateReplace();
558      }
559    }
560
561    protected override int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
562      btnApplySort.Enabled = sortedColumns.Any();
563      return base.Sort(sortedColumns);
564    }
565
566    protected override void ClearSorting() {
567      btnApplySort.Enabled = false;
568      base.ClearSorting();
569    }
570
571    private IDictionary<int, IList<int>> GetSelectedCells() {
572      IDictionary<int, IList<int>> selectedCells = new Dictionary<int, IList<int>>();
573      for (int i = 0; i < dataGridView.SelectedCells.Count; i++) {
574        var columnIndex = dataGridView.SelectedCells[i].ColumnIndex;
575        if (!selectedCells.ContainsKey(columnIndex)) {
576          selectedCells.Add(columnIndex, new List<int>());
577        }
578        selectedCells[columnIndex].Add(dataGridView.SelectedCells[i].RowIndex);
579      }
580      return selectedCells;
581    }
582
583    private void StartReplacing() {
584      isReplacing = true;
585      SuspendRepaint();
586    }
587
588    private void StopReplacing() {
589      isReplacing = false;
590      ResumeRepaint(true);
591    }
592
593    private void ReplaceTransaction(Action action) {
594      StartReplacing();
595      action();
596      StopReplacing();
597    }
598
599    private void ReplaceWithAverage_Column_Click(object sender, EventArgs e) {
600      ReplaceTransaction(() => {
601        Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);
602      });
603    }
604    private void ReplaceWithAverage_Selection_Click(object sender, EventArgs e) {
605      ReplaceTransaction(() => {
606        Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);
607      });
608    }
609
610    private void ReplaceWithMedian_Column_Click(object sender, EventArgs e) {
611      ReplaceTransaction(() => {
612        Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
613      });
614    }
615    private void ReplaceWithMedian_Selection_Click(object sender, EventArgs e) {
616      ReplaceTransaction(() => {
617        Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
618      });
619    }
620
621    private void ReplaceWithRandom_Column_Click(object sender, EventArgs e) {
622      ReplaceTransaction(() => {
623        Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
624      });
625    }
626    private void ReplaceWithRandom_Selection_Click(object sender, EventArgs e) {
627      ReplaceTransaction(() => {
628        Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
629      });
630    }
631
632    private void ReplaceWithMostCommon_Column_Click(object sender, EventArgs e) {
633      ReplaceTransaction(() => {
634        Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);
635      });
636    }
637    private void ReplaceWithMostCommon_Selection_Click(object sender, EventArgs e) {
638      ReplaceTransaction(() => {
639        Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);
640      });
641    }
642
643    private void ReplaceWithInterpolation_Column_Click(object sender, EventArgs e) {
644      ReplaceTransaction(() => {
645        Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
646      });
647    }
648
649    private void ReplaceWithSmoothing_Selection_Click(object sender, EventArgs e) {
650      ReplaceTransaction(() => {
651        Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells());
652      });
653    }
654
655    private void btnSearch_Click(object sender, EventArgs e) {
656      CreateFindAndReplaceDialog();
657      findAndReplaceDialog.ActivateSearch();
658    }
659
660    private void btnReplace_Click(object sender, EventArgs e) {
661      CreateFindAndReplaceDialog();
662      findAndReplaceDialog.ActivateReplace();
663    }
664  }
665}
Note: See TracBrowser for help on using the repository browser.