Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs @ 15914

Last change on this file since 15914 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 4.8 KB
RevLine 
[14075]1#region License Information
2/* HeuristicLab
[15584]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[14075]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.Linq;
[10712]24using HeuristicLab.Collections;
[10589]25using HeuristicLab.Core.Views;
[10712]26using HeuristicLab.DataPreprocessing.Filter;
[10589]27using HeuristicLab.MainForm;
28
[10712]29namespace HeuristicLab.DataPreprocessing.Views {
[10589]30  [View("CheckedFilterCollection View")]
[10712]31  [Content(typeof(FilterContent), true)]
32  public partial class FilterView : ItemView {
[15242]33    public new FilterContent Content {
34      get { return (FilterContent)base.Content; }
35      set { base.Content = value; }
36    }
[10589]37
[10712]38    public FilterView() {
[10589]39      InitializeComponent();
[10637]40      tbTotal.Text = "0";
[11044]41      tbRemaining.Text = "0";
[10637]42      tbPercentage.Text = "0%";
[10589]43    }
44
[14075]45    protected override void OnContentChanged() {
[10813]46      base.OnContentChanged();
[14075]47      if (Content != null) {
[15535]48        checkedFilterView.Content = Content.Filters;
49        rBtnAnd.Checked = Content.IsAndCombination;
50        rBtnOr.Checked = !Content.IsAndCombination;
51        UpdateFilter();
52      } else {
53        checkedFilterView.Content = null;
[10813]54      }
55    }
[15535]56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.Filters.ItemsAdded += Content_ItemsAdded;
59      Content.Filters.ItemsRemoved += Content_ItemsRemoved;
60      Content.Filters.CheckedItemsChanged += Content_CheckedItemsChanged;
[10693]61    }
[15535]62    protected override void DeregisterContentEvents() {
63      Content.Filters.ItemsAdded -= Content_ItemsAdded;
64      Content.Filters.ItemsRemoved -= Content_ItemsRemoved;
65      Content.Filters.CheckedItemsChanged -= Content_CheckedItemsChanged;
66      base.DeregisterContentEvents();
67    }
[10693]68
[15535]69    private void UpdateFilter() {
70      bool activeFilters = Content.ActiveFilters.Any();
71      applyFilterButton.Enabled = activeFilters;
[10877]72
[15535]73      Content.PreprocessingData.ResetFilter();
[10877]74
[15535]75      int numTotal = Content.PreprocessingData.Rows;
76      int numRemaining = numTotal;
[10589]77
[15535]78      if (activeFilters) {
79        var remainingRows = Content.GetRemainingRows();
80        numRemaining = remainingRows.Count(x => x);
81
82        if (numRemaining < numTotal) {
83          Content.PreprocessingData.SetFilter(remainingRows);
[10933]84        }
[10877]85      }
[15535]86
87      tbRemaining.Text = numRemaining.ToString();
88      double ratio = numTotal > 0 ? numRemaining / (double)numTotal : 0.0;
89      tbPercentage.Text = ratio.ToString("P4");
90      tbTotal.Text = numTotal.ToString();
[10589]91    }
92
[15535]93
94    #region Content Events
[10637]95    //whenever a new filter is added the preprocessing data is set to the filter
[10712]96    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
[14075]97      if (Content != null) {
98        foreach (IFilter filter in e.Items) {
[15535]99          filter.ConstrainedValue = Content.PreprocessingData;
[10877]100        }
[10637]101      }
102    }
[10712]103    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
[14075]104      if (Content != null) {
[15535]105        UpdateFilter();
[10877]106      }
[10693]107    }
[15535]108    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
109      if (Content != null) {
110        foreach (IFilter filter in e.Items) {
111          filter.Active = checkedFilterView.Content.ItemChecked(filter);
112        }
113        UpdateFilter();
114      }
115    }
116    #endregion
[10693]117
[15535]118    #region Controls Events
[14075]119    private void rBtnAnd_CheckedChanged(object sender, EventArgs e) {
120      if (Content != null) {
[11002]121        Content.IsAndCombination = rBtnAnd.Checked;
[15535]122        UpdateFilter();
[10877]123      }
[10785]124    }
[15535]125    private void applyFilterButton_Click(object sender, EventArgs e) {
126      if (Content != null) {
127        //apply filters
128        Content.PreprocessingData.PersistFilter();
129        Content.PreprocessingData.ResetFilter();
130        //deactivate checked filters
131        foreach (var filter in Content.Filters.CheckedItems.ToList()) {
132          checkedFilterView.Content.SetItemCheckedState(filter, false);
133          filter.Active = false;
134        }
135        UpdateFilter();
136      }
137    }
138    #endregion
[10589]139  }
140}
Note: See TracBrowser for help on using the repository browser.