Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Scheduling/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisSolutionView.cs @ 6319

Last change on this file since 6319 was 5834, checked in by mkommend, 14 years ago

#1313: Updated view names.

File size: 4.3 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.Windows.Forms;
25using HeuristicLab.Common.Resources;
26using HeuristicLab.MainForm;
27using HeuristicLab.Optimization.Views;
28
29namespace HeuristicLab.Problems.DataAnalysis.Views {
30  [View("DataAnalysisSolution View")]
31  [Content(typeof(DataAnalysisSolution), true)]
32  public partial class DataAnalysisSolutionView : ResultCollectionView {
33    public DataAnalysisSolutionView() {
34      InitializeComponent();
35    }
36
37    public new DataAnalysisSolution Content {
38      get { return (DataAnalysisSolution)base.Content; }
39      set { base.Content = value; }
40    }
41
42    protected override void OnContentChanged() {
43      string selectedName = null;
44      if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
45        selectedName = itemsListView.SelectedItems[0].Text;
46
47      //cache old viewTypes;
48      var viewTypes = new List<Type>();
49      foreach (ListViewItem item in ItemsListView.Items) {
50        var viewType = item.Tag as Type;
51        if (viewType != null) viewTypes.Add(viewType);
52      }
53
54      base.OnContentChanged();
55
56      //readd viewTypes
57      foreach (Type viewType in viewTypes)
58        AddViewListViewItem(viewType);
59
60      //recover selection
61      if (selectedName != null) {
62        foreach (ListViewItem item in itemsListView.Items) {
63          if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
64            item.Selected = true;
65        }
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) {
88      if (!typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(viewType))
89        throw new ArgumentException("Given type " + viewType + " is not a IDataAnalysisSolutionEvaluationView.");
90
91      ListViewItem listViewItem = new ListViewItem();
92      listViewItem.Text = ViewAttribute.GetViewName(viewType);
93      itemsListView.SmallImageList.Images.Add(VSImageLibrary.Graph);
94      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
95      listViewItem.Tag = viewType;
96      itemsListView.Items.Add(listViewItem);
97
98      AdjustListViewColumnSizes();
99    }
100
101    protected void RemoveViewListViewItem(Type viewType) {
102      List<ListViewItem> itemsToRemove = new List<ListViewItem>(); ;
103      foreach (ListViewItem item in itemsListView.Items)
104        if (item.Tag as Type == typeof(ClassificationSolutionEstimatedClassValuesView))
105          itemsToRemove.Add(item);
106
107      foreach (ListViewItem item in itemsToRemove)
108        itemsListView.Items.Remove(item);
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.