Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Views/3.4/ProblemInstanceConsumerView.cs @ 7664

Last change on this file since 7664 was 7664, checked in by sforsten, 13 years ago

#1784:

  • added Keijzer, Korns, Vladislavleva und Nguyen regression problem instances
  • changes have been made in the ProblemView. Some parts have been replaced with views from Problems.Instances.Views
File size: 5.5 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Diagnostics;
25using System.Linq;
26using System.Windows.Forms;
27using HeuristicLab.Common.Resources;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30using HeuristicLab.PluginInfrastructure;
31
32namespace HeuristicLab.Problems.Instances.Views {
33  [View("ProblemInstanceConsumerView")]
34  [Content(typeof(IProblemInstanceConsumer), IsDefaultView = true)]
35  public sealed partial class ProblemInstanceConsumerView : AsynchronousContentView {
36
37    public new IProblemInstanceConsumer Content {
38      get { return (IProblemInstanceConsumer)base.Content; }
39      set { base.Content = value; }
40    }
41
42    private IProblemInstanceProvider SelectedProvider {
43      get { return (problemInstanceProviderComboBox.SelectedIndex >= 0 ? (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem : null); }
44    }
45
46    public ProblemInstanceConsumerView() {
47      InitializeComponent();
48      libraryInfoButton.Text = String.Empty;
49      libraryInfoButton.Image = VSImageLibrary.Internet;
50    }
51
52    protected override void OnContentChanged() {
53      base.OnContentChanged();
54      if (Content == null) {
55        problemInstanceProviderComboBox.DataSource = null;
56      } else {
57        problemInstanceProviderComboBox.DisplayMember = "Name";
58        problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList();
59      }
60      SetEnabledStateOfControls();
61    }
62
63    public bool ContainsProviders() {
64      return problemInstanceProviderComboBox.Items.Count > 0;
65    }
66
67    protected override void SetEnabledStateOfControls() {
68      base.SetEnabledStateOfControls();
69      problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null && problemInstanceProviderComboBox.Items.Count > 0;
70      libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null;
71    }
72
73    private void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
74      if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
75        //dynamic provider = SelectedProvider;
76        //dynamic consumer = Content;
77        //provider.Consumer = consumer;
78        problemInstanceProviderViewHost.Content = SelectedProvider;
79        dynamic view = problemInstanceProviderViewHost.ActiveView;
80        view.Consumer = Content;
81        //Check if IProblemInstanceExporterView is implemented
82        view.Exporter = Content;
83        //SetTooltip();
84      }
85      SetEnabledStateOfControls();
86    }
87
88    private void comboBox_DataSourceChanged(object sender, EventArgs e) {
89      var comboBox = (ComboBox)sender;
90      if (comboBox.DataSource == null)
91        comboBox.Items.Clear();
92    }
93
94    private void libraryInfoButton_Click(object sender, EventArgs e) {
95      if (problemInstanceProviderComboBox.SelectedIndex >= 0) {
96        if (SelectedProvider != null && SelectedProvider.WebLink != null)
97          Process.Start(SelectedProvider.WebLink.ToString());
98      }
99    }
100
101    private IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() {
102      var consumerTypes = Content.GetType().GetInterfaces()
103        .Where(x => x.IsGenericType
104          && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>));
105
106      if (consumerTypes.Any()) {
107        var instanceTypes = consumerTypes
108          .Select(x => x.GetGenericArguments().First())
109          .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x));
110
111        foreach (var type in instanceTypes) {
112          foreach (var provider in ApplicationManager.Manager.GetInstances(type))
113            yield return (IProblemInstanceProvider)provider;
114        }
115      }
116    }
117
118    //protected void SetTooltip() {
119    //  toolTip.SetToolTip(problemInstanceProviderComboBox, GetProviderToolTip());
120    //  if (SelectedProvider.WebLink != null)
121    //    toolTip.SetToolTip(libraryInfoButton, "Browse to " + SelectedProvider.WebLink.ToString());
122    //  else toolTip.SetToolTip(libraryInfoButton, "Library does not have a web reference.");
123    //}
124
125    //protected string GetProviderToolTip() {
126    //  var provider = SelectedProvider;
127    //  string toolTip = provider.Name;
128
129    //  if (!String.IsNullOrEmpty(provider.ReferencePublication)) {
130    //    toolTip = toolTip
131    //        + Environment.NewLine + Environment.NewLine
132    //        + provider.ReferencePublication;
133    //  }
134    //  if (provider.WebLink != null) {
135    //    toolTip = toolTip
136    //        + Environment.NewLine
137    //        + provider.WebLink.ToString();
138    //  }
139
140    //  return toolTip;
141    //}
142  }
143}
Note: See TracBrowser for help on using the repository browser.