Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/02/13 20:11:14 (9 years ago)
Author:
abeham
Message:

#2110: merged to stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimization.Views/3.3/ProblemView.cs

    r9456 r10021  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Windows.Forms;
    2625using HeuristicLab.Core.Views;
    2726using HeuristicLab.MainForm;
     
    3736  public partial class ProblemView : ParameterizedNamedItemView {
    3837
    39     private static Type neededViewType = typeof(ProblemInstanceConsumerView);
    40 
    4138    public new IProblem Content {
    4239      get { return (IProblem)base.Content; }
    4340      set { base.Content = value; }
    4441    }
     42
     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; }
    4549
    4650    /// <summary>
     
    5357    protected override void OnContentChanged() {
    5458      base.OnContentChanged();
    55       IProblemInstanceConsumer consumer = Content as IProblemInstanceConsumer;
    56       if (consumer != null) {
    57         IEnumerable<Type> viewTypes = MainFormManager.GetViewTypes(consumer.GetType(), true);
    58         Type genericView = viewTypes.Where(x => x.IsSubclassOf(neededViewType)).First();
    59         ProblemInstanceConsumerViewHost.Content = null; //necessary to enable the change of the ViewType
    60         ProblemInstanceConsumerViewHost.ViewType = genericView;
    61         ProblemInstanceConsumerViewHost.Content = consumer;
    62         ProblemInstanceConsumerView view = (ProblemInstanceConsumerView)ProblemInstanceConsumerViewHost.ActiveView;
    63         problemInstanceSplitContainer.Panel1Collapsed = !view.ProblemInstanceProviders.Any();
     59      if (Content == null) {
     60        problemInstanceProviders = null;
     61        problemInstanceProviderComboBox.DataSource = null;
     62        problemInstanceSplitContainer.Panel1Collapsed = true;
    6463      } else {
    65         problemInstanceSplitContainer.Panel1Collapsed = true;
     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;
     73        } else
     74          problemInstanceSplitContainer.Panel1Collapsed = true;
    6675      }
    6776      SetEnabledStateOfControls();
    6877    }
    6978
     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
    70124  }
    71125}
Note: See TracChangeset for help on using the changeset viewer.