Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridContent.cs @ 12983

Last change on this file since 12983 was 12983, checked in by pfleck, 9 years ago

#2486
Allows pasting of multiple values that extend the current data limits (rows and/or columns).
In case, additional rows and columns are added with the default value of the column's type.

File size: 4.8 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.Drawing;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28
29namespace HeuristicLab.DataPreprocessing {
30
31  [Item("DataGrid", "Represents a data grid.")]
32  public class DataGridContent : Item, IViewShortcut, IDataGridContent {
33
34    public ITransactionalPreprocessingData PreProcessingData { get; private set; }
35
36    public static new Image StaticItemImage {
37      get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
38    }
39
40    public IManipulationLogic ManipulationLogic { get; private set; }
41    public IFilterLogic FilterLogic { get; private set; }
42
43    private IEnumerable<string> rowNames;
44
45    public int Rows {
46      get {
47        return PreProcessingData.Rows;
48      }
49      set {
50        //does nothing
51      }
52    }
53
54    public int Columns {
55      get {
56        return PreProcessingData.Columns;
57      }
58      set {
59        //does nothing
60      }
61    }
62
63    public IEnumerable<string> ColumnNames {
64      get {
65        return PreProcessingData.VariableNames;
66      }
67      set {
68
69      }
70    }
71
72    public IEnumerable<string> RowNames {
73      get {
74        return rowNames;
75      }
76      set {
77        throw new NotSupportedException();
78      }
79    }
80
81    public bool SortableView {
82      get {
83        return true;
84      }
85      set {
86        throw new NotSupportedException();
87      }
88    }
89
90    public bool ReadOnly {
91      get { return false; }
92    }
93
94
95    public IDictionary<int, IList<int>> Selection {
96      get { return PreProcessingData.Selection; }
97      set { PreProcessingData.Selection = value; }
98    }
99
100
101    public DataGridContent(ITransactionalPreprocessingData preProcessingData, IManipulationLogic theManipulationLogic, IFilterLogic theFilterLogic) {
102      ManipulationLogic = theManipulationLogic;
103      FilterLogic = theFilterLogic;
104      PreProcessingData = preProcessingData;
105      createRowNames();
106    }
107
108    public DataGridContent(DataGridContent dataGridContent, Cloner cloner)
109      : base(dataGridContent, cloner) {
110
111    }
112    public override IDeepCloneable Clone(Cloner cloner) {
113      return new DataGridContent(this, cloner);
114    }
115
116    public void DeleteRows(IEnumerable<int> rows) {
117      PreProcessingData.DeleteRowsWithIndices(rows);
118      createRowNames();
119    }
120
121    public void DeleteColumn(int column) {
122      PreProcessingData.DeleteColumn(column);
123    }
124
125    public bool Validate(string value, out string errorMessage, int columnIndex) {
126      return PreProcessingData.Validate(value, out errorMessage, columnIndex);
127    }
128
129    public string GetValue(int rowIndex, int columnIndex) {
130      return PreProcessingData.GetCellAsString(columnIndex, rowIndex);
131    }
132
133    public bool SetValue(string value, int rowIndex, int columnIndex) {
134      return PreProcessingData.SetValue(value, columnIndex, rowIndex);
135    }
136
137    private void createRowNames() {
138      rowNames = Enumerable.Range(1, Rows).Select(n => n.ToString());
139    }
140
141    public event DataPreprocessingChangedEventHandler Changed {
142      add { PreProcessingData.Changed += value; }
143      remove { PreProcessingData.Changed -= value; }
144    }
145
146
147    #region unused stuff/not implemented but necessary due to IStringConvertibleMatrix
148#pragma warning disable 0067
149    // Is not used since DataGridContentView overrides dataGridView_CellValidating and uses
150    // DataGridLogic#Validate(string value, out string errorMessage, int columnIndex)
151    public bool Validate(string value, out string errorMessage) {
152      errorMessage = string.Empty;
153      return true;
154    }
155
156    public event EventHandler ColumnsChanged;
157    public event EventHandler RowsChanged;
158    public event EventHandler ColumnNamesChanged;
159    public event EventHandler RowNamesChanged;
160    public event EventHandler SortableViewChanged;
161    public event EventHandler<EventArgs<int, int>> ItemChanged;
162    public event EventHandler Reset;
163
164#pragma warning restore 0067
165    #endregion
166
167  }
168}
Note: See TracBrowser for help on using the repository browser.