Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GradientBoostedTreesModelView.cs @ 16303

Last change on this file since 16303 was 15730, checked in by fholzing, 7 years ago

#2890: Changed from ListBox to ListView; Added GroupBox to underline to distinction between outer and inner ViewHost; Simplified naming to "Model 1 - Model N"

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Diagnostics;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Common;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30using HeuristicLab.Problems.DataAnalysis;
31
32namespace HeuristicLab.Algorithms.DataAnalysis.Views {
33  [View("Gradient boosted trees model")]
34  [Content(typeof(IGradientBoostedTreesModel), true)]
35  public partial class GradientBoostedTreesModelView : ItemView {
36    #region Getter/Setter
37    public new IGradientBoostedTreesModel Content {
38      get { return (IGradientBoostedTreesModel)base.Content; }
39      set { base.Content = value; }
40    }
41    #endregion
42
43    #region Ctor
44    public GradientBoostedTreesModelView()
45      : base() {
46      InitializeComponent();
47    }
48    #endregion
49
50    #region Events
51    protected override void SetEnabledStateOfControls() {
52      base.SetEnabledStateOfControls();
53      listView.Enabled = Content != null;
54      viewHost.Enabled = Content != null;
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59      if (Content == null) {
60        viewHost.Content = null;
61        listView.Items.Clear();
62      } else {
63        viewHost.Content = null;
64        listView.BeginUpdate();
65        listView.Items.Clear();
66        int i = 1;
67        listView.Items.AddRange(
68          new ListViewItem(Content.Models.First().ToString()) { Tag = Content.Models.First() }.ToEnumerable()
69          .Union(Content.Models.Skip(1).Select(v => new ListViewItem("Model " + i++) { Tag = v }))
70          .ToArray()
71        );
72        listView.EndUpdate();
73      }
74    }
75
76
77    private void listView_SelectedIndexChanged(object sender, EventArgs e) {
78      if (listView.SelectedItems.Count == 1) {
79        var item = listView.SelectedItems[0];
80        viewHost.Content = ConvertModel(item);
81      }
82    }
83
84    private void listView_DoubleClick(object sender, EventArgs e) {
85      if (listView.SelectedItems.Count == 1) {
86        var item = listView.SelectedItems[0];
87        var content = ConvertModel(item);
88        if (content != null) { MainFormManager.MainForm.ShowContent(content); }
89      }
90    }
91    #endregion
92
93    #region Helper Methods
94    private IContent ConvertModel(ListViewItem item) {
95      if (item.Tag is RegressionTreeModel) {
96        return (item.Tag as RegressionTreeModel).CreateSymbolicRegressionModel();
97      } else if (item.Tag is IRegressionModel) {
98        return item.Tag as IRegressionModel;
99      } else {
100        return null;
101      }
102    }
103    #endregion
104  }
105}
Note: See TracBrowser for help on using the repository browser.