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

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

FilterView + Design

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