Changeset 1398 for branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/PersistenceConfigurationForm.cs
- Timestamp:
- 03/23/09 15:44:53 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/PersistenceConfigurationForm.cs
r1382 r1398 10 10 namespace HeuristicLab.Persistence.GUI { 11 11 12 public partial class PersistenceConfigurationForm : Form { 12 public partial class PersistenceConfigurationForm : Form { 13 14 private readonly Dictionary<string, IFormatter> formatterTable; 15 private readonly Dictionary<string, Type> typeNameTable; 16 13 17 public PersistenceConfigurationForm() { 14 18 InitializeComponent(); 15 decomposerList.Items.Clear(); 19 formatterTable = new Dictionary<string, IFormatter>(); 20 typeNameTable = new Dictionary<string, Type>(); 21 decomposerList.Items.Clear(); 16 22 foreach ( IDecomposer decomposer in ConfigurationService.Instance.AllDecomposers ) { 17 23 var item = decomposerList.Items.Add(decomposer.GetType().Name); … … 19 25 item.Tag = decomposer; 20 26 } 21 27 22 28 foreach ( var formats in ConfigurationService.Instance.AllFormatters ) { 23 TabPage page = new TabPage(formats.Key.Name) ;29 TabPage page = new TabPage(formats.Key.Name) {Tag = formats.Key}; 24 30 formatterTabs.TabPages.Add(page); 25 31 DataGridView gridView = new DataGridView { … … 28 34 AllowUserToAddRows = false, 29 35 AllowUserToDeleteRows = false, 30 AllowUserToResizeRows = false, 36 AllowUserToResizeRows = false, 37 Name = "GridView", 31 38 }; 32 //gridView.CellValueChanged += gridView_CellValueChanged; 33 //gridView.DataError += gridView_DataError; 34 //gridView.CellFormatting += gridView_CellFormatting; 35 page.Controls.Add(gridView); 39 gridView.CellValueChanged += gridView_CellValueChanged; 40 page.Controls.Add(gridView); 36 41 gridView.Columns.Add(new DataGridViewTextBoxColumn { 37 42 Name = "Type", ReadOnly = true, … … 42 47 gridView.Columns.Add(new DataGridViewComboBoxColumn 43 48 { AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill }); 44 var formatterMap = new Dictionary< Type, List<IFormatter>>();49 var formatterMap = new Dictionary<string, List<string>>(); 45 50 foreach (var formatter in formats.Value) { 46 if (!formatterMap.ContainsKey(formatter.Type)) 47 formatterMap.Add(formatter.Type, new List<IFormatter>()); 48 formatterMap[formatter.Type].Add(formatter); 51 string formatterName = formatter.GetType().Name; 52 if (formatterTable.ContainsKey(formatterName)) { 53 IFormatter otherFormatter = formatterTable[formatterName]; 54 formatterTable.Remove(formatterName); 55 formatterTable.Add(otherFormatter.GetType().FullName, otherFormatter); 56 formatterName = formatter.GetType().FullName; 57 } 58 formatterTable.Add(formatterName, formatter); 59 string typeName = formatter.Type.Name; 60 if (typeNameTable.ContainsKey(typeName)) { 61 Type otherType = typeNameTable[typeName]; 62 if (otherType != formatter.Type) { 63 typeNameTable.Remove(typeName); 64 typeNameTable.Add(otherType.FullName, otherType); 65 typeName = formatter.Type.FullName; 66 typeNameTable.Add(typeName, formatter.Type); 67 } 68 } else { 69 typeNameTable.Add(typeName, formatter.Type); 70 } 71 } 72 foreach (var formatter in formats.Value) { 73 string formatterName = 74 formatterTable.ContainsKey(formatter.GetType().Name) ? 75 formatter.GetType().Name : 76 formatter.GetType().FullName; 77 string typeName = 78 typeNameTable.ContainsKey(formatter.Type.Name) ? 79 formatter.Type.Name : 80 formatter.Type.FullName; 81 if (!formatterMap.ContainsKey(typeName)) 82 formatterMap.Add(typeName, new List<string>()); 83 formatterMap[typeName].Add(formatterName); 49 84 } 50 85 foreach ( var formatterMapping in formatterMap ) { 51 86 var row = gridView.Rows[gridView.Rows.Add()]; 52 row.Cells[0].Value = formatterMapping.Key .SimpleFullName();53 row.Cells[0].ToolTipText = formatterMapping.Key .AssemblyQualifiedName;87 row.Cells[0].Value = formatterMapping.Key; 88 row.Cells[0].ToolTipText = formatterMapping.Key; 54 89 row.Cells[1].Value = true; 55 var comboBoxCell = (DataGridViewComboBoxCell) row.Cells[2]; 56 //comboBoxCell.ValueType = typeof(IFormatter); 57 foreach ( var formatter in formatterMapping.Value ) { 58 comboBoxCell.Items.Add(formatter.GetType().Name); 90 var comboBoxCell = (DataGridViewComboBoxCell) row.Cells[2]; 91 foreach ( var formatter in formatterMapping.Value ) { 92 comboBoxCell.Items.Add(formatter); 59 93 } 60 94 comboBoxCell.Value = comboBoxCell.Items[0]; … … 68 102 } 69 103 70 void gridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { 71 e.Value = e.Value.ToString(); 72 e.FormattingApplied = true; 104 void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { 105 UpdatePreview(); 73 106 } 74 107 … … 105 138 i++; 106 139 } 107 Update ();140 UpdatePreview(); 108 141 } 109 142 … … 121 154 } 122 155 123 private void Update () {124 checkbox.Items.Clear(); 156 private void UpdatePreview() { 157 checkbox.Items.Clear(); 125 158 foreach (var decomposer in GetDecomposers()) 126 checkbox.Items.Add(decomposer.GetType().Name); 159 checkbox.Items.Add(decomposer.GetType().Name + " (D)"); 160 IFormat activeFormat = (IFormat) formatterTabs.SelectedTab.Tag; 161 if (activeFormat != null) { 162 foreach (var formatter in GetCurrentConfiguration(activeFormat).Formatters) { 163 checkbox.Items.Add(formatter.GetType().Name + " (F)"); 164 } 165 } 127 166 } 128 167 129 168 private void decomposerList_ItemChecked(object sender, ItemCheckedEventArgs e) { 130 Update(); 169 UpdatePreview(); 170 } 171 172 public Configuration GetCurrentConfiguration(IFormat format) { 173 Dictionary<Type, IFormatter> formatters = new Dictionary<Type, IFormatter>(); 174 foreach ( TabPage page in formatterTabs.TabPages ) { 175 if ( page.Text == format.Name ) { 176 Control[] controls = page.Controls.Find("GridView", false); 177 if (controls.Length == 1) { 178 foreach (DataGridViewRow row in ((DataGridView) controls[0]).Rows) { 179 if ( row.Cells[1].Value != null && 180 row.Cells[0].Value != null && 181 row.Cells[2].Value != null && 182 (bool)row.Cells[1].Value == true ) { 183 formatters.Add( 184 typeNameTable[(string)row.Cells[0].Value], 185 formatterTable[(string)row.Cells[2].Value]); 186 } 187 } 188 } 189 } 190 } 191 return new Configuration(formatters, GetDecomposers()); 131 192 } 132 193
Note: See TracChangeset
for help on using the changeset viewer.