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
RevLine 
[10539]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10539]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;
[10236]23using System.Collections.Generic;
[10246]24using System.Drawing;
[11002]25using System.Linq;
[10246]26using HeuristicLab.Common;
[10239]27using HeuristicLab.Core;
[10236]28
29namespace HeuristicLab.DataPreprocessing {
[10239]30
[10313]31  [Item("DataGrid", "Represents a data grid.")]
[10614]32  public class DataGridContent : Item, IViewShortcut, IDataGridContent {
[10246]33
[11002]34    public ITransactionalPreprocessingData PreProcessingData { get; private set; }
35
[10999]36    public static new Image StaticItemImage {
37      get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
38    }
39
[10977]40    public IManipulationLogic ManipulationLogic { get; private set; }
41    public IFilterLogic FilterLogic { get; private set; }
[10614]42
[11002]43    private IEnumerable<string> rowNames;
44
[10236]45    public int Rows {
46      get {
[11002]47        return PreProcessingData.Rows;
[10236]48      }
49      set {
[10246]50        //does nothing
[10236]51      }
52    }
53
54    public int Columns {
55      get {
[11002]56        return PreProcessingData.Columns;
[10236]57      }
58      set {
[10246]59        //does nothing
[10236]60      }
61    }
62
63    public IEnumerable<string> ColumnNames {
64      get {
[11002]65        return PreProcessingData.VariableNames;
[10236]66      }
67      set {
[10246]68
[10236]69      }
70    }
71
72    public IEnumerable<string> RowNames {
73      get {
[11002]74        return rowNames;
[10236]75      }
76      set {
[12983]77        throw new NotSupportedException();
[10236]78      }
79    }
80
81    public bool SortableView {
82      get {
83        return true;
84      }
85      set {
[12983]86        throw new NotSupportedException();
[10236]87      }
88    }
89
90    public bool ReadOnly {
[10312]91      get { return false; }
[10236]92    }
93
[11002]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) {
[10977]102      ManipulationLogic = theManipulationLogic;
103      FilterLogic = theFilterLogic;
[11002]104      PreProcessingData = preProcessingData;
105      createRowNames();
[10236]106    }
107
[10964]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
[12676]116    public void DeleteRows(IEnumerable<int> rows) {
[11002]117      PreProcessingData.DeleteRowsWithIndices(rows);
118      createRowNames();
119    }
120
[12676]121    public void DeleteColumn(int column) {
122      PreProcessingData.DeleteColumn(column);
123    }
124
[11002]125    public bool Validate(string value, out string errorMessage, int columnIndex) {
126      return PreProcessingData.Validate(value, out errorMessage, columnIndex);
127    }
128
[10236]129    public string GetValue(int rowIndex, int columnIndex) {
[11002]130      return PreProcessingData.GetCellAsString(columnIndex, rowIndex);
[10236]131    }
132
[10629]133    public bool SetValue(string value, int rowIndex, int columnIndex) {
[11002]134      return PreProcessingData.SetValue(value, columnIndex, rowIndex);
[10236]135    }
136
[11002]137    private void createRowNames() {
138      rowNames = Enumerable.Range(1, Rows).Select(n => n.ToString());
139    }
140
[10964]141    public event DataPreprocessingChangedEventHandler Changed {
[11002]142      add { PreProcessingData.Changed += value; }
143      remove { PreProcessingData.Changed -= value; }
[10964]144    }
145
146
147    #region unused stuff/not implemented but necessary due to IStringConvertibleMatrix
[11070]148#pragma warning disable 0067
[10964]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
[10236]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;
[10246]161    public event EventHandler<EventArgs<int, int>> ItemChanged;
[10236]162    public event EventHandler Reset;
[11070]163
164#pragma warning restore 0067
[10964]165    #endregion
[10236]166
167  }
168}
Note: See TracBrowser for help on using the repository browser.