Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionEnsembleSolutionModelView.cs @ 14309

Last change on this file since 14309 was 14186, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 5.1 KB
RevLine 
[6612]1#region License Information
2/* HeuristicLab
[14186]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6612]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
[6666]21
[8719]22using System;
[6666]23using System.Linq;
[6642]24using System.Windows.Forms;
[6666]25using HeuristicLab.Common;
[8719]26using HeuristicLab.Core;
[6642]27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
[6612]30
31namespace HeuristicLab.Problems.DataAnalysis.Views {
[6642]32  [View("Ensemble Solutions")]
33  [Content(typeof(RegressionEnsembleSolution), false)]
34  internal sealed partial class RegressionEnsembleSolutionModelView : DataAnalysisSolutionEvaluationView {
35    private ModelsView view;
[6612]36
37    public RegressionEnsembleSolutionModelView() {
38      InitializeComponent();
[6642]39      view = new ModelsView();
40      view.Dock = DockStyle.Fill;
41      Controls.Add(view);
[6612]42    }
43
[6642]44    public new RegressionEnsembleSolution Content {
45      get { return (RegressionEnsembleSolution)base.Content; }
46      set { base.Content = value; }
[6612]47    }
[6642]48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
[6666]51      if (Content != null) {
52        view.Locked = Content.ProblemData == RegressionEnsembleProblemData.EmptyProblemData;
[6642]53        view.Content = Content.RegressionSolutions;
[6666]54      } else
[6642]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();
[13976]65        addButton.Enabled = false;
66        removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && !ReadOnly && itemsListView.SelectedItems.Count > 0;
[6666]67        itemsListView.Enabled = Content != null && !Locked;
[6642]68        detailsGroupBox.Enabled = Content != null && itemsListView.SelectedItems.Count == 1;
[13976]69        sortAscendingButton.Enabled = false;
70        sortDescendingButton.Enabled = false;
[6642]71      }
[6666]72
[13976]73      //forbid sorting
74      protected override void SortItemsListView(SortOrder sortOrder) { }
75
[6666]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          }
[8719]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          }
[6666]99        }
100      }
[8719]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      }
[6642]120    }
[6612]121  }
122}
Note: See TracBrowser for help on using the repository browser.