Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GradientBoostedTreesModelView.cs @ 17514

Last change on this file since 17514 was 16057, checked in by jkarder, 6 years ago

#2839:

File size: 3.4 KB
RevLine 
[15106]1#region License Information
2/* HeuristicLab
[16057]3 * Copyright (C) 2002-2018 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
[16057]22using System;
23using System.Diagnostics;
24using System.Linq;
25using System.Windows.Forms;
[15106]26using HeuristicLab.Common;
[15124]27using HeuristicLab.Core.Views;
[15106]28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
[16057]30using HeuristicLab.Problems.DataAnalysis;
[15106]31
32namespace HeuristicLab.Algorithms.DataAnalysis.Views {
33  [View("Gradient boosted trees model")]
34  [Content(typeof(IGradientBoostedTreesModel), true)]
[15124]35  public partial class GradientBoostedTreesModelView : ItemView {
[16057]36    #region Getter/Setter
[15106]37    public new IGradientBoostedTreesModel Content {
38      get { return (IGradientBoostedTreesModel)base.Content; }
39      set { base.Content = value; }
40    }
[16057]41    #endregion
[15106]42
[16057]43    #region Ctor
44    public GradientBoostedTreesModelView()
45      : base() {
46      InitializeComponent();
47    }
48    #endregion
49
50    #region Events
[15106]51    protected override void SetEnabledStateOfControls() {
52      base.SetEnabledStateOfControls();
[16057]53      listView.Enabled = Content != null;
[15106]54      viewHost.Enabled = Content != null;
55    }
56
57    protected override void OnContentChanged() {
58      base.OnContentChanged();
59      if (Content == null) {
60        viewHost.Content = null;
[16057]61        listView.Items.Clear();
[15106]62      } else {
63        viewHost.Content = null;
[16057]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();
[15106]73      }
74    }
75
[16057]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);
[15106]81      }
82    }
83
[16057]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      }
[15106]90    }
[16057]91    #endregion
[15106]92
[16057]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;
[15106]101      }
102    }
[16057]103    #endregion
[15106]104  }
105}
Note: See TracBrowser for help on using the repository browser.