Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8032 was 7404, checked in by sforsten, 13 years ago

#1758:

  • branch has been adjusted
  • bug fix in DataAnalysisSolutionView
File size: 6.2 KB
RevLine 
[3884]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3884]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
[5829]21
[3884]22using System;
[5829]23using System.Collections.Generic;
[6612]24using System.Drawing;
25using System.Linq;
[3884]26using System.Windows.Forms;
[6692]27using HeuristicLab.Core;
[6652]28using HeuristicLab.Core.Views;
[3884]29using HeuristicLab.MainForm;
[6652]30using HeuristicLab.Optimization;
[5829]31using HeuristicLab.Optimization.Views;
[3884]32
33namespace HeuristicLab.Problems.DataAnalysis.Views {
[5834]34  [View("DataAnalysisSolution View")]
[6652]35  [Content(typeof(DataAnalysisSolution), false)]
36  public partial class DataAnalysisSolutionView : NamedItemCollectionView<IResult> {
[3884]37    public DataAnalysisSolutionView() {
38      InitializeComponent();
[6652]39      viewHost.ViewsLabelVisible = false;
[3884]40    }
41
[5829]42    public new DataAnalysisSolution Content {
43      get { return (DataAnalysisSolution)base.Content; }
[3884]44      set { base.Content = value; }
45    }
46
[6666]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
[3884]60    protected override void OnContentChanged() {
[5829]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
[3884]65      base.OnContentChanged();
[6642]66      AddEvaluationViewTypes();
[5829]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        }
[3884]74      }
75    }
76
[6652]77    protected override IResult CreateItem() {
78      return null;
79    }
80
[6642]81    protected virtual void AddEvaluationViewTypes() {
[6666]82      if (Content != null && !Content.ProblemData.IsEmpty) {
[6642]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
[5829]90    protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
[6652]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) {
[5829]102        MainFormManager.MainForm.ShowContent(Content, viewType);
[6652]103      }
[3884]104    }
[3915]105
[5829]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);
[3884]114    }
[3915]115
[6612]116    protected void AddViewListViewItem(Type viewType, Image image) {
[5829]117      ListViewItem listViewItem = new ListViewItem();
118      listViewItem.Text = ViewAttribute.GetViewName(viewType);
[6612]119      itemsListView.SmallImageList.Images.Add(image);
[5829]120      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
121      listViewItem.Tag = viewType;
122      itemsListView.Items.Add(listViewItem);
123
124      AdjustListViewColumnSizes();
[3915]125    }
[5829]126
127    protected void RemoveViewListViewItem(Type viewType) {
[6612]128      List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
[5829]129
130      foreach (ListViewItem item in itemsToRemove)
131        itemsListView.Items.Remove(item);
[3884]132    }
[6653]133
134    #region drag and drop
135    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
136      validDragOperation = false;
[6692]137      if (ReadOnly) return;
138
139      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
140      if (dropData is DataAnalysisProblemData) validDragOperation = true;
141      else if (dropData is IValueParameter) {
142        var param = (IValueParameter)dropData;
143        if (param.Value is DataAnalysisProblemData) validDragOperation = true;
[6653]144      }
145    }
146
147    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
148      if (e.Effect != DragDropEffects.None) {
[6692]149        var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
150        if (dropData is DataAnalysisProblemData) {
151          DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
[6653]152          Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
[6692]153        } else if (dropData is IValueParameter) {
154          var param = (IValueParameter)dropData;
155          DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
156          if (problemData != null)
157            Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
[6653]158        }
159      }
160    }
161    #endregion
[3884]162  }
163}
Note: See TracBrowser for help on using the repository browser.