Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16755 was 16565, checked in by gkronber, 6 years ago

#2520: merged changes from PersistenceOverhaul branch (r16451:16564) into trunk

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