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