#region License Information /* HeuristicLab * Copyright (C) 2002-2013 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.ComponentModel; using System.Linq; using HeuristicLab.MainForm; using HeuristicLab.Problems.Instances.Views; namespace HeuristicLab.Problems.Instances.QAPGenerator.Views { [View("QAP Instance Generators")] [Content(typeof(QAPInstanceGeneratorProvider), IsDefaultView = true)] public sealed partial class QAPInstanceGeneratorProviderView : ProblemInstanceProviderView { public new QAPInstanceGeneratorProvider Content { get { return (QAPInstanceGeneratorProvider)base.Content; } set { base.Content = value; } } private QAPInstanceGeneratorDescriptor SelectedDescriptor { get { return descriptorsComboBox.SelectedIndex >= 0 ? (QAPInstanceGeneratorDescriptor)descriptorsComboBox.SelectedItem : null; } } public QAPInstanceGeneratorProviderView() { InitializeComponent(); splitContainer1.Visible = false; descriptorsComboBox.DisplayMember = "Name"; } protected override void OnContentChanged() { base.OnContentChanged(); DeregisterDescriptorEvents(); descriptorsComboBox.Items.Clear(); if (Content == null) { descriptorViewHost.Content = null; } else { foreach (var descriptor in Content.GetDataDescriptors()) { descriptorsComboBox.Items.Add(descriptor); } descriptorsComboBox.SelectedIndex = descriptorsComboBox.Items.Count > 0 ? 0 : -1; } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); loadButton.Enabled = !ReadOnly && !Locked && Content != null && SelectedDescriptor != null && SelectedDescriptor.IsConfigurationValid && GenericConsumer != null; } private void RegisterDescriptorEvents() { if (SelectedDescriptor != null) SelectedDescriptor.PropertyChanged += SelectedDescriptorOnPropertyChanged; } private void DeregisterDescriptorEvents() { foreach (var descriptor in descriptorsComboBox.Items.OfType()) descriptor.PropertyChanged -= SelectedDescriptorOnPropertyChanged; } private void SelectedDescriptorOnPropertyChanged(object sender, PropertyChangedEventArgs e) { SetEnabledStateOfControls(); } private void descriptorsComboBox_SelectedIndexChanged(object sender, EventArgs e) { DeregisterDescriptorEvents(); RegisterDescriptorEvents(); descriptorViewHost.Content = (QAPInstanceGeneratorDescriptor)descriptorsComboBox.SelectedItem; SetEnabledStateOfControls(); } private void loadButton_Click(object sender, EventArgs e) { GenericConsumer.Load(SelectedDescriptor.GetInstance()); } } }