Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataPreprocessingView.cs @ 10586

Last change on this file since 10586 was 10586, checked in by tsteinre, 11 years ago
  • divided/refactored PreprocessingData into TransactionalPreprocessingData and preprocessingData
File size: 5.7 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.Windows.Forms;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.DataPreprocessing.Views {
30  [View("DataPreprocessing View")]
31  [Content(typeof(IPreprocessingContext), true)]
32  public partial class DataPreprocessingView : ItemView {
33
34    private DataGridContent dataGridContent;
35    private StatisticsContent statisticsContent;
36    private FilterContent filterContent;
37    private TransformationContent tranformationContent;
38    private LineChartContent lineChartContent;
39    private HistogramContent histogramContent;
40
41    public DataPreprocessingView() {
42      InitializeComponent();
43    }
44
45    protected override void OnContentChanged() {
46      base.OnContentChanged();
47      InitializeContents();
48    }
49
50    //Create list view item for content list view
51    private ListViewItem CreateListViewItem(IItem item) {
52      ListViewItem listViewItem = new ListViewItem();
53
54      listViewItem.Text = item.ToString();
55      listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
56      contentListView.SmallImageList.Images.Add(item.ItemImage);
57      listViewItem.ImageIndex = contentListView.SmallImageList.Images.Count - 1;
58      listViewItem.Tag = item;
59
60      return listViewItem;
61    }
62
63    private void InitializeContents() {
64
65      //create content items
66      ITransactionalPreprocessingData data = Content.Data;
67      ISearchLogic searchLogic = new SearchLogic(data);
68      var dataGridLogic = new DataGridLogic(data);
69      StatisticsLogic statisticsLogic = new StatisticsLogic(data, searchLogic);
70      dataGridContent = new DataGridContent(dataGridLogic, new ManipulationLogic(data, searchLogic, statisticsLogic));
71      statisticsContent = new StatisticsContent(statisticsLogic);
72      filterContent = new FilterContent(new FilterLogic());
73      tranformationContent = new TransformationContent(new TransformationLogic(data, searchLogic, statisticsLogic));
74      lineChartContent = new LineChartContent(new LineChartLogic(data));
75      histogramContent = new HistogramContent(new HistogramLogic(data));
76
77      //create view items
78      contentListView.SmallImageList = new ImageList();
79      ListViewItem contentListViewItem = CreateListViewItem(dataGridContent);
80      ListViewItem statisticsListViewItem = CreateListViewItem(statisticsContent);
81      ListViewItem filterListViewItem = CreateListViewItem(filterContent);
82      ListViewItem transformationListViewItem = CreateListViewItem(tranformationContent);
83      ListViewItem lineChartListViewItem = CreateListViewItem(lineChartContent);
84      ListViewItem histogramListViewItem = CreateListViewItem(histogramContent);
85
86      //add view items to content list view
87      contentListView.Items.Add(statisticsListViewItem);
88      contentListView.Items.Add(contentListViewItem);
89      contentListView.Items.Add(filterListViewItem);
90      contentListView.Items.Add(transformationListViewItem);
91      contentListView.Items.Add(lineChartListViewItem);
92      contentListView.Items.Add(histogramListViewItem);
93
94      //default view -> statistic view
95      contentListView.SelectedIndices.Add(0);
96    }
97
98    public new PreprocessingContext Content {
99      get { return (PreprocessingContext)base.Content; }
100      set {
101        base.Content = value;
102      }
103    }
104
105    private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
106
107      if (contentListView.SelectedItems.Count > 0) {
108        ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0];
109        this.viewHost.Content = (IItem)listViewItem.Tag;
110      }
111    }
112
113    private void listView1_DoubleClick(object sender, EventArgs e) {
114      if (contentListView.SelectedItems.Count > 0) {
115        ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0];
116        MainFormManager.MainForm.ShowContent((IItem)listViewItem.Tag);
117      }
118    }
119
120    private void exportProblemButton_Click(object sender, EventArgs e) {
121      var problem = Content.ExportProblem();
122
123      var saveFileDialog = new SaveFileDialog {
124        Title = "Save Item",
125        DefaultExt = "hl",
126        Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*",
127        FilterIndex = 2
128      };
129
130      var content = problem as IStorableContent;
131      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
132        bool compressed = saveFileDialog.FilterIndex != 1;
133        ContentManager.Save(content, saveFileDialog.FileName, compressed);
134      }
135    }
136
137    private void applyInNewTabButton_Click(object sender, EventArgs e) {
138      var item = Content.ExportAlgorithmOrProblem();
139
140      MainFormManager.MainForm.ShowContent(item);
141    }
142
143    private void undoButton_Click(object sender, EventArgs e) {
144      Content.Data.Undo();
145    }
146  }
147}
Note: See TracBrowser for help on using the repository browser.