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 | //cache old viewTypes;
|
---|
49 | var viewTypes = new List<Tuple<Type, Image>>();
|
---|
50 | foreach (ListViewItem item in ItemsListView.Items) {
|
---|
51 | var viewType = item.Tag as Type;
|
---|
52 | if (viewType != null) viewTypes.Add(Tuple.Create(viewType, imageList.Images[item.ImageIndex]));
|
---|
53 | }
|
---|
54 |
|
---|
55 | base.OnContentChanged();
|
---|
56 |
|
---|
57 | //readd viewTypes
|
---|
58 | foreach (var tuple in viewTypes)
|
---|
59 | AddViewListViewItem(tuple.Item1, tuple.Item2);
|
---|
60 |
|
---|
61 | //recover selection
|
---|
62 | if (selectedName != null) {
|
---|
63 | foreach (ListViewItem item in itemsListView.Items) {
|
---|
64 | if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
|
---|
65 | item.Selected = true;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
71 | if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
72 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
73 | MainFormManager.MainForm.ShowContent(Content, viewType);
|
---|
74 | } else
|
---|
75 | base.itemsListView_DoubleClick(sender, e);
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
79 | if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
80 | detailsGroupBox.Enabled = true;
|
---|
81 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
82 | viewHost.ViewType = viewType;
|
---|
83 | viewHost.Content = Content;
|
---|
84 | } else
|
---|
85 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected void AddViewListViewItem(Type viewType, Image image) {
|
---|
89 | ListViewItem listViewItem = new ListViewItem();
|
---|
90 | listViewItem.Text = ViewAttribute.GetViewName(viewType);
|
---|
91 | itemsListView.SmallImageList.Images.Add(image);
|
---|
92 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
93 | listViewItem.Tag = viewType;
|
---|
94 | itemsListView.Items.Add(listViewItem);
|
---|
95 |
|
---|
96 | AdjustListViewColumnSizes();
|
---|
97 | }
|
---|
98 |
|
---|
99 | protected void RemoveViewListViewItem(Type viewType) {
|
---|
100 | List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
|
---|
101 |
|
---|
102 | foreach (ListViewItem item in itemsToRemove)
|
---|
103 | itemsListView.Items.Remove(item);
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|