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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Core.Views;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
30 | using HeuristicLab.Problems.DataAnalysis;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.DatastreamAnalysis.Views {
|
---|
33 | [View("Ensemble Models")]
|
---|
34 | [Content(typeof(RegressionEnsembleModel), true)]
|
---|
35 | internal sealed partial class RegressionEnsembleModelView : NamedItemView {
|
---|
36 | private ModelsView view;
|
---|
37 | private ItemCollection<IRegressionModel> models;
|
---|
38 |
|
---|
39 | public RegressionEnsembleModelView() {
|
---|
40 | InitializeComponent();
|
---|
41 | view = new ModelsView();
|
---|
42 | view.Dock = DockStyle.Fill;
|
---|
43 | Controls.Add(view);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public new RegressionEnsembleModel Content {
|
---|
47 | get { return (RegressionEnsembleModel)base.Content; }
|
---|
48 | set { base.Content = value; }
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 | protected override void OnContentChanged() {
|
---|
54 | base.OnContentChanged();
|
---|
55 | if (Content != null) {
|
---|
56 | models = new ItemCollection<IRegressionModel>(Content.Models);
|
---|
57 | view.Content = models;
|
---|
58 | } else {
|
---|
59 | view.Content = null;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | private class ModelsView : ItemCollectionView<IRegressionModel> {
|
---|
64 | protected override void SetEnabledStateOfControls() {
|
---|
65 | base.SetEnabledStateOfControls();
|
---|
66 | addButton.Enabled = false;
|
---|
67 | removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && !ReadOnly && itemsListView.SelectedItems.Count > 0;
|
---|
68 | itemsListView.Enabled = Content != null && !Locked;
|
---|
69 | detailsGroupBox.Enabled = Content != null && itemsListView.SelectedItems.Count == 1;
|
---|
70 | sortAscendingButton.Enabled = false;
|
---|
71 | sortDescendingButton.Enabled = false;
|
---|
72 | }
|
---|
73 |
|
---|
74 | protected override void SortItemsListView(SortOrder sortOrder) { }
|
---|
75 |
|
---|
76 |
|
---|
77 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
78 | validDragOperation = false;
|
---|
79 | if (ReadOnly || Locked) return;
|
---|
80 | if (Content.IsReadOnly) return;
|
---|
81 |
|
---|
82 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
83 | validDragOperation = dropData.GetObjectGraphObjects().OfType<IRegressionModel>().Any();
|
---|
84 | }
|
---|
85 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
86 | if (e.Effect != DragDropEffects.None) {
|
---|
87 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
88 | var solutions = dropData.GetObjectGraphObjects().OfType<IRegressionModel>();
|
---|
89 | if (e.Effect.HasFlag(DragDropEffects.Copy)) {
|
---|
90 | Cloner cloner = new Cloner();
|
---|
91 | solutions = solutions.Select(s => cloner.Clone(s));
|
---|
92 | }
|
---|
93 | var solutionCollection = Content as ItemCollection<IRegressionModel>;
|
---|
94 | if (solutionCollection != null) {
|
---|
95 | solutionCollection.AddRange(solutions);
|
---|
96 | } else {
|
---|
97 | foreach (var solution in solutions)
|
---|
98 | Content.Add(solution);
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 | protected override void itemsListView_KeyDown(object sender, KeyEventArgs e) {
|
---|
103 | var solutionCollection = Content as ItemCollection<IRegressionModel>;
|
---|
104 | if (e.KeyCode == Keys.Delete && solutionCollection != null) {
|
---|
105 | if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) {
|
---|
106 | solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IRegressionModel)x.Tag));
|
---|
107 | }
|
---|
108 | } else {
|
---|
109 | base.itemsListView_KeyDown(sender, e);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | protected override void removeButton_Click(object sender, EventArgs e) {
|
---|
113 | var solutionCollection = Content as ItemCollection<IRegressionModel>;
|
---|
114 | if (itemsListView.SelectedItems.Count > 0 && solutionCollection != null) {
|
---|
115 | solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IRegressionModel)x.Tag));
|
---|
116 | itemsListView.SelectedItems.Clear();
|
---|
117 | } else {
|
---|
118 | base.removeButton_Click(sender, e);
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | }
|
---|
124 |
|
---|
125 | }
|
---|
126 | }
|
---|