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