Changeset 7538 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs
- Timestamp:
- 03/01/12 15:15:22 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs
r7505 r7538 23 23 using System.Linq; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Common.Resources; 25 26 using HeuristicLab.MainForm; 26 27 using HeuristicLab.MainForm.WindowsForms; … … 29 30 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views { 30 31 [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 { 33 34 34 public new IProblemInstanceProvider Content {35 get { return (IProblemInstanceProvider )base.Content; }35 public new IProblemInstanceProvider<T> Content { 36 get { return (IProblemInstanceProvider<T>)base.Content; } 36 37 set { base.Content = value; } 37 38 } … … 39 40 public ProblemInstanceProviderView() { 40 41 InitializeComponent(); 42 importButton.Image = VSImageLibrary.Open; 41 43 } 42 44 … … 53 55 protected override void SetEnabledStateOfControls() { 54 56 base.SetEnabledStateOfControls(); 55 instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer CanBeFed;56 loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer CanBeFed;57 instancesComboBox.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null; 58 loadButton.Enabled = !ReadOnly && !Locked && Content != null && Content.Consumer != null; 57 59 } 58 60 59 61 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 } 63 85 } 64 86 } … … 69 91 comboBox.Items.Clear(); 70 92 } 71 72 private void instancesComboBox_ToolTipRequired(object sender, ToolTipRequiredEventArgs e) {73 var instance = (IInstanceDescriptor)instancesComboBox.SelectedItem;74 e.ToolTip = instance.Description;75 }76 93 } 77 94 }
Note: See TracChangeset
for help on using the changeset viewer.