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.Common.Resources;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
28 | using HeuristicLab.Problems.Instances;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
|
---|
31 | [View("ProblemInstanceProviderView")]
|
---|
32 | [Content(typeof(IProblemInstanceProvider<>), IsDefaultView = true)]
|
---|
33 | public partial class ProblemInstanceProviderView<T> : AsynchronousContentView {
|
---|
34 |
|
---|
35 | public new IProblemInstanceProvider<T> Content {
|
---|
36 | get { return (IProblemInstanceProvider<T>)base.Content; }
|
---|
37 | set { base.Content = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public ProblemInstanceProviderView() {
|
---|
41 | InitializeComponent();
|
---|
42 | importButton.Image = VSImageLibrary.Open;
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void OnContentChanged() {
|
---|
46 | base.OnContentChanged();
|
---|
47 | if (Content == null) {
|
---|
48 | instancesComboBox.DataSource = null;
|
---|
49 | } else {
|
---|
50 | instancesComboBox.DisplayMember = "Name";
|
---|
51 | instancesComboBox.DataSource = Content.GetInstanceDescriptors().ToList();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | protected override void SetEnabledStateOfControls() {
|
---|
56 | base.SetEnabledStateOfControls();
|
---|
57 | instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
|
---|
58 | loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void loadButton_Click(object sender, EventArgs e) {
|
---|
62 | var descriptor = (IInstanceDescriptor)instancesComboBox.SelectedItem;
|
---|
63 | var instance = Content.LoadInstance(descriptor);
|
---|
64 | if (!Content.Consumer.LoadFrom(instance)) {
|
---|
65 | MessageBox.Show("This problem does not support loading the instance " + descriptor.Name + ".", "Cannot load instance");
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | private void importButton_Click(object sender, EventArgs e) {
|
---|
70 | if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
71 | T instance = default(T);
|
---|
72 | try {
|
---|
73 | instance = Content.LoadInstance(openFileDialog.FileName);
|
---|
74 | } catch {
|
---|
75 | MessageBox.Show("There was an error parsing the file.", "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
76 | return;
|
---|
77 | }
|
---|
78 | try {
|
---|
79 | if (!Content.Consumer.LoadFrom(instance)) {
|
---|
80 | MessageBox.Show("This problem does not support loading the instance in the file.", "Cannot load instance", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
81 | }
|
---|
82 | } catch {
|
---|
83 | MessageBox.Show("There was an error while importing the file.");
|
---|
84 | }
|
---|
85 | }
|
---|
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 | }
|
---|