Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/21/17 10:09:40 (7 years ago)
Author:
jzenisek
Message:

#2839 fixed tree building routine in ResourcesView

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r15422 r15557  
    301301      if (!resources.Any()) return null;
    302302
    303       var slaveGroups = new HashSet<SlaveGroup>(resources.OfType<SlaveGroup>());
    304       var slaves = new HashSet<Slave>(resources.OfType<Slave>());
    305 
    306       var stack = new Stack<Resource>(slaveGroups.OrderByDescending(x => x.Name));
     303      var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>().Where(x => x.ParentResourceId == null));
     304      var subResources = new HashSet<Resource>(resources.Except(mainResources));
     305
     306      var stack = new Stack<Resource>(mainResources.OrderByDescending(x => x.Name));
    307307      var top = stack.Peek();
    308308
     
    310310      Resource currentResource = null;
    311311
    312       while (stack.Any()) {
     312      while(stack.Any()) {
    313313        var newResource = stack.Pop();
    314314        var newNode = new TreeNode(newResource.Name) { Tag = newResource };
    315315
    316         while (currentNode != null && newResource.ParentResourceId != currentResource.Id) {
     316        // search for parent node of newNode and save in currentNode
     317        // necessary since newNodes (stack top items) might be siblings
     318        // or grand..grandparents of previous node (currentNode)
     319        while(currentNode != null && newResource.ParentResourceId != currentResource.Id) {
    317320          currentNode = currentNode.Parent;
    318321          currentResource = currentNode == null ? null : (Resource)currentNode.Tag;
    319322        }
    320323
    321         if (currentNode == null) {
     324        if(currentNode == null) {
    322325          treeView.Nodes.Add(newNode);
    323326        } else {
     
    325328        }
    326329
    327         if (newResource is Slave) {
     330        if(newResource is Slave) {
    328331          newNode.ImageIndex = slaveImageIndex;
    329332        } else {
    330333          newNode.ImageIndex = slaveGroupImageIndex;
    331334
    332           var childSlaves = slaves.Where(x => x.ParentResourceId == newResource.Id);
    333           foreach (var slave in childSlaves.OrderBy(x => x.Name)) {
    334             slaves.Remove(slave);
    335             var slaveNode = new TreeNode(slave.Name) { Tag = slave };
    336 
    337             slaveNode.SelectedImageIndex = slaveNode.ImageIndex = slaveImageIndex;
    338             if (slave.OwnerUserId == UserInformation.Instance.User.Id)
    339               slaveNode.BackColor = ownedResourceColor;
    340 
    341             newNode.Nodes.Add(slaveNode);
    342           }
    343 
    344           var childSlaveGroups = slaveGroups.Where(x => x.ParentResourceId == newResource.Id);
    345           if (childSlaveGroups.Any()) {
    346             foreach (var slaveGroup in childSlaveGroups.OrderByDescending(x => x.Name)) {
    347               slaveGroups.Remove(slaveGroup);
    348               stack.Push(slaveGroup);
     335          var childResources = subResources.Where(x => x.ParentResourceId == newResource.Id);
     336          if(childResources.Any()) {
     337            foreach(var resource in childResources.OrderByDescending(x => x.Name)) {
     338              subResources.Remove(resource);
     339              stack.Push(resource);
    349340            }
    350341            currentNode = newNode;
     
    352343          }
    353344        }
    354 
    355345        newNode.SelectedImageIndex = newNode.ImageIndex;
    356346        if (newResource.OwnerUserId == UserInformation.Instance.User.Id)
     
    366356      };
    367357
    368       foreach (var slave in slaves.OrderBy(x => x.Name)) {
     358      foreach (var slave in subResources.OfType<Slave>().OrderBy(x => x.Name)) {
    369359        var slaveNode = new TreeNode(slave.Name) { Tag = slave };
    370360        ungroupedNode.Nodes.Add(slaveNode);
Note: See TracChangeset for help on using the changeset viewer.