Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs @ 6675

Last change on this file since 6675 was 6666, checked in by mkommend, 13 years ago

#1592: Enabled creation of empty ensemble solutions and problem data changes.

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