Changeset 7956 for trunk/sources/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceConsumerView.cs
- Timestamp:
- 06/04/12 21:50:19 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceConsumerView.cs
r7860 r7956 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Diagnostics;25 using System.Linq;26 23 using System.Windows.Forms; 27 using HeuristicLab.Common.Resources;28 24 using HeuristicLab.MainForm; 29 25 using HeuristicLab.MainForm.WindowsForms; … … 32 28 [View("ProblemInstanceConsumerView")] 33 29 [Content(typeof(IProblemInstanceConsumer), IsDefaultView = false)] 34 public sealedpartial class ProblemInstanceConsumerView : AsynchronousContentView {30 public partial class ProblemInstanceConsumerView : AsynchronousContentView { 35 31 36 32 public new IProblemInstanceConsumer Content { … … 39 35 } 40 36 41 public IProblemInstanceProvider SelectedProvider { 42 get; 43 private set; 44 } 45 37 protected IEnumerable<IProblemInstanceProvider> problemInstanceProviders; 46 38 public IEnumerable<IProblemInstanceProvider> ProblemInstanceProviders { 47 get; 48 private set; 39 get { return new List<IProblemInstanceProvider>(problemInstanceProviders); } 49 40 } 50 41 51 42 public ProblemInstanceConsumerView() { 52 43 InitializeComponent(); 53 libraryInfoButton.Text = String.Empty;54 libraryInfoButton.Image = VSImageLibrary.Help;55 44 } 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 ToolTip110 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 = toolTip123 + Environment.NewLine + Environment.NewLine124 + provider.ReferencePublication;125 }126 if (provider.WebLink != null) {127 toolTip = toolTip128 + Environment.NewLine129 + provider.WebLink.ToString();130 }131 132 return toolTip;133 }134 #endregion135 45 } 136 46 }
Note: See TracChangeset
for help on using the changeset viewer.