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;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
27 | using HeuristicLab.Problems.Instances;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
|
---|
30 | [View("ProblemInstanceProviderView")]
|
---|
31 | [Content(typeof(IProblemInstanceProvider), IsDefaultView = true)]
|
---|
32 | public partial class ProblemInstanceProviderView : AsynchronousContentView {
|
---|
33 |
|
---|
34 | public new IProblemInstanceProvider Content {
|
---|
35 | get { return (IProblemInstanceProvider)base.Content; }
|
---|
36 | set { base.Content = value; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public ProblemInstanceProviderView() {
|
---|
40 | InitializeComponent();
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void OnContentChanged() {
|
---|
44 | base.OnContentChanged();
|
---|
45 | if (Content == null) {
|
---|
46 | instancesComboBox.DataSource = null;
|
---|
47 | } else {
|
---|
48 | instancesComboBox.DisplayMember = "Name";
|
---|
49 | instancesComboBox.DataSource = Content.GetInstanceDescriptors().ToList();
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void SetEnabledStateOfControls() {
|
---|
54 | base.SetEnabledStateOfControls();
|
---|
55 | instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
|
---|
56 | loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void loadButton_Click(object sender, EventArgs e) {
|
---|
60 | var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;
|
---|
61 | if (!Content.FeedConsumer(instance)) {
|
---|
62 | MessageBox.Show("This problem does not support loading the instance " + instance.Name + ".", "Cannot load instance");
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | private void comboBox_DataSourceChanged(object sender, EventArgs e) {
|
---|
67 | var comboBox = (ComboBox)sender;
|
---|
68 | if (comboBox.DataSource == null)
|
---|
69 | comboBox.Items.Clear();
|
---|
70 | }
|
---|
71 |
|
---|
72 | private void instancesComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {
|
---|
73 | var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;
|
---|
74 | e.ToolTip = instance.Description;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|