Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/12 21:50:19 (12 years ago)
Author:
sforsten
Message:

#1782: improvements from mkommend's comment have been applied

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceConsumerView.cs

    r7860 r7956  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Diagnostics;
    25 using System.Linq;
    2623using System.Windows.Forms;
    27 using HeuristicLab.Common.Resources;
    2824using HeuristicLab.MainForm;
    2925using HeuristicLab.MainForm.WindowsForms;
     
    3228  [View("ProblemInstanceConsumerView")]
    3329  [Content(typeof(IProblemInstanceConsumer), IsDefaultView = false)]
    34   public sealed partial class ProblemInstanceConsumerView : AsynchronousContentView {
     30  public partial class ProblemInstanceConsumerView : AsynchronousContentView {
    3531
    3632    public new IProblemInstanceConsumer Content {
     
    3935    }
    4036
    41     public IProblemInstanceProvider SelectedProvider {
    42       get;
    43       private set;
    44     }
    45 
     37    protected IEnumerable<IProblemInstanceProvider> problemInstanceProviders;
    4638    public IEnumerable<IProblemInstanceProvider> ProblemInstanceProviders {
    47       get;
    48       private set;
     39      get { return new List<IProblemInstanceProvider>(problemInstanceProviders); }
    4940    }
    5041
    5142    public ProblemInstanceConsumerView() {
    5243      InitializeComponent();
    53       libraryInfoButton.Text = String.Empty;
    54       libraryInfoButton.Image = VSImageLibrary.Help;
    5544    }
    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
    13545  }
    13646}
Note: See TracChangeset for help on using the changeset viewer.