Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/21/14 13:42:43 (10 years ago)
Author:
psteiner
Message:

Filters stored in Content
Preparation DataCompletenessChart

File:
1 edited

Legend:

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

    r10849 r10877  
    2020      tbFiltered.Text = "0";
    2121      tbPercentage.Text = "0%";
    22       checkedFilterView.Content = new CheckedItemCollection<IFilter>();
    23       checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
    24       checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
    25       checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
     22    }
     23
     24    private void InitData()
     25    {
     26        checkedFilterView.Content = Content.Filters;
     27        checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
     28        checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
     29        checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
    2630    }
    2731
     
    3640      if (Content != null)
    3741      {
    38         ImportFiltersFromContent();
     42        InitData();
    3943        UpdateFilterInfo();
    4044      }
     
    4246
    4347    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
    44      
    45       foreach (IFilter filter in e.Items)
     48      if (Content != null)
    4649      {
    47         filter.Active = checkedFilterView.Content.ItemChecked(filter);
     50        foreach (IFilter filter in e.Items)
     51        {
     52          filter.Active = checkedFilterView.Content.ItemChecked(filter);
     53        }
     54        UpdateFilterInfo();
    4855      }
    49       UpdateFilterInfo();
    50       ExportFiltersToContent();
    51       Refresh();
    52       ResumeRepaint(true);
    5356    }
    5457
    5558    private void UpdateFilterInfo() {
    56       List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
     59        //List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
     60        List<IFilter> filters = Content.Filters.ToList();
    5761
    58       int activeFilters = filters.Count(c => c.Active);
     62        int activeFilters = filters.Count(c => c.Active);
    5963
    60       applyFilterButton.Enabled = (activeFilters > 0);
    61       rBtnAnd.Enabled = (activeFilters > 0);
    62       rBtnOr.Enabled = (activeFilters > 0);
    63       btnReset.Enabled = (activeFilters > 0);
    64       Content.FilterLogic.Reset();
    65       bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
    66      
    67       int filteredCnt = result.Count(c => c);
    68  
    69       tbFiltered.Text = filteredCnt.ToString();
    70       double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / result.Length;
    71       tbPercentage.Text = percentage.ToString() + "%";
    72       tbTotal.Text = result.Length.ToString();
     64        applyFilterButton.Enabled = (activeFilters > 0);
     65        rBtnAnd.Enabled = (activeFilters > 0);
     66        rBtnOr.Enabled = (activeFilters > 0);
     67        btnReset.Enabled = (activeFilters > 0);
     68        Content.FilterLogic.Reset();
     69        bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
     70
     71        int filteredCnt = result.Count(c => c);
     72
     73        tbFiltered.Text = filteredCnt.ToString();
     74        double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / result.Length;
     75        tbPercentage.Text = percentage.ToString() + "%";
     76        tbTotal.Text = result.Length.ToString();
    7377    }
    7478
    7579    private void applyFilterButton_Click(object sender, EventArgs e) {
    76       List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
    77       Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
     80      if (Content != null)
     81      {
     82        List<IFilter> filters = Content.Filters.ToList();
     83        Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
     84      }
    7885    }
    7986
    8087    //whenever a new filter is added the preprocessing data is set to the filter
    8188    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
    82       foreach (IFilter filter in e.Items) {
    83         filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
     89      if (Content != null)
     90      {
     91        foreach (IFilter filter in e.Items)
     92        {
     93          filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
     94        }
     95        UpdateFilterInfo();
    8496      }
    85       UpdateFilterInfo();
    86       ExportFiltersToContent();
    8797    }
    8898
    8999    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
    90       UpdateFilterInfo();
    91       ExportFiltersToContent();
     100      if (Content != null)
     101      {
     102        UpdateFilterInfo();
     103      }
    92104    }
    93105
    94106    private void rBtnAnd_CheckedChanged(object sender, EventArgs e)
    95107    {
    96       UpdateFilterInfo();
    97       ExportFiltersToContent();
    98       Content.isAndCombination = rBtnAnd.Checked;
     108      if (Content != null)
     109      {
     110        UpdateFilterInfo();
     111        Content.isAndCombination = rBtnAnd.Checked;
     112      }
    99113    }
    100114
    101115    private void btnReset_Click(object sender, EventArgs e)
    102116    {
    103       Content.FilterLogic.Reset();
    104     }
    105 
    106     private void ImportFiltersFromContent()
    107     {
    108       checkedFilterView.ItemCollection.AddRange(Content.Filters);
    109 
    110       foreach (IFilter filter in checkedFilterView.ItemCollection) {
    111         if (filter.Active)
    112         {
    113           checkedFilterView.Content.SetItemCheckedState(filter, true);
    114         }
    115         else
    116         {
    117           checkedFilterView.Content.SetItemCheckedState(filter, false);
    118         }
    119         rBtnAnd.Checked = Content.isAndCombination;
    120         rBtnOr.Checked = !Content.isAndCombination;
     117      if (Content != null)
     118      {
     119        Content.FilterLogic.Reset();
    121120      }
    122121    }
    123122
    124     private void ExportFiltersToContent()
    125     {
    126       Content.Filters = checkedFilterView.ItemCollection.ToList<IFilter>();
    127     }
    128123  }
    129124}
Note: See TracChangeset for help on using the changeset viewer.