Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6524


Ignore:
Timestamp:
07/07/11 00:17:21 (13 years ago)
Author:
mkommend
Message:

#1555: ExperimentTreeView

  • Corrected flickering during item image update
  • Corrected state of details view host during algorithm execution (readonly, locked)
  • Added algorithm child nodes (problem, parameters, results)
Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.Designer.cs

    r6517 r6524  
    4242      this.moveDownButton = new System.Windows.Forms.Button();
    4343      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();
    4545      this.imageList = new System.Windows.Forms.ImageList(this.components);
    4646      this.detailsGroupBox = new System.Windows.Forms.GroupBox();
     
    8383      this.splitContainer.Panel1.Controls.Add(this.moveDownButton);
    8484      this.splitContainer.Panel1.Controls.Add(this.addButton);
    85       this.splitContainer.Panel1.Controls.Add(this.optimizerTreeView);
     85      this.splitContainer.Panel1.Controls.Add(this.treeView);
    8686      //
    8787      // splitContainer.Panel2
     
    155155      // optimizerTreeView
    156156      //
    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)
    159159            | System.Windows.Forms.AnchorStyles.Left)
    160160            | 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);
    178178      //
    179179      // imageList
     
    255255    private System.Windows.Forms.GroupBox optimizersGroupBox;
    256256    private System.Windows.Forms.SplitContainer splitContainer;
    257     private HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView optimizerTreeView;
     257    private HeuristicLab.Optimization.Views.ExperimentTreeView.CustomTreeView treeView;
    258258    private System.Windows.Forms.GroupBox detailsGroupBox;
    259259    private MainForm.WindowsForms.ViewHost detailsViewHost;
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentTreeView.cs

    r6517 r6524  
    2828using HeuristicLab.Collections;
    2929using HeuristicLab.Common;
     30using HeuristicLab.Core;
    3031using HeuristicLab.Core.Views;
    3132using HeuristicLab.MainForm;
     
    3536  public sealed partial class ExperimentTreeView : ItemView {
    3637    private TypeSelectorDialog typeSelectorDialog;
    37     private Dictionary<IOptimizer, List<TreeNode>> optimizerTreeViewMapping;
     38    private Dictionary<INamedItem, List<TreeNode>> treeNodeTagMapping;
    3839
    3940    public ExperimentTreeView() {
    4041      InitializeComponent();
    41       optimizerTreeViewMapping = new Dictionary<IOptimizer, List<TreeNode>>();
     42      treeNodeTagMapping = new Dictionary<INamedItem, List<TreeNode>>();
    4243    }
    4344
     
    9192      Content.Optimizers.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsReplaced);
    9293      Content.Optimizers.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_CollectionReset);
    93       foreach (var optimizer in optimizerTreeViewMapping.Keys)
    94         DeregisterOptimizerEvents(optimizer);
     94      foreach (var optimizer in treeNodeTagMapping.Keys)
     95        DeregisterNamedItemEvents(optimizer);
    9596      base.DeregisterContentEvents();
    9697    }
    9798
    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) {
    105110        batchRun.OptimizerChanged += new EventHandler(batchRun_OptimizerChanged);
    106       }
    107       if (experiment != null) {
     111      } else if (experiment != null) {
    108112        experiment.Optimizers.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
    109113        experiment.Optimizers.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsMoved);
     
    114118    }
    115119
    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) {
    123132        batchRun.OptimizerChanged -= new EventHandler(batchRun_OptimizerChanged);
    124       }
    125       if (experiment != null) {
     133      } else if (experiment != null) {
    126134        experiment.Optimizers.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsAdded);
    127135        experiment.Optimizers.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<IOptimizer>>(Optimizers_ItemsMoved);
     
    136144      base.OnContentChanged();
    137145      if (Content == null) {
    138         optimizerTreeView.Nodes.Clear();
     146        treeView.Nodes.Clear();
    139147      } else {
    140148        UpdateOptimizerTreeView();
    141         optimizerTreeView.ExpandAll();
     149        treeView.ExpandAll();
    142150      }
    143151    }
     
    149157        return;
    150158      }
    151       RebuildImageList();
    152159      SetEnabledStateOfControls();
    153160    }
    154161
    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()) {
    171171          DisposeTreeNode(childNode);
    172172          childNode.Remove();
    173173        }
     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        }
    174194
    175195        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);
    179197          node.Expand();
    180198        }
     
    192210      var optimizerList = (OptimizerList)sender;
    193211      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 };
    195213      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);
    198216      }
    199217
     
    217235      var optimizerList = (OptimizerList)sender;
    218236      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 };
    220238      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);
    223241      }
    224242
     
    249267      var optimizerList = (OptimizerList)sender;
    250268      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 };
    252270      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);
    255273      }
    256274
     
    273291      var optimizerList = (OptimizerList)sender;
    274292      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 };
    276294      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);
    279297      }
    280298
     
    302320      var optimizerList = (OptimizerList)sender;
    303321      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 };
    305323      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);
    308326      }
    309327
     
    324342    }
    325343
    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();
    334365    }
    335366    #endregion
     367
     368    protected override void PropagateStateChanges(Control control, Type type, System.Reflection.PropertyInfo propertyInfo) {
     369      return;
     370    }
    336371
    337372    protected override void SetEnabledStateOfControls() {
    338373      base.SetEnabledStateOfControls();
     374      IOptimizer optimizer = null;
     375      IAlgorithm algorithm = null;
    339376      BatchRun batchRun = null;
    340       BatchRun parentBatchRun = null;
    341377      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      }
    351399
    352400      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));
    354402      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;
    356404      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;
    360407    }
    361408
    362409    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    }
    368414
    369415    private void UpdateChildTreeNodes(TreeNodeCollection collection, IOptimizer optimizer) {
    370416      var batchRun = optimizer as BatchRun;
    371417      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);
    374421    }
    375422    private void UpdateChildTreeNodes(TreeNodeCollection collection, IEnumerable<IOptimizer> optimizers) {
     
    387434
    388435      TreeNode selectedNode = (TreeNode)e.Item;
    389       var optimizer = (IOptimizer)selectedNode.Tag;
     436      var item = (IItem)selectedNode.Tag;
    390437      DataObject data = new DataObject();
    391       data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, optimizer);
     438      data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, item);
    392439      validDragOperation = true;
    393440
    394       if (ReadOnly) {
     441      if (ReadOnly || !(item is IOptimizer)) {
    395442        DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    396443      } else {
    397444        DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    398445        if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     446          var optimizer = (IOptimizer)item;
    399447          if (selectedNode.Parent == null) Content.Optimizers.Remove(optimizer);
    400448          else {
     
    429477      e.Effect = DragDropEffects.None;
    430478      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);
    433481        Experiment experiment = null;
    434482        BatchRun batchRun = null;
     
    467515    }
    468516    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);
    471519      Experiment experiment = null;
    472520      BatchRun batchRun = null;
     
    501549      if (e.X < e.Node.Bounds.Left || e.X > e.Node.Bounds.Right) return;
    502550      e.Node.Toggle();
    503       IOptimizer optimizer = (IOptimizer)e.Node.Tag;
     551      IContent optimizer = (IContent)e.Node.Tag;
    504552      MainFormManager.MainForm.ShowContent(optimizer);
    505553    }
    506554    private void optimizerTreeview_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
    507555      if (e.X < e.Node.Bounds.Left || e.X > e.Node.Bounds.Right) return;
    508       optimizerTreeView.SelectedNode = e.Node;
    509       detailsViewHost.Content = (IOptimizer)e.Node.Tag;
     556      treeView.SelectedNode = e.Node;
     557      detailsViewHost.Content = (IContent)e.Node.Tag;
    510558      SetEnabledStateOfControls();
    511559    }
     
    513561      // enables deselection of treeNodes
    514562      if (e.Button != MouseButtons.Right) rightClickOccured = false;
    515       if (optimizerTreeView.SelectedNode == null) return;
     563      if (treeView.SelectedNode == null) return;
    516564      Point coordinates = new Point(e.X, e.Y);
    517       TreeNode node = optimizerTreeView.GetNodeAt(coordinates);
     565      TreeNode node = treeView.GetNodeAt(coordinates);
    518566      if (node == null || coordinates.X < node.Bounds.Left || coordinates.X > node.Bounds.Right) {
    519         optimizerTreeView.SelectedNode = null;
     567        treeView.SelectedNode = null;
    520568        detailsViewHost.Content = null;
    521569        SetEnabledStateOfControls();
     
    526574    private void optimizerTreeView_KeyDown(object sender, KeyEventArgs e) {
    527575      if (ReadOnly) return;
    528       if (optimizerTreeView.SelectedNode == null) return;
    529576      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;
    532581      var optimizer = (IOptimizer)treeNode.Tag;
    533582
     
    539588        if (batchRun != null) batchRun.Optimizer = null;
    540589        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());
    542591      }
    543592      SetEnabledStateOfControls();
     
    550599    private void optimizerTreeView_RightClick(object sender, EventArgs e) {
    551600      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);
    554603
    555604      if (toolStripMenuNode != null && coordinates.X >= toolStripMenuNode.Bounds.Left && coordinates.X <= toolStripMenuNode.Bounds.Right) {
    556         optimizerTreeView.SelectedNode = toolStripMenuNode;
     605        treeView.SelectedNode = toolStripMenuNode;
    557606        detailsViewHost.Content = (IContent)toolStripMenuNode.Tag;
    558607        SetEnabledStateOfControls();
     
    575624
    576625    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) {
    579633        typeSelectorDialog.Caption = "Select Optimizer";
    580634        typeSelectorDialog.TypeSelector.Caption = "Available Optimizers";
    581635        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);
    582640      }
    583641
    584642      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    585643        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;
    594657          }
    595658        }
     
    601664
    602665    private void moveUpButton_Click(object sender, EventArgs e) {
    603       var optimizer = optimizerTreeView.SelectedNode.Tag as IOptimizer;
     666      var optimizer = (IOptimizer)treeView.SelectedNode.Tag;
    604667      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;
    609672      experiment.Optimizers.Reverse(index - 1, 2);
    610       optimizerTreeView.SelectedNode = optimizerTreeViewMapping[optimizer].First();
     673      treeView.SelectedNode = treeNodeTagMapping[optimizer].First();
    611674      SetEnabledStateOfControls();
    612675      UpdateDetailsViewHost();
     
    614677    }
    615678    private void moveDownButton_Click(object sender, EventArgs e) {
    616       var optimizer = optimizerTreeView.SelectedNode.Tag as IOptimizer;
     679      var optimizer = (IOptimizer)treeView.SelectedNode.Tag;
    617680      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;
    622685      experiment.Optimizers.Reverse(index, 2);
    623       optimizerTreeView.SelectedNode = optimizerTreeViewMapping[optimizer].First();
     686      treeView.SelectedNode = treeNodeTagMapping[optimizer].First();
    624687      SetEnabledStateOfControls();
    625688      UpdateDetailsViewHost();
     
    628691
    629692    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;
    632695
    633696      if (treeNode.Parent == null)
     
    638701        if (batchRun != null) batchRun.Optimizer = null;
    639702        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());
    641704      }
    642705      SetEnabledStateOfControls();
     
    648711      if (showDetailsCheckBox.Checked) {
    649712        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;
    652715      } else {
    653716        splitContainer.Panel2Collapsed = true;
     
    659722    #region helpers
    660723    private void UpdateDetailsViewHost() {
    661       if (optimizerTreeView.SelectedNode != null)
    662         detailsViewHost.Content = (IOptimizer)optimizerTreeView.SelectedNode.Tag;
     724      if (treeView.SelectedNode != null)
     725        detailsViewHost.Content = (IContent)treeView.SelectedNode.Tag;
    663726      else
    664727        detailsViewHost.Content = null;
     
    668731      TreeNode node = new TreeNode(optimizer.ToString());
    669732      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
    670740      List<TreeNode> nodes;
    671       if (!optimizerTreeViewMapping.TryGetValue(optimizer, out nodes)) {
     741      if (!treeNodeTagMapping.TryGetValue(optimizer, out nodes)) {
    672742        nodes = new List<TreeNode>();
    673         optimizerTreeViewMapping.Add(optimizer, nodes);
    674         RegisterOptimizerEvents(optimizer);
     743        treeNodeTagMapping.Add(optimizer, nodes);
     744        RegisterNamedItemEvents(optimizer);
    675745      }
    676746      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      }
    677759      return node;
    678760    }
    679761
     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
    680781    private void DisposeTreeNode(TreeNode node) {
    681       var optimizer = (IOptimizer)node.Tag;
     782      var namedItem = node.Tag as INamedItem;
     783      if (namedItem == null) return;
     784
    682785      List<TreeNode> nodes;
    683       if (!optimizerTreeViewMapping.TryGetValue(optimizer, out nodes))
     786      if (!treeNodeTagMapping.TryGetValue(namedItem, out nodes))
    684787        throw new ArgumentException();
    685788      nodes.Remove(node);
    686789      if (nodes.Count == 0) {
    687         optimizerTreeViewMapping.Remove(optimizer);
    688         DeregisterOptimizerEvents(optimizer);
     790        treeNodeTagMapping.Remove(namedItem);
     791        DeregisterNamedItemEvents(namedItem);
    689792      }
    690793    }
     
    693796      TreeNodeCollection nodes;
    694797      if (node == null)
    695         nodes = optimizerTreeView.Nodes;
     798        nodes = treeView.Nodes;
    696799      else {
    697800        nodes = node.Nodes;
     
    710813      }
    711814
    712       optimizerTreeView.ImageList.Images.Clear();
     815      treeView.ImageList.Images.Clear();
    713816      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;
    717820        treeNode.SelectedImageIndex = treeNode.ImageIndex;
    718821      }
  • trunk/sources/HeuristicLab.Optimization/3.3/ResultCollection.cs

    r5445 r6524  
    4040      return new ResultCollection(this, cloner);
    4141    }
     42
     43    public override System.Drawing.Image ItemImage {
     44      get { return HeuristicLab.Common.Resources.VSImageLibrary.Object; }
     45    }
    4246  }
    4347}
Note: See TracChangeset for help on using the changeset viewer.