using System; using System.Collections.Generic; using System.Windows.Forms; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; namespace HeuristicLab.DataPreprocessing { [View("DataPreprocessing View")] [Content(typeof(PreprocessingContext), true)] public partial class DataPreprocessingView : ItemView { private DataGridContent dataGridContent; private StatisticsContent statisticsContent; private FilterContent filterContent; private TransformationContent tranformationContent; private LineChartContent lineChartContent; private HistogramContent histogramContent; private Dictionary listViewItemItemMapping; public DataPreprocessingView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); InitializeContents(); } private ListViewItem CreateListViewItem(IItem item) { ListViewItem listViewItem = new ListViewItem(); listViewItem.Text = item.ToString(); //listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription; //itemsListView.SmallImageList.Images.Add(content.); //listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1; //listViewItem.Tag = item; return listViewItem; } private void InitializeContents() { IPreprocessingData data = Content.Data; ISearchLogic searchLogic = new SearchLogic(data); dataGridContent = new DataGridContent(new DataGridLogic(data), new PreprocessingDataManipulation(data, searchLogic, new StatisticsLogic(data, searchLogic))); statisticsContent = new StatisticsContent(new StatisticsLogic(data, searchLogic)); filterContent = new FilterContent(new FilterLogic()); tranformationContent = new TransformationContent(new TransformationLogic()); lineChartContent = new LineChartContent(new LineChartLogic()); histogramContent = new HistogramContent(new HistogramLogic()); listViewItemItemMapping = new Dictionary(); ListViewItem contentListViewItem = CreateListViewItem(dataGridContent); listViewItemItemMapping[contentListViewItem] = dataGridContent; ListViewItem statisticsListViewItem = CreateListViewItem(statisticsContent); listViewItemItemMapping[statisticsListViewItem] = statisticsContent; ListViewItem filterListViewItem = CreateListViewItem(filterContent); listViewItemItemMapping[filterListViewItem] = filterContent; ListViewItem transformationListViewItem = CreateListViewItem(tranformationContent); listViewItemItemMapping[transformationListViewItem] = tranformationContent; ListViewItem lineChartListViewItem = CreateListViewItem(lineChartContent); listViewItemItemMapping[lineChartListViewItem] = lineChartContent; ListViewItem histogramListViewItem = CreateListViewItem(histogramContent); listViewItemItemMapping[histogramListViewItem] = histogramContent; contentListView.Items.Add(statisticsListViewItem); contentListView.Items.Add(contentListViewItem); contentListView.Items.Add(filterListViewItem); contentListView.Items.Add(transformationListViewItem); contentListView.Items.Add(lineChartListViewItem); contentListView.Items.Add(histogramListViewItem); } public new PreprocessingContext Content { get { return (PreprocessingContext)base.Content; } set { base.Content = value; } } private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (contentListView.SelectedItems.Count > 0) { ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0]; this.viewHost.Content = listViewItemItemMapping[listViewItem]; } } private void listView1_DoubleClick(object sender, EventArgs e) { ListViewItem listViewItem = (ListViewItem)contentListView.SelectedItems[0]; MainFormManager.MainForm.ShowContent(listViewItemItemMapping[listViewItem]); } private void exportProblemButton_Click(object sender, EventArgs e) { var cloner = new PreprocessingCloner(Content); var alteredClone = cloner.GenerateAlteredClone(Content.Problem); var saveFileDialog = new SaveFileDialog { Title = "Save Item", DefaultExt = "hl", Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*", FilterIndex = 2 }; var content = alteredClone as IStorableContent; if (saveFileDialog.ShowDialog() == DialogResult.OK) { bool compressed = saveFileDialog.FilterIndex != 1; ContentManager.Save(content, saveFileDialog.FileName, compressed); } } private void applyInNewTabButton_Click(object sender, EventArgs e) { IPreprocessingData data = Content.Data; foreach (string variable in data.VariableNames) { for (int j = 0; j < data.Rows; j++) { // assume: all double data.SetCell(variable, j, 1.0); } } MessageBox.Show("Success, now cloning... "); var cloner = new PreprocessingCloner(Content); var item = cloner.GenerateAlteredClone(Content.ParentItem); MainFormManager.MainForm.ShowContent(item); } } }