Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs @ 14996

Last change on this file since 14996 was 14996, checked in by pfleck, 7 years ago

#2709

  • Fixed initial selection of the grouping text box (empty string instead of null to select the first entry).
  • General code fixes (removed unnessecary bank lines and code, class member order, ...)
File size: 4.3 KB
RevLine 
[13502]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13502]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
[10589]23using System.Collections.Generic;
24using System.Linq;
[10712]25using HeuristicLab.Collections;
[10589]26using HeuristicLab.Core.Views;
[10712]27using HeuristicLab.DataPreprocessing.Filter;
[10589]28using HeuristicLab.MainForm;
29
[10712]30namespace HeuristicLab.DataPreprocessing.Views {
[10589]31  [View("CheckedFilterCollection View")]
[10712]32  [Content(typeof(FilterContent), true)]
33  public partial class FilterView : ItemView {
[14996]34    public new FilterContent Content {
35      get { return (FilterContent)base.Content; }
36      set { base.Content = value; }
37    }
[10589]38
[10712]39    public FilterView() {
[10589]40      InitializeComponent();
[10637]41      tbTotal.Text = "0";
[11044]42      tbRemaining.Text = "0";
[10637]43      tbPercentage.Text = "0%";
[10589]44    }
45
[13502]46    private void InitData() {
47      checkedFilterView.Content = Content.Filters;
48      checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
49      checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
50      checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
[10877]51    }
52
[13502]53    protected override void OnContentChanged() {
[10813]54      base.OnContentChanged();
[13502]55      if (Content != null) {
[10877]56        InitData();
[10813]57        UpdateFilterInfo();
58      }
59    }
60
[10712]61    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
[13502]62      if (Content != null) {
63        foreach (IFilter filter in e.Items) {
[10877]64          filter.Active = checkedFilterView.Content.ItemChecked(filter);
65        }
66        UpdateFilterInfo();
[10637]67      }
[10693]68    }
69
[10712]70    private void UpdateFilterInfo() {
[13502]71      List<IFilter> filters = Content.Filters.ToList();
72      int activeFilters = filters.Count(c => c.Active);
73      applyFilterButton.Enabled = (activeFilters > 0);
74      rBtnAnd.Enabled = (activeFilters > 0);
75      rBtnOr.Enabled = (activeFilters > 0);
76      Content.FilterLogic.Reset();
77      bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
[10877]78
[13502]79      int filteredCnt = result.Count(c => !c);
[10877]80
[13502]81      tbRemaining.Text = filteredCnt.ToString();
82      double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / (double)result.Length;
83      tbPercentage.Text = String.Format("{0:0.0000}%", percentage);
84      tbTotal.Text = result.Length.ToString();
[10589]85    }
86
[10712]87    private void applyFilterButton_Click(object sender, EventArgs e) {
[13502]88      if (Content != null) {
[10877]89        List<IFilter> filters = Content.Filters.ToList();
[10933]90        //apply filters
[10877]91        Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
[10933]92        //deactivate checked filters
93        filters = checkedFilterView.Content.CheckedItems.ToList();
[13502]94        foreach (IFilter filter in filters) {
[10933]95          checkedFilterView.Content.SetItemCheckedState(filter, false);
96          filter.Active = false;
97        }
98        UpdateFilterInfo();
[10877]99      }
[10589]100    }
101
[10637]102    //whenever a new filter is added the preprocessing data is set to the filter
[10712]103    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
[13502]104      if (Content != null) {
105        foreach (IFilter filter in e.Items) {
[10877]106          filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
107        }
[10637]108      }
109    }
110
[10712]111    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
[13502]112      if (Content != null) {
[10877]113        UpdateFilterInfo();
114      }
[10693]115    }
116
[13502]117    private void rBtnAnd_CheckedChanged(object sender, EventArgs e) {
118      if (Content != null) {
[10877]119        UpdateFilterInfo();
[11002]120        Content.IsAndCombination = rBtnAnd.Checked;
[10877]121      }
[10785]122    }
[10589]123  }
124}
Note: See TracBrowser for help on using the repository browser.