Changeset 10246
- Timestamp:
- 12/18/13 15:30:35 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/HeuristicLab.DataPreprocessing-3.3.csproj
r10245 r10246 78 78 <ItemGroup> 79 79 <Compile Include="Implementations\DataGridLogic.cs" /> 80 <Compile Include="Interfaces\IDataGridLogic.cs" /> 81 <Compile Include="Interfaces\IPreprocessingDataManipulation.cs" /> 80 82 <Compile Include="Implementations\FilterContent.cs" /> 81 83 <Compile Include="Implementations\FilterLogic.cs" /> … … 92 94 <Compile Include="Interfaces\ILineChartLogic.cs" /> 93 95 <Compile Include="Interfaces\IStatisticsLogic.cs" /> 94 <Compile Include="Interfaces\IDataGridLogic.cs" />95 96 <Compile Include="Interfaces\ITransformationLogic.cs" /> 96 97 <Compile Include="Views\DataPreprocessingView.cs"> -
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 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataGridLogic.cs
r10239 r10246 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Globalization; 3 4 using System.Linq; 4 using System.Text; 5 using HeuristicLab.DataPreprocessing; 5 using HeuristicLab.Data; 6 6 7 7 namespace HeuristicLab.DataPreprocessing { … … 14 14 } 15 15 16 public IEnumerable<string> GetVariableNames() 17 { 18 return preprocessingData.VariableNames; 16 public int Rows { 17 get { 18 return preprocessingData.Rows; 19 } 19 20 } 20 21 21 public IList<IList<string>> GetAllValues() { 22 public int Columns { 23 get { 24 return preprocessingData.Columns; 25 } 26 } 22 27 23 IEnumerable<string> variableNames = preprocessingData.VariableNames; 24 IList<IList<string>> allValues = new List<IList<string>>(); 28 public IEnumerable<string> ColumnNames { 29 get { 30 return preprocessingData.VariableNames; 31 } 32 } 25 33 26 IList<IEnumerable<string>> columnValuesList = new List<IEnumerable<string>>(); 34 public IEnumerable<string> RowNames { 35 get { 36 return Enumerable.Range(1, Rows).Select(n => n.ToString()); 37 } 38 } 27 39 28 foreach (string variableName in variableNames) { 29 30 columnValuesList.Add(preprocessingData.GetValues<string>(variableName)); 40 public bool Validate(string value, out string errorMessage, int columnIndex) { 41 if (columnIndex < 0 || columnIndex > preprocessingData.VariableNames.Count()) { 42 throw new ArgumentOutOfRangeException("column index is out of range"); 43 } 44 bool valid = false; 45 string variableName = preprocessingData.GetVariableName(columnIndex); 46 if (preprocessingData.IsType<double>(variableName)) { 47 double val; 48 valid = double.TryParse(value, out val); 49 errorMessage = string.Empty; 50 if (!valid) { 51 errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")"; 52 } 53 } else if (preprocessingData.IsType<string>(variableName)) { 54 valid = value != null; 55 errorMessage = string.Empty; 56 if (!valid) { 57 errorMessage = "Invalid Value (string must not be null)"; 58 } 59 } else if (preprocessingData.IsType<DateTime>(variableName)) { 60 DateTime date; 61 valid = DateTime.TryParse(value, out date); 62 errorMessage = string.Empty; 63 if (!valid) { 64 errorMessage = "Invalid Value (Valid Value Format: \"" + CultureInfo.CurrentCulture.DateTimeFormat + "\""; 65 } 66 } else { 67 throw new ArgumentException("column with variableName: " + variableName + " contains a non supported type."); 31 68 } 32 69 70 return valid; 71 } 33 72 34 if (columnValuesList.Count > 0) { 35 for (int i = 0; i < columnValuesList.ElementAt(0).Count(); i++) { 36 allValues.Add(new List<string>()); 37 foreach (IEnumerable<string> columnValues in columnValuesList) { 38 allValues[i].Add(columnValues.ElementAt(i)); 39 } 73 public string GetValue(int rowIndex, int columnIndex) { 74 return preprocessingData.GetCellAsString(preprocessingData.GetVariableName(columnIndex), rowIndex); 75 } 76 77 public bool SetValue(string value, int rowIndex, int columnIndex) { 78 string variableName = preprocessingData.GetVariableName(columnIndex); 79 bool valid = false; 80 if (preprocessingData.IsType<double>(variableName)) { 81 double val; 82 valid = double.TryParse(value, out val); 83 if (valid) { 84 preprocessingData.SetCell<double>(variableName, rowIndex, val); 40 85 } 86 } else if (preprocessingData.IsType<string>(variableName)) { 87 valid = value != null; 88 if (valid) { 89 preprocessingData.SetCell<string>(variableName, rowIndex, value); 90 } 91 } else if (preprocessingData.IsType<DateTime>(variableName)) { 92 DateTime date; 93 valid = DateTime.TryParse(value, out date); 94 if (valid) { 95 preprocessingData.SetCell<DateTime>(variableName, rowIndex, date); 96 } 97 } else { 98 throw new ArgumentException("column with variableName: " + variableName + " contains a non supported type."); 41 99 } 42 return allValues; 100 101 return valid; 43 102 } 44 103 104 public event EventHandler ColumnsChanged; 105 106 public event EventHandler RowsChanged; 107 108 public event EventHandler ColumnNamesChanged; 109 110 public event EventHandler RowNamesChanged; 111 112 public event EventHandler SortableViewChanged; 113 114 public event EventHandler<Common.EventArgs<int, int>> ItemChanged; 115 116 public event EventHandler Reset; 117 118 45 119 } 46 120 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingDataManipulation.cs
r10238 r10246 5 5 using System.Text; 6 6 7 namespace HeuristicLab.DataPreprocessing .Implementations7 namespace HeuristicLab.DataPreprocessing 8 8 { 9 class PreprocessingDataManipulation 9 class PreprocessingDataManipulation : IPreprocessingDataManipulation 10 10 { 11 11 private IPreprocessingData preprocessingData; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IDataGridContent.cs
r10236 r10246 7 7 namespace HeuristicLab.DataPreprocessing { 8 8 public interface IDataGridContent : IStringConvertibleMatrix { 9 bool Validate(string value, out string errorMessage, int columnIndex);9 IDataGridLogic DataGridLogic { get; } 10 10 } 11 11 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataGridContentView.cs
r10239 r10246 29 29 if (!dataGridView.ReadOnly) { 30 30 string errorMessage; 31 if (Content != null && !Content. Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex)) {31 if (Content != null && !Content.DataGridLogic.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex)) { 32 32 e.Cancel = true; 33 33 dataGridView.Rows[e.RowIndex].ErrorText = errorMessage; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.cs
r10239 r10246 45 45 46 46 private void InitializeContents() { 47 dataGridContent = new DataGridContent( this.Content);47 dataGridContent = new DataGridContent(new DataGridLogic(this.Content)); 48 48 49 49 listViewItemItemMapping = new Dictionary<ListViewItem,IItem>();
Note: See TracChangeset
for help on using the changeset viewer.