Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataGridContentView.cs @ 10539

Last change on this file since 10539 was 10539, checked in by rstoll, 10 years ago

Added License notice

File size: 4.6 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.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Data.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29
30namespace HeuristicLab.DataPreprocessing {
31  [View("Data Grid Content View")]
32  [Content(typeof(IDataGridContent), true)]
33  public partial class DataGridContentView : StringConvertibleMatrixView {
34
35    private int lastClickedRow;
36    private int lastClickedColumn;
37
38    public new IDataGridContent Content {
39      get { return (IDataGridContent)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public DataGridContentView() {
44      InitializeComponent();
45      dataGridView.CellMouseClick += dataGridView_CellMouseClick;
46      contextMenuCell.Items.Add(ShowHideColumns);
47    }
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51    }
52
53
54    private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
55      if (!dataGridView.ReadOnly) {
56        string errorMessage;
57        if (Content != null && !Content.DataGridLogic.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex)) {
58          e.Cancel = true;
59          dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
60        }
61      }
62    }
63
64    protected override void SetEnabledStateOfControls() {
65      base.SetEnabledStateOfControls();
66      rowsTextBox.ReadOnly = true;
67      columnsTextBox.ReadOnly = true;
68    }
69
70    private void btnApplySort_Click(object sender, System.EventArgs e) {
71      Content.PreprocessingDataManipulation.ReOrderToIndices(virtualRowIndices);
72      OnContentChanged();
73    }
74
75    private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
76      if (Content == null) return;
77      if (e.Button == System.Windows.Forms.MouseButtons.Right) {
78        if (e.ColumnIndex == -1 || e.RowIndex == -1) {
79          contextMenu.Show(MousePosition);
80        } else {
81          interpolationToolStripMenuItem.Enabled = !(e.RowIndex == 0 || e.RowIndex == Content.Rows);
82          contextMenuCell.Show(MousePosition);
83          lastClickedColumn = e.ColumnIndex;
84          lastClickedRow = e.RowIndex;
85        }
86      }
87    }
88
89    protected override int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
90      btnApplySort.Enabled = sortedColumns.Any();
91      return base.Sort(sortedColumns);
92    }
93
94    protected override void ClearSorting() {
95      btnApplySort.Enabled = false;
96      base.ClearSorting();
97    }
98
99    private void ReplaceWithAverage_Click(object sender, EventArgs e) {
100      Content.PreprocessingDataManipulation.ReplaceIndicesByAverageValue(lastClickedColumn, new List<int>() { lastClickedRow });
101      OnContentChanged();
102    }
103
104    private void ReplaceWithMedian_Click(object sender, EventArgs e) {
105      Content.PreprocessingDataManipulation.ReplaceIndicesByMedianValue(lastClickedColumn, new List<int>() { lastClickedRow });
106      OnContentChanged();
107    }
108
109    private void ReplaceWithRandom_Click(object sender, EventArgs e) {
110      Content.PreprocessingDataManipulation.ReplaceIndicesByRandomValue(lastClickedColumn, new List<int>() { lastClickedRow });
111      OnContentChanged();
112    }
113
114    private void ReplaceWithMostCommon_Click(object sender, EventArgs e) {
115      Content.PreprocessingDataManipulation.ReplaceIndicesByMostCommonValue(lastClickedColumn, new List<int>() { lastClickedRow });
116      OnContentChanged();
117    }
118
119    private void ReplaceWithInterpolation_Click(object sender, EventArgs e) {
120      Content.PreprocessingDataManipulation.ReplaceIndicesByLinearInterpolationOfNeighbours(lastClickedColumn, new List<int>() { lastClickedRow });
121      OnContentChanged();
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.