Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/18/13 15:30:35 (10 years ago)
Author:
rstoll
Message:
  • Moved logic from DataGridContent to DataGridContentLogic
  • Created interface for IPreprocessingDataManipulation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataGridContent.cs

    r10243 r10246  
    11using System;
    22using System.Collections.Generic;
    3 using System.Globalization;
    4 using System.Linq;
    5 using System.Text;
    6 using HeuristicLab.Data;
     3using System.Drawing;
     4using HeuristicLab.Common;
    75using HeuristicLab.Core;
    8 using HeuristicLab.Common;
    9 using System.Drawing;
    106
    117namespace HeuristicLab.DataPreprocessing {
    128
    139  [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;
    2015    }
    2116
    2217    public DataGridContent(DataGridContent dataGridContent, Cloner cloner)
    23         : base(dataGridContent, cloner)
    24     {
     18      : base(dataGridContent, cloner) {
    2519
    2620    }
    2721
    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      }
    3326    }
    3427
    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; }
    3830    }
    3931
    40     #region IStringConvertibleMatrix Members
     32    public override IDeepCloneable Clone(Cloner cloner) {
     33      return new DataGridContent(this, cloner);
     34    }
    4135
    4236    public int Rows {
    4337      get {
    44         return preprocessingData.Rows;
     38        return dataGridLogic.Rows;
    4539      }
    4640      set {
    47         //does nothing, use something else :P
     41        //does nothing
    4842      }
    4943    }
     
    5145    public int Columns {
    5246      get {
    53         return preprocessingData.Columns;
     47        return dataGridLogic.Columns;
    5448      }
    5549      set {
    56         //does nothing, use something else :P
     50        //does nothing
    5751      }
    5852    }
     
    6054    public IEnumerable<string> ColumnNames {
    6155      get {
    62         return preprocessingData.VariableNames;
     56        return dataGridLogic.ColumnNames;
    6357      }
    6458      set {
    65         //not supported
     59
    6660      }
    6761    }
     
    6963    public IEnumerable<string> RowNames {
    7064      get {
    71         return Enumerable.Range(1, Rows).Select(n => n.ToString());
     65        return dataGridLogic.RowNames;
    7266      }
    7367      set {
    74         //not supported 
     68        //not supported
    7569      }
    7670    }
     
    8175      }
    8276      set {
    83         //not supported 
     77        //not supported
    8478      }
    8579    }
    8680
    8781    public bool ReadOnly {
    88       get { return false; }
     82      get { return true; }
    8983    }
    9084
     
    9589
    9690    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);
    12792    }
    12893
    12994    public string GetValue(int rowIndex, int columnIndex) {
    130       return preprocessingData.GetCellAsString(preprocessingData.GetVariableName(columnIndex), rowIndex);
     95      return dataGridLogic.GetValue(rowIndex, columnIndex);
    13196    }
    13297
    13398    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);
    158100    }
    159101
     
    168110    public event EventHandler SortableViewChanged;
    169111
    170     public event EventHandler<Common.EventArgs<int, int>> ItemChanged;
     112    public event EventHandler<EventArgs<int, int>> ItemChanged;
    171113
    172114    public event EventHandler Reset;
    173115
    174     #endregion
    175116  }
    176117}
Note: See TracChangeset for help on using the changeset viewer.