Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs @ 13765

Last change on this file since 13765 was 13289, checked in by mkommend, 9 years ago

#2486: Merged r12983, r12986, r13252 and r13271 into stable.

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