Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.DataPreprocessing.Views/3.4/TransformationView.cs @ 16755

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

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

File size: 3.6 KB
RevLine 
[10539]1#region License Information
2/* HeuristicLab
[15584]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10539]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
[10786]22using System;
[10902]23using System.Linq;
[10814]24using System.Windows.Forms;
[10303]25using HeuristicLab.MainForm;
[10712]26using HeuristicLab.MainForm.WindowsForms;
[11068]27using HeuristicLab.Problems.DataAnalysis;
[10303]28
29namespace HeuristicLab.DataPreprocessing.Views {
30  [View("Transformation View")]
[10712]31  [Content(typeof(TransformationContent), true)]
32  public partial class TransformationView : AsynchronousContentView {
[11068]33    public new TransformationContent Content {
[10998]34      get { return (TransformationContent)base.Content; }
35      set { base.Content = value; }
36    }
37
[10303]38    public TransformationView() {
39      InitializeComponent();
40    }
41
[10772]42    protected override void OnContentChanged() {
43      base.OnContentChanged();
44      if (Content == null) {
[10902]45        transformationListView.Content = null;
[10772]46      } else {
[10902]47        transformationListView.Content = Content.CheckedTransformationList;
[10977]48        CheckFilters();
[10772]49      }
50    }
[10786]51
[10977]52    protected override void RegisterContentEvents() {
[15535]53      Content.PreprocessingData.FilterChanged += FilterLogic_FilterChanged;
[10977]54    }
55
56    protected override void DeregisterContentEvents() {
[15535]57      Content.PreprocessingData.FilterChanged -= FilterLogic_FilterChanged;
[10977]58    }
59
60    void FilterLogic_FilterChanged(object sender, EventArgs e) {
61      if (Content != null) {
62        CheckFilters();
63      }
64    }
65
66    private void CheckFilters() {
[15535]67      if (Content.PreprocessingData.IsFiltered) {
[10977]68        applyButton.Enabled = false;
69        lblFilterNotice.Visible = true;
70      } else {
71        applyButton.Enabled = true;
72        lblFilterNotice.Visible = false;
73      }
74    }
75
[10786]76    private void applyButton_Click(object sender, EventArgs e) {
[10902]77      var transformations = Content.CheckedTransformationList.CheckedItems.Select(x => x.Value);
[10786]78
[10945]79      if (transformations.Any(x => ((Transformation)x).ColumnParameter.Value == null)) {
80        MessageBox.Show(this, "Parameter \"Column\" of a selected Transformation is not set.", "Applying Transformations...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
81        return;
82      }
83
[15535]84      var transformator = new PreprocessingTransformator(Content.PreprocessingData);
[10948]85      bool preserve = preserveColumnsCheckbox.CheckState == CheckState.Checked;
[10819]86      string errorMsg;
[10948]87      bool success = transformator.ApplyTransformations(transformations, preserve, out errorMsg);
[10786]88      if (success) {
[10902]89        Content.CheckedTransformationList.Clear();
[10814]90        MessageBox.Show(this, "Transformations applied.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
[10819]91      } else {
92        MessageBox.Show(this,
93          "Error in Transformation.\nValue is copied when transformion of cell failed.\n" + errorMsg,
94          "Transformation failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
[10786]95      }
96    }
[10303]97  }
98}
Note: See TracBrowser for help on using the repository browser.