Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionModelView.cs @ 16724

Last change on this file since 16724 was 16565, checked in by gkronber, 6 years ago

#2520: merged changes from PersistenceOverhaul branch (r16451:16564) into trunk

File size: 5.0 KB
RevLine 
[6612]1#region License Information
2/* HeuristicLab
[16565]3 * Copyright (C) 2002-2019 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(ClassificationEnsembleSolution), false)]
34  internal sealed partial class ClassificationEnsembleSolutionModelView : DataAnalysisSolutionEvaluationView {
35    private ModelsView view;
[6612]36
[6613]37    public ClassificationEnsembleSolutionModelView() {
[6612]38      InitializeComponent();
[6642]39      view = new ModelsView();
40      view.Dock = DockStyle.Fill;
41      Controls.Add(view);
[6612]42    }
43
[6642]44    public new ClassificationEnsembleSolution Content {
45      get { return (ClassificationEnsembleSolution)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 == ClassificationEnsembleProblemData.EmptyProblemData;
[6642]53        view.Content = Content.ClassificationSolutions;
[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<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      }
[6666]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          }
[8719]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          }
[6666]94        }
95      }
[8719]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      }
[6642]115    }
[6612]116  }
117}
Note: See TracBrowser for help on using the repository browser.