Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/12 16:30:27 (12 years ago)
Author:
abeham
Message:

#1614: changed according to architects review

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs

    r7538 r7548  
    2121
    2222using System;
     23using System.IO;
    2324using System.Linq;
    2425using System.Windows.Forms;
     
    4041    public ProblemInstanceProviderView() {
    4142      InitializeComponent();
     43      importButton.Text = String.Empty;
    4244      importButton.Image = VSImageLibrary.Open;
     45      toolTip.SetToolTip(importButton, "Import a " + GetProblemType() + " instance from file.");
     46      loadButton.Text = String.Empty;
     47      loadButton.Image = VSImageLibrary.Checkout;
     48      toolTip.SetToolTip(loadButton, "Load the selected instance.");
    4349    }
    4450
     
    4955      } else {
    5056        instancesComboBox.DisplayMember = "Name";
    51         instancesComboBox.DataSource = Content.GetInstanceDescriptors().ToList();
     57        instancesComboBox.DataSource = Content.GetDataDescriptors().ToList();
    5258      }
    5359    }
     
    6066
    6167    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");
     68      var descriptor = (IDataDescriptor)instancesComboBox.SelectedItem;
     69      var instance = Content.LoadData(descriptor);
     70      try {
     71        Content.Consumer.Load(instance);
     72      } catch (Exception ex) {
     73        MessageBox.Show(String.Format("This problem does not support loading the instance {0}: {1}", descriptor.Name, Environment.NewLine + ex.Message), "Cannot load instance");
    6674      }
    6775    }
    6876
    6977    private void importButton_Click(object sender, EventArgs e) {
     78      openFileDialog.FileName = GetProblemType() + " instance";
    7079      if (openFileDialog.ShowDialog() == DialogResult.OK) {
    7180        T instance = default(T);
    7281        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);
     82          instance = Content.LoadData(openFileDialog.FileName);
     83        } catch (Exception ex) {
     84          MessageBox.Show(String.Format("There was an error parsing the file: {0}", Environment.NewLine + ex.Message), "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
    7685          return;
    7786        }
    7887        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.");
     88          Content.Consumer.Load(instance);
     89        } catch (Exception ex) {
     90          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");
    8491        }
    8592      }
     
    9198        comboBox.Items.Clear();
    9299    }
     100
     101    private string GetProblemType() {
     102      string dataTypeName = typeof(T).Name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Last();
     103      if (dataTypeName.EndsWith("Data"))
     104        return dataTypeName.Substring(0, dataTypeName.Length - "Data".Length);
     105      else return dataTypeName;
     106    }
    93107  }
    94108}
Note: See TracChangeset for help on using the changeset viewer.