1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Diagnostics;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using HeuristicLab.Common.Resources;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.Instances.Views {
|
---|
32 | [View("ProblemInstanceConsumerView")]
|
---|
33 | [Content(typeof(IProblemInstanceConsumer), IsDefaultView = false)]
|
---|
34 | public sealed partial class ProblemInstanceConsumerView : AsynchronousContentView {
|
---|
35 |
|
---|
36 | public new IProblemInstanceConsumer Content {
|
---|
37 | get { return (IProblemInstanceConsumer)base.Content; }
|
---|
38 | set { base.Content = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public IProblemInstanceProvider SelectedProvider {
|
---|
42 | get;
|
---|
43 | private set;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public IEnumerable<IProblemInstanceProvider> ProblemInstanceProviders {
|
---|
47 | get;
|
---|
48 | private set;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public ProblemInstanceConsumerView() {
|
---|
52 | InitializeComponent();
|
---|
53 | libraryInfoButton.Text = String.Empty;
|
---|
54 | libraryInfoButton.Image = VSImageLibrary.Help;
|
---|
55 | }
|
---|
56 |
|
---|
57 | protected override void OnContentChanged() {
|
---|
58 | base.OnContentChanged();
|
---|
59 | if (Content == null) {
|
---|
60 | ProblemInstanceProviders = null;
|
---|
61 | problemInstanceProviderComboBox.DataSource = null;
|
---|
62 | } else {
|
---|
63 | problemInstanceProviderComboBox.DisplayMember = "Name";
|
---|
64 | ProblemInstanceProviders = ProblemInstanceManager.GetProviders(Content);
|
---|
65 | problemInstanceProviderComboBox.DataSource = ProblemInstanceProviders.OrderBy(x => x.Name).ToList();
|
---|
66 | }
|
---|
67 | SetEnabledStateOfControls();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public bool ContainsProviders() {
|
---|
71 | return problemInstanceProviderComboBox.Items.Count > 0;
|
---|
72 | }
|
---|
73 |
|
---|
74 | protected override void SetEnabledStateOfControls() {
|
---|
75 | base.SetEnabledStateOfControls();
|
---|
76 | problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null && problemInstanceProviderComboBox.Items.Count > 0;
|
---|
77 | libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null;
|
---|
78 | }
|
---|
79 |
|
---|
80 | private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
81 | if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
|
---|
82 | SelectedProvider = (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem;
|
---|
83 | problemInstanceProviderViewHost.Content = SelectedProvider;
|
---|
84 | ProblemInstanceProviderView view = (ProblemInstanceProviderView)problemInstanceProviderViewHost.ActiveView;
|
---|
85 | view.Consumer = Content;
|
---|
86 | if (CheckForIProblemInstanceExporter(Content)) {
|
---|
87 | view.Exporter = (IProblemInstanceExporter)Content;
|
---|
88 | }
|
---|
89 | SetTooltip();
|
---|
90 | } else {
|
---|
91 | SelectedProvider = null;
|
---|
92 | }
|
---|
93 |
|
---|
94 | SetEnabledStateOfControls();
|
---|
95 | }
|
---|
96 |
|
---|
97 | private bool CheckForIProblemInstanceExporter(IProblemInstanceConsumer content) {
|
---|
98 | return Content.GetType().GetInterfaces()
|
---|
99 | .Any(x => x.Equals(typeof(IProblemInstanceExporter)));
|
---|
100 | }
|
---|
101 |
|
---|
102 | private void libraryInfoButton_Click(object sender, EventArgs e) {
|
---|
103 | if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
|
---|
104 | if (SelectedProvider != null && SelectedProvider.WebLink != null)
|
---|
105 | Process.Start(SelectedProvider.WebLink.ToString());
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | #region ToolTip
|
---|
110 | private void SetTooltip() {
|
---|
111 | toolTip.SetToolTip(problemInstanceProviderComboBox, GetProviderToolTip());
|
---|
112 | if (SelectedProvider.WebLink != null)
|
---|
113 | toolTip.SetToolTip(libraryInfoButton, "Browse to " + SelectedProvider.WebLink.ToString());
|
---|
114 | else toolTip.SetToolTip(libraryInfoButton, "Library does not have a web reference.");
|
---|
115 | }
|
---|
116 |
|
---|
117 | private string GetProviderToolTip() {
|
---|
118 | var provider = SelectedProvider;
|
---|
119 | string toolTip = provider.Name;
|
---|
120 |
|
---|
121 | if (!String.IsNullOrEmpty(provider.ReferencePublication)) {
|
---|
122 | toolTip = toolTip
|
---|
123 | + Environment.NewLine + Environment.NewLine
|
---|
124 | + provider.ReferencePublication;
|
---|
125 | }
|
---|
126 | if (provider.WebLink != null) {
|
---|
127 | toolTip = toolTip
|
---|
128 | + Environment.NewLine
|
---|
129 | + provider.WebLink.ToString();
|
---|
130 | }
|
---|
131 |
|
---|
132 | return toolTip;
|
---|
133 | }
|
---|
134 | #endregion
|
---|
135 | }
|
---|
136 | }
|
---|