Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/18/13 15:30:35 (11 years ago)
Author:
rstoll
Message:
  • Moved logic from DataGridContent to DataGridContentLogic
  • Created interface for IPreprocessingDataManipulation
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  
    7878  <ItemGroup>
    7979    <Compile Include="Implementations\DataGridLogic.cs" />
     80    <Compile Include="Interfaces\IDataGridLogic.cs" />
     81    <Compile Include="Interfaces\IPreprocessingDataManipulation.cs" />
    8082    <Compile Include="Implementations\FilterContent.cs" />
    8183    <Compile Include="Implementations\FilterLogic.cs" />
     
    9294    <Compile Include="Interfaces\ILineChartLogic.cs" />
    9395    <Compile Include="Interfaces\IStatisticsLogic.cs" />
    94     <Compile Include="Interfaces\IDataGridLogic.cs" />
    9596    <Compile Include="Interfaces\ITransformationLogic.cs" />
    9697    <Compile Include="Views\DataPreprocessingView.cs">
  • 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}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataGridLogic.cs

    r10239 r10246  
    11using System;
    22using System.Collections.Generic;
     3using System.Globalization;
    34using System.Linq;
    4 using System.Text;
    5 using HeuristicLab.DataPreprocessing;
     5using HeuristicLab.Data;
    66
    77namespace HeuristicLab.DataPreprocessing {
     
    1414    }
    1515
    16     public IEnumerable<string> GetVariableNames()
    17     {
    18       return preprocessingData.VariableNames;
     16    public int Rows {
     17      get {
     18        return preprocessingData.Rows;
     19      }
    1920    }
    2021
    21     public IList<IList<string>> GetAllValues() {
     22    public int Columns {
     23      get {
     24        return preprocessingData.Columns;
     25      }
     26    }
    2227
    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    }
    2533
    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    }
    2739
    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.");
    3168      }
    3269
     70      return valid;
     71    }
    3372
    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);
    4085        }
     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.");
    4199      }
    42       return allValues;
     100
     101      return valid;
    43102    }
    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
    45119  }
    46120}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingDataManipulation.cs

    r10238 r10246  
    55using System.Text;
    66
    7 namespace HeuristicLab.DataPreprocessing.Implementations
     7namespace HeuristicLab.DataPreprocessing
    88{
    9     class PreprocessingDataManipulation
     9    class PreprocessingDataManipulation : IPreprocessingDataManipulation
    1010    {
    1111        private IPreprocessingData preprocessingData;
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IDataGridContent.cs

    r10236 r10246  
    77namespace HeuristicLab.DataPreprocessing {
    88  public interface IDataGridContent : IStringConvertibleMatrix {
    9     bool Validate(string value, out string errorMessage, int columnIndex);
     9    IDataGridLogic DataGridLogic { get; }
    1010  }
    1111}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataGridContentView.cs

    r10239 r10246  
    2929      if (!dataGridView.ReadOnly) {
    3030        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)) {
    3232          e.Cancel = true;
    3333          dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.cs

    r10239 r10246  
    4545
    4646    private void InitializeContents() {
    47       dataGridContent = new DataGridContent(this.Content);
     47      dataGridContent = new DataGridContent(new DataGridLogic(this.Content));
    4848
    4949      listViewItemItemMapping = new Dictionary<ListViewItem,IItem>();
Note: See TracChangeset for help on using the changeset viewer.