source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/TransformationView.cs @ 10998

Last change on this file since 10998 was 10998, checked in by psteiner, 8 years ago

Formatting Sourcecode Views

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Transformations;
28
29namespace HeuristicLab.DataPreprocessing.Views {
30
31  [View("Transformation View")]
32  [Content(typeof(TransformationContent), true)]
33  public partial class TransformationView : AsynchronousContentView {
34
35    public new TransformationContent Content
36    {
37      get { return (TransformationContent)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public TransformationView() {
42      InitializeComponent();
43    }
44
45    protected override void OnContentChanged() {
46      base.OnContentChanged();
47      if (Content == null) {
48        transformationListView.Content = null;
49      } else {
50        transformationListView.Content = Content.CheckedTransformationList;
51        CheckFilters();
52      }
53    }
54
55    /// <summary>
56    /// Adds eventhandlers to the current instance.
57    /// </summary>
58    protected override void RegisterContentEvents() {
59      Content.FilterLogic.FilterChanged += FilterLogic_FilterChanged;
60    }
61
62    /// <summary>
63    /// Removes the eventhandlers from the current instance.
64    /// </summary>
65    protected override void DeregisterContentEvents() {
66      Content.FilterLogic.FilterChanged -= FilterLogic_FilterChanged;
67    }
68
69    void FilterLogic_FilterChanged(object sender, EventArgs e) {
70      if (Content != null) {
71        CheckFilters();
72      }
73    }
74
75    private void CheckFilters() {
76      if (Content.FilterLogic.IsFiltered) {
77        applyButton.Enabled = false;
78        lblFilterNotice.Visible = true;
79      } else {
80        applyButton.Enabled = true;
81        lblFilterNotice.Visible = false;
82      }
83    }
84
85    private void applyButton_Click(object sender, EventArgs e) {
86      var transformations = Content.CheckedTransformationList.CheckedItems.Select(x => x.Value);
87
88      if (transformations.Any(x => ((Transformation)x).ColumnParameter.Value == null)) {
89        MessageBox.Show(this, "Parameter \"Column\" of a selected Transformation is not set.", "Applying Transformations...", MessageBoxButtons.OK, MessageBoxIcon.Warning);
90        return;
91      }
92
93      var transformator = new PreprocessingTransformator(Content.Data);
94      bool preserve = preserveColumnsCheckbox.CheckState == CheckState.Checked;
95      string errorMsg;
96      bool success = transformator.ApplyTransformations(transformations, preserve, out errorMsg);
97      if (success) {
98        Content.CheckedTransformationList.Clear();
99        MessageBox.Show(this, "Transformations applied.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
100      } else {
101        MessageBox.Show(this,
102          "Error in Transformation.\nValue is copied when transformion of cell failed.\n" + errorMsg,
103          "Transformation failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
104      }
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.