#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Linq; using System.Windows.Forms; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; using HeuristicLab.Problems.DataAnalysis; namespace HeuristicLab.DatastreamAnalysis.Views { [View("Ensemble Models")] [Content(typeof(RegressionEnsembleModel), true)] internal sealed partial class RegressionEnsembleModelView : NamedItemView { //private ItemCollectionView view; private ItemCollection models = new ItemCollection(); public RegressionEnsembleModelView() { InitializeComponent(); models = new ItemCollection(); models.ItemsAdded += Models_ItemsAdded; models.ItemsRemoved += Models_ItemsRemoved; models.CollectionReset += Models_CollectionReset; } public new RegressionEnsembleModel Content { get { return (RegressionEnsembleModel)base.Content; } set { base.Content = value; } } protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null) { models.ItemsAdded -= Models_ItemsAdded; models.ItemsRemoved -= Models_ItemsRemoved; models.CollectionReset -= Models_CollectionReset; models.Clear(); models.AddRange(Content.Models); modelsView.Content = models; models.ItemsAdded += Models_ItemsAdded; models.ItemsRemoved += Models_ItemsRemoved; models.CollectionReset += Models_CollectionReset; } else { modelsView.Content = null; } } private void Models_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs e) { Content = null; } private void Models_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs e) { Content.AddRange(e.Items); } private void Models_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs e) { Content.RemoveRange(e.Items); } private class ModelsView : ItemCollectionView { public ModelsView() : base() { } } //private class ModelsView : ItemCollectionView { // protected override void SetEnabledStateOfControls() { // base.SetEnabledStateOfControls(); // addButton.Enabled = false; // removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && !ReadOnly && itemsListView.SelectedItems.Count > 0; // itemsListView.Enabled = Content != null && !Locked; // detailsGroupBox.Enabled = Content != null && itemsListView.SelectedItems.Count == 1; // sortAscendingButton.Enabled = false; // sortDescendingButton.Enabled = false; // } // protected override void SortItemsListView(SortOrder sortOrder) { } // protected override void itemsListView_DragEnter(object sender, DragEventArgs e) { // validDragOperation = false; // if (ReadOnly || Locked) return; // if (Content.IsReadOnly) return; // var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); // validDragOperation = dropData.GetObjectGraphObjects().OfType().Any(); // } // protected override void itemsListView_DragDrop(object sender, DragEventArgs e) { // if (e.Effect != DragDropEffects.None) { // var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); // var solutions = dropData.GetObjectGraphObjects().OfType(); // if (e.Effect.HasFlag(DragDropEffects.Copy)) { // Cloner cloner = new Cloner(); // solutions = solutions.Select(s => cloner.Clone(s)); // } // var solutionCollection = Content as ItemCollection; // if (solutionCollection != null) { // solutionCollection.AddRange(solutions); // } else { // foreach (var solution in solutions) // Content.Add(solution); // } // } // } // protected override void itemsListView_KeyDown(object sender, KeyEventArgs e) { // var solutionCollection = Content as ItemCollection; // if (e.KeyCode == Keys.Delete && solutionCollection != null) { // if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) { // solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast().Select(x => (IRegressionModel)x.Tag)); // } // } else { // base.itemsListView_KeyDown(sender, e); // } // } // protected override void removeButton_Click(object sender, EventArgs e) { // var solutionCollection = Content as ItemCollection; // if (itemsListView.SelectedItems.Count > 0 && solutionCollection != null) { // solutionCollection.RemoveRange(itemsListView.SelectedItems.Cast().Select(x => (IRegressionModel)x.Tag)); // itemsListView.SelectedItems.Clear(); // } else { // base.removeButton_Click(sender, e); // } // } //} } }