Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ChangeDatasetOfRegressionModel/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs @ 12547

Last change on this file since 12547 was 8513, checked in by sforsten, 12 years ago

#1758: merged r8023:8509 from trunk to branch to make it useable again

File size: 6.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Drawing;
25using System.Linq;
26using System.Windows.Forms;
27using HeuristicLab.Core;
28using HeuristicLab.Core.Views;
29using HeuristicLab.MainForm;
30using HeuristicLab.Optimization;
31using HeuristicLab.Optimization.Views;
32
33namespace 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    }
56    protected override void DeregisterContentEvents() {
57      base.DeregisterContentEvents();
58    }
59
60    protected override void OnContentChanged() {
61      string selectedName = null;
62      if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
63        selectedName = itemsListView.SelectedItems[0].Text;
64
65      base.OnContentChanged();
66      AddEvaluationViewTypes();
67
68      //recover selection
69      if (selectedName != null) {
70        foreach (ListViewItem item in itemsListView.Items) {
71          if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
72            item.Selected = true;
73        }
74      }
75    }
76
77    protected override IResult CreateItem() {
78      return null;
79    }
80
81    protected virtual void AddEvaluationViewTypes() {
82      if (Content != null && !Content.ProblemData.IsEmpty) {
83        var viewTypes = MainFormManager.GetViewTypes(Content.GetType(), true)
84          .Where(t => typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(t));
85        foreach (var viewType in viewTypes)
86          AddViewListViewItem(viewType, ((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
87      }
88    }
89
90    protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
91      if (itemsListView.SelectedItems.Count != 1) return;
92
93      IResult result = itemsListView.SelectedItems[0].Tag as IResult;
94      Type viewType = itemsListView.SelectedItems[0].Tag as Type;
95      if (result != null) {
96        IContentView view = MainFormManager.MainForm.ShowContent(result, typeof(ResultView));
97        if (view != null) {
98          view.ReadOnly = ReadOnly;
99          view.Locked = Locked;
100        }
101      } else if (viewType != null) {
102        MainFormManager.MainForm.ShowContent(Content, viewType);
103      }
104    }
105
106    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
107      if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
108        detailsGroupBox.Enabled = true;
109        Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
110        viewHost.ViewType = viewType;
111        viewHost.Content = Content;
112      } else
113        base.itemsListView_SelectedIndexChanged(sender, e);
114    }
115
116    protected void AddViewListViewItem(Type viewType, Image image) {
117      ListViewItem listViewItem = new ListViewItem();
118      listViewItem.Text = ViewAttribute.GetViewName(viewType);
119      itemsListView.SmallImageList.Images.Add(image);
120      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
121      listViewItem.Tag = viewType;
122      itemsListView.Items.Add(listViewItem);
123
124      AdjustListViewColumnSizes();
125    }
126
127    protected void RemoveViewListViewItem(Type viewType) {
128      List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
129
130      foreach (ListViewItem item in itemsToRemove)
131        itemsListView.Items.Remove(item);
132    }
133
134    protected override void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
135      if (showDetailsCheckBox.Checked && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
136        Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
137        viewHost.ViewType = viewType;
138        viewHost.Content = Content;
139        splitContainer.Panel2Collapsed = false;
140        detailsGroupBox.Enabled = true;
141      } else base.showDetailsCheckBox_CheckedChanged(sender, e);
142    }
143
144    #region drag and drop
145    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
146      validDragOperation = false;
147      if (ReadOnly) return;
148
149      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
150      if (dropData is DataAnalysisProblemData) validDragOperation = true;
151      else if (dropData is IValueParameter) {
152        var param = (IValueParameter)dropData;
153        if (param.Value is DataAnalysisProblemData) validDragOperation = true;
154      }
155    }
156
157    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
158      if (e.Effect != DragDropEffects.None) {
159        var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
160        if (dropData is DataAnalysisProblemData) {
161          DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
162          Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
163        } else if (dropData is IValueParameter) {
164          var param = (IValueParameter)dropData;
165          DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
166          if (problemData != null)
167            Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
168        }
169      }
170    }
171    #endregion
172  }
173}
Note: See TracBrowser for help on using the repository browser.