Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs @ 8508

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

#1776: merged r7864:8507 trunk into branch

File size: 7.0 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      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    #region drag and drop
150    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
151      validDragOperation = false;
152      if (ReadOnly) return;
153
154      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
155      if (dropData is DataAnalysisProblemData) validDragOperation = true;
156      else if (dropData is IValueParameter) {
157        var param = (IValueParameter)dropData;
158        if (param.Value is DataAnalysisProblemData) validDragOperation = true;
159      }
160    }
161
162    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
163      if (e.Effect != DragDropEffects.None) {
164        var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
165        if (dropData is DataAnalysisProblemData) {
166          DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
167          Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
168        } else if (dropData is IValueParameter) {
169          var param = (IValueParameter)dropData;
170          DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
171          if (problemData != null)
172            Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
173        }
174      }
175    }
176    #endregion
177  }
178}
Note: See TracBrowser for help on using the repository browser.