Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2901_StaticSelectionMethods/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionModelView.cs @ 16824

Last change on this file since 16824 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 5.0 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(ClassificationEnsembleSolution), false)]
34  internal sealed partial class ClassificationEnsembleSolutionModelView : DataAnalysisSolutionEvaluationView {
35    private ModelsView view;
36
37    public ClassificationEnsembleSolutionModelView() {
38      InitializeComponent();
39      view = new ModelsView();
40      view.Dock = DockStyle.Fill;
41      Controls.Add(view);
42    }
43
44    public new ClassificationEnsembleSolution Content {
45      get { return (ClassificationEnsembleSolution)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 == ClassificationEnsembleProblemData.EmptyProblemData;
53        view.Content = Content.ClassificationSolutions;
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<IClassificationSolution> {
63      protected override void SetEnabledStateOfControls() {
64        base.SetEnabledStateOfControls();
65        addButton.Enabled = Content != null && !Content.IsReadOnly && !Locked;
66        removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && itemsListView.SelectedItems.Count > 0;
67        itemsListView.Enabled = Content != null;
68        detailsGroupBox.Enabled = Content != null && itemsListView.SelectedItems.Count == 1;
69      }
70
71      protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
72        validDragOperation = false;
73        if (ReadOnly || Locked) return;
74        if (Content.IsReadOnly) return;
75
76        var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
77        validDragOperation = dropData.GetObjectGraphObjects().OfType<IClassificationSolution>().Any();
78      }
79      protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
80        if (e.Effect != DragDropEffects.None) {
81          var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
82          var solutions = dropData.GetObjectGraphObjects().OfType<IClassificationSolution>();
83          if (e.Effect.HasFlag(DragDropEffects.Copy)) {
84            Cloner cloner = new Cloner();
85            solutions = solutions.Select(s => cloner.Clone(s));
86          }
87          var solutionCollection = Content as ItemCollection<IClassificationSolution>;
88          if (solutionCollection != null) {
89            solutionCollection.AddRange(solutions);
90          } else {
91            foreach (var solution in solutions)
92              Content.Add(solution);
93          }
94        }
95      }
96      protected override void itemsListView_KeyDown(object sender, KeyEventArgs e) {
97        var solutionCollection = Content as ItemCollection<IClassificationSolution>;
98        if (e.KeyCode == Keys.Delete && solutionCollection != null) {
99          if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) {
100            solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IClassificationSolution)x.Tag));
101          }
102        } else {
103          base.itemsListView_KeyDown(sender, e);
104        }
105      }
106      protected override void removeButton_Click(object sender, EventArgs e) {
107        var solutionCollection = Content as ItemCollection<IClassificationSolution>;
108        if (itemsListView.SelectedItems.Count > 0 && solutionCollection != null) {
109          solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(x => (IClassificationSolution)x.Tag));
110          itemsListView.SelectedItems.Clear();
111        } else {
112          base.removeButton_Click(sender, e);
113        }
114      }
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.