Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionEnsembleSolutionModelView.cs @ 17495

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

#2839:

File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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;
30
31namespace HeuristicLab.Problems.DataAnalysis.Views {
32  [View("Ensemble Solutions")]
33  [Content(typeof(RegressionEnsembleSolution), false)]
34  internal sealed partial class RegressionEnsembleSolutionModelView : DataAnalysisSolutionEvaluationView {
35    private ModelsView view;
36
37    public RegressionEnsembleSolutionModelView() {
38      InitializeComponent();
39      view = new ModelsView();
40      view.Dock = DockStyle.Fill;
41      Controls.Add(view);
42    }
43
44    public new RegressionEnsembleSolution Content {
45      get { return (RegressionEnsembleSolution)base.Content; }
46      set { base.Content = value; }
47    }
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      if (Content != null) {
52        view.Locked = Content.ProblemData == RegressionEnsembleProblemData.EmptyProblemData;
53        view.Content = Content.RegressionSolutions;
54      } else
55        view.Content = null;
56    }
57
58    public override System.Drawing.Image ViewImage {
59      get { return HeuristicLab.Common.Resources.VSImageLibrary.Properties; }
60    }
61
62    private class ModelsView : ItemCollectionView<IRegressionSolution> {
63      protected override void SetEnabledStateOfControls() {
64        base.SetEnabledStateOfControls();
65        addButton.Enabled = false;
66        removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && !ReadOnly && itemsListView.SelectedItems.Count > 0;
67        itemsListView.Enabled = Content != null && !Locked;
68        detailsGroupBox.Enabled = Content != null && itemsListView.SelectedItems.Count == 1;
69        sortAscendingButton.Enabled = false;
70        sortDescendingButton.Enabled = false;
71      }
72
73      //forbid sorting
74      protected override void SortItemsListView(SortOrder sortOrder) { }
75
76      protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
77        validDragOperation = false;
78        if (ReadOnly || Locked) return;
79        if (Content.IsReadOnly) return;
80
81        var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
82        validDragOperation = dropData.GetObjectGraphObjects().OfType<IRegressionSolution>().Any();
83      }
84      protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
85        if (e.Effect != DragDropEffects.None) {
86          var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
87          var solutions = dropData.GetObjectGraphObjects().OfType<IRegressionSolution>();
88          if (e.Effect.HasFlag(DragDropEffects.Copy)) {
89            Cloner cloner = new Cloner();
90            solutions = solutions.Select(s => cloner.Clone(s));
91          }
92          var solutionCollection = Content as ItemCollection<IRegressionSolution>;
93          if (solutionCollection != null) {
94            solutionCollection.AddRange(solutions);
95          } else {
96            foreach (var solution in solutions)
97              Content.Add(solution);
98          }
99        }
100      }
101      protected override void itemsListView_KeyDown(object sender, KeyEventArgs e) {
102        var solutionCollection = Content as ItemCollection<IRegressionSolution>;
103        if (e.KeyCode == Keys.Delete && solutionCollection != null) {
104          if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) {
105            solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IRegressionSolution)x.Tag));
106          }
107        } else {
108          base.itemsListView_KeyDown(sender, e);
109        }
110      }
111      protected override void removeButton_Click(object sender, EventArgs e) {
112        var solutionCollection = Content as ItemCollection<IRegressionSolution>;
113        if (itemsListView.SelectedItems.Count > 0 && solutionCollection != null) {
114          solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IRegressionSolution)x.Tag));
115          itemsListView.SelectedItems.Clear();
116        } else {
117          base.removeButton_Click(sender, e);
118        }
119      }
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.