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.Core;
|
---|
28 | using HeuristicLab.Core.Views;
|
---|
29 | using HeuristicLab.MainForm;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 | using HeuristicLab.Optimization.Views;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
34 | [View("DataAnalysisSolution View")]
|
---|
35 | [Content(typeof(DataAnalysisSolution), false)]
|
---|
36 | public partial class DataAnalysisSolutionView : NamedItemCollectionView<IResult> {
|
---|
37 | public DataAnalysisSolutionView() {
|
---|
38 | InitializeComponent();
|
---|
39 | viewHost.ViewsLabelVisible = false;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public new DataAnalysisSolution Content {
|
---|
43 | get { return (DataAnalysisSolution)base.Content; }
|
---|
44 | set { base.Content = value; }
|
---|
45 | }
|
---|
46 |
|
---|
47 | protected override void SetEnabledStateOfControls() {
|
---|
48 | base.SetEnabledStateOfControls();
|
---|
49 | addButton.Enabled = false;
|
---|
50 | removeButton.Enabled = false;
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void RegisterContentEvents() {
|
---|
54 | base.RegisterContentEvents();
|
---|
55 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
56 | }
|
---|
57 | protected override void DeregisterContentEvents() {
|
---|
58 | base.DeregisterContentEvents();
|
---|
59 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
60 | }
|
---|
61 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
62 | OnContentChanged();
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void OnContentChanged() {
|
---|
66 | string selectedName = null;
|
---|
67 | if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
|
---|
68 | selectedName = itemsListView.SelectedItems[0].Text;
|
---|
69 |
|
---|
70 | base.OnContentChanged();
|
---|
71 | AddEvaluationViewTypes();
|
---|
72 |
|
---|
73 | //recover selection
|
---|
74 | if (selectedName != null) {
|
---|
75 | foreach (ListViewItem item in itemsListView.Items) {
|
---|
76 | if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
|
---|
77 | item.Selected = true;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | protected override IResult CreateItem() {
|
---|
83 | return null;
|
---|
84 | }
|
---|
85 |
|
---|
86 | protected virtual void AddEvaluationViewTypes() {
|
---|
87 | if (Content != null && !Content.ProblemData.IsEmpty) {
|
---|
88 | var viewTypes = MainFormManager.GetViewTypes(Content.GetType(), true)
|
---|
89 | .Where(t => typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(t));
|
---|
90 | foreach (var viewType in viewTypes)
|
---|
91 | AddViewListViewItem(viewType, ((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
96 | if (itemsListView.SelectedItems.Count != 1) return;
|
---|
97 |
|
---|
98 | IResult result = itemsListView.SelectedItems[0].Tag as IResult;
|
---|
99 | Type viewType = itemsListView.SelectedItems[0].Tag as Type;
|
---|
100 | if (result != null) {
|
---|
101 | IContentView view = MainFormManager.MainForm.ShowContent(result, typeof(ResultView));
|
---|
102 | if (view != null) {
|
---|
103 | view.ReadOnly = ReadOnly;
|
---|
104 | view.Locked = Locked;
|
---|
105 | }
|
---|
106 | } else if (viewType != null) {
|
---|
107 | MainFormManager.MainForm.ShowContent(Content, viewType);
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
112 | if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
113 | detailsGroupBox.Enabled = true;
|
---|
114 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
115 | viewHost.ViewType = viewType;
|
---|
116 | viewHost.Content = Content;
|
---|
117 | } else
|
---|
118 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
119 | }
|
---|
120 |
|
---|
121 | protected void AddViewListViewItem(Type viewType, Image image) {
|
---|
122 | ListViewItem listViewItem = new ListViewItem();
|
---|
123 | listViewItem.Text = ViewAttribute.GetViewName(viewType);
|
---|
124 | itemsListView.SmallImageList.Images.Add(image);
|
---|
125 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
126 | listViewItem.Tag = viewType;
|
---|
127 | itemsListView.Items.Add(listViewItem);
|
---|
128 |
|
---|
129 | AdjustListViewColumnSizes();
|
---|
130 | }
|
---|
131 |
|
---|
132 | protected void RemoveViewListViewItem(Type viewType) {
|
---|
133 | List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
|
---|
134 |
|
---|
135 | foreach (ListViewItem item in itemsToRemove)
|
---|
136 | itemsListView.Items.Remove(item);
|
---|
137 | }
|
---|
138 |
|
---|
139 | #region drag and drop
|
---|
140 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
141 | validDragOperation = false;
|
---|
142 | if (ReadOnly) return;
|
---|
143 |
|
---|
144 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
145 | if (dropData is DataAnalysisProblemData) validDragOperation = true;
|
---|
146 | else if (dropData is IValueParameter) {
|
---|
147 | var param = (IValueParameter)dropData;
|
---|
148 | if (param.Value is DataAnalysisProblemData) validDragOperation = true;
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
153 | if (e.Effect != DragDropEffects.None) {
|
---|
154 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
155 | if (dropData is DataAnalysisProblemData) {
|
---|
156 | DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
|
---|
157 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
158 | } else if (dropData is IValueParameter) {
|
---|
159 | var param = (IValueParameter)dropData;
|
---|
160 | DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
|
---|
161 | if (problemData != null)
|
---|
162 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 | #endregion
|
---|
167 | }
|
---|
168 | }
|
---|