Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Optimization.Views/3.3/ProblemInstanceProvidersControl.cs @ 18242

Last change on this file since 18242 was 17953, checked in by mkommend, 4 years ago

#2521: Added first version (draft) of ResultsProducingItem, an according view and a refactored ProblemView.

File size: 3.6 KB
RevLine 
[17953]1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Problems.Instances;
26using HeuristicLab.Problems.Instances.Views;
27
28namespace HeuristicLab.Optimization.Views {
29  public partial class ProblemInstanceProvidersControl : UserControl {
30    public ProblemInstanceProvidersControl() {
31      InitializeComponent();
32    }
33
34    private IProblemInstanceConsumer consumer;
35    public IProblemInstanceConsumer Consumer {
36      get => consumer;
37      set { consumer = value; OnConsumerChanged(); }
38    }
39
40    public bool ProvidersAvailable => problemInstanceProviderComboBox.DataSource != null;
41
42
43    private void OnConsumerChanged() {
44      if (Consumer == null) {
45        problemInstanceProviderComboBox.DataSource = null;
46        return;
47      }
48
49      var problemInstanceProviders = ProblemInstanceManager.GetProviders(Consumer);
50      if (problemInstanceProviders.Any()) {
51        problemInstanceProviderComboBox.DisplayMember = "Name";
52        problemInstanceProviderComboBox.DataSource = problemInstanceProviders.OrderBy(x => x.Name).ToList();
53      } else {
54        problemInstanceProviderComboBox.DataSource = null;
55      }
56
57    }
58
59    private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, EventArgs e) {
60      if (problemInstanceProviderComboBox.SelectedIndex < 0) return;
61
62      var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
63      problemInstanceProviderViewHost.Content = provider;
64      var view = (ProblemInstanceProviderView)problemInstanceProviderViewHost.ActiveView;
65      view.Consumer = Consumer;
66      if (CheckForIProblemInstanceExporter(consumer))
67        view.Exporter = (IProblemInstanceExporter)consumer;
68      else view.Exporter = null;
69      SetTooltip();
70    }
71
72    private static bool CheckForIProblemInstanceExporter(IProblemInstanceConsumer consumer) {
73      return consumer.GetType().GetInterfaces().Any(x => x == typeof(IProblemInstanceExporter));
74    }
75
76
77    private void SetTooltip() {
78      var provider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
79      var toolTipText = GetProviderToolTipText(provider);
80      toolTip.SetToolTip(problemInstanceProviderComboBox, toolTipText);
81    }
82
83    private static string GetProviderToolTipText(IProblemInstanceProvider provider) {
84      string toolTip = provider.Name;
85
86      if (!string.IsNullOrEmpty(provider.ReferencePublication)) {
87        toolTip = toolTip
88            + Environment.NewLine + Environment.NewLine
89            + provider.ReferencePublication;
90      }
91      if (provider.WebLink != null) {
92        toolTip = toolTip
93            + Environment.NewLine
94            + provider.WebLink.ToString();
95      }
96
97      return toolTip;
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.