Changeset 10999 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridLogic.cs
- Timestamp:
- 06/11/14 15:28:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridLogic.cs
r10978 r10999 29 29 public class DataGridLogic : IDataGridLogic { 30 30 31 private ITransactionalPreprocessingData preprocessingData;31 private ITransactionalPreprocessingData PreprocessingData { get; private set; } 32 32 private IEnumerable<string> rowNames; 33 34 public DataGridLogic(ITransactionalPreprocessingData preprocessingData) {35 this.preprocessingData = preprocessingData;36 createRowNames();37 }38 39 private void createRowNames() {40 rowNames = Enumerable.Range(1, Rows).Select(n => n.ToString());41 }42 33 43 34 public int Rows { 44 35 get { 45 return preprocessingData.Rows;36 return PreprocessingData.Rows; 46 37 } 47 38 } … … 49 40 public int Columns { 50 41 get { 51 return preprocessingData.Columns;42 return PreprocessingData.Columns; 52 43 } 53 44 } … … 55 46 public IEnumerable<string> ColumnNames { 56 47 get { 57 return preprocessingData.VariableNames;48 return PreprocessingData.VariableNames; 58 49 } 59 50 } … … 65 56 } 66 57 58 public DataGridLogic(ITransactionalPreprocessingData preprocessingData) { 59 PreprocessingData = preprocessingData; 60 createRowNames(); 61 } 62 63 private void createRowNames() { 64 rowNames = Enumerable.Range(1, Rows).Select(n => n.ToString()); 65 } 66 67 68 67 69 public bool Validate(string value, out string errorMessage, int columnIndex) { 68 if (columnIndex < 0 || columnIndex > preprocessingData.VariableNames.Count()) {70 if (columnIndex < 0 || columnIndex > PreprocessingData.VariableNames.Count()) { 69 71 throw new ArgumentOutOfRangeException("column index is out of range"); 70 72 } … … 72 74 bool valid = false; 73 75 errorMessage = string.Empty; 74 if ( preprocessingData.IsType<double>(columnIndex)) {76 if (PreprocessingData.IsType<double>(columnIndex)) { 75 77 double val; 76 78 valid = double.TryParse(value, out val); … … 78 80 errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")"; 79 81 } 80 } else if ( preprocessingData.IsType<string>(columnIndex)) {82 } else if (PreprocessingData.IsType<string>(columnIndex)) { 81 83 valid = value != null; 82 84 if (!valid) { 83 85 errorMessage = "Invalid Value (string must not be null)"; 84 86 } 85 } else if ( preprocessingData.IsType<DateTime>(columnIndex)) {87 } else if (PreprocessingData.IsType<DateTime>(columnIndex)) { 86 88 DateTime date; 87 89 valid = DateTime.TryParse(value, out date); … … 97 99 98 100 public string GetValue(int columnIndex, int rowIndex) { 99 return preprocessingData.GetCellAsString(columnIndex, rowIndex);101 return PreprocessingData.GetCellAsString(columnIndex, rowIndex); 100 102 } 101 103 102 104 public bool SetValue(string value, int columnIndex, int rowIndex) { 103 105 bool valid = false; 104 if ( preprocessingData.IsType<double>(columnIndex)) {106 if (PreprocessingData.IsType<double>(columnIndex)) { 105 107 double val; 106 108 valid = double.TryParse(value, out val); 107 109 SetValueIfValid(columnIndex, rowIndex, valid, val); 108 } else if ( preprocessingData.IsType<string>(columnIndex)) {110 } else if (PreprocessingData.IsType<string>(columnIndex)) { 109 111 valid = value != null; 110 112 SetValueIfValid(columnIndex, rowIndex, valid, value); 111 } else if ( preprocessingData.IsType<DateTime>(columnIndex)) {113 } else if (PreprocessingData.IsType<DateTime>(columnIndex)) { 112 114 DateTime date; 113 115 valid = DateTime.TryParse(value, out date); … … 121 123 private void SetValueIfValid<T>(int columnIndex, int rowIndex, bool valid, T value) { 122 124 if (valid) { 123 preprocessingData.SetCell<T>(columnIndex, rowIndex, value);125 PreprocessingData.SetCell<T>(columnIndex, rowIndex, value); 124 126 } 125 127 } 126 128 127 129 public void DeleteRow(List<int> rows) { 128 preprocessingData.InTransaction(() => {130 PreprocessingData.InTransaction(() => { 129 131 foreach (int rowIndex in rows) { 130 preprocessingData.DeleteRow(rowIndex);132 PreprocessingData.DeleteRow(rowIndex); 131 133 } 132 134 }); … … 135 137 136 138 public event DataPreprocessingChangedEventHandler Changed { 137 add { preprocessingData.Changed += value; }138 remove { preprocessingData.Changed -= value; }139 add { PreprocessingData.Changed += value; } 140 remove { PreprocessingData.Changed -= value; } 139 141 } 140 142 141 143 public bool AreAllStringColumns(IEnumerable<int> columnIndices) { 142 return columnIndices.All(x => preprocessingData.IsType<string>(x));144 return columnIndices.All(x => PreprocessingData.IsType<string>(x)); 143 145 } 144 146 145 147 146 148 public void SetSelection(IDictionary<int, IList<int>> selection) { 147 preprocessingData.Selection = selection;149 PreprocessingData.Selection = selection; 148 150 } 149 151 150 152 public IDictionary<int, IList<int>> GetSelection() { 151 return preprocessingData.Selection;153 return PreprocessingData.Selection; 152 154 } 153 155 public void ClearSelection() { 154 preprocessingData.ClearSelection();156 PreprocessingData.ClearSelection(); 155 157 } 156 158 157 159 public event EventHandler SelectionChanged { 158 add { preprocessingData.SelectionChanged += value; }159 remove { preprocessingData.SelectionChanged -= value; }160 add { PreprocessingData.SelectionChanged += value; } 161 remove { PreprocessingData.SelectionChanged -= value; } 160 162 } 161 163
Note: See TracChangeset
for help on using the changeset viewer.