Changeset 10900


Ignore:
Timestamp:
05/28/14 12:52:24 (8 years ago)
Author:
sbreuer
Message:
  • deleted unused method
  • refactored filter logic
  • added filter changed event
  • changed datagridview validation (cannot modify, if filter is active)
  • update datagridview if preview is active
Location:
branches/DataPreprocessing
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataGridContentView.cs

    r10898 r10900  
    9696      base.RegisterContentEvents();
    9797      Content.Changed += Content_Changed;
    98     }
     98      Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
     99    }
     100
     101    void FilterLogic_FilterChanged(object sender, EventArgs e) {
     102      OnContentChanged();
     103      searchIterator = null;
     104    }   
    99105
    100106    protected override void DeregisterContentEvents() {
    101107      base.DeregisterContentEvents();
    102108      Content.Changed -= Content_Changed;
     109      Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
    103110    }
    104111
     
    121128      if (!dataGridView.ReadOnly) {
    122129        string errorMessage;
    123         if (Content != null && !Content.DataGridLogic.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex)) {
    124           e.Cancel = true;
    125           dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
     130        if (Content != null){
     131          if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered()) {
     132            errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
     133          } else {
     134            Content.DataGridLogic.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex);
     135          }
     136
     137          if (!String.IsNullOrEmpty(errorMessage)) {
     138            e.Cancel = true;
     139            dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
     140          }
    126141        }
    127142      }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/FilterView.cs

    r10877 r10900  
    9393          filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
    9494        }
    95         UpdateFilterInfo();
    9695      }
    9796    }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataGridContent.cs

    r10809 r10900  
    123123    }
    124124
    125     public bool Validate(string value, out string errorMessage, int columnIndex) {
    126       return dataGridLogic.Validate(value, out errorMessage, columnIndex);
    127     }
    128 
    129125    public string GetValue(int rowIndex, int columnIndex) {
    130126      return dataGridLogic.GetValue(columnIndex, rowIndex);
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataGridLogic.cs

    r10804 r10900  
    6969        throw new ArgumentOutOfRangeException("column index is out of range");
    7070      }
     71
    7172      bool valid = false;
     73      errorMessage = string.Empty;
    7274      if (preprocessingData.IsType<double>(columnIndex)) {
    7375        double val;
    7476        valid = double.TryParse(value, out val);
    75         errorMessage = string.Empty;
    7677        if (!valid) {
    7778          errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")";
     
    7980      } else if (preprocessingData.IsType<string>(columnIndex)) {
    8081        valid = value != null;
    81         errorMessage = string.Empty;
    8282        if (!valid) {
    8383          errorMessage = "Invalid Value (string must not be null)";
     
    8686        DateTime date;
    8787        valid = DateTime.TryParse(value, out date);
    88         errorMessage = string.Empty;
    8988        if (!valid) {
    9089          errorMessage = "Invalid Value (Valid Value Format: \"" + CultureInfo.CurrentCulture.DateTimeFormat + "\"";
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/FilterLogic.cs

    r10849 r10900  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3738
    3839      if (activeFilters.Count == 0) {
    39         return new bool[preprocessingData.Rows];
     40        return CreateBoolArray(preprocessingData.Rows, false);
    4041      }
     42      return GetActiveFilterResult(activeFilters, isAndCombination);
     43    }
    4144
     45    private bool[] GetActiveFilterResult(IList<IFilter> activeFilters, bool isAndCombination) {
    4246      bool[] result = CreateBoolArray(preprocessingData.Rows, !isAndCombination);
    4347
     
    5256
    5357    public bool[] Preview(IList<IFilter> filters, bool isAndCombination) {
    54       var result = GetFilterResult(filters, isAndCombination);
    55       preprocessingData.SetFilter(result);
    56       return result;
     58      IList<IFilter> activeFilters = filters.Where(f => f.Active && f.ConstraintData != null).ToList<IFilter>();
     59      if (activeFilters.Count > 0) {
     60        var result = GetActiveFilterResult(activeFilters, isAndCombination);
     61        preprocessingData.SetFilter(result);
     62        return result;
     63      } else {
     64        return CreateBoolArray(preprocessingData.Rows, false);
     65      }
    5766    }
    5867
     
    7483    }
    7584
     85    public bool IsFiltered() {
     86      return preprocessingData.IsFiltered;
     87    }
     88
    7689    public IPreprocessingData PreprocessingData {
    7790      get { return preprocessingData; }
    7891    }
     92
     93    public event EventHandler FilterChanged {
     94      add { preprocessingData.FilterChanged += value; }
     95      remove { preprocessingData.FilterChanged -= value; }
     96    }
    7997  }
    8098}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/FilteredPreprocessingData.cs

    r10847 r10900  
    118118        }
    119119      }
     120
     121      OnFilterChanged();
    120122    }
    121123
    122124    public void PersistFilter() {
    123       originalData = (ITransactionalPreprocessingData)filteredData.Clone();
     125      originalData.InTransaction(() => {
     126        for (int i = 0; i < filteredData.Columns; ++i) {
     127          if (filteredData.IsType<double>(i)) {
     128            originalData.SetValues<double>(i, filteredData.GetValues<double>(i));
     129          } else if (filteredData.IsType<string>(i)) {
     130            originalData.SetValues<string>(i, filteredData.GetValues<string>(i));
     131          } else if (filteredData.IsType<DateTime>(i)) {
     132            originalData.SetValues<DateTime>(i, filteredData.GetValues<DateTime>(i));
     133          } else {
     134            throw new ArgumentException("Data types of columns do not match");
     135          }
     136        }
     137      });
    124138      ResetFilter();
    125139    }
     
    127141    public void ResetFilter() {
    128142      filteredData = null;
     143      OnFilterChanged();
     144    }
     145
     146    private void OnFilterChanged() {
     147      if (FilterChanged != null) {
     148        FilterChanged(this, new EventArgs());
     149      }
    129150    }
    130151
     
    171192    }
    172193
     194    public event EventHandler FilterChanged;
     195
    173196    #region IPreprocessingData Members
    174197
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IFilterLogic.cs

    r10844 r10900  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.DataPreprocessing.Filter;
     
    2526  public interface IFilterLogic {
    2627    bool[] GetFilterResult(IList<IFilter> filters, bool isAndCombination);
     28    /// <summary>
     29    /// Return an array which indicates whether the corresponding row should be filtered (true) or kept (false)
     30    /// </summary>
     31    /// <param name="filters"></param>
     32    /// <param name="isAndCombination"></param>
     33    /// <returns></returns>
    2734    bool[] Preview(IList<IFilter> filters, bool isAndCombination);
    2835    void Apply(IList<IFilter> filters, bool isAndCombination);
    2936    IPreprocessingData PreprocessingData { get; }
    3037    void Reset();
     38    bool IsFiltered();
     39
     40    event EventHandler FilterChanged;
    3141  }
    3242}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IFilteredPreprocessingData.cs

    r10783 r10900  
    1111    void PersistFilter();
    1212    void ResetFilter();
     13    bool IsFiltered { get; }
     14
     15    event EventHandler FilterChanged;
    1316   }
    1417}
Note: See TracChangeset for help on using the changeset viewer.