Changeset 6524
- Timestamp:
- 07/07/11 00:17:21 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.Designer.cs
r6517 r6524 42 42 this.moveDownButton = new System.Windows.Forms.Button(); 43 43 this.addButton = new System.Windows.Forms.Button(); 44 this. optimizerTreeView = new HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView();44 this.treeView = new HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView(); 45 45 this.imageList = new System.Windows.Forms.ImageList(this.components); 46 46 this.detailsGroupBox = new System.Windows.Forms.GroupBox(); … … 83 83 this.splitContainer.Panel1.Controls.Add(this.moveDownButton); 84 84 this.splitContainer.Panel1.Controls.Add(this.addButton); 85 this.splitContainer.Panel1.Controls.Add(this. optimizerTreeView);85 this.splitContainer.Panel1.Controls.Add(this.treeView); 86 86 // 87 87 // splitContainer.Panel2 … … 155 155 // optimizerTreeView 156 156 // 157 this. optimizerTreeView.AllowDrop = true;158 this. optimizerTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)157 this.treeView.AllowDrop = true; 158 this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 159 159 | System.Windows.Forms.AnchorStyles.Left) 160 160 | System.Windows.Forms.AnchorStyles.Right))); 161 this. optimizerTreeView.HideSelection = false;162 this. optimizerTreeView.ImageIndex = 0;163 this. optimizerTreeView.ImageList = this.imageList;164 this. optimizerTreeView.Location = new System.Drawing.Point(4, 34);165 this. optimizerTreeView.Name = "optimizerTreeView";166 this. optimizerTreeView.SelectedImageIndex = 0;167 this. optimizerTreeView.Size = new System.Drawing.Size(191, 402);168 this. optimizerTreeView.TabIndex = 10;169 this. optimizerTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.optimizerTreeView_ItemDrag);170 this. optimizerTreeView.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeview_NodeMouseClick);171 this. optimizerTreeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeView_NodeMouseDoubleClick);172 this. optimizerTreeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragDrop);173 this. optimizerTreeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragEnter);174 this. optimizerTreeView.DragOver += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragOver);175 this. optimizerTreeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.optimizerTreeView_KeyDown);176 this. optimizerTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.optimizerTreeView_MouseDown);177 this. optimizerTreeView.RightClick += new System.EventHandler(optimizerTreeView_RightClick);161 this.treeView.HideSelection = false; 162 this.treeView.ImageIndex = 0; 163 this.treeView.ImageList = this.imageList; 164 this.treeView.Location = new System.Drawing.Point(4, 34); 165 this.treeView.Name = "optimizerTreeView"; 166 this.treeView.SelectedImageIndex = 0; 167 this.treeView.Size = new System.Drawing.Size(191, 402); 168 this.treeView.TabIndex = 10; 169 this.treeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.optimizerTreeView_ItemDrag); 170 this.treeView.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeview_NodeMouseClick); 171 this.treeView.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.optimizerTreeView_NodeMouseDoubleClick); 172 this.treeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragDrop); 173 this.treeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragEnter); 174 this.treeView.DragOver += new System.Windows.Forms.DragEventHandler(this.optimizerTreeView_DragOver); 175 this.treeView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.optimizerTreeView_KeyDown); 176 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.optimizerTreeView_MouseDown); 177 this.treeView.RightClick += new System.EventHandler(optimizerTreeView_RightClick); 178 178 // 179 179 // imageList … … 255 255 private System.Windows.Forms.GroupBox optimizersGroupBox; 256 256 private System.Windows.Forms.SplitContainer splitContainer; 257 private HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView optimizerTreeView;257 private HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView treeView; 258 258 private System.Windows.Forms.GroupBox detailsGroupBox; 259 259 private MainForm.WindowsForms.ViewHost detailsViewHost; -
trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.cs
r6517 r6524 28 28 using HeuristicLab.Collections; 29 29 using HeuristicLab.Common; 30 using HeuristicLab.Core; 30 31 using HeuristicLab.Core.Views; 31 32 using HeuristicLab.MainForm; … … 35 36 public sealed partial class ExperimentTreeView : ItemView { 36 37 private TypeSelectorDialog typeSelectorDialog; 37 private Dictionary<I Optimizer, List<TreeNode>> optimizerTreeViewMapping;38 private Dictionary<INamedItem, List<TreeNode>> treeNodeTagMapping; 38 39 39 40 public ExperimentTreeView() { 40 41 InitializeComponent(); 41 optimizerTreeViewMapping = new Dictionary<IOptimizer, List<TreeNode>>();42 treeNodeTagMapping = new Dictionary<INamedItem, List<TreeNode>>(); 42 43 } 43 44 … … 91 92 Content.Optimizers.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced); 92 93 Content.Optimizers.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset); 93 foreach (var optimizer in optimizerTreeViewMapping.Keys)94 Deregister OptimizerEvents(optimizer);94 foreach (var optimizer in treeNodeTagMapping.Keys) 95 DeregisterNamedItemEvents(optimizer); 95 96 base.DeregisterContentEvents(); 96 97 } 97 98 98 private void RegisterOptimizerEvents(IOptimizer optimizer) { 99 optimizer.ToStringChanged += new EventHandler(optimizer_ToStringChanged); 100 optimizer.ExecutionStateChanged += new EventHandler(optimizer_ExecutionStateChanged); 101 102 var batchRun = optimizer as BatchRun; 103 var experiment = optimizer as Experiment; 104 if (batchRun != null) { 99 private void RegisterNamedItemEvents(INamedItem namedItem) { 100 namedItem.ToStringChanged += new EventHandler(namedItem_ToStringChanged); 101 namedItem.ItemImageChanged += new EventHandler(namedItem_ItemImageChanged); 102 103 var algorithm = namedItem as IAlgorithm; 104 var batchRun = namedItem as BatchRun; 105 var experiment = namedItem as Experiment; 106 107 if (algorithm != null) { 108 algorithm.ProblemChanged += new EventHandler(algorithm_ProblemChanged); 109 } else if (batchRun != null) { 105 110 batchRun.OptimizerChanged += new EventHandler(batchRun_OptimizerChanged); 106 } 107 if (experiment != null) { 111 } else if (experiment != null) { 108 112 experiment.Optimizers.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded); 109 113 experiment.Optimizers.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsMoved); … … 114 118 } 115 119 116 private void DeregisterOptimizerEvents(IOptimizer optimizer) { 117 optimizer.ToStringChanged -= new EventHandler(optimizer_ToStringChanged); 118 optimizer.ExecutionStateChanged -= new EventHandler(optimizer_ExecutionStateChanged); 119 120 var batchRun = optimizer as BatchRun; 121 var experiment = optimizer as Experiment; 122 if (batchRun != null) { 120 121 122 private void DeregisterNamedItemEvents(INamedItem namedItem) { 123 namedItem.ToStringChanged -= new EventHandler(namedItem_ToStringChanged); 124 namedItem.ItemImageChanged -= new EventHandler(namedItem_ItemImageChanged); 125 126 var algorithm = namedItem as IAlgorithm; 127 var batchRun = namedItem as BatchRun; 128 var experiment = namedItem as Experiment; 129 if (algorithm != null) { 130 algorithm.ProblemChanged -= new EventHandler(algorithm_ProblemChanged); 131 } else if (batchRun != null) { 123 132 batchRun.OptimizerChanged -= new EventHandler(batchRun_OptimizerChanged); 124 } 125 if (experiment != null) { 133 } else if (experiment != null) { 126 134 experiment.Optimizers.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded); 127 135 experiment.Optimizers.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsMoved); … … 136 144 base.OnContentChanged(); 137 145 if (Content == null) { 138 optimizerTreeView.Nodes.Clear();146 treeView.Nodes.Clear(); 139 147 } else { 140 148 UpdateOptimizerTreeView(); 141 optimizerTreeView.ExpandAll();149 treeView.ExpandAll(); 142 150 } 143 151 } … … 149 157 return; 150 158 } 151 RebuildImageList();152 159 SetEnabledStateOfControls(); 153 160 } 154 161 155 private void optimizer_ExecutionStateChanged(object sender, EventArgs e) { 156 if (InvokeRequired) { 157 Invoke((Action<object, EventArgs>)optimizer_ExecutionStateChanged, sender, e); 158 return; 159 } 160 RebuildImageList(); 161 } 162 163 private void batchRun_OptimizerChanged(object sender, EventArgs e) { 164 if (InvokeRequired) { 165 Invoke((Action<object, EventArgs>)batchRun_OptimizerChanged, sender, e); 166 return; 167 } 168 var batchRun = (BatchRun)sender; 169 foreach (TreeNode node in optimizerTreeViewMapping[batchRun]) { 170 foreach (TreeNode childNode in node.Nodes) { 162 private void algorithm_ProblemChanged(object sender, EventArgs e) { 163 if (InvokeRequired) { 164 Invoke((Action<object, EventArgs>)algorithm_ProblemChanged, sender, e); 165 return; 166 } 167 168 var algorithm = (IAlgorithm)sender; 169 foreach (TreeNode node in treeNodeTagMapping[algorithm]) { 170 foreach (TreeNode childNode in node.Nodes.OfType<TreeNode>().ToList()) { 171 171 DisposeTreeNode(childNode); 172 172 childNode.Remove(); 173 173 } 174 foreach (TreeNode childNode in CreateAlgorithmChildNodes(algorithm)) 175 node.Nodes.Add(childNode); 176 node.Expand(); 177 } 178 179 RebuildImageList(); 180 UpdateDetailsViewHost(); 181 } 182 183 private void batchRun_OptimizerChanged(object sender, EventArgs e) { 184 if (InvokeRequired) { 185 Invoke((Action<object, EventArgs>)batchRun_OptimizerChanged, sender, e); 186 return; 187 } 188 var batchRun = (BatchRun)sender; 189 foreach (TreeNode node in treeNodeTagMapping[batchRun]) { 190 foreach (TreeNode childNode in node.Nodes.OfType<TreeNode>().ToList()) { 191 DisposeTreeNode(childNode); 192 childNode.Remove(); 193 } 174 194 175 195 if (batchRun.Optimizer != null) { 176 TreeNode childNode = CreateTreeNode(batchRun.Optimizer); 177 UpdateChildTreeNodes(childNode.Nodes, batchRun.Optimizer); 178 node.Nodes.Add(childNode); 196 UpdateChildTreeNodes(node.Nodes, batchRun); 179 197 node.Expand(); 180 198 } … … 192 210 var optimizerList = (OptimizerList)sender; 193 211 IEnumerable<TreeNodeCollection> parentNodes; 194 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { optimizerTreeView.Nodes };212 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { treeView.Nodes }; 195 213 else { 196 Experiment experiment = optimizerTreeViewMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First();197 parentNodes = optimizerTreeViewMapping[experiment].Select(node => node.Nodes);214 Experiment experiment = treeNodeTagMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First(); 215 parentNodes = treeNodeTagMapping[experiment].Select(node => node.Nodes); 198 216 } 199 217 … … 217 235 var optimizerList = (OptimizerList)sender; 218 236 IEnumerable<TreeNodeCollection> parentNodes; 219 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { optimizerTreeView.Nodes };237 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { treeView.Nodes }; 220 238 else { 221 Experiment experiment = optimizerTreeViewMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First();222 parentNodes = optimizerTreeViewMapping[experiment].Select(node => node.Nodes);239 Experiment experiment = treeNodeTagMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First(); 240 parentNodes = treeNodeTagMapping[experiment].Select(node => node.Nodes); 223 241 } 224 242 … … 249 267 var optimizerList = (OptimizerList)sender; 250 268 IEnumerable<TreeNodeCollection> parentNodes; 251 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { optimizerTreeView.Nodes };269 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { treeView.Nodes }; 252 270 else { 253 Experiment experiment = optimizerTreeViewMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First();254 parentNodes = optimizerTreeViewMapping[experiment].Select(node => node.Nodes);271 Experiment experiment = treeNodeTagMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First(); 272 parentNodes = treeNodeTagMapping[experiment].Select(node => node.Nodes); 255 273 } 256 274 … … 273 291 var optimizerList = (OptimizerList)sender; 274 292 IEnumerable<TreeNodeCollection> parentNodes; 275 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { optimizerTreeView.Nodes };293 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { treeView.Nodes }; 276 294 else { 277 Experiment experiment = optimizerTreeViewMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First();278 parentNodes = optimizerTreeViewMapping[experiment].Select(node => node.Nodes);295 Experiment experiment = treeNodeTagMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First(); 296 parentNodes = treeNodeTagMapping[experiment].Select(node => node.Nodes); 279 297 } 280 298 … … 302 320 var optimizerList = (OptimizerList)sender; 303 321 IEnumerable<TreeNodeCollection> parentNodes; 304 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { optimizerTreeView.Nodes };322 if (optimizerList == Content.Optimizers) parentNodes = new List<TreeNodeCollection>() { treeView.Nodes }; 305 323 else { 306 Experiment experiment = optimizerTreeViewMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First();307 parentNodes = optimizerTreeViewMapping[experiment].Select(node => node.Nodes);324 Experiment experiment = treeNodeTagMapping.Keys.OfType<Experiment>().Where(exp => exp.Optimizers == optimizerList).First(); 325 parentNodes = treeNodeTagMapping[experiment].Select(node => node.Nodes); 308 326 } 309 327 … … 324 342 } 325 343 326 private void optimizer_ToStringChanged(object sender, EventArgs e) { 327 if (InvokeRequired) { 328 Invoke((Action<object, EventArgs>)optimizer_ToStringChanged, sender, e); 329 return; 330 } 331 var optimizer = (IOptimizer)sender; 332 foreach (TreeNode node in optimizerTreeViewMapping[optimizer]) 333 node.Text = optimizer.ToString(); 344 private void namedItem_ToStringChanged(object sender, EventArgs e) { 345 if (InvokeRequired) { 346 Invoke((Action<object, EventArgs>)namedItem_ToStringChanged, sender, e); 347 return; 348 } 349 var namedItem = (INamedItem)sender; 350 foreach (TreeNode node in treeNodeTagMapping[namedItem]) 351 node.Text = namedItem.ToString(); 352 } 353 354 private void namedItem_ItemImageChanged(object sender, EventArgs e) { 355 if (InvokeRequired) { 356 Invoke((Action<object, EventArgs>)namedItem_ItemImageChanged, sender, e); 357 return; 358 } 359 INamedItem namedItem = (INamedItem)sender; 360 foreach (TreeNode node in treeNodeTagMapping[namedItem]) { 361 treeView.ImageList.Images[node.ImageIndex] = namedItem.ItemImage; 362 node.ImageIndex = node.ImageIndex; 363 } 364 SetEnabledStateOfControls(); 334 365 } 335 366 #endregion 367 368 protected override void PropagateStateChanges(Control control, Type type, System.Reflection.PropertyInfo propertyInfo) { 369 return; 370 } 336 371 337 372 protected override void SetEnabledStateOfControls() { 338 373 base.SetEnabledStateOfControls(); 374 IOptimizer optimizer = null; 375 IAlgorithm algorithm = null; 339 376 BatchRun batchRun = null; 340 BatchRun parentBatchRun = null;341 377 Experiment experiment = null; 342 if (optimizerTreeView.SelectedNode != null) { 343 batchRun = optimizerTreeView.SelectedNode.Tag as BatchRun; 344 experiment = optimizerTreeView.SelectedNode.Tag as Experiment; 345 if (optimizerTreeView.SelectedNode.Parent != null) 346 parentBatchRun = optimizerTreeView.SelectedNode.Parent.Tag as BatchRun; 347 } 348 349 optimizerTreeView.Enabled = Content != null; 350 detailsViewHost.Enabled = Content != null && optimizerTreeView.SelectedNode != null; 378 379 IOptimizer parentOptimizer = null; 380 Experiment parentExperiment = null; 381 382 if (treeView.SelectedNode != null) { 383 optimizer = treeView.SelectedNode.Tag as IOptimizer; 384 algorithm = optimizer as IAlgorithm; 385 batchRun = optimizer as BatchRun; 386 experiment = optimizer as Experiment; 387 388 if (treeView.SelectedNode.Parent != null) parentOptimizer = treeView.SelectedNode.Parent.Tag as IOptimizer; 389 else parentOptimizer = Content; 390 391 parentExperiment = parentOptimizer as Experiment; 392 } 393 394 treeView.Enabled = Content != null; 395 if (parentOptimizer != null) { 396 detailsViewHost.ReadOnly = parentOptimizer.ExecutionState == ExecutionState.Started; 397 detailsViewHost.Locked = parentOptimizer.ExecutionState == ExecutionState.Started; 398 } 351 399 352 400 addButton.Enabled = Content != null && !Locked && !ReadOnly && 353 ( optimizerTreeView.SelectedNode == null || experiment != null || (batchRun != null && batchRun.Optimizer== null));401 (treeView.SelectedNode == null || experiment != null || (batchRun != null && batchRun.Optimizer == null) || (algorithm != null && algorithm.Problem == null)); 354 402 moveUpButton.Enabled = Content != null && !Locked && !ReadOnly && 355 optimizerTreeView.SelectedNode != null && optimizerTreeView.SelectedNode.PrevNode != null && parentBatchRun == null;403 treeView.SelectedNode != null && treeView.SelectedNode.PrevNode != null && parentExperiment != null; 356 404 moveDownButton.Enabled = Content != null && !Locked && !ReadOnly && 357 optimizerTreeView.SelectedNode != null && optimizerTreeView.SelectedNode.NextNode != null && parentBatchRun == null; 358 removeButton.Enabled = Content != null && !Locked && !ReadOnly && 359 optimizerTreeView.SelectedNode != null; 405 treeView.SelectedNode != null && treeView.SelectedNode.NextNode != null && parentExperiment != null; 406 removeButton.Enabled = Content != null && !Locked && !ReadOnly && optimizer != null; 360 407 } 361 408 362 409 private void UpdateOptimizerTreeView() { 363 optimizerTreeView.Nodes.Clear(); 364 UpdateChildTreeNodes(optimizerTreeView.Nodes, Content); 365 RebuildImageList(); 366 } 367 410 treeView.Nodes.Clear(); 411 UpdateChildTreeNodes(treeView.Nodes, Content); 412 RebuildImageList(); 413 } 368 414 369 415 private void UpdateChildTreeNodes(TreeNodeCollection collection, IOptimizer optimizer) { 370 416 var batchRun = optimizer as BatchRun; 371 417 var experiment = optimizer as Experiment; 372 if (experiment != null) UpdateChildTreeNodes(collection, experiment.Optimizers); 373 else if (batchRun != null && batchRun.Optimizer != null) UpdateChildTreeNodes(collection, new List<IOptimizer>() { batchRun.Optimizer }); 418 419 if (batchRun != null && batchRun.Optimizer != null) UpdateChildTreeNodes(collection, new List<IOptimizer>() { batchRun.Optimizer }); 420 else if (experiment != null) UpdateChildTreeNodes(collection, experiment.Optimizers); 374 421 } 375 422 private void UpdateChildTreeNodes(TreeNodeCollection collection, IEnumerable<IOptimizer> optimizers) { … … 387 434 388 435 TreeNode selectedNode = (TreeNode)e.Item; 389 var optimizer = (IOptimizer)selectedNode.Tag;436 var item = (IItem)selectedNode.Tag; 390 437 DataObject data = new DataObject(); 391 data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, optimizer);438 data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, item); 392 439 validDragOperation = true; 393 440 394 if (ReadOnly ) {441 if (ReadOnly || !(item is IOptimizer)) { 395 442 DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link); 396 443 } else { 397 444 DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move); 398 445 if ((result & DragDropEffects.Move) == DragDropEffects.Move) { 446 var optimizer = (IOptimizer)item; 399 447 if (selectedNode.Parent == null) Content.Optimizers.Remove(optimizer); 400 448 else { … … 429 477 e.Effect = DragDropEffects.None; 430 478 if (validDragOperation) { 431 Point coordinates = optimizerTreeView.PointToClient(new Point(e.X, e.Y));432 TreeNode node = optimizerTreeView.GetNodeAt(coordinates);479 Point coordinates = treeView.PointToClient(new Point(e.X, e.Y)); 480 TreeNode node = treeView.GetNodeAt(coordinates); 433 481 Experiment experiment = null; 434 482 BatchRun batchRun = null; … … 467 515 } 468 516 private void optimizerTreeView_DragDrop(object sender, DragEventArgs e) { 469 Point coordinates = optimizerTreeView.PointToClient(new Point(e.X, e.Y));470 TreeNode node = optimizerTreeView.GetNodeAt(coordinates);517 Point coordinates = treeView.PointToClient(new Point(e.X, e.Y)); 518 TreeNode node = treeView.GetNodeAt(coordinates); 471 519 Experiment experiment = null; 472 520 BatchRun batchRun = null; … … 501 549 if (e.X < e.Node.Bounds.Left || e.X > e.Node.Bounds.Right) return; 502 550 e.Node.Toggle(); 503 I Optimizer optimizer = (IOptimizer)e.Node.Tag;551 IContent optimizer = (IContent)e.Node.Tag; 504 552 MainFormManager.MainForm.ShowContent(optimizer); 505 553 } 506 554 private void optimizerTreeview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { 507 555 if (e.X < e.Node.Bounds.Left || e.X > e.Node.Bounds.Right) return; 508 optimizerTreeView.SelectedNode = e.Node;509 detailsViewHost.Content = (I Optimizer)e.Node.Tag;556 treeView.SelectedNode = e.Node; 557 detailsViewHost.Content = (IContent)e.Node.Tag; 510 558 SetEnabledStateOfControls(); 511 559 } … … 513 561 // enables deselection of treeNodes 514 562 if (e.Button != MouseButtons.Right) rightClickOccured = false; 515 if ( optimizerTreeView.SelectedNode == null) return;563 if (treeView.SelectedNode == null) return; 516 564 Point coordinates = new Point(e.X, e.Y); 517 TreeNode node = optimizerTreeView.GetNodeAt(coordinates);565 TreeNode node = treeView.GetNodeAt(coordinates); 518 566 if (node == null || coordinates.X < node.Bounds.Left || coordinates.X > node.Bounds.Right) { 519 optimizerTreeView.SelectedNode = null;567 treeView.SelectedNode = null; 520 568 detailsViewHost.Content = null; 521 569 SetEnabledStateOfControls(); … … 526 574 private void optimizerTreeView_KeyDown(object sender, KeyEventArgs e) { 527 575 if (ReadOnly) return; 528 if (optimizerTreeView.SelectedNode == null) return;529 576 if (e.KeyCode != Keys.Delete) return; 530 531 var treeNode = optimizerTreeView.SelectedNode; 577 if (treeView.SelectedNode == null) return; 578 if (!(treeView.SelectedNode.Tag is IOptimizer)) return; 579 580 var treeNode = treeView.SelectedNode; 532 581 var optimizer = (IOptimizer)treeNode.Tag; 533 582 … … 539 588 if (batchRun != null) batchRun.Optimizer = null; 540 589 else if (experiment != null) experiment.Optimizers.Remove(optimizer); 541 else throw new NotSupportedException("Handling for specific type not implemented" + optimizerTreeView.SelectedNode.Tag.GetType());590 else throw new NotSupportedException("Handling for specific type not implemented" + treeView.SelectedNode.Tag.GetType()); 542 591 } 543 592 SetEnabledStateOfControls(); … … 550 599 private void optimizerTreeView_RightClick(object sender, EventArgs e) { 551 600 rightClickOccured = true; 552 Point coordinates = optimizerTreeView.PointToClient(Cursor.Position);553 toolStripMenuNode = optimizerTreeView.GetNodeAt(coordinates);601 Point coordinates = treeView.PointToClient(Cursor.Position); 602 toolStripMenuNode = treeView.GetNodeAt(coordinates); 554 603 555 604 if (toolStripMenuNode != null && coordinates.X >= toolStripMenuNode.Bounds.Left && coordinates.X <= toolStripMenuNode.Bounds.Right) { 556 optimizerTreeView.SelectedNode = toolStripMenuNode;605 treeView.SelectedNode = toolStripMenuNode; 557 606 detailsViewHost.Content = (IContent)toolStripMenuNode.Tag; 558 607 SetEnabledStateOfControls(); … … 575 624 576 625 private void addButton_Click(object sender, System.EventArgs e) { 577 if (typeSelectorDialog == null) { 578 typeSelectorDialog = new TypeSelectorDialog(); 626 if (typeSelectorDialog == null) typeSelectorDialog = new TypeSelectorDialog(); 627 628 IAlgorithm algorithm = null; 629 if (treeView.SelectedNode != null && (treeView.SelectedNode.Tag is IAlgorithm)) 630 algorithm = (IAlgorithm)treeView.SelectedNode.Tag; 631 632 if (algorithm == null) { 579 633 typeSelectorDialog.Caption = "Select Optimizer"; 580 634 typeSelectorDialog.TypeSelector.Caption = "Available Optimizers"; 581 635 typeSelectorDialog.TypeSelector.Configure(typeof(IOptimizer), false, true); 636 } else { 637 typeSelectorDialog.Caption = "Select Problem"; 638 typeSelectorDialog.TypeSelector.Caption = "Available Problems"; 639 typeSelectorDialog.TypeSelector.Configure(algorithm.ProblemType, false, true); 582 640 } 583 641 584 642 if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) { 585 643 try { 586 IOptimizer optimizer = (IOptimizer)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(); 587 if (optimizerTreeView.SelectedNode == null) Content.Optimizers.Add(optimizer); 588 else { 589 var batchRun = optimizerTreeView.SelectedNode.Tag as BatchRun; 590 var experiment = optimizerTreeView.SelectedNode.Tag as Experiment; 591 if (batchRun != null) batchRun.Optimizer = optimizer; 592 else if (experiment != null) experiment.Optimizers.Add(optimizer); 593 else throw new NotSupportedException("Handling for specific type not implemented" + optimizerTreeView.SelectedNode.Tag.GetType()); 644 if (algorithm == null) { 645 IOptimizer optimizer = (IOptimizer)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(); 646 if (treeView.SelectedNode == null) Content.Optimizers.Add(optimizer); 647 else { 648 var batchRun = treeView.SelectedNode.Tag as BatchRun; 649 var experiment = treeView.SelectedNode.Tag as Experiment; 650 if (batchRun != null) batchRun.Optimizer = optimizer; 651 else if (experiment != null) experiment.Optimizers.Add(optimizer); 652 else throw new NotSupportedException("Handling for specific type not implemented" + treeView.SelectedNode.Tag.GetType()); 653 } 654 } else { 655 IProblem problem = (IProblem)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(); 656 algorithm.Problem = problem; 594 657 } 595 658 } … … 601 664 602 665 private void moveUpButton_Click(object sender, EventArgs e) { 603 var optimizer = optimizerTreeView.SelectedNode.Tag as IOptimizer;666 var optimizer = (IOptimizer)treeView.SelectedNode.Tag; 604 667 Experiment experiment = null; 605 if ( optimizerTreeView.SelectedNode.Parent == null) experiment = Content;606 else experiment = (Experiment) optimizerTreeView.SelectedNode.Parent.Tag;607 608 int index = optimizerTreeView.SelectedNode.Index;668 if (treeView.SelectedNode.Parent == null) experiment = Content; 669 else experiment = (Experiment)treeView.SelectedNode.Parent.Tag; 670 671 int index = treeView.SelectedNode.Index; 609 672 experiment.Optimizers.Reverse(index - 1, 2); 610 optimizerTreeView.SelectedNode = optimizerTreeViewMapping[optimizer].First();673 treeView.SelectedNode = treeNodeTagMapping[optimizer].First(); 611 674 SetEnabledStateOfControls(); 612 675 UpdateDetailsViewHost(); … … 614 677 } 615 678 private void moveDownButton_Click(object sender, EventArgs e) { 616 var optimizer = optimizerTreeView.SelectedNode.Tag as IOptimizer;679 var optimizer = (IOptimizer)treeView.SelectedNode.Tag; 617 680 Experiment experiment = null; 618 if ( optimizerTreeView.SelectedNode.Parent == null) experiment = Content;619 else experiment = (Experiment) optimizerTreeView.SelectedNode.Parent.Tag;620 621 int index = optimizerTreeView.SelectedNode.Index;681 if (treeView.SelectedNode.Parent == null) experiment = Content; 682 else experiment = (Experiment)treeView.SelectedNode.Parent.Tag; 683 684 int index = treeView.SelectedNode.Index; 622 685 experiment.Optimizers.Reverse(index, 2); 623 optimizerTreeView.SelectedNode = optimizerTreeViewMapping[optimizer].First();686 treeView.SelectedNode = treeNodeTagMapping[optimizer].First(); 624 687 SetEnabledStateOfControls(); 625 688 UpdateDetailsViewHost(); … … 628 691 629 692 private void removeButton_Click(object sender, EventArgs e) { 630 var treeNode = optimizerTreeView.SelectedNode;631 var optimizer = (IOptimizer)treeNode.Tag;693 var treeNode = treeView.SelectedNode; 694 var optimizer = treeNode.Tag as IOptimizer; 632 695 633 696 if (treeNode.Parent == null) … … 638 701 if (batchRun != null) batchRun.Optimizer = null; 639 702 else if (experiment != null) experiment.Optimizers.Remove(optimizer); 640 else throw new NotSupportedException("Handling for specific type not implemented" + optimizerTreeView.SelectedNode.Tag.GetType());703 else throw new NotSupportedException("Handling for specific type not implemented" + treeView.SelectedNode.Tag.GetType()); 641 704 } 642 705 SetEnabledStateOfControls(); … … 648 711 if (showDetailsCheckBox.Checked) { 649 712 splitContainer.Panel2Collapsed = false; 650 detailsGroupBox.Enabled = optimizerTreeView.SelectedNode != null;651 detailsViewHost.Content = optimizerTreeView.SelectedNode != null ? (IOptimizer)optimizerTreeView.SelectedNode.Tag : null;713 detailsGroupBox.Enabled = treeView.SelectedNode != null; 714 detailsViewHost.Content = treeView.SelectedNode != null ? (IContent)treeView.SelectedNode.Tag : null; 652 715 } else { 653 716 splitContainer.Panel2Collapsed = true; … … 659 722 #region helpers 660 723 private void UpdateDetailsViewHost() { 661 if ( optimizerTreeView.SelectedNode != null)662 detailsViewHost.Content = (I Optimizer)optimizerTreeView.SelectedNode.Tag;724 if (treeView.SelectedNode != null) 725 detailsViewHost.Content = (IContent)treeView.SelectedNode.Tag; 663 726 else 664 727 detailsViewHost.Content = null; … … 668 731 TreeNode node = new TreeNode(optimizer.ToString()); 669 732 node.Tag = optimizer; 733 734 var algorithm = optimizer as IAlgorithm; 735 if (algorithm != null) { 736 foreach (TreeNode childNode in CreateAlgorithmChildNodes(algorithm)) 737 node.Nodes.Add(childNode); 738 } 739 670 740 List<TreeNode> nodes; 671 if (! optimizerTreeViewMapping.TryGetValue(optimizer, out nodes)) {741 if (!treeNodeTagMapping.TryGetValue(optimizer, out nodes)) { 672 742 nodes = new List<TreeNode>(); 673 optimizerTreeViewMapping.Add(optimizer, nodes);674 Register OptimizerEvents(optimizer);743 treeNodeTagMapping.Add(optimizer, nodes); 744 RegisterNamedItemEvents(optimizer); 675 745 } 676 746 nodes.Add(node); 747 748 foreach (TreeNode childNode in node.Nodes) { 749 NamedItem namedItem = childNode.Tag as NamedItem; 750 if (namedItem != null) { 751 if (!treeNodeTagMapping.TryGetValue(namedItem, out nodes)) { 752 nodes = new List<TreeNode>(); 753 treeNodeTagMapping.Add(namedItem, nodes); 754 RegisterNamedItemEvents(namedItem); 755 } 756 nodes.Add(childNode); 757 } 758 } 677 759 return node; 678 760 } 679 761 762 private IEnumerable<TreeNode> CreateAlgorithmChildNodes(IAlgorithm algorithm) { 763 TreeNode problemNode; 764 if (algorithm.Problem != null) { 765 problemNode = new TreeNode(algorithm.Problem.Name); 766 problemNode.Tag = algorithm.Problem; 767 } else { 768 problemNode = new TreeNode("No Problem"); 769 problemNode.Tag = null; 770 } 771 TreeNode parametersNode = new TreeNode("Parameters"); 772 parametersNode.Tag = algorithm.Parameters; 773 TreeNode resultsNode = new TreeNode("Results"); 774 resultsNode.Tag = algorithm.Results; 775 776 yield return problemNode; 777 yield return parametersNode; 778 yield return resultsNode; 779 } 780 680 781 private void DisposeTreeNode(TreeNode node) { 681 var optimizer = (IOptimizer)node.Tag; 782 var namedItem = node.Tag as INamedItem; 783 if (namedItem == null) return; 784 682 785 List<TreeNode> nodes; 683 if (! optimizerTreeViewMapping.TryGetValue(optimizer, out nodes))786 if (!treeNodeTagMapping.TryGetValue(namedItem, out nodes)) 684 787 throw new ArgumentException(); 685 788 nodes.Remove(node); 686 789 if (nodes.Count == 0) { 687 optimizerTreeViewMapping.Remove(optimizer);688 Deregister OptimizerEvents(optimizer);790 treeNodeTagMapping.Remove(namedItem); 791 DeregisterNamedItemEvents(namedItem); 689 792 } 690 793 } … … 693 796 TreeNodeCollection nodes; 694 797 if (node == null) 695 nodes = optimizerTreeView.Nodes;798 nodes = treeView.Nodes; 696 799 else { 697 800 nodes = node.Nodes; … … 710 813 } 711 814 712 optimizerTreeView.ImageList.Images.Clear();815 treeView.ImageList.Images.Clear(); 713 816 foreach (TreeNode treeNode in IterateTreeNodes()) { 714 var optimizer = (IOptimizer)treeNode.Tag;715 optimizerTreeView.ImageList.Images.Add(optimizer == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : optimizer.ItemImage);716 treeNode.ImageIndex = optimizerTreeView.ImageList.Images.Count - 1;817 var item = (IItem)treeNode.Tag; 818 treeView.ImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage); 819 treeNode.ImageIndex = treeView.ImageList.Images.Count - 1; 717 820 treeNode.SelectedImageIndex = treeNode.ImageIndex; 718 821 } -
trunk/sources/HeuristicLab.Optimization/3.3/ResultCollection.cs
r5445 r6524 40 40 return new ResultCollection(this, cloner); 41 41 } 42 43 public override System.Drawing.Image ItemImage { 44 get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; } 45 } 42 46 } 43 47 }
Note: See TracChangeset
for help on using the changeset viewer.