Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/24/13 11:49:28 (11 years ago)
Author:
jkarder
Message:

#2110: refactored ProblemInstanceProviderViews

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.Instances.VehicleRouting.Views/3.4/VRPInstanceProviderView.cs

    r9999 r10000  
    2424using System.Windows.Forms;
    2525using HeuristicLab.MainForm;
    26 using HeuristicLab.MainForm.WindowsForms;
    2726using HeuristicLab.PluginInfrastructure;
    2827using HeuristicLab.Problems.Instances.Views;
     
    3029namespace HeuristicLab.Problems.Instances.VehicleRouting.Views {
    3130  [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     }
     31  [Content(typeof(IProblemInstanceProvider<IVRPData>), IsDefaultView = true)]
     32  public partial class VRPInstanceProviderView<T> : ProblemInstanceProviderViewGeneric<T> where T : class, IVRPData {
    3933
    4034    public VRPInstanceProviderView() {
     
    4236    }
    4337
    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 
    5638    protected override void importButton_Click(object sender, EventArgs e) {
    57       IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
     39      var provider = Content as IVRPInstanceProvider;
    5840      if (provider != null) {
    59         using (var dialog = new VRPImportDialog(SelectedProvider.Name)) {
     41        using (var dialog = new VRPImportDialog(Content.Name)) {
    6042          if (dialog.ShowDialog() == DialogResult.OK) {
    6143            var instance = provider.Import(dialog.VRPFileName, dialog.TourFileName);
    6244            try {
    6345              GenericConsumer.Load(instance as T);
    64             }
    65             catch (Exception ex) {
     46              instancesComboBox.SelectedIndex = -1;
     47            } catch (Exception ex) {
    6648              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");
    6749            }
     
    7254
    7355    protected override void exportButton_Click(object sender, EventArgs e) {
    74       IVRPInstanceProvider provider = SelectedProvider as IVRPInstanceProvider;
     56      var provider = Content as IVRPInstanceProvider;
    7557      if (provider != null) {
    7658        if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
    7759          try {
    7860            provider.Export(GenericExporter.Export(), saveFileDialog.FileName);
    79           }
    80           catch (Exception ex) {
     61          } catch (Exception ex) {
    8162            ErrorHandling.ShowErrorDialog(this, ex);
    8263          }
Note: See TracChangeset for help on using the changeset viewer.