#region License Information
/* HeuristicLab
* Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
namespace HeuristicLab.DataPreprocessing {
[Item("DataGrid", "Represents a data grid.")]
public class DataGridContent : Item, IViewShortcut, IDataGridContent {
public ITransactionalPreprocessingData PreProcessingData { get; private set; }
public static new Image StaticItemImage {
get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
}
public IManipulationLogic ManipulationLogic { get; private set; }
public IFilterLogic FilterLogic { get; private set; }
private IEnumerable rowNames;
public int Rows {
get {
return PreProcessingData.Rows;
}
set {
//does nothing
}
}
public int Columns {
get {
return PreProcessingData.Columns;
}
set {
//does nothing
}
}
public IEnumerable ColumnNames {
get {
return PreProcessingData.VariableNames;
}
set {
}
}
public IEnumerable RowNames {
get {
return rowNames;
}
set {
//not supported
}
}
public bool SortableView {
get {
return true;
}
set {
//not supported
}
}
public bool ReadOnly {
get { return false; }
}
public IDictionary> Selection {
get { return PreProcessingData.Selection; }
set { PreProcessingData.Selection = value; }
}
public DataGridContent(ITransactionalPreprocessingData preProcessingData, IManipulationLogic theManipulationLogic, IFilterLogic theFilterLogic) {
ManipulationLogic = theManipulationLogic;
FilterLogic = theFilterLogic;
PreProcessingData = preProcessingData;
createRowNames();
}
public DataGridContent(DataGridContent dataGridContent, Cloner cloner)
: base(dataGridContent, cloner) {
}
public override IDeepCloneable Clone(Cloner cloner) {
return new DataGridContent(this, cloner);
}
public void DeleteRow(IEnumerable rows) {
PreProcessingData.DeleteRowsWithIndices(rows);
createRowNames();
}
public bool Validate(string value, out string errorMessage, int columnIndex) {
return PreProcessingData.Validate(value, out errorMessage, columnIndex);
}
public string GetValue(int rowIndex, int columnIndex) {
return PreProcessingData.GetCellAsString(columnIndex, rowIndex);
}
public bool SetValue(string value, int rowIndex, int columnIndex) {
return PreProcessingData.SetValue(value, columnIndex, rowIndex);
}
private void createRowNames() {
rowNames = Enumerable.Range(1, Rows).Select(n => n.ToString());
}
public event DataPreprocessingChangedEventHandler Changed {
add { PreProcessingData.Changed += value; }
remove { PreProcessingData.Changed -= value; }
}
#region unused stuff/not implemented but necessary due to IStringConvertibleMatrix
#pragma warning disable 0067
// Is not used since DataGridContentView overrides dataGridView_CellValidating and uses
// DataGridLogic#Validate(string value, out string errorMessage, int columnIndex)
public bool Validate(string value, out string errorMessage) {
errorMessage = string.Empty;
return true;
}
public event EventHandler ColumnsChanged;
public event EventHandler RowsChanged;
public event EventHandler ColumnNamesChanged;
public event EventHandler RowNamesChanged;
public event EventHandler SortableViewChanged;
public event EventHandler> ItemChanged;
public event EventHandler Reset;
#pragma warning restore 0067
#endregion
}
}