Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

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