Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs @ 6646

Last change on this file since 6646 was 6642, checked in by mkommend, 13 years ago

#1612: Implemented RegressionSolutionErrorCharacteristicsView and adapted loading of DataAnalysisSolutionEvaluationViews.

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Drawing;
25using System.Linq;
26using System.Windows.Forms;
27using HeuristicLab.MainForm;
28using HeuristicLab.Optimization.Views;
29
30namespace HeuristicLab.Problems.DataAnalysis.Views {
31  [View("DataAnalysisSolution View")]
32  [Content(typeof(DataAnalysisSolution), true)]
33  public partial class DataAnalysisSolutionView : ResultCollectionView {
34    public DataAnalysisSolutionView() {
35      InitializeComponent();
36    }
37
38    public new DataAnalysisSolution Content {
39      get { return (DataAnalysisSolution)base.Content; }
40      set { base.Content = value; }
41    }
42
43    protected override void OnContentChanged() {
44      string selectedName = null;
45      if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
46        selectedName = itemsListView.SelectedItems[0].Text;
47
48      base.OnContentChanged();
49      AddEvaluationViewTypes();
50
51      //recover selection
52      if (selectedName != null) {
53        foreach (ListViewItem item in itemsListView.Items) {
54          if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
55            item.Selected = true;
56        }
57      }
58    }
59
60    protected virtual void AddEvaluationViewTypes() {
61      if (Content != null) {
62        var viewTypes = MainFormManager.GetViewTypes(Content.GetType(), true)
63          .Where(t => typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(t));
64        foreach (var viewType in viewTypes)
65          AddViewListViewItem(viewType, ((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
66      }
67    }
68
69    protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
70      if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
71        Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
72        MainFormManager.MainForm.ShowContent(Content, viewType);
73      } else
74        base.itemsListView_DoubleClick(sender, e);
75    }
76
77    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
78      if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
79        detailsGroupBox.Enabled = true;
80        Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
81        viewHost.ViewType = viewType;
82        viewHost.Content = Content;
83      } else
84        base.itemsListView_SelectedIndexChanged(sender, e);
85    }
86
87    protected void AddViewListViewItem(Type viewType, Image image) {
88      ListViewItem listViewItem = new ListViewItem();
89      listViewItem.Text = ViewAttribute.GetViewName(viewType);
90      itemsListView.SmallImageList.Images.Add(image);
91      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
92      listViewItem.Tag = viewType;
93      itemsListView.Items.Add(listViewItem);
94
95      AdjustListViewColumnSizes();
96    }
97
98    protected void RemoveViewListViewItem(Type viewType) {
99      List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
100
101      foreach (ListViewItem item in itemsToRemove)
102        itemsListView.Items.Remove(item);
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.