Changeset 7548 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs
- Timestamp:
- 03/05/12 16:30:27 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Views/3.3/ProblemInstanceProviderView.cs
r7538 r7548 21 21 22 22 using System; 23 using System.IO; 23 24 using System.Linq; 24 25 using System.Windows.Forms; … … 40 41 public ProblemInstanceProviderView() { 41 42 InitializeComponent(); 43 importButton.Text = String.Empty; 42 44 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."); 43 49 } 44 50 … … 49 55 } else { 50 56 instancesComboBox.DisplayMember = "Name"; 51 instancesComboBox.DataSource = Content.Get InstanceDescriptors().ToList();57 instancesComboBox.DataSource = Content.GetDataDescriptors().ToList(); 52 58 } 53 59 } … … 60 66 61 67 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"); 66 74 } 67 75 } 68 76 69 77 private void importButton_Click(object sender, EventArgs e) { 78 openFileDialog.FileName = GetProblemType() + " instance"; 70 79 if (openFileDialog.ShowDialog() == DialogResult.OK) { 71 80 T instance = default(T); 72 81 try { 73 instance = Content.Load Instance(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); 76 85 return; 77 86 } 78 87 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"); 84 91 } 85 92 } … … 91 98 comboBox.Items.Clear(); 92 99 } 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 } 93 107 } 94 108 }
Note: See TracChangeset
for help on using the changeset viewer.