Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceProviderViewGeneric.cs @ 12448

Last change on this file since 12448 was 9363, checked in by spimming, 12 years ago

#1888:

  • Merged revisions from trunk
File size: 3.7 KB
RevLine 
[7683]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
[8198]27using HeuristicLab.PluginInfrastructure;
[7683]28
29namespace HeuristicLab.Problems.Instances.Views {
[7684]30  [View("ProblemInstanceProviderViewGeneric")]
[7683]31  [Content(typeof(IProblemInstanceProvider<>), IsDefaultView = true)]
[7684]32  public partial class ProblemInstanceProviderViewGeneric<T> : ProblemInstanceProviderView {
[7683]33
34    public new IProblemInstanceProvider<T> Content {
35      get { return (IProblemInstanceProvider<T>)base.Content; }
36      set { base.Content = value; }
37    }
38
[7956]39    private IProblemInstanceConsumer<T> GenericConsumer { get { return Consumer as IProblemInstanceConsumer<T>; } }
40
[9363]41    private IProblemInstanceConsumer consumer;
[7684]42    public override IProblemInstanceConsumer Consumer {
43      get { return consumer; }
44      set {
45        consumer = value;
46        SetEnabledStateOfControls();
47      }
48    }
[7683]49
[7684]50    public ProblemInstanceProviderViewGeneric() {
[7683]51      InitializeComponent();
52    }
53
54    protected override void OnContentChanged() {
55      base.OnContentChanged();
56      if (Content == null) {
57        instancesComboBox.DataSource = null;
58      } else {
59        instancesComboBox.DisplayMember = "Name";
[9363]60        var dataDescriptors = Content.GetDataDescriptors().ToList();
61        ShowInstanceLoad(dataDescriptors.Any());
[7860]62        instancesComboBox.DataSource = dataDescriptors;
[8031]63        instancesComboBox.SelectedIndex = -1;
[7683]64      }
65    }
66
[7860]67    protected void ShowInstanceLoad(bool show) {
68      if (show) {
69        instanceLabel.Show();
70        instancesComboBox.Show();
71      } else {
72        instanceLabel.Hide();
73        instancesComboBox.Hide();
74      }
75    }
76
[7683]77    protected override void SetEnabledStateOfControls() {
78      base.SetEnabledStateOfControls();
[7684]79      instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && GenericConsumer != null;
[7683]80    }
81
[7956]82    private void instancesComboBox_DataSourceChanged(object sender, EventArgs e) {
[7683]83      var comboBox = (ComboBox)sender;
84      if (comboBox.DataSource == null)
85        comboBox.Items.Clear();
[9363]86      toolTip.SetToolTip(comboBox, String.Empty);
[7683]87    }
[8031]88
[8196]89    private void instancesComboBox_SelectionChangeCommitted(object sender, System.EventArgs e) {
90      if (instancesComboBox.SelectedIndex >= 0) {
91        var descriptor = (IDataDescriptor)instancesComboBox.SelectedItem;
92        T instance = Content.LoadData(descriptor);
[8198]93        try {
94          GenericConsumer.Load(instance);
[9363]95        } catch (Exception ex) {
[8201]96          ErrorHandling.ShowErrorDialog(String.Format("This problem does not support loading the instance {0}", descriptor.Name), ex);
[8198]97        }
[9363]98        toolTip.SetToolTip(instancesComboBox, descriptor.Description);
99      } else toolTip.SetToolTip(instancesComboBox, String.Empty);
[8031]100    }
[7683]101  }
102}
Note: See TracBrowser for help on using the repository browser.