Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/RegressionEnsembleModelView.cs @ 17980

Last change on this file since 17980 was 17980, checked in by jzenisek, 3 years ago

#2719 merged head of HeuristicLab.Problems.DataAnalysis into branch; added several minor items

File size: 6.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HeuristicLab.Core;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25using HeuristicLab.Problems.DataAnalysis;
26
27namespace HeuristicLab.DatastreamAnalysis.Views {
28  [View("Ensemble Models")]
29  [Content(typeof(RegressionEnsembleModel), true)]
30  internal sealed partial class RegressionEnsembleModelView : NamedItemView {
31    //private ItemCollectionView<IRegressionModel> view;
32    private ItemCollection<IRegressionModel> models = new ItemCollection<IRegressionModel>();
33
34    public RegressionEnsembleModelView() {
35      InitializeComponent();
36      models = new ItemCollection<IRegressionModel>();
37
38      models.ItemsAdded += Models_ItemsAdded;
39      models.ItemsRemoved += Models_ItemsRemoved;
40      models.CollectionReset += Models_CollectionReset;
41
42    }
43
44    public new RegressionEnsembleModel Content {
45      get { return (RegressionEnsembleModel)base.Content; }
46      set { base.Content = value; }
47    }
48
49 
50    protected override void OnContentChanged() {
51      base.OnContentChanged();
52      if (Content != null) {
53        models.ItemsAdded -= Models_ItemsAdded;
54        models.ItemsRemoved -= Models_ItemsRemoved;
55        models.CollectionReset -= Models_CollectionReset;
56
57        models.Clear();
58        models.AddRange(Content.Models);
59        modelsView.Content = models;
60
61        models.ItemsAdded += Models_ItemsAdded;
62        models.ItemsRemoved += Models_ItemsRemoved;
63        models.CollectionReset += Models_CollectionReset;
64      } else {
65        modelsView.Content = null;
66      }
67    }
68
69    private void Models_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IRegressionModel> e) {
70      Content = null;
71    }
72
73    private void Models_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IRegressionModel> e) {
74      Content.AddRange(e.Items);
75    }
76
77    private void Models_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IRegressionModel> e) {
78      Content.RemoveRange(e.Items);
79    }
80
81    private class ModelsView : ItemCollectionView<IRegressionModel> {
82      public ModelsView() : base() {
83      }
84    }
85
86    //private class ModelsView : ItemCollectionView<IRegressionModel> {
87    //  protected override void SetEnabledStateOfControls() {
88    //    base.SetEnabledStateOfControls();
89    //    addButton.Enabled = false;
90    //    removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && !ReadOnly && itemsListView.SelectedItems.Count > 0;
91    //    itemsListView.Enabled = Content != null && !Locked;
92    //    detailsGroupBox.Enabled = Content != null && itemsListView.SelectedItems.Count == 1;
93    //    sortAscendingButton.Enabled = false;
94    //    sortDescendingButton.Enabled = false;
95    //  }
96
97    //  protected override void SortItemsListView(SortOrder sortOrder) { }
98
99
100    //  protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
101    //    validDragOperation = false;
102    //    if (ReadOnly || Locked) return;
103    //    if (Content.IsReadOnly) return;
104
105    //    var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
106    //    validDragOperation = dropData.GetObjectGraphObjects().OfType<IRegressionModel>().Any();
107    //  }
108    //  protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
109    //    if (e.Effect != DragDropEffects.None) {
110    //      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
111    //      var solutions = dropData.GetObjectGraphObjects().OfType<IRegressionModel>();
112    //      if (e.Effect.HasFlag(DragDropEffects.Copy)) {
113    //        Cloner cloner = new Cloner();
114    //        solutions = solutions.Select(s => cloner.Clone(s));
115    //      }
116    //      var solutionCollection = Content as ItemCollection<IRegressionModel>;
117    //      if (solutionCollection != null) {
118    //        solutionCollection.AddRange(solutions);
119    //      } else {
120    //        foreach (var solution in solutions)
121    //          Content.Add(solution);
122    //      }
123    //    }
124    //  }
125    //  protected override void itemsListView_KeyDown(object sender, KeyEventArgs e) {
126    //    var solutionCollection = Content as ItemCollection<IRegressionModel>;
127    //    if (e.KeyCode == Keys.Delete && solutionCollection != null) {
128    //      if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) {
129    //        solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IRegressionModel)x.Tag));
130    //      }
131    //    } else {
132    //      base.itemsListView_KeyDown(sender, e);
133    //    }
134    //  }
135    //  protected override void removeButton_Click(object sender, EventArgs e) {
136    //    var solutionCollection = Content as ItemCollection<IRegressionModel>;
137    //    if (itemsListView.SelectedItems.Count > 0 && solutionCollection != null) {
138    //      solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IRegressionModel)x.Tag));
139    //      itemsListView.SelectedItems.Clear();
140    //    } else {
141    //      base.removeButton_Click(sender, e);
142    //    }
143    //  }
144    //}
145
146  }
147}
Note: See TracBrowser for help on using the repository browser.