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

Last change on this file since 10785 was 10785, checked in by psteiner, 8 years ago

filter or combination
filter control: checkedlistview

File size: 3.5 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    //private CheckedItemCollectionView<IFilter> filterView;
17
18    public FilterView() {
19      InitializeComponent();
20      tbTotal.Text = "0";
21      tbFiltered.Text = "0";
22      tbPercentage.Text = "0%";
23      checkedFilterView.Content = new CheckedItemCollection<IFilter>();
24      //filterView = new CheckedItemCollectionView<IFilter>();
25      //filterView = new CheckedFilterCollectionView();
26      /*filterView.Dock = DockStyle.Fill;
27      filterView.Content = new CheckedItemCollection<IFilter>();
28       * */
29      checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
30      checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
31      checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
32      //groupBoxFilter.Controls.Add(filterView);*/
33    }
34
35    public new FilterContent Content {
36      get { return (FilterContent)base.Content; }
37      set { base.Content = value; UpdateFilterInfo(); }
38    }
39
40    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
41     
42      foreach (IFilter filter in e.Items)
43      {
44        filter.Active = !filter.Active;
45      }
46      UpdateFilterInfo();
47      Refresh();
48      ResumeRepaint(true);
49    }
50
51    private void UpdateFilterInfo() {
52      List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
53
54      int activeFilters = filters.Count(c => c.Active);
55
56      applyFilterButton.Enabled = (activeFilters > 0);
57      rBtnAnd.Enabled = (activeFilters > 0);
58      rBtnOr.Enabled = (activeFilters > 0);
59      btnReset.Enabled = (activeFilters > 0);
60
61      bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
62     
63      int filteredCnt = result.Count(c => c);
64 
65      tbFiltered.Text = filteredCnt.ToString();
66      double percentage = filteredCnt * 100 / result.Length;
67      tbPercentage.Text = percentage.ToString() + "%";
68      tbTotal.Text = result.Length.ToString();
69    }
70
71    private void applyFilterButton_Click(object sender, EventArgs e) {
72      List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
73      Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
74    }
75
76    //whenever a new filter is added the preprocessing data is set to the filter
77    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
78      foreach (IFilter filter in e.Items) {
79        filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
80        filter.Active = true;
81        checkedFilterView.Content.SetItemCheckedState(filter, false);
82      }
83      UpdateFilterInfo();
84    }
85
86    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
87      UpdateFilterInfo();
88    }
89
90    private void rBtnAnd_CheckedChanged(object sender, EventArgs e)
91    {
92      UpdateFilterInfo();
93    }
94
95    private void btnReset_Click(object sender, EventArgs e)
96    {
97      Content.FilterLogic.Reset();
98    }
99
100  }
101}
Note: See TracBrowser for help on using the repository browser.