Changeset 15920


Ignore:
Timestamp:
04/25/18 13:12:02 (4 years ago)
Author:
jzenisek
Message:

#2839: fixed several bugs in JobAdmin:

  • disabled play button if no project or resource is selected
  • extract stats for selected or alternatively for checked resources
  • collapse slaves-only groups if no slave is assigned explicitly
  • prevent unnecessary resource tree rebuilds (reset and style instead)
  • suppress double clicks in resource tree (i.e. prevent win forms check-error)

...

Location:
branches/2839_HiveProjectManagement
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.Designer.cs

    r15627 r15920  
    5454      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    5555      this.projectsTreeView = new System.Windows.Forms.TreeView();
    56       this.resourcesTreeView = new System.Windows.Forms.TreeView();
     56      this.resourcesTreeView = new HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView();
    5757      this.summaryGroupBox = new System.Windows.Forms.GroupBox();
    5858      this.coresLabel = new System.Windows.Forms.Label();
     
    246246    private System.Windows.Forms.SplitContainer splitContainer2;
    247247    protected System.Windows.Forms.TreeView projectsTreeView;
    248     protected System.Windows.Forms.TreeView resourcesTreeView;
     248    protected HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView resourcesTreeView;
    249249    private System.Windows.Forms.GroupBox summaryGroupBox;
    250250    private System.Windows.Forms.Label coresLabel;
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs

    r15914 r15920  
    6262    private readonly HashSet<Resource> newIncludedResources = new HashSet<Resource>();
    6363
    64     private IEnumerable<Resource> addedResources;
    65     private IEnumerable<Resource> removedResources;
    66     private IEnumerable<Resource> addedIncludes;
    67     private IEnumerable<Resource> removedIncludes;
    68 
    6964    private readonly Color addedAssignmentColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1
    7065    private readonly Color removedAssignmentColor = Color.FromArgb(255, 236, 159, 72); // #ec9f48
     
    141136      set {
    142137        if (selectedProject == value) return;
     138
     139        if ((JobId == Guid.Empty || JobId == null)
     140          && (value == null || SelectedProject == null || value.Id != SelectedProject.Id)) selectedResourceIds = null;
    143141        lastSelectedProject = selectedProject;
    144142        selectedProject = value;
    145143
    146         if (JobId == Guid.Empty || JobId == null) selectedResourceIds = null;
    147144        UpdateResourceTree();
    148145        ExtractStatistics();
     
    238235      }
    239236      SelectedProject = node;
    240       //ExtractStatistics();
    241237    }
    242238
     
    246242      if (node == null) {
    247243        resourcesTreeView.SelectedNode = null;
    248       }
    249 
    250       ExtractStatistics((Resource)node?.Tag);
     244        ExtractStatistics();
     245      } else {
     246        ExtractStatistics((Resource)node.Tag);
     247      }
    251248    }
    252249
    253250    private void resourcesTreeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) {
    254251      var checkedResource = (Resource)e.Node.Tag;
    255       if (newIncludedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) e.Cancel = true;
     252      if (newIncludedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) {
     253        e.Cancel = true;
     254        ExtractStatistics((Resource)resourcesTreeView.SelectedNode?.Tag);
     255      }
    256256    }
    257257
     
    264264      }
    265265
    266       UpdateNewResourceTree();
     266      UpdateResourceTreeAfterCheck();
    267267      ExtractStatistics();
    268       //ExtractStatistics((Resource)resourcesTreeView.SelectedNode?.Tag);
    269268      OnAssignedResourcesChanged();
    270269    }
     
    384383    }
    385384
    386     private void UpdateNewResourceTree() {
     385    private void UpdateResourceTreeAfterCheck() {
     386      resourcesTreeView.BeforeCheck -= resourcesTreeView_BeforeCheck;
     387      resourcesTreeView.AfterCheck -= resourcesTreeView_AfterCheck;
    387388      UpdateNewAssignedResources();
    388389      UpdateNewIncludedResources();
    389       BuildResourceTree(availableResources);
     390      SetTreeNodes(resourcesTreeView.Nodes);
     391      resourcesTreeView.BeforeCheck += resourcesTreeView_BeforeCheck;
     392      resourcesTreeView.AfterCheck += resourcesTreeView_AfterCheck;
    390393    }
    391394
     
    497500      var removedIncludes = includedResources.Except(newIncludedResources);
    498501
    499       HashSet<TreeNode> expandedNodes = new HashSet<TreeNode>();
    500502      TreeNode currentNode = null;
    501503      Resource currentResource = null;
     
    519521        } else {
    520522          currentNode.Nodes.Add(newNode);
    521         }
    522 
    523         if(newAssignedResources.Select(x => x.Id).Contains(newResource.Id)
    524           || assignedResources.Select(x => x.Id).Contains(newResource.Id)
    525           || newIncludedResources.Select(x => x.Id).Contains(newResource.Id)
    526           || includedResources.Select(x => x.Id).Contains(newResource.Id)) {
    527           expandedNodes.Add(newNode);
    528523        }
    529524
     
    593588      }
    594589
    595      
    596       foreach (var node in expandedNodes) {
    597         node.Expand();
    598         var parent = node.Parent;
    599         while(parent != null) {
    600           parent.Expand();
    601           parent = parent.Parent;
    602         }
    603       }
     590      ExpandResourceNodesOfInterest(resourcesTreeView.Nodes);
    604591
    605592      resourcesTreeView.BeforeCheck += resourcesTreeView_BeforeCheck;
    606593      resourcesTreeView.AfterCheck += resourcesTreeView_AfterCheck;
    607       //resourcesTreeView.ExpandAll();
    608     }
    609 
    610     private void ExpandSlaveGroupNodes() {
    611       foreach (TreeNode n in nodeStore.Where(x => x.Tag is SlaveGroup)) {
    612         TreeNode[] children = new TreeNode[n.Nodes.Count];
    613         n.Nodes.CopyTo(children, 0);
    614         if (children.Any(x => x.Tag is SlaveGroup)) n.Expand();
     594    }
     595
     596    private void ExpandResourceNodesOfInterest(TreeNodeCollection nodes) {
     597      foreach(TreeNode n in nodes) {
     598        Resource r = (Resource)n.Tag;
     599        if(n.Nodes.Count > 0) {
     600          if(HiveClient.Instance.GetAvailableChildResources(r.Id).OfType<SlaveGroup>().Any()
     601            || HiveClient.Instance.GetAvailableChildResources(r.Id).OfType<Slave>().Intersect(assignedResources.Union(newAssignedResources)).Any()) {
     602            n.Expand();
     603            ExpandResourceNodesOfInterest(n.Nodes);
     604          } else {
     605            n.Collapse();
     606          }   
     607        } else {
     608          n.Collapse();
     609        }
     610      }
     611    }
     612
     613    private void CollapseSlaveOnlyNodes(TreeNode tn) {
     614      if (!(tn.Tag is Resource)) return;
     615
     616      Resource r = (Resource)tn.Tag;
     617      if (HiveClient.Instance.ResourceDescendants.ContainsKey(r.Id)) {
     618        if (HiveClient.Instance.GetAvailableChildResources(r.Id).OfType<SlaveGroup>().Any()) {
     619          tn.Expand();
     620          foreach (TreeNode n in tn.Nodes) CollapseSlaveOnlyNodes(n);
     621        } else {
     622          tn.Collapse();
     623        }
    615624      }
    616625    }
     
    619628      HashSet<Slave> newAssignedSlaves = new HashSet<Slave>(newAssignedResources.OfType<Slave>());
    620629      foreach (var slaveGroup in newAssignedResources.OfType<SlaveGroup>()) {
    621         foreach(var slave in HiveClient.Instance.ResourceDescendants[slaveGroup.Id].OfType<Slave>()) {
     630        foreach (var slave in HiveClient.Instance.GetAvailableChildResources(slaveGroup.Id).OfType<Slave>()) {
    622631          newAssignedSlaves.Add(slave);
    623632        }
     
    629638        var slaveGroup = resource as SlaveGroup;
    630639        if (slaveGroup != null) {
    631           selectedSlaves = new HashSet<Slave>(HiveClient.Instance.ResourceDescendants[slaveGroup.Id].OfType<Slave>());
    632           //selectedSlaves.IntersectWith(newAssignedSlaves);
     640          selectedSlaves = new HashSet<Slave>(HiveClient.Instance.GetAvailableChildResources(slaveGroup.Id).OfType<Slave>());
    633641        } else {
    634642          selectedSlaves = new HashSet<Slave>(new[] { resource as Slave });
     
    665673    }
    666674
     675    private void SetTreeNodes(TreeNodeCollection nodes) {
     676      var addedAssignments = newAssignedResources.Except(assignedResources);
     677      var removedAssignments = assignedResources.Except(newAssignedResources);
     678      var addedIncludes = newIncludedResources.Except(includedResources);
     679      var removedIncludes = includedResources.Except(newIncludedResources);
     680
     681      foreach (TreeNode n in nodes) {
     682
     683        if(n.Tag is Resource) {
     684          // reset
     685          var resource = (Resource)n.Tag;
     686          n.Text = resource.Name;
     687          n.BackColor = Color.Transparent;
     688          n.ForeColor = Color.Black;
     689          n.Checked = false;
     690
     691          // add additional info
     692          if (newAssignedResources.Select(x => x.Id).Contains(resource.Id)) {
     693            n.Checked = true;
     694          } else if (newIncludedResources.Select(x => x.Id).Contains(resource.Id)) {
     695            n.Checked = true;
     696            n.ForeColor = grayTextColor;
     697          }
     698
     699          if (includedResources.Select(x => x.Id).Contains(resource.Id) && newIncludedResources.Select(x => x.Id).Contains(resource.Id)) {
     700            n.Text += INCLUDED_TAG;
     701          } else if (addedIncludes.Select(x => x.Id).Contains(resource.Id)) {
     702            n.BackColor = addedIncludeColor;
     703            n.ForeColor = grayTextColor;
     704            n.Text += ADDED_INCLUDE_TAG;
     705          } else if (removedIncludes.Select(x => x.Id).Contains(resource.Id)) {
     706            n.BackColor = removedIncludeColor;
     707            n.Text += REMOVED_INCLUDE_TAG;
     708          }
     709
     710          if (addedAssignments.Select(x => x.Id).Contains(resource.Id)) {
     711            n.BackColor = addedAssignmentColor;
     712            n.ForeColor = controlTextColor;
     713            n.Text += ADDED_SELECTION_TAG;
     714          } else if (removedAssignments.Select(x => x.Id).Contains(resource.Id)) {
     715            n.BackColor = removedAssignmentColor;
     716            n.ForeColor = controlTextColor;
     717            n.Text += REMOVED_SELECTION_TAG;
     718          }
     719        }
     720
     721        if(n.Nodes.Count > 0) {
     722          SetTreeNodes(n.Nodes);
     723        }
     724      }
     725    }
     726
    667727    #endregion
    668728
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r15914 r15920  
    392392          Content.Job.ResourceIds = null;
    393393        }
     394        SetEnabledStateOfExecutableButtons();
    394395      }
    395396    }
     
    509510        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = false;
    510511      } else {
    511         startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
     512        startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0
     513          && Content.Job.ProjectId != null && Content.Job.ProjectId != Guid.Empty && Content.Job.ResourceIds != null  && Content.Job.ResourceIds.Any()
     514          && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
    512515        pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
    513516        stopButton.Enabled = Content.IsControllable && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
Note: See TracChangeset for help on using the changeset viewer.