1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.DataPreprocessing {
|
---|
32 | [Item("Data Grid", "Represents a data grid.")]
|
---|
33 | [StorableClass]
|
---|
34 | public class DataGridContent : PreprocessingContent, IStringConvertibleMatrix, IViewShortcut {
|
---|
35 | public static new Image StaticItemImage {
|
---|
36 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | [Storable]
|
---|
40 | public ManipulationLogic ManipulationLogic { get; private set; }
|
---|
41 |
|
---|
42 | public int Rows {
|
---|
43 | get { return PreprocessingData.Rows; }
|
---|
44 | set { }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public int Columns {
|
---|
48 | get { return PreprocessingData.Columns; }
|
---|
49 | set { }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public IEnumerable<string> ColumnNames {
|
---|
53 | get { return PreprocessingData.VariableNames; }
|
---|
54 | set { }
|
---|
55 | }
|
---|
56 |
|
---|
57 | public IEnumerable<string> RowNames {
|
---|
58 | get { return Enumerable.Range(1, Rows).Select(n => n.ToString()); }
|
---|
59 | set { throw new NotSupportedException(); }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public bool SortableView {
|
---|
63 | get { return true; }
|
---|
64 | set { throw new NotSupportedException(); }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public bool ReadOnly {
|
---|
68 | get { return false; }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public IDictionary<int, IList<int>> Selection {
|
---|
72 | get { return PreprocessingData.Selection; }
|
---|
73 | set { PreprocessingData.Selection = value; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | #region Constructor, Cloning & Persistence
|
---|
77 | public DataGridContent(IFilteredPreprocessingData preprocessingData, ManipulationLogic manipulationLogic)
|
---|
78 | : base(preprocessingData) {
|
---|
79 | ManipulationLogic = manipulationLogic;
|
---|
80 | }
|
---|
81 |
|
---|
82 | public DataGridContent(DataGridContent original, Cloner cloner)
|
---|
83 | : base(original, cloner) {
|
---|
84 | ManipulationLogic = cloner.Clone(original.ManipulationLogic);
|
---|
85 | }
|
---|
86 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
87 | return new DataGridContent(this, cloner);
|
---|
88 | }
|
---|
89 |
|
---|
90 | [StorableConstructor]
|
---|
91 | protected DataGridContent(bool deserializing)
|
---|
92 | : base(deserializing) { }
|
---|
93 | #endregion
|
---|
94 |
|
---|
95 | public void DeleteRows(IEnumerable<int> rows) {
|
---|
96 | PreprocessingData.DeleteRowsWithIndices(rows);
|
---|
97 | }
|
---|
98 |
|
---|
99 | public void DeleteColumn(int column) {
|
---|
100 | PreprocessingData.DeleteColumn(column);
|
---|
101 | }
|
---|
102 |
|
---|
103 | public bool Validate(string value, out string errorMessage, int columnIndex) {
|
---|
104 | return PreprocessingData.Validate(value, out errorMessage, columnIndex);
|
---|
105 | }
|
---|
106 |
|
---|
107 | public string GetValue(int rowIndex, int columnIndex) {
|
---|
108 | return PreprocessingData.GetCellAsString(columnIndex, rowIndex);
|
---|
109 | }
|
---|
110 |
|
---|
111 | public bool SetValue(string value, int rowIndex, int columnIndex) {
|
---|
112 | return PreprocessingData.SetValue(value, columnIndex, rowIndex);
|
---|
113 | }
|
---|
114 |
|
---|
115 | public event DataPreprocessingChangedEventHandler Changed {
|
---|
116 | add { PreprocessingData.Changed += value; }
|
---|
117 | remove { PreprocessingData.Changed -= value; }
|
---|
118 | }
|
---|
119 |
|
---|
120 | #region unused stuff/not implemented but necessary due to IStringConvertibleMatrix
|
---|
121 | #pragma warning disable 0067
|
---|
122 | // Is not used since DataGridContentView overrides dataGridView_CellValidating and uses
|
---|
123 | // DataGridLogic#Validate(string value, out string errorMessage, int columnIndex)
|
---|
124 | public bool Validate(string value, out string errorMessage) {
|
---|
125 | errorMessage = string.Empty;
|
---|
126 | return true;
|
---|
127 | }
|
---|
128 |
|
---|
129 | public event EventHandler ColumnsChanged;
|
---|
130 | public event EventHandler RowsChanged;
|
---|
131 | public event EventHandler ColumnNamesChanged;
|
---|
132 | public event EventHandler RowNamesChanged;
|
---|
133 | public event EventHandler SortableViewChanged;
|
---|
134 | public event EventHandler<EventArgs<int, int>> ItemChanged;
|
---|
135 | public event EventHandler Reset;
|
---|
136 | #pragma warning restore 0067
|
---|
137 | #endregion
|
---|
138 | }
|
---|
139 | }
|
---|