Changeset 8086 for branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Views/3.3/ProblemView.cs
- Timestamp:
- 06/22/12 11:11:38 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Views/3.3/ProblemView.cs
r7641 r8086 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics;25 24 using System.Linq; 26 25 using System.Windows.Forms; 27 using HeuristicLab.Common.Resources;28 26 using HeuristicLab.Core.Views; 29 27 using HeuristicLab.MainForm; 30 using HeuristicLab.PluginInfrastructure;31 28 using HeuristicLab.Problems.Instances; 29 using HeuristicLab.Problems.Instances.Views; 32 30 33 31 namespace HeuristicLab.Optimization.Views { … … 38 36 [Content(typeof(IProblem), true)] 39 37 public partial class ProblemView : ParameterizedNamedItemView { 38 39 private static Type neededViewType = typeof(ProblemInstanceConsumerView); 40 40 41 public new IProblem Content { 41 42 get { return (IProblem)base.Content; } 42 43 set { base.Content = value; } 43 }44 45 protected IProblemInstanceProvider SelectedProvider {46 get { return (problemInstanceProviderComboBox.SelectedIndex >= 0 ? (IProblemInstanceProvider)problemInstanceProviderComboBox.SelectedItem : null); }47 44 } 48 45 … … 52 49 public ProblemView() { 53 50 InitializeComponent(); 54 libraryInfoButton.Text = String.Empty;55 libraryInfoButton.Image = VSImageLibrary.Internet;56 51 } 57 52 58 53 protected override void OnContentChanged() { 59 54 base.OnContentChanged(); 60 if (Content == null) { 61 problemInstanceProviderComboBox.DataSource = null; 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.ViewType = genericView; 60 ProblemInstanceConsumerViewHost.Content = consumer; 61 ProblemInstanceConsumerView view = (ProblemInstanceConsumerView)ProblemInstanceConsumerViewHost.ActiveView; 62 problemInstanceSplitContainer.Panel1Collapsed = !view.ProblemInstanceProviders.Any(); 62 63 } else { 63 problemInstanceProviderComboBox.DisplayMember = "Name"; 64 problemInstanceProviderComboBox.DataSource = GetProblemInstanceProviders().ToList(); 65 problemInstanceSplitContainer.Panel1Collapsed = problemInstanceProviderComboBox.Items.Count <= 0; 66 64 problemInstanceSplitContainer.Panel1Collapsed = true; 67 65 } 68 66 SetEnabledStateOfControls(); 69 67 } 70 68 71 protected override void SetEnabledStateOfControls() {72 base.SetEnabledStateOfControls();73 problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null && problemInstanceProviderComboBox.Items.Count > 0;74 libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null;75 }76 77 protected virtual void problemInstanceProviderComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {78 if (problemInstanceProviderComboBox.SelectedIndex >= 0) {79 dynamic provider = SelectedProvider;80 dynamic consumer = Content;81 provider.Consumer = consumer;82 problemInstanceProviderViewHost.Content = SelectedProvider;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 protected virtual 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 protected virtual IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() {102 var consumerTypes = Content.GetType().GetInterfaces()103 .Where(x => x.IsGenericType104 && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>));105 106 if (consumerTypes.Any()) {107 var instanceTypes = consumerTypes108 .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 virtual 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 virtual string GetProviderToolTip() {126 var provider = SelectedProvider;127 string toolTip = provider.Name;128 129 if (!String.IsNullOrEmpty(provider.ReferencePublication)) {130 toolTip = toolTip131 + Environment.NewLine + Environment.NewLine132 + provider.ReferencePublication;133 }134 if (provider.WebLink != null) {135 toolTip = toolTip136 + Environment.NewLine137 + provider.WebLink.ToString();138 }139 140 return toolTip;141 }142 69 } 143 70 }
Note: See TracChangeset
for help on using the changeset viewer.