#region License Information /* HeuristicLab * Copyright (C) 2002-2012 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.Collections.Generic; using System.Linq; using System.Windows.Forms; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; using HeuristicLab.Optimization; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Problems.Instances; namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views { [View("ProblemView")] [Content(typeof(Problem), IsDefaultView = true)] public partial class ProblemView : ParameterizedNamedItemView { public new Problem Content { get { return (Problem)base.Content; } set { base.Content = value; } } public ProblemView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { problemInstanceProviderComboBox.DataSource = null; } else { problemInstanceProviderComboBox.DisplayMember = "Name"; problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList(); } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null; } private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) { if (problemInstanceProviderComboBox.SelectedIndex >= 0) { var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem; provider.SetConsumer((IProblemInstanceConsumer)Content); problemInstanceProviderViewHost.Content = provider; } } private void comboBox_DataSourceChanged(object sender, EventArgs e) { var comboBox = (ComboBox)sender; if (comboBox.DataSource == null) comboBox.Items.Clear(); } protected virtual IEnumerable GetProblemInstanceProviders() { var consumerTypes = Content.GetType().GetInterfaces() .Where(x => x.IsGenericType && typeof(IProblemInstanceConsumer).IsAssignableFrom(x)); if (consumerTypes.Any()) { var instanceTypes = consumerTypes .Select(x => x.GetGenericArguments().First()) .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x)); foreach (var type in instanceTypes) { foreach (var provider in ApplicationManager.Manager.GetInstances(type)) yield return (IProblemInstanceProvider)provider; } } } protected virtual string GetProviderToolTip(IProblemInstanceProvider provider) { if (provider.WebLink != null) { return provider.Name + Environment.NewLine + provider.WebLink.ToString() + Environment.NewLine + Environment.NewLine + provider.ReferencePublication; } else { return provider.Name + Environment.NewLine + Environment.NewLine + provider.ReferencePublication; } } private void problemInstanceProviderComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) { e.ToolTip = GetProviderToolTip((IProblemInstanceProvider)e.Item); } } }