Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10311 was 10310, checked in by tsteinre, 11 years ago
  • Created PreprocessingCloner
  • Implemented Export Problem Logic
File size: 5.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Windows.Forms;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Core.Views;
7using HeuristicLab.MainForm;
8
9namespace HeuristicLab.DataPreprocessing {
10  [View("DataPreprocessing View")]
11  [Content(typeof(PreprocessingContext), true)]
12  public partial class DataPreprocessingView : ItemView {
13
14    private DataGridContent dataGridContent;
15    private StatisticsContent statisticsContent;
16    private FilterContent filterContent;
17    private TransformationContent tranformationContent;
18    private LineChartContent lineChartContent;
19    private HistogramContent histogramContent;
20
21    private Dictionary<ListViewItem, IItem> listViewItemItemMapping;
22
23    public DataPreprocessingView() {
24      InitializeComponent();
25    }
26
27    protected override void OnContentChanged() {
28      base.OnContentChanged();
29      InitializeContents();
30    }
31
32    private ListViewItem CreateListViewItem(IItem item) {
33      ListViewItem listViewItem = new ListViewItem();
34
35      listViewItem.Text = item.ToString();
36      //listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
37      //itemsListView.SmallImageList.Images.Add(content.);
38      //listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
39      //listViewItem.Tag = item;
40      return listViewItem;
41    }
42
43    private void InitializeContents() {
44      IPreprocessingData data = Content.Data;
45      ISearchLogic searchLogic = new SearchLogic(data);
46      dataGridContent = new DataGridContent(new DataGridLogic(data), new PreprocessingDataManipulation(data, searchLogic, new StatisticsLogic(data, searchLogic)));
47      statisticsContent = new StatisticsContent(new StatisticsLogic(data, searchLogic));
48      filterContent = new FilterContent(new FilterLogic());
49      tranformationContent = new TransformationContent(new TransformationLogic());
50      lineChartContent = new LineChartContent(new LineChartLogic());
51      histogramContent = new HistogramContent(new HistogramLogic());
52
53      listViewItemItemMapping = new Dictionary<ListViewItem, IItem>();
54      ListViewItem contentListViewItem = CreateListViewItem(dataGridContent);
55      listViewItemItemMapping[contentListViewItem] = dataGridContent;
56
57      ListViewItem statisticsListViewItem = CreateListViewItem(statisticsContent);
58      listViewItemItemMapping[statisticsListViewItem] = statisticsContent;
59
60      ListViewItem filterListViewItem = CreateListViewItem(filterContent);
61      listViewItemItemMapping[filterListViewItem] = filterContent;
62
63      ListViewItem transformationListViewItem = CreateListViewItem(tranformationContent);
64      listViewItemItemMapping[transformationListViewItem] = tranformationContent;
65
66      ListViewItem lineChartListViewItem = CreateListViewItem(lineChartContent);
67      listViewItemItemMapping[lineChartListViewItem] = lineChartContent;
68
69      ListViewItem histogramListViewItem = CreateListViewItem(histogramContent);
70      listViewItemItemMapping[histogramListViewItem] = histogramContent;
71
72      contentListView.Items.Add(statisticsListViewItem);
73      contentListView.Items.Add(contentListViewItem);
74      contentListView.Items.Add(filterListViewItem);
75      contentListView.Items.Add(transformationListViewItem);
76      contentListView.Items.Add(lineChartListViewItem);
77      contentListView.Items.Add(histogramListViewItem);
78    }
79
80    public new PreprocessingContext Content {
81      get { return (PreprocessingContext)base.Content; }
82      set {
83        base.Content = value;
84      }
85    }
86
87    private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
88
89      if (contentListView.SelectedItems.Count > 0) {
90        ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0];
91        this.viewHost.Content = listViewItemItemMapping[listViewItem];
92      }
93    }
94
95    private void listView1_DoubleClick(object sender, EventArgs e) {
96      ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0];
97      MainFormManager.MainForm.ShowContent(listViewItemItemMapping[listViewItem]);
98    }
99
100    private void exportProblemButton_Click(object sender, EventArgs e) {
101      var cloner = new PreprocessingCloner(Content);
102      var alteredClone = cloner.GenerateAlteredClone(Content.Problem);
103
104      var saveFileDialog = new SaveFileDialog {
105        Title = "Save Item",
106        DefaultExt = "hl",
107        Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*",
108        FilterIndex = 2
109      };
110
111      var content = alteredClone as IStorableContent;
112      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
113        bool compressed = saveFileDialog.FilterIndex != 1;
114        ContentManager.Save(content, saveFileDialog.FileName, compressed);
115      }
116    }
117
118    private void applyInNewTabButton_Click(object sender, EventArgs e) {
119      IPreprocessingData data = Content.Data;
120
121      foreach (string variable in data.VariableNames) {
122        for (int j = 0; j < data.Rows; j++) {
123          // assume: all double
124          data.SetCell(variable, j, 1.0);
125        }
126      }
127      MessageBox.Show("Success, now cloning... ");
128
129      var cloner = new PreprocessingCloner(Content);
130      var item = cloner.GenerateAlteredClone(Content.ParentItem);
131
132      MainFormManager.MainForm.ShowContent(item);
133    }
134  }
135}
Note: See TracBrowser for help on using the repository browser.