Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/ProblemView.cs @ 12689

Last change on this file since 12689 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 4.5 KB
RevLine 
[2796]1#region License Information
2/* HeuristicLab
[12012]3 * Copyright (C) 2002-2015 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]22using System;
23using System.Collections.Generic;
[7641]24using System.Linq;
[2834]25using HeuristicLab.Core.Views;
[2796]26using HeuristicLab.MainForm;
[7641]27using HeuristicLab.Problems.Instances;
[7956]28using HeuristicLab.Problems.Instances.Views;
[2796]29
[2852]30namespace 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}
Note: See TracBrowser for help on using the repository browser.