[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 |
|
---|
| 22 | using System;
|
---|
[7860] | 23 | using System.Collections.Generic;
|
---|
[7683] | 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Common.Resources;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Instances.Views {
|
---|
[7684] | 31 | [View("ProblemInstanceProviderViewGeneric")]
|
---|
[7683] | 32 | [Content(typeof(IProblemInstanceProvider<>), IsDefaultView = true)]
|
---|
[7684] | 33 | public partial class ProblemInstanceProviderViewGeneric<T> : ProblemInstanceProviderView {
|
---|
[7683] | 34 |
|
---|
| 35 | public new IProblemInstanceProvider<T> Content {
|
---|
| 36 | get { return (IProblemInstanceProvider<T>)base.Content; }
|
---|
| 37 | set { base.Content = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[7956] | 40 | private IProblemInstanceConsumer<T> GenericConsumer { get { return Consumer as IProblemInstanceConsumer<T>; } }
|
---|
| 41 |
|
---|
| 42 | public IProblemInstanceConsumer consumer;
|
---|
[7684] | 43 | public override IProblemInstanceConsumer Consumer {
|
---|
| 44 | get { return consumer; }
|
---|
| 45 | set {
|
---|
| 46 | consumer = value;
|
---|
| 47 | SetEnabledStateOfControls();
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
[7683] | 50 |
|
---|
[7684] | 51 | public ProblemInstanceProviderViewGeneric() {
|
---|
[7683] | 52 | InitializeComponent();
|
---|
| 53 | loadButton.Text = String.Empty;
|
---|
| 54 | loadButton.Image = VSImageLibrary.RefreshDocument;
|
---|
[7758] | 55 | toolTip.SetToolTip(loadButton, "Load the selected problem.");
|
---|
[7683] | 56 | }
|
---|
| 57 |
|
---|
| 58 | protected override void OnContentChanged() {
|
---|
| 59 | base.OnContentChanged();
|
---|
| 60 | if (Content == null) {
|
---|
| 61 | instancesComboBox.DataSource = null;
|
---|
| 62 | } else {
|
---|
| 63 | instancesComboBox.DisplayMember = "Name";
|
---|
[7860] | 64 | IEnumerable<IDataDescriptor> dataDescriptors = Content.GetDataDescriptors().ToList();
|
---|
| 65 | ShowInstanceLoad(dataDescriptors.Count() > 0);
|
---|
| 66 | instancesComboBox.DataSource = dataDescriptors;
|
---|
[8031] | 67 | instancesComboBox.SelectedIndex = -1;
|
---|
[7683] | 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[7860] | 71 | protected void ShowInstanceLoad(bool show) {
|
---|
| 72 | if (show) {
|
---|
| 73 | instanceLabel.Show();
|
---|
| 74 | instancesComboBox.Show();
|
---|
| 75 | loadButton.Show();
|
---|
| 76 | } else {
|
---|
| 77 | instanceLabel.Hide();
|
---|
| 78 | instancesComboBox.Hide();
|
---|
| 79 | loadButton.Hide();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[7683] | 83 | protected override void SetEnabledStateOfControls() {
|
---|
| 84 | base.SetEnabledStateOfControls();
|
---|
[7684] | 85 | instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && GenericConsumer != null;
|
---|
[8031] | 86 | loadButton.Enabled = !ReadOnly && !Locked && Content != null && GenericConsumer != null && instancesComboBox.SelectedIndex >= 0;
|
---|
[7683] | 87 | }
|
---|
| 88 |
|
---|
| 89 | protected virtual void loadButton_Click(object sender, EventArgs e) {
|
---|
| 90 | var descriptor = (IDataDescriptor)instancesComboBox.SelectedItem;
|
---|
[7770] | 91 | T instance = Content.LoadData(descriptor);
|
---|
[7683] | 92 | try {
|
---|
[7684] | 93 | GenericConsumer.Load(instance);
|
---|
[7683] | 94 | }
|
---|
| 95 | catch (Exception ex) {
|
---|
| 96 | MessageBox.Show(String.Format("This problem does not support loading the instance {0}: {1}", descriptor.Name, Environment.NewLine + ex.Message), "Cannot load instance");
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[7956] | 100 | private void instancesComboBox_DataSourceChanged(object sender, EventArgs e) {
|
---|
[7683] | 101 | var comboBox = (ComboBox)sender;
|
---|
| 102 | if (comboBox.DataSource == null)
|
---|
| 103 | comboBox.Items.Clear();
|
---|
| 104 | }
|
---|
[8031] | 105 |
|
---|
| 106 | private void instancesComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 107 | SetEnabledStateOfControls();
|
---|
| 108 | }
|
---|
[7683] | 109 | }
|
---|
| 110 | }
|
---|