Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1618: Enabled problem data changes in DataAnalysisSolutions.

File size: 5.3 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 OnContentChanged() {
47      string selectedName = null;
48      if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
49        selectedName = itemsListView.SelectedItems[0].Text;
50
51      base.OnContentChanged();
52      AddEvaluationViewTypes();
53
54      //recover selection
55      if (selectedName != null) {
56        foreach (ListViewItem item in itemsListView.Items) {
57          if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
58            item.Selected = true;
59        }
60      }
61    }
62
63    protected override IResult CreateItem() {
64      return null;
65    }
66
67    protected virtual void AddEvaluationViewTypes() {
68      if (Content != null) {
69        var viewTypes = MainFormManager.GetViewTypes(Content.GetType(), true)
70          .Where(t => typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(t));
71        foreach (var viewType in viewTypes)
72          AddViewListViewItem(viewType, ((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
73      }
74    }
75
76    protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
77      if (itemsListView.SelectedItems.Count != 1) return;
78
79      IResult result = itemsListView.SelectedItems[0].Tag as IResult;
80      Type viewType = itemsListView.SelectedItems[0].Tag as Type;
81      if (result != null) {
82        IContentView view = MainFormManager.MainForm.ShowContent(result, typeof(ResultView));
83        if (view != null) {
84          view.ReadOnly = ReadOnly;
85          view.Locked = Locked;
86        }
87      } else if (viewType != null) {
88        MainFormManager.MainForm.ShowContent(Content, viewType);
89      }
90    }
91
92    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
93      if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
94        detailsGroupBox.Enabled = true;
95        Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
96        viewHost.ViewType = viewType;
97        viewHost.Content = Content;
98      } else
99        base.itemsListView_SelectedIndexChanged(sender, e);
100    }
101
102    protected void AddViewListViewItem(Type viewType, Image image) {
103      ListViewItem listViewItem = new ListViewItem();
104      listViewItem.Text = ViewAttribute.GetViewName(viewType);
105      itemsListView.SmallImageList.Images.Add(image);
106      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
107      listViewItem.Tag = viewType;
108      itemsListView.Items.Add(listViewItem);
109
110      AdjustListViewColumnSizes();
111    }
112
113    protected void RemoveViewListViewItem(Type viewType) {
114      List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
115
116      foreach (ListViewItem item in itemsToRemove)
117        itemsListView.Items.Remove(item);
118    }
119
120    #region drag and drop
121    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
122      validDragOperation = false;
123      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is DataAnalysisProblemData)) {
124        validDragOperation = true;
125      }
126    }
127
128    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
129      if (e.Effect != DragDropEffects.None) {
130        if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is DataAnalysisProblemData) {
131          DataAnalysisProblemData problemData = (DataAnalysisProblemData)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
132          Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
133        }
134      }
135    }
136    #endregion
137  }
138}
Note: See TracBrowser for help on using the repository browser.