Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12141


Ignore:
Timestamp:
03/05/15 14:37:02 (10 years ago)
Author:
bburlacu
Message:

#2276:

  • Implemented a ModifiableDatasetView which allows values in the modifiable dataset to be visually edited.
  • Made SetValue and Validate implementations explicit in the Dataset class
  • Added explicit implementations of SetValue and Validate in the ModifiableDataset
  • Renamed ChangeVariableValue method to SetVariableValue for consistency
Location:
branches/HeuristicLab.DatasetRefactor/sources
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r12031 r12141  
    177177    <Compile Include="Interfaces\IDataPreprocessorStarter.cs" />
    178178    <Compile Include="MenuItems\ShrinkDataAnalysisRunsMenuItem.cs" />
     179    <Compile Include="ModifiableDatasetView.cs">
     180      <SubType>UserControl</SubType>
     181    </Compile>
     182    <Compile Include="ModifiableDatasetView.Designer.cs">
     183      <DependentUpon>ModifiableDatasetView.cs</DependentUpon>
     184    </Compile>
    179185    <Compile Include="Plugin.cs" />
    180186    <Compile Include="ProblemDataView.cs">
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r12031 r12141  
    222222      return variableValues[variableNames[columnIndex]][rowIndex].ToString();
    223223    }
    224     public bool SetValue(string value, int rowIndex, int columnIndex) {
     224    bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) {
    225225      throw new NotSupportedException();
    226226    }
    227     public bool Validate(string value, out string errorMessage) {
     227    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
    228228      throw new NotSupportedException();
    229229    }
  • branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis/3.4/ModifiableDataset.cs

    r12032 r12141  
    2828using HeuristicLab.Common;
    2929using HeuristicLab.Core;
     30using HeuristicLab.Data;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132
     
    3334  [Item("ModifiableDataset", "Represents a dataset containing data that should be analyzed, which can be modified by adding or replacing variables and values.")]
    3435  [StorableClass]
    35   public class ModifiableDataset : Dataset {
     36  public class ModifiableDataset : Dataset, IStringConvertibleMatrix {
    3637    [StorableConstructor]
    3738    private ModifiableDataset(bool deserializing) : base(deserializing) { }
     
    99100    }
    100101
    101     public void ChangeVariableValue(object value, string variableName, int row) {
     102    public void SetVariableValue(object value, string variableName, int row) {
    102103      IList list;
    103104      variableValues.TryGetValue(variableName, out list);
     
    106107      if (row < 0 || list.Count < row)
    107108        throw new ArgumentOutOfRangeException("Invalid row value");
     109      if (GetVariableType(variableName) != value.GetType())
     110        throw new ArgumentException("The type of the provided value does not match the variable type.");
     111
    108112      list[row] = value;
    109113    }
     
    116120      return list[0].GetType();
    117121    }
     122
     123    bool IStringConvertibleMatrix.SetValue(string value, int rowIndex, int columnIndex) {
     124      var variableName = variableNames[columnIndex];
     125      // if value represents a double
     126      double dv;
     127      if (double.TryParse(value, out dv)) {
     128        SetVariableValue(dv, variableName, rowIndex);
     129        return true;
     130      }
     131      // if value represents a DateTime object
     132      DateTime dt;
     133      if (DateTime.TryParse(value, out dt)) {
     134        SetVariableValue(dt, variableName, rowIndex);
     135        return true;
     136      }
     137      // if value is simply a string
     138      SetVariableValue(value, variableName, rowIndex);
     139      return true;
     140    }
     141
     142    bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) {
     143      return ValidateValue(value, out errorMessage);
     144    }
     145
     146    private static bool ValidateValue(string value, out string errorMessage) {
     147      double dv;
     148      if (double.TryParse(value, out dv)) {
     149        errorMessage = string.Empty;
     150        return true;
     151      }
     152      DateTime dt;
     153      if (DateTime.TryParse(value, out dt)) {
     154        errorMessage = string.Empty;
     155        return true;
     156      }
     157      errorMessage = "Value could not be validated. Please ensure that the value is either a string, a double, or a DateTime value.";
     158      return false;
     159    }
    118160  }
    119161}
Note: See TracChangeset for help on using the changeset viewer.