source: trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/DataPreprocessingView.cs @ 13507

Last change on this file since 13507 was 13507, checked in by pfleck, 6 years ago

#2559

  • Enabled different export types for preprocessing.
  • Hid unused buttons in ViewShortcutListView.
  • Made data preprocessing a NamedItem to allow naming.
File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Collections.Generic;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Core.Views;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.DataPreprocessing.Views {
32  [View("DataPreprocessing View")]
33  [Content(typeof(PreprocessingContext), true)]
34  public partial class DataPreprocessingView : NamedItemView {
35
36    public DataPreprocessingView() {
37      InitializeComponent();
38    }
39
40    public new PreprocessingContext Content {
41      get { return (PreprocessingContext)base.Content; }
42      set { base.Content = value; }
43    }
44
45    protected override void OnContentChanged() {
46      base.OnContentChanged();
47      if (Content != null) {
48        var data = Content.Data;
49        var filterLogic = new FilterLogic(data);
50        var searchLogic = new SearchLogic(data, filterLogic);
51        var statisticsLogic = new StatisticsLogic(data, searchLogic);
52        var manipulationLogic = new ManipulationLogic(data, searchLogic, statisticsLogic);
53
54        var viewShortcuts = new ItemList<IViewShortcut> {
55          new DataGridContent(data, manipulationLogic, filterLogic),
56          new StatisticsContent(statisticsLogic),
57
58          new LineChartContent(data),
59          new HistogramContent(data),
60          new ScatterPlotContent(data),
61          new CorrelationMatrixContent(Content),
62          new DataCompletenessChartContent(searchLogic),
63
64          new FilterContent(filterLogic),
65          new ManipulationContent(manipulationLogic, searchLogic, filterLogic),
66          new TransformationContent(data, filterLogic)
67        };
68
69        viewShortcutListView.Content = viewShortcuts.AsReadOnly();
70
71        viewShortcutListView.ItemsListView.Items[0].Selected = true;
72        viewShortcutListView.Select();
73
74        applyComboBox.Items.Clear();
75        applyComboBox.DataSource = Content.ExportPossibilities.ToList();
76        applyComboBox.DisplayMember = "Key";
77        if (applyComboBox.Items.Count > 0)
78          applyComboBox.SelectedIndex = 0;
79      } else {
80        viewShortcutListView.Content = null;
81      }
82    }
83
84    protected override void RegisterContentEvents() {
85      base.RegisterContentEvents();
86      Content.Data.FilterChanged += Data_FilterChanged;
87    }
88
89    protected override void DeregisterContentEvents() {
90      base.DeregisterContentEvents();
91      Content.Data.FilterChanged -= Data_FilterChanged;
92    }
93
94    void Data_FilterChanged(object sender, EventArgs e) {
95      lblFilterActive.Visible = Content.Data.IsFiltered;
96    }
97
98    protected override void SetEnabledStateOfControls() {
99      base.SetEnabledStateOfControls();
100      viewShortcutListView.Enabled = Content != null;
101      applyInNewTabButton.Enabled = Content != null;
102      exportProblemButton.Enabled = Content != null && Content.CanExport;
103      undoButton.Enabled = Content != null;
104    }
105
106    private void exportProblemButton_Click(object sender, EventArgs e) {
107      var exportOption = (KeyValuePair<string, Func<IItem>>)applyComboBox.SelectedItem;
108      var exportItem = exportOption.Value();
109
110      var saveFileDialog = new SaveFileDialog {
111        Title = "Save Item",
112        DefaultExt = "hl",
113        Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*",
114        FilterIndex = 2
115      };
116
117      var content = exportItem as IStorableContent;
118      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
119        bool compressed = saveFileDialog.FilterIndex != 1;
120        ContentManager.Save(content, saveFileDialog.FileName, compressed);
121      }
122    }
123
124    private void applyInNewTabButton_Click(object sender, EventArgs e) {
125      var exportOption = (KeyValuePair<string, Func<IItem>>)applyComboBox.SelectedItem;
126      var exportItem = exportOption.Value();
127
128      MainFormManager.MainForm.ShowContent(exportItem);
129    }
130
131    private void undoButton_Click(object sender, EventArgs e) {
132      Content.Data.Undo();
133    }
134  }
135}
Note: See TracBrowser for help on using the repository browser.