[2796] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16956] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2796] | 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 |
|
---|
[7956] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[7641] | 24 | using System.Linq;
|
---|
[2834] | 25 | using HeuristicLab.Core.Views;
|
---|
[2796] | 26 | using HeuristicLab.MainForm;
|
---|
[7641] | 27 | using HeuristicLab.Problems.Instances;
|
---|
[7956] | 28 | using HeuristicLab.Problems.Instances.Views;
|
---|
[2796] | 29 |
|
---|
[2852] | 30 | namespace HeuristicLab.Optimization.Views {
|
---|
[2796] | 31 | /// <summary>
|
---|
| 32 | /// The base class for visual representations of items.
|
---|
| 33 | /// </summary>
|
---|
[2917] | 34 | [View("Problem View")]
|
---|
[2865] | 35 | [Content(typeof(IProblem), true)]
|
---|
[2851] | 36 | public partial class ProblemView : ParameterizedNamedItemView {
|
---|
[7956] | 37 |
|
---|
[2796] | 38 | public new IProblem Content {
|
---|
| 39 | get { return (IProblem)base.Content; }
|
---|
| 40 | set { base.Content = value; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[10000] | 43 | protected IEnumerable<IProblemInstanceProvider> problemInstanceProviders;
|
---|
| 44 | public IEnumerable<IProblemInstanceProvider> ProblemInstanceProviders {
|
---|
| 45 | get { return new List<IProblemInstanceProvider>(problemInstanceProviders); }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public IProblemInstanceProvider SelectedProvider { get; protected set; }
|
---|
| 49 |
|
---|
[2796] | 50 | /// <summary>
|
---|
| 51 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 52 | /// </summary>
|
---|
| 53 | public ProblemView() {
|
---|
| 54 | InitializeComponent();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | protected override void OnContentChanged() {
|
---|
| 58 | base.OnContentChanged();
|
---|
[10000] | 59 | if (Content == null) {
|
---|
| 60 | problemInstanceProviders = null;
|
---|
| 61 | problemInstanceProviderComboBox.DataSource = null;
|
---|
| 62 | problemInstanceSplitContainer.Panel1Collapsed = true;
|
---|
[7641] | 63 | } else {
|
---|
[10000] | 64 | var consumer = Content as IProblemInstanceConsumer;
|
---|
| 65 | if (consumer != null) {
|
---|
| 66 | problemInstanceProviders = ProblemInstanceManager.GetProviders(Content);
|
---|
| 67 | bool expand = problemInstanceProviders.Any();
|
---|
| 68 | if (expand) {
|
---|
| 69 | problemInstanceProviderComboBox.DisplayMember = "Name";
|
---|
| 70 | problemInstanceProviderComboBox.DataSource = ProblemInstanceProviders.OrderBy(x => x.Name).ToList();
|
---|
| 71 | }
|
---|
| 72 | problemInstanceSplitContainer.Panel1Collapsed = !expand;
|
---|
[10003] | 73 | } else
|
---|
| 74 | problemInstanceSplitContainer.Panel1Collapsed = true;
|
---|
[7641] | 75 | }
|
---|
| 76 | SetEnabledStateOfControls();
|
---|
[2796] | 77 | }
|
---|
[7641] | 78 |
|
---|
[10000] | 79 | protected virtual void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 80 | if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
|
---|
| 81 | SelectedProvider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
|
---|
| 82 | problemInstanceProviderViewHost.Content = SelectedProvider;
|
---|
| 83 | var view = (ProblemInstanceProviderView)problemInstanceProviderViewHost.ActiveView;
|
---|
| 84 | var consumer = (IProblemInstanceConsumer)Content;
|
---|
| 85 | view.Consumer = consumer;
|
---|
| 86 | if (CheckForIProblemInstanceExporter(consumer))
|
---|
| 87 | view.Exporter = (IProblemInstanceExporter)Content;
|
---|
| 88 | else view.Exporter = null;
|
---|
| 89 | SetTooltip();
|
---|
| 90 | } else {
|
---|
| 91 | SelectedProvider = null;
|
---|
| 92 | }
|
---|
| 93 | SetEnabledStateOfControls();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | protected bool CheckForIProblemInstanceExporter(IProblemInstanceConsumer content) {
|
---|
| 97 | return Content.GetType().GetInterfaces()
|
---|
| 98 | .Any(x => x == typeof(IProblemInstanceExporter));
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | #region ToolTip
|
---|
| 102 | protected void SetTooltip() {
|
---|
| 103 | toolTip.SetToolTip(problemInstanceProviderComboBox, GetProviderToolTip());
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private string GetProviderToolTip() {
|
---|
| 107 | var provider = SelectedProvider;
|
---|
| 108 | string toolTip = provider.Name;
|
---|
| 109 |
|
---|
| 110 | if (!String.IsNullOrEmpty(provider.ReferencePublication)) {
|
---|
| 111 | toolTip = toolTip
|
---|
| 112 | + Environment.NewLine + Environment.NewLine
|
---|
| 113 | + provider.ReferencePublication;
|
---|
| 114 | }
|
---|
| 115 | if (provider.WebLink != null) {
|
---|
| 116 | toolTip = toolTip
|
---|
| 117 | + Environment.NewLine
|
---|
| 118 | + provider.WebLink.ToString();
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | return toolTip;
|
---|
| 122 | }
|
---|
| 123 | #endregion
|
---|
[2796] | 124 | }
|
---|
| 125 | }
|
---|