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

Last change on this file since 12986 was 12986, checked in by pfleck, 4 years ago

#2486

  • Added buttons for adding columns and rows.
  • Fixed a bug with row names.
File size: 4.7 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    public int Rows {
44      get {
45        return PreProcessingData.Rows;
46      }
47      set {
48        //does nothing
49      }
50    }
51
52    public int Columns {
53      get {
54        return PreProcessingData.Columns;
55      }
56      set {
57        //does nothing
58      }
59    }
60
61    public IEnumerable<string> ColumnNames {
62      get {
63        return PreProcessingData.VariableNames;
64      }
65      set {
66
67      }
68    }
69
70    public IEnumerable<string> RowNames {
71      get {
72        return Enumerable.Range(1, Rows).Select(n => n.ToString());
73      }
74      set {
75        throw new NotSupportedException();
76      }
77    }
78
79    public bool SortableView {
80      get {
81        return true;
82      }
83      set {
84        throw new NotSupportedException();
85      }
86    }
87
88    public bool ReadOnly {
89      get { return false; }
90    }
91
92
93    public IDictionary<int, IList<int>> Selection {
94      get { return PreProcessingData.Selection; }
95      set { PreProcessingData.Selection = value; }
96    }
97
98
99    public DataGridContent(ITransactionalPreprocessingData preProcessingData, IManipulationLogic theManipulationLogic, IFilterLogic theFilterLogic) {
100      ManipulationLogic = theManipulationLogic;
101      FilterLogic = theFilterLogic;
102      PreProcessingData = preProcessingData;
103    }
104
105    public DataGridContent(DataGridContent dataGridContent, Cloner cloner)
106      : base(dataGridContent, cloner) {
107
108    }
109    public override IDeepCloneable Clone(Cloner cloner) {
110      return new DataGridContent(this, cloner);
111    }
112
113    public void DeleteRows(IEnumerable<int> rows) {
114      PreProcessingData.DeleteRowsWithIndices(rows);
115    }
116
117    public void DeleteColumn(int column) {
118      PreProcessingData.DeleteColumn(column);
119    }
120
121    public bool Validate(string value, out string errorMessage, int columnIndex) {
122      return PreProcessingData.Validate(value, out errorMessage, columnIndex);
123    }
124
125    public string GetValue(int rowIndex, int columnIndex) {
126      return PreProcessingData.GetCellAsString(columnIndex, rowIndex);
127    }
128
129    public bool SetValue(string value, int rowIndex, int columnIndex) {
130      return PreProcessingData.SetValue(value, columnIndex, rowIndex);
131    }
132
133    public event DataPreprocessingChangedEventHandler Changed {
134      add { PreProcessingData.Changed += value; }
135      remove { PreProcessingData.Changed -= value; }
136    }
137
138
139    #region unused stuff/not implemented but necessary due to IStringConvertibleMatrix
140#pragma warning disable 0067
141    // Is not used since DataGridContentView overrides dataGridView_CellValidating and uses
142    // DataGridLogic#Validate(string value, out string errorMessage, int columnIndex)
143    public bool Validate(string value, out string errorMessage) {
144      errorMessage = string.Empty;
145      return true;
146    }
147
148    public event EventHandler ColumnsChanged;
149    public event EventHandler RowsChanged;
150    public event EventHandler ColumnNamesChanged;
151    public event EventHandler RowNamesChanged;
152    public event EventHandler SortableViewChanged;
153    public event EventHandler<EventArgs<int, int>> ItemChanged;
154    public event EventHandler Reset;
155
156#pragma warning restore 0067
157    #endregion
158
159  }
160}
Note: See TracBrowser for help on using the repository browser.