Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Problems.Instances.VehicleRouting.Views/3.4/VRPInstanceConsumerView.cs @ 17146

Last change on this file since 17146 was 8192, checked in by sforsten, 12 years ago

#1782:

  • renamed CanSave to CanExportData and SaveData to ExportData
  • added the same functionality for importing problem instance as we implemented for exporting
  • some special changes had to be made in Problems.Instances.VehicleRouting
File size: 3.7 KB
Line 
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.IO;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27using HeuristicLab.PluginInfrastructure;
28using HeuristicLab.Problems.Instances.Views;
29
30namespace HeuristicLab.Problems.Instances.VehicleRouting.Views {
31  [View("VRP InstanceProvider View")]
32  [Content(typeof(IProblemInstanceConsumer<IVRPData>), IsDefaultView = true)]
33  public partial class VRPInstanceProviderView<T> : ProblemInstanceConsumerViewGeneric<T> where T : class, IVRPData {
34
35    public new IProblemInstanceConsumer<T> Content {
36      get { return (IProblemInstanceConsumer<T>)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public VRPInstanceProviderView() {
41      InitializeComponent();
42    }
43
44    protected override void SetEnabledStateOfControls() {
45      problemInstanceProviderComboBox.Enabled = !ReadOnly && !Locked && Content != null && problemInstanceProviderComboBox.Items.Count > 0;
46      libraryInfoButton.Enabled = SelectedProvider != null && SelectedProvider.WebLink != null;
47      IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
48      importButton.Enabled = !ReadOnly && !Locked && Content != null && Consumer != null &&
49                             provider != null && provider.CanImportData;
50      ProviderImportSplitContainer.Panel2Collapsed = !importButton.Enabled;
51      exportButton.Enabled = !ReadOnly && !Locked && Content != null && Exporter != null &&
52                             provider != null && provider.CanExportData;
53      ProviderExportSplitContainer.Panel2Collapsed = !exportButton.Enabled;
54    }
55
56    protected override void importButton_Click(object sender, EventArgs e) {
57      IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
58      if (provider != null) {
59        using (var dialog = new VRPImportDialog(SelectedProvider.Name)) {
60          if (dialog.ShowDialog() == DialogResult.OK) {
61            var instance = provider.Import(dialog.VRPFileName, dialog.TourFileName);
62            try {
63              GenericConsumer.Load(instance as T);
64            }
65            catch (Exception ex) {
66              MessageBox.Show(String.Format("This problem does not support loading the instance {0}: {1}", Path.GetFileName(openFileDialog.FileName), Environment.NewLine + ex.Message), "Cannot load instance");
67            }
68          }
69        }
70      }
71    }
72
73    protected override void exportButton_Click(object sender, EventArgs e) {
74      IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
75      if (provider != null) {
76        if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
77          try {
78            provider.Export(GenericExporter.Export(), saveFileDialog.FileName);
79          }
80          catch (Exception ex) {
81            ErrorHandling.ShowErrorDialog(this, ex);
82          }
83        }
84      }
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.