Free cookie consent management tool by TermsFeed Policy Generator

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

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