Changeset 1566 for trunk/sources/HeuristicLab.Persistence.GUI/3.3
- Timestamp:
- 04/16/09 12:58:14 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence.GUI/3.3/PersistenceConfigurationForm.cs
r1565 r1566 17 17 private readonly Dictionary<string, IFormatter> formatterTable; 18 18 private readonly Dictionary<string, bool> simpleFormatterTable; 19 private readonly Dictionary<IFormatter, string> reverseFormatterTable; 19 private readonly Dictionary<IFormatter, string> reverseFormatterTable; 20 20 private readonly Dictionary<string, Type> typeNameTable; 21 21 private readonly Dictionary<Type, string> reverseTypeNameTable; 22 22 23 public PersistenceConfigurationForm() { 23 public PersistenceConfigurationForm() { 24 24 InitializeComponent(); 25 25 formatterTable = new Dictionary<string, IFormatter>(); … … 52 52 } 53 53 54 private void UpdateDecomposerList(ListView decomposerList, Configuration config) { 54 private void UpdateDecomposerList(ListView decomposerList, Configuration config) { 55 55 decomposerList.Items.Clear(); 56 56 var availableDecomposers = new Dictionary<string, IDecomposer>(); 57 foreach (IDecomposer d in ConfigurationService.Instance.Decomposers) { 57 foreach (IDecomposer d in ConfigurationService.Instance.Decomposers) { 58 58 availableDecomposers.Add(d.GetType().VersionInvariantName(), d); 59 } 60 foreach (IDecomposer decomposer in config.Decomposers) { 61 var item = decomposerList.Items.Add(decomposer.GetType().Name); 59 } 60 foreach (IDecomposer decomposer in config.Decomposers) { 61 var item = decomposerList.Items.Add(decomposer.GetType().Name); 62 62 item.Checked = true; 63 63 item.Tag = decomposer; 64 64 availableDecomposers.Remove(decomposer.GetType().VersionInvariantName()); 65 } 65 } 66 66 foreach (KeyValuePair<string, IDecomposer> pair in availableDecomposers) { 67 67 var item = decomposerList.Items.Add(pair.Value.GetType().Name); … … 69 69 item.Tag = pair.Value; 70 70 } 71 } 71 } 72 72 73 73 private void UpdateFromConfigurationService() { 74 foreach ( IFormat format in ConfigurationService.Instance.Formats) {74 foreach (IFormat format in ConfigurationService.Instance.Formats) { 75 75 Configuration config = ConfigurationService.Instance.GetConfiguration(format); 76 76 UpdateFormatterGrid( 77 77 (DataGridView)GetControlsOnPage(format.Name, "GridView"), 78 config); 78 config); 79 79 UpdateDecomposerList( 80 80 (ListView)GetControlsOnPage(format.Name, "DecomposerList"), 81 81 config); 82 82 } 83 } 83 } 84 84 85 85 private void initializeConfigPages() { 86 configurationTabs.TabPages.Clear(); 87 foreach ( IFormat format in ConfigurationService.Instance.Formats) {86 configurationTabs.TabPages.Clear(); 87 foreach (IFormat format in ConfigurationService.Instance.Formats) { 88 88 List<IFormatter> formatters = ConfigurationService.Instance.Formatters[format.SerialDataType]; 89 89 TabPage page = new TabPage(format.Name) { … … 107 107 horizontalSplit.Panel1.Controls.Add(decomposerList); 108 108 DataGridView gridView = createGridView(); 109 verticalSplit.Panel2.Controls.Add(gridView); 109 verticalSplit.Panel2.Controls.Add(gridView); 110 110 fillDataGrid(gridView, formatters); 111 111 ListBox checkBox = new ListBox { … … 167 167 new ColumnHeader { 168 168 Name = "DecomposerColumn", Text = "Decomposers", 169 }); 169 }); 170 170 foreach (IDecomposer decomposer in ConfigurationService.Instance.Decomposers) { 171 171 var item = decomposerList.Items.Add(decomposer.GetType().Name); … … 176 176 } 177 177 178 private void fillDataGrid(DataGridView gridView, IEnumerable<IFormatter> formatters) { 178 private void fillDataGrid(DataGridView gridView, IEnumerable<IFormatter> formatters) { 179 179 Dictionary<string, List<string>> formatterMap = createFormatterMap(formatters); 180 foreach ( var formatterMapping in formatterMap) {180 foreach (var formatterMapping in formatterMap) { 181 181 var row = gridView.Rows[gridView.Rows.Add()]; 182 182 row.Cells["Type"].Value = formatterMapping.Key; 183 183 row.Cells["Type"].ToolTipText = formatterMapping.Key; 184 row.Cells["Active"].Value = true; 185 var comboBoxCell = (DataGridViewComboBoxCell) row.Cells["Formatter"];186 foreach ( var formatter in formatterMapping.Value) {184 row.Cells["Active"].Value = true; 185 var comboBoxCell = (DataGridViewComboBoxCell)row.Cells["Formatter"]; 186 foreach (var formatter in formatterMapping.Value) { 187 187 comboBoxCell.Items.Add(formatter); 188 } 189 comboBoxCell.Value = comboBoxCell.Items[0]; 188 } 189 comboBoxCell.Value = comboBoxCell.Items[0]; 190 190 comboBoxCell.ToolTipText = comboBoxCell.Items[0].ToString(); 191 191 if (comboBoxCell.Items.Count == 1) { 192 192 comboBoxCell.ReadOnly = true; 193 193 comboBoxCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; 194 } 194 } 195 195 } 196 196 } 197 197 198 198 private Dictionary<string, List<string>> createFormatterMap(IEnumerable<IFormatter> formatters) { 199 var formatterMap = new Dictionary<string, List<string>>(); 199 var formatterMap = new Dictionary<string, List<string>>(); 200 200 foreach (var formatter in formatters) { 201 201 string formatterName = reverseFormatterTable[formatter]; 202 string typeName = reverseTypeNameTable[formatter.SourceType]; 202 string typeName = reverseTypeNameTable[formatter.SourceType]; 203 203 if (!formatterMap.ContainsKey(typeName)) 204 204 formatterMap.Add(typeName, new List<string>()); … … 221 221 } 222 222 simpleFormatterTable[formatter.GetType().Name] = true; 223 formatterTable.Add(formatterName, formatter); 223 formatterTable.Add(formatterName, formatter); 224 224 reverseFormatterTable.Add(formatter, formatterName); 225 225 … … 244 244 } 245 245 } 246 } 246 } 247 247 248 248 void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { 249 249 UpdatePreview(); 250 } 250 } 251 251 252 252 private void decomposerList_ItemDrag(object sender, ItemDragEventArgs e) { 253 ListView decomposerList = (ListView) 253 ListView decomposerList = (ListView)sender; 254 254 decomposerList.DoDragDrop(decomposerList.SelectedItems, DragDropEffects.Move); 255 255 } 256 256 257 private void decomposerList_DragEnter(object sender, DragEventArgs e) { 258 if ( 257 private void decomposerList_DragEnter(object sender, DragEventArgs e) { 258 if (e.Data.GetDataPresent(typeof(ListView.SelectedListViewItemCollection).FullName)) { 259 259 e.Effect = DragDropEffects.Move; 260 } 260 } 261 261 } 262 262 … … 266 266 return; 267 267 } 268 Point cp = decomposerList.PointToClient(new Point(e.X, e.Y)); 269 ListViewItem targetItem = decomposerList.GetItemAt(cp.X, cp.Y); 268 Point cp = decomposerList.PointToClient(new Point(e.X, e.Y)); 269 ListViewItem targetItem = decomposerList.GetItemAt(cp.X, cp.Y); 270 270 if (targetItem == null) 271 return; 272 int targetIndex = targetItem.Index; 271 return; 272 int targetIndex = targetItem.Index; 273 273 var selectedItems = new List<ListViewItem>(decomposerList.SelectedItems.Cast<ListViewItem>()); 274 274 int i = 0; 275 foreach ( ListViewItem dragItem in selectedItems ) {275 foreach (ListViewItem dragItem in selectedItems) { 276 276 if (targetIndex == dragItem.Index) 277 277 return; 278 278 if (dragItem.Index < targetIndex) { 279 decomposerList.Items.Insert(targetIndex + 1, (ListViewItem) 279 decomposerList.Items.Insert(targetIndex + 1, (ListViewItem)dragItem.Clone()); 280 280 } else { 281 decomposerList.Items.Insert(targetIndex + i, (ListViewItem)dragItem.Clone()); 282 } 281 decomposerList.Items.Insert(targetIndex + i, (ListViewItem)dragItem.Clone()); 282 } 283 283 decomposerList.Items.Remove(dragItem); 284 284 i++; … … 288 288 289 289 private void decomposerList_Resize(object sender, EventArgs e) { 290 ListView decomposerList = (ListView)sender; 291 decomposerList.Columns["DecomposerColumn"].Width = decomposerList.Width - 4; 292 } 293 290 ListView decomposerList = (ListView)sender; 291 decomposerList.Columns["DecomposerColumn"].Width = decomposerList.Width - 4; 292 } 293 294 294 private void UpdatePreview() { 295 ListBox checkBox = (ListBox)GetActiveControl("CheckBox"); 295 ListBox checkBox = (ListBox)GetActiveControl("CheckBox"); 296 296 IFormat activeFormat = (IFormat)configurationTabs.SelectedTab.Tag; 297 if (activeFormat != null && checkBox != null 297 if (activeFormat != null && checkBox != null) { 298 298 checkBox.Items.Clear(); 299 299 Configuration activeConfig = GetActiveConfiguration(); … … 302 302 } 303 303 foreach (var decomposer in activeConfig.Decomposers) 304 checkBox.Items.Add(decomposer.GetType().Name + " (D)"); 305 } 304 checkBox.Items.Add(decomposer.GetType().Name + " (D)"); 305 } 306 306 } 307 307 … … 316 316 } else { 317 317 return null; 318 } 319 } 320 321 private Control GetControlsOnPage(string pageName, string name) { 318 } 319 } 320 321 private Control GetControlsOnPage(string pageName, string name) { 322 322 Control[] controls = configurationTabs.TabPages[pageName].Controls.Find(name, true); 323 323 if (controls.Length == 1) { … … 325 325 } else { 326 326 return null; 327 } 327 } 328 328 } 329 329 … … 358 358 359 359 private Configuration GetConfiguration(IFormat format) { 360 361 362 363 } 364 360 return GenerateConfiguration(format, 361 (DataGridView)GetControlsOnPage(format.Name, "GridView"), 362 (ListView)GetControlsOnPage(format.Name, "DecomposerList")); 363 } 364 365 365 private void updateButton_Click(object sender, EventArgs e) { 366 366 IFormat format = (IFormat)configurationTabs.SelectedTab.Tag; … … 368 368 ConfigurationService.Instance.DefineConfiguration( 369 369 GetActiveConfiguration()); 370 } 371 370 } 371 372 372 } 373 373 … … 383 383 384 384 public override Empty Format(Type o) { 385 385 return null; 386 386 } 387 387 … … 400 400 public override bool Parse(Empty o) { 401 401 return false; 402 } 403 } 402 } 403 } 404 404 405 405 [EmptyStorableClass] … … 424 424 } 425 425 426 private static void SimpleFullName(Type type, StringBuilder sb) { 426 private static void SimpleFullName(Type type, StringBuilder sb) { 427 427 if (type.IsGenericType) { 428 428 sb.Append(type.Name, 0, type.Name.LastIndexOf('`'));
Note: See TracChangeset
for help on using the changeset viewer.