Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis.Views/3.4/RegressionEnsembleModelView.cs @ 15287

Last change on this file since 15287 was 14536, checked in by jzenisek, 8 years ago

#2719 added datastream type; updated the optimizer view and control functionality

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