- Timestamp:
- 04/20/18 11:52:33 (7 years ago)
- Location:
- branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs
r15658 r15913 43 43 public const string additionalSlavesGroupDescription = "Contains additional slaves which are either ungrouped or the parenting slave group is not assigned to the selected project."; 44 44 45 private const string CURRENT_SELECTION_TAG = " [current selection]"; 46 private const string NEW_SELECTION_TAG = " [new selection]"; 47 private const string CHANGED_SELECTION_TAG = " [changed selection]"; 45 48 46 49 private readonly HashSet<TreeNode> mainTreeNodes = new HashSet<TreeNode>(); … … 54 57 private readonly HashSet<Resource> newIncludedResources = new HashSet<Resource>(); 55 58 56 private readonly Dictionary<Guid, HashSet<Project>> projectAncestors = new Dictionary<Guid, HashSet<Project>>();57 private readonly Dictionary<Guid, HashSet<Project>> projectDescendants = new Dictionary<Guid, HashSet<Project>>();58 private readonly Dictionary<Guid, HashSet<Resource>> resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();59 private readonly Dictionary<Guid, HashSet<Resource>> resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();60 61 59 private IEnumerable<Resource> addedResources; 62 60 private IEnumerable<Resource> removedResources; … … 68 66 private readonly Color addedIncludeColor = Color.FromArgb(25, 169, 221, 221); // #a9dddd 69 67 private readonly Color removedIncludeColor = Color.FromArgb(25, 249, 210, 145); // #f9d291 70 private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b 68 private readonly Color selectedBackColor = Color.DodgerBlue; 69 private readonly Color selectedForeColor = Color.White; 71 70 72 71 private string currentSearchString; … … 173 172 base.OnContentChanged(); 174 173 175 if (Content != null) { 176 UpdateProjectGenealogy(); 177 UpdateResourceGenealogy(); 178 174 if (Content != null) { 179 175 if (SelectedProjectId.HasValue && SelectedProjectId.Value != Guid.Empty) { 180 176 SelectedProject = GetSelectedProjectById(SelectedProjectId.Value); … … 218 214 projectsTreeView.SelectedNode = null; 219 215 } else { 220 ReColorTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent, true); 221 e.Node.BackColor = selectedColor; 216 ResetTreeNodes(projectsTreeView.Nodes); 217 e.Node.BackColor = selectedBackColor; 218 e.Node.ForeColor = selectedForeColor; 222 219 223 220 if(node.Id == projectId) { 224 e.Node.Text += " [current selection]";221 e.Node.Text += CURRENT_SELECTION_TAG; 225 222 } else if(projectId == null || projectId == Guid.Empty) { 226 e.Node.Text += " [new selection]";223 e.Node.Text += NEW_SELECTION_TAG; 227 224 } else { 228 e.Node.Text += " [changed selection]";225 e.Node.Text += CHANGED_SELECTION_TAG; 229 226 } 230 227 … … 270 267 271 268 #region Helpers 272 273 274 #region old275 private void UpdateMainTree() {276 mainTreeNodes.Clear();277 278 foreach (Project g in Content.OrderBy(x => x.Name)) {279 if (g.ParentProjectId == null) {280 TreeNode tn = new TreeNode();281 tn.ImageIndex = greenFlagImageIndex;282 tn.SelectedImageIndex = tn.ImageIndex;283 284 tn.Tag = g;285 tn.Text = g.Name;286 tn.Checked = assignedResources.Any(x => x.Id == g.Id);287 288 BuildMainTree(tn);289 mainTreeNodes.Add(tn);290 }291 }292 UpdateFilteredTree();293 }294 295 private void BuildMainTree(TreeNode tn) {296 foreach (Project r in Content.Where(s => s.ParentProjectId != null && s.ParentProjectId == ((Project)tn.Tag).Id).OrderBy(x => x.Name)) {297 TreeNode stn = new TreeNode(r.Name);298 stn.ImageIndex = redFlagImageIndex;299 stn.SelectedImageIndex = stn.ImageIndex;300 stn.Tag = r;301 stn.Checked = assignedResources.Any(x => x.Id == r.Id);302 tn.Nodes.Add(stn);303 mainTreeNodes.Add(stn);304 305 BuildMainTree(stn);306 }307 }308 309 private void UpdateFilteredTree() {310 filteredTreeNodes.Clear();311 foreach (TreeNode n in mainTreeNodes) {312 n.BackColor = SystemColors.Window;313 if (currentSearchString == null || ((Project)n.Tag).Name.ToLower().Contains(currentSearchString)) {314 n.BackColor = string.IsNullOrEmpty(currentSearchString) ? SystemColors.Window : Color.LightBlue;315 filteredTreeNodes.Add(n);316 TraverseParentNodes(n);317 }318 }319 UpdateProjectsTree();320 }321 322 private void UpdateProjectsTree() {323 projectsTreeView.Nodes.Clear();324 nodeStore.Clear();325 326 foreach (TreeNode node in filteredTreeNodes) {327 var clone = nodeStore.SingleOrDefault(x => ((Project)x.Tag).Id == ((Project)node.Tag).Id);328 if (clone == null) {329 clone = (TreeNode)node.Clone();330 nodeStore.Add(clone);331 clone.Nodes.Clear();332 }333 foreach (TreeNode child in node.Nodes)334 if (filteredTreeNodes.Any(x => ((Project)x.Tag).Id == ((Project)child.Tag).Id)) {335 var childClone = nodeStore.SingleOrDefault(x => ((Project)x.Tag).Id == ((Project)child.Tag).Id);336 if (childClone == null) {337 childClone = (TreeNode)child.Clone();338 nodeStore.Add(childClone);339 childClone.Nodes.Clear();340 }341 clone.Nodes.Add(childClone);342 }343 }344 projectsTreeView.Nodes.AddRange(nodeStore.Where(x => ((Project)x.Tag).ParentProjectId == null).ToArray());345 if (string.IsNullOrEmpty(currentSearchString)) ExpandSlaveGroupNodes();346 else projectsTreeView.ExpandAll();347 }348 349 private void TraverseParentNodes(TreeNode node) {350 if (node != null) {351 for (TreeNode parent = node.Parent; parent != null; parent = parent.Parent)352 filteredTreeNodes.Add(parent);353 }354 }355 #endregion356 269 357 270 private Project GetSelectedProjectById(Guid projectId) { … … 368 281 if(project.Name.ToLower().Contains(currentSearchString.ToLower())) { 369 282 filteredProjects.Add(project); 370 filteredProjects.UnionWith( projectAncestors[project.Id]);283 filteredProjects.UnionWith(Content.Where(p => HiveClient.Instance.ProjectAncestors[project.Id].Contains(p.Id))); 371 284 } 372 285 } … … 379 292 if (!projects.Any()) return; 380 293 381 // select all top level projects (withouth parent, or without parentwithin current project collection)294 // select all top level projects (withouth parent, or without any ancestor within current project collection) 382 295 var mainProjects = new HashSet<Project>(projects.Where(x => x.ParentProjectId == null)); 383 296 var parentedMainProjects = new HashSet<Project>(projects 384 297 .Where(x => x.ParentProjectId.HasValue 385 && !projects.Select(y => y.Id).Contains(x.ParentProjectId.Value))); 298 && !projects.Select(y => y.Id).Contains(x.ParentProjectId.Value) 299 && !projects.SelectMany(y => HiveClient.Instance.ProjectAncestors[y.Id]).Contains(x.ParentProjectId.Value))); 386 300 mainProjects.UnionWith(parentedMainProjects); 387 301 var subProbjects = new HashSet<Project>(projects.Except(mainProjects)); 302 foreach(var p in subProbjects) { 303 p.ParentProjectId = HiveClient.Instance.ProjectAncestors[p.Id].Where(x => projects.Select(y => y.Id).Contains(x)).FirstOrDefault(); 304 } 388 305 389 306 var stack = new Stack<Project>(mainProjects.OrderByDescending(x => x.Name)); … … 412 329 413 330 if (SelectedProject != null && SelectedProject.Id.Equals(newProject.Id)) { 414 newNode.BackColor = selectedColor; 331 newNode.BackColor = selectedBackColor; 332 newNode.ForeColor = selectedForeColor; 415 333 if(SelectedProject.Id == projectId) { 416 newNode.Text += " [current selection]";334 newNode.Text += CURRENT_SELECTION_TAG; 417 335 } else if (projectId == null || projectId == Guid.Empty) { 418 newNode.Text += " [new selection]";336 newNode.Text += NEW_SELECTION_TAG; 419 337 } else { 420 newNode.Text += " [changed selection]";338 newNode.Text += CHANGED_SELECTION_TAG; 421 339 } 422 340 } … … 439 357 projectsTreeView.ExpandAll(); 440 358 } 441 442 private void UpdateProjectGenealogy() {443 projectAncestors.Clear();444 projectDescendants.Clear();445 var projects = Content;446 447 foreach (var p in projects) {448 projectAncestors.Add(p.Id, new HashSet<Project>());449 projectDescendants.Add(p.Id, new HashSet<Project>());450 }451 452 foreach (var p in projects) {453 var parentProjectId = p.ParentProjectId;454 while (parentProjectId != null) {455 var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);456 if (parent != null) {457 projectAncestors[p.Id].Add(parent);458 projectDescendants[parent.Id].Add(p);459 parentProjectId = parent.ParentProjectId;460 } else {461 parentProjectId = null;462 }463 }464 }465 }466 467 359 468 360 private static IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) { … … 495 387 foreach (var resource in assignedProjectResources) { 496 388 availableResources.Add(resource); 497 foreach(var descendant in resourceDescendants[resource.Id]) {389 foreach(var descendant in HiveClient.Instance.Resources.Where(x => HiveClient.Instance.ResourceDescendants[resource.Id].Contains(x.Id))) { 498 390 availableResources.Add(descendant); 499 391 } … … 544 436 private void UpdateNewAssignedResources() { 545 437 for(int i = newAssignedResources.Count-1; i>=0; i--) { 546 if(newAssignedResources.Intersect( resourceAncestors[newAssignedResources.ElementAt(i).Id]).Any()) {438 if(newAssignedResources.Intersect(HiveClient.Instance.GetAvailableParentResources(newAssignedResources.ElementAt(i).Id)).Any()) { 547 439 newAssignedResources.Remove(newAssignedResources.ElementAt(i)); 548 440 } … … 556 448 if (JobId != Guid.Empty) { 557 449 foreach (var item in assignedResources) { 558 foreach (var descendant in resourceDescendants[item.Id]) {450 foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) { 559 451 includedResources.Add(descendant); 560 452 } … … 563 455 564 456 foreach (var item in newAssignedResources) { 565 foreach (var descendant in resourceDescendants[item.Id]) {457 foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) { 566 458 newIncludedResources.Add(descendant); 567 459 } … … 572 464 newIncludedResources.Clear(); 573 465 foreach (var item in newAssignedResources) { 574 foreach (var descendant in resourceDescendants[item.Id]) {466 foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) { 575 467 newIncludedResources.Add(descendant); 576 }577 }578 }579 580 private void UpdateResourceGenealogy() {581 resourceAncestors.Clear();582 resourceDescendants.Clear();583 var resources = HiveClient.Instance.Resources;584 585 foreach (var r in resources) {586 resourceAncestors.Add(r.Id, new HashSet<Resource>());587 resourceDescendants.Add(r.Id, new HashSet<Resource>());588 }589 590 foreach (var r in resources) {591 var parentResourceId = r.ParentResourceId;592 while (parentResourceId != null) {593 var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);594 if (parent != null) {595 resourceAncestors[r.Id].Add(parent);596 resourceDescendants[parent.Id].Add(r);597 parentResourceId = parent.ParentResourceId;598 } else {599 parentResourceId = null;600 }601 468 } 602 469 } … … 743 610 HashSet<Slave> newAssignedSlaves = new HashSet<Slave>(newAssignedResources.OfType<Slave>()); 744 611 foreach (var slaveGroup in newAssignedResources.OfType<SlaveGroup>()) { 745 foreach(var slave in resourceDescendants[slaveGroup.Id].OfType<Slave>()) {612 foreach(var slave in HiveClient.Instance.ResourceDescendants[slaveGroup.Id].OfType<Slave>()) { 746 613 newAssignedSlaves.Add(slave); 747 614 } … … 753 620 var slaveGroup = resource as SlaveGroup; 754 621 if (slaveGroup != null) { 755 selectedSlaves = new HashSet<Slave>( resourceDescendants[slaveGroup.Id].OfType<Slave>());622 selectedSlaves = new HashSet<Slave>(HiveClient.Instance.ResourceDescendants[slaveGroup.Id].OfType<Slave>()); 756 623 //selectedSlaves.IntersectWith(newAssignedSlaves); 757 624 } else { … … 771 638 } 772 639 773 private void ReColorTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) { 640 private void StyleTreeNode(TreeNode n, string name) { 641 n.Text = name; 642 n.BackColor = Color.Transparent; 643 n.ForeColor = Color.Black; 644 } 645 646 private void ResetTreeNodes(TreeNodeCollection nodes) { 774 647 foreach (TreeNode n in nodes) { 775 if (n.BackColor.Equals(c1)) {776 n.BackColor = c2;777 if(resetText) n.Text = ((Project)n.Tag).Name;778 }648 string name = ""; 649 if (n.Tag is Project) name = ((Project)n.Tag).Name; 650 else if (n.Tag is Resource) name = ((Resource)n.Tag).Name; 651 StyleTreeNode(n, name); 779 652 if (n.Nodes.Count > 0) { 780 Re ColorTreeNodes(n.Nodes, c1, c2, resetText);653 ResetTreeNodes(n.Nodes); 781 654 } 782 655 } -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelectorDialog.cs
r15658 r15913 161 161 hiveResourceSelector.SelectedProjectId = selectedProjectId; 162 162 hiveResourceSelector.SelectedResourceIds = selectedResourceIds; 163 var projectList = new ItemList<Project>(HiveServiceLocator.Instance.CallHiveService(s => s.GetProjects())); 164 hiveResourceSelector.Content = projectList; 163 hiveResourceSelector.Content = HiveClient.Instance.Projects; 165 164 } 166 165 -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
r15642 r15913 482 482 } 483 483 484 //private void updateButton_Click(object sender, EventArgs e) {485 // var task = System.Threading.Tasks.Task.Factory.StartNew(UpdateJobAsync, Content);486 // task.ContinueWith((t) => {487 // Content.Progress.Finish();488 // MessageBox.Show("An error occured updating the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);489 // Content.Log.LogException(t.Exception);490 // }, TaskContinuationOptions.OnlyOnFaulted);491 //}492 493 //private void UpdateJobAsync(object job) {494 // Content.Progress.Start("Updating job...");495 // HiveClient.UpdateJob((RefreshableJob)job);496 // Content.Progress.Finish();497 //}498 499 484 private void UnloadButton_Click(object sender, EventArgs e) { 500 485 Content.Unload();
Note: See TracChangeset
for help on using the changeset viewer.