1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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 | protected override void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
140 | if (showDetailsCheckBox.Checked && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
141 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
142 | viewHost.ViewType = viewType;
|
---|
143 | viewHost.Content = Content;
|
---|
144 | splitContainer.Panel2Collapsed = false;
|
---|
145 | detailsGroupBox.Enabled = true;
|
---|
146 | } else base.showDetailsCheckBox_CheckedChanged(sender, e);
|
---|
147 | }
|
---|
148 |
|
---|
149 | protected override void RebuildImageList() {
|
---|
150 | itemsListView.SmallImageList.Images.Clear();
|
---|
151 | foreach (ListViewItem listViewItem in itemsListView.Items) {
|
---|
152 | IResult result = listViewItem.Tag as IResult;
|
---|
153 | Type viewType = listViewItem.Tag as Type;
|
---|
154 | if (result != null) itemsListView.SmallImageList.Images.Add(result.ItemImage);
|
---|
155 | else if (viewType != null && typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(viewType))
|
---|
156 | itemsListView.SmallImageList.Images.Add(((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
|
---|
157 | else itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Nothing);
|
---|
158 |
|
---|
159 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | #region drag and drop
|
---|
164 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
165 | validDragOperation = false;
|
---|
166 | if (ReadOnly) return;
|
---|
167 |
|
---|
168 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
169 | if (dropData is DataAnalysisProblemData) validDragOperation = true;
|
---|
170 | else if (dropData is IValueParameter) {
|
---|
171 | var param = (IValueParameter)dropData;
|
---|
172 | if (param.Value is DataAnalysisProblemData) validDragOperation = true;
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
177 | if (e.Effect != DragDropEffects.None) {
|
---|
178 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
179 | if (dropData is DataAnalysisProblemData) {
|
---|
180 | DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
|
---|
181 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
182 | } else if (dropData is IValueParameter) {
|
---|
183 | var param = (IValueParameter)dropData;
|
---|
184 | DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
|
---|
185 | if (problemData != null)
|
---|
186 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
187 | }
|
---|
188 | }
|
---|
189 | }
|
---|
190 | #endregion
|
---|
191 | }
|
---|
192 | }
|
---|