1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.Core.Views;
|
---|
10 | using HeuristicLab.MainForm;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 | using HeuristicLab.DataPreprocessing.Filter;
|
---|
13 | using HeuristicLab.Collections;
|
---|
14 | using HeuristicLab.Data;
|
---|
15 |
|
---|
16 | namespace HeuristicLab.DataPreprocessing.Views
|
---|
17 | {
|
---|
18 | [View("CheckedFilterCollection View")]
|
---|
19 | [Content(typeof(FilterContent), false)]
|
---|
20 | public partial class FilterView : ItemView
|
---|
21 | {
|
---|
22 | private CheckedItemCollectionView<IFilter> filterView;
|
---|
23 |
|
---|
24 | public FilterView()
|
---|
25 | {
|
---|
26 | InitializeComponent();
|
---|
27 | tbTotal.Text = "0";
|
---|
28 | tbFiltered.Text = "0";
|
---|
29 | tbPercentage.Text = "0%";
|
---|
30 | filterView = new CheckedItemCollectionView<IFilter>();
|
---|
31 | filterView.Dock = DockStyle.Fill;
|
---|
32 | filterView.Content = new CheckedItemCollection<IFilter>();
|
---|
33 | filterView.Content.ItemsAdded += Content_ItemsAdded;
|
---|
34 | filterView.Content.ItemsRemoved += Content_ItemsRemoved;
|
---|
35 | filterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
|
---|
36 | groupBoxFilter.Controls.Add(filterView);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public new FilterContent Content
|
---|
40 | {
|
---|
41 | get { return (FilterContent)base.Content; }
|
---|
42 | set { base.Content = value;}
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e)
|
---|
46 | {
|
---|
47 |
|
---|
48 | foreach (IFilter filter in e.Items)
|
---|
49 | {
|
---|
50 | if (filterView.Content.CheckedItems.Contains(filter) && (filter.ConstraintData == null || string.IsNullOrEmpty(((StringValue)filter.ConstraintData).Value)) )
|
---|
51 | {
|
---|
52 | filter.ConstraintData = new StringValue("0");
|
---|
53 | }
|
---|
54 | filter.Active = !filter.Active;
|
---|
55 | }
|
---|
56 | UpdateFilterInfo();
|
---|
57 | Refresh();
|
---|
58 | ResumeRepaint(true);
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void UpdateFilterInfo()
|
---|
62 | {
|
---|
63 | List<IFilter> filters = filterView.ItemCollection.ToList<IFilter>();
|
---|
64 |
|
---|
65 | int activeFilters = filters.Count(c => c.Active);
|
---|
66 |
|
---|
67 | applyFilterButton.Enabled = (activeFilters > 0);
|
---|
68 |
|
---|
69 | bool[] result = Content.FilterLogic.Preview(filters);
|
---|
70 |
|
---|
71 | int filteredCnt = result.Count(c => !c);
|
---|
72 |
|
---|
73 | tbFiltered.Text = filteredCnt.ToString();
|
---|
74 | double percentage = 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 | {
|
---|
81 | List<IFilter> filters = filterView.ItemCollection.ToList<IFilter>();
|
---|
82 | Content.FilterLogic.Apply(filters);
|
---|
83 | }
|
---|
84 |
|
---|
85 | //whenever a new filter is added the preprocessing data is set to the filter
|
---|
86 | private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e)
|
---|
87 | {
|
---|
88 | foreach (IFilter filter in e.Items)
|
---|
89 | {
|
---|
90 | filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
|
---|
91 | filter.Active = true;
|
---|
92 | filterView.Content.SetItemCheckedState(filter, false);
|
---|
93 | }
|
---|
94 | UpdateFilterInfo();
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e)
|
---|
98 | {
|
---|
99 | UpdateFilterInfo();
|
---|
100 | }
|
---|
101 |
|
---|
102 | }
|
---|
103 | }
|
---|