Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/01/12 15:15:22 (12 years ago)
Author:
abeham
Message:

#1614

  • Fixed plugin dependencies
  • Updated GQAP view
  • Changed instances infrastructure
    • Changed interface types into classes
    • Removed the library specific instance classes
File:
1 edited

Legend:

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

    r7505 r7538  
    2323using System.Linq;
    2424using System.Windows.Forms;
     25using HeuristicLab.Common.Resources;
    2526using HeuristicLab.MainForm;
    2627using HeuristicLab.MainForm.WindowsForms;
     
    2930namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views {
    3031  [View("ProblemInstanceProviderView")]
    31   [Content(typeof(IProblemInstanceProvider), IsDefaultView = true)]
    32   public partial class ProblemInstanceProviderView : AsynchronousContentView {
     32  [Content(typeof(IProblemInstanceProvider<>), IsDefaultView = true)]
     33  public partial class ProblemInstanceProviderView<T> : AsynchronousContentView {
    3334
    34     public new IProblemInstanceProvider Content {
    35       get { return (IProblemInstanceProvider)base.Content; }
     35    public new IProblemInstanceProvider<T> Content {
     36      get { return (IProblemInstanceProvider<T>)base.Content; }
    3637      set { base.Content = value; }
    3738    }
     
    3940    public ProblemInstanceProviderView() {
    4041      InitializeComponent();
     42      importButton.Image = VSImageLibrary.Open;
    4143    }
    4244
     
    5355    protected override void SetEnabledStateOfControls() {
    5456      base.SetEnabledStateOfControls();
    55       instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
    56       loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.ConsumerCanBeFed;
     57      instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
     58      loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null;
    5759    }
    5860
    5961    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");
     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        }
    6385      }
    6486    }
     
    6991        comboBox.Items.Clear();
    7092    }
    71 
    72     private void instancesComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {
    73       var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;
    74       e.ToolTip = instance.Description;
    75     }
    7693  }
    7794}
Note: See TracChangeset for help on using the changeset viewer.