Changeset 10246 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataGridContent.cs
- Timestamp:
- 12/18/13 15:30:35 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataGridContent.cs
r10243 r10246 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Globalization; 4 using System.Linq; 5 using System.Text; 6 using HeuristicLab.Data; 3 using System.Drawing; 4 using HeuristicLab.Common; 7 5 using HeuristicLab.Core; 8 using HeuristicLab.Common;9 using System.Drawing;10 6 11 7 namespace HeuristicLab.DataPreprocessing { 12 8 13 9 [Item("DataGridContent", "Represents a data grid.")] 14 public class DataGridContent : Item,IDataGridContent,IContent 15 { 16 private readonly IPreprocessingData preprocessingData; 17 18 public DataGridContent(IPreprocessingData thePreprocessingData) { 19 preprocessingData = thePreprocessingData; 10 public class DataGridContent : Item, IDataGridContent, IContent { 11 12 private readonly IDataGridLogic dataGridLogic; 13 public DataGridContent(IDataGridLogic theDataGridLogic) { 14 dataGridLogic = theDataGridLogic; 20 15 } 21 16 22 17 public DataGridContent(DataGridContent dataGridContent, Cloner cloner) 23 : base(dataGridContent, cloner) 24 { 18 : base(dataGridContent, cloner) { 25 19 26 20 } 27 21 28 public IDataGridLogic DataGridLogic { get; set; } 29 30 public static new Image StaticItemImage 31 { 32 get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; } 22 public IDataGridLogic DataGridLogic { 23 get { 24 return dataGridLogic; 25 } 33 26 } 34 27 35 public override IDeepCloneable Clone(Cloner cloner) 36 { 37 return new DataGridContent(this, cloner); 28 public static new Image StaticItemImage { 29 get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; } 38 30 } 39 31 40 #region IStringConvertibleMatrix Members 32 public override IDeepCloneable Clone(Cloner cloner) { 33 return new DataGridContent(this, cloner); 34 } 41 35 42 36 public int Rows { 43 37 get { 44 return preprocessingData.Rows;38 return dataGridLogic.Rows; 45 39 } 46 40 set { 47 //does nothing , use something else :P41 //does nothing 48 42 } 49 43 } … … 51 45 public int Columns { 52 46 get { 53 return preprocessingData.Columns;47 return dataGridLogic.Columns; 54 48 } 55 49 set { 56 //does nothing , use something else :P50 //does nothing 57 51 } 58 52 } … … 60 54 public IEnumerable<string> ColumnNames { 61 55 get { 62 return preprocessingData.VariableNames;56 return dataGridLogic.ColumnNames; 63 57 } 64 58 set { 65 //not supported 59 66 60 } 67 61 } … … 69 63 public IEnumerable<string> RowNames { 70 64 get { 71 return Enumerable.Range(1, Rows).Select(n => n.ToString());65 return dataGridLogic.RowNames; 72 66 } 73 67 set { 74 //not supported 68 //not supported 75 69 } 76 70 } … … 81 75 } 82 76 set { 83 //not supported 77 //not supported 84 78 } 85 79 } 86 80 87 81 public bool ReadOnly { 88 get { return false; }82 get { return true; } 89 83 } 90 84 … … 95 89 96 90 public bool Validate(string value, out string errorMessage, int columnIndex) { 97 if (columnIndex < 0 || columnIndex > preprocessingData.VariableNames.Count()) { 98 throw new ArgumentOutOfRangeException("column index is out of range"); 99 } 100 bool valid = false; 101 string variableName = preprocessingData.GetVariableName(columnIndex); 102 if (preprocessingData.IsType<double>(variableName)) { 103 double val; 104 valid = double.TryParse(value, out val); 105 errorMessage = string.Empty; 106 if (!valid) { 107 errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")"; 108 } 109 } else if (preprocessingData.IsType<string>(variableName)) { 110 valid = value != null; 111 errorMessage = string.Empty; 112 if (!valid) { 113 errorMessage = "Invalid Value (string must not be null)"; 114 } 115 } else if (preprocessingData.IsType<DateTime>(variableName)) { 116 DateTime date; 117 valid = DateTime.TryParse(value, out date); 118 errorMessage = string.Empty; 119 if (!valid) { 120 errorMessage = "Invalid Value (Valid Value Format: \"" + CultureInfo.CurrentCulture.DateTimeFormat + "\""; 121 } 122 } else { 123 throw new ArgumentException("column with variableName: " + variableName + " contains a non supported type."); 124 } 125 126 return valid; 91 return dataGridLogic.Validate(value, out errorMessage, columnIndex); 127 92 } 128 93 129 94 public string GetValue(int rowIndex, int columnIndex) { 130 return preprocessingData.GetCellAsString(preprocessingData.GetVariableName(columnIndex), rowIndex);95 return dataGridLogic.GetValue(rowIndex, columnIndex); 131 96 } 132 97 133 98 public bool SetValue(string value, int rowIndex, int columnIndex) { 134 string variableName = preprocessingData.GetVariableName(columnIndex); 135 bool valid = false; 136 if (preprocessingData.IsType<double>(variableName)) { 137 double val; 138 valid = double.TryParse(value, out val); 139 if (valid) { 140 preprocessingData.SetCell<double>(variableName, rowIndex, val); 141 } 142 } else if (preprocessingData.IsType<string>(variableName)) { 143 valid = value != null; 144 if (valid) { 145 preprocessingData.SetCell<string>(variableName, rowIndex, value); 146 } 147 } else if (preprocessingData.IsType<DateTime>(variableName)) { 148 DateTime date; 149 valid = DateTime.TryParse(value, out date); 150 if (valid) { 151 preprocessingData.SetCell<DateTime>(variableName, rowIndex, date); 152 } 153 } else { 154 throw new ArgumentException("column with variableName: " + variableName + " contains a non supported type."); 155 } 156 157 return valid; 99 return dataGridLogic.SetValue(value, rowIndex, columnIndex); 158 100 } 159 101 … … 168 110 public event EventHandler SortableViewChanged; 169 111 170 public event EventHandler< Common.EventArgs<int, int>> ItemChanged;112 public event EventHandler<EventArgs<int, int>> ItemChanged; 171 113 172 114 public event EventHandler Reset; 173 115 174 #endregion175 116 } 176 117 }
Note: See TracChangeset
for help on using the changeset viewer.