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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using HeuristicLab.Optimization.Views;
|
---|
29 |
|
---|
30 | namespace 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 | }
|
---|