Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/FilterView.cs @ 10877

Last change on this file since 10877 was 10877, checked in by psteiner, 10 years ago

Filters stored in Content
Preparation DataCompletenessChart

File size: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Windows.Forms;
5using HeuristicLab.Collections;
6using HeuristicLab.Core;
7using HeuristicLab.Core.Views;
8using HeuristicLab.Data;
9using HeuristicLab.DataPreprocessing.Filter;
10using HeuristicLab.MainForm;
11
12namespace HeuristicLab.DataPreprocessing.Views {
13  [View("CheckedFilterCollection View")]
14  [Content(typeof(FilterContent), true)]
15  public partial class FilterView : ItemView {
16
17    public FilterView() {
18      InitializeComponent();
19      tbTotal.Text = "0";
20      tbFiltered.Text = "0";
21      tbPercentage.Text = "0%";
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;
30    }
31
32    public new FilterContent Content {
33      get { return (FilterContent)base.Content; }
34      set { base.Content = value; }
35    }
36
37    protected override void OnContentChanged()
38    {
39      base.OnContentChanged();
40      if (Content != null)
41      {
42        InitData();
43        UpdateFilterInfo();
44      }
45    }
46
47    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
48      if (Content != null)
49      {
50        foreach (IFilter filter in e.Items)
51        {
52          filter.Active = checkedFilterView.Content.ItemChecked(filter);
53        }
54        UpdateFilterInfo();
55      }
56    }
57
58    private void UpdateFilterInfo() {
59        //List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
60        List<IFilter> filters = Content.Filters.ToList();
61
62        int activeFilters = filters.Count(c => c.Active);
63
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();
77    }
78
79    private void applyFilterButton_Click(object sender, EventArgs e) {
80      if (Content != null)
81      {
82        List<IFilter> filters = Content.Filters.ToList();
83        Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
84      }
85    }
86
87    //whenever a new filter is added the preprocessing data is set to the filter
88    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
89      if (Content != null)
90      {
91        foreach (IFilter filter in e.Items)
92        {
93          filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
94        }
95        UpdateFilterInfo();
96      }
97    }
98
99    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
100      if (Content != null)
101      {
102        UpdateFilterInfo();
103      }
104    }
105
106    private void rBtnAnd_CheckedChanged(object sender, EventArgs e)
107    {
108      if (Content != null)
109      {
110        UpdateFilterInfo();
111        Content.isAndCombination = rBtnAnd.Checked;
112      }
113    }
114
115    private void btnReset_Click(object sender, EventArgs e)
116    {
117      if (Content != null)
118      {
119        Content.FilterLogic.Reset();
120      }
121    }
122
123  }
124}
Note: See TracBrowser for help on using the repository browser.