Changeset 15777 for branches/2839_HiveProjectManagement
- Timestamp:
- 02/14/18 11:19:55 (7 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.Designer.cs
r15767 r15777 126 126 this.projectsTreeView.TabIndex = 9; 127 127 this.projectsTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.projectsTreeView_ItemDrag); 128 this.projectsTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.projectsTreeView_AfterSelect); 128 this.projectsTreeView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.projectsTreeView_BeforeSelect); 129 this.projectsTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.projectsTreeView_MouseDown); 129 130 this.projectsTreeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.projectsTreeView_DragDrop); 130 131 this.projectsTreeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.projectsTreeView_DragEnterOver); -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
r15767 r15777 43 43 private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1 44 44 private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b 45 45 46 private Project selectedProject = null; 47 public Project SelectedProject { 48 get { return selectedProject; } 49 set { if (selectedProject != value) ChangeSelectedProject(value); } 50 } 46 51 47 52 private readonly object locker = new object(); … … 93 98 projectResourcesView.Content = null; 94 99 } else { 95 var top = BuildProjectTree(Content); 96 projectView.Content = top; 97 projectPermissionsView.Content = top; 98 projectResourcesView.Content = top; 99 100 if(top != null && top.Id == Guid.Empty) { 101 projectPermissionsView.Locked = true; 102 projectResourcesView.Locked = true; 103 } 100 BuildProjectTree(Content); 104 101 } 105 102 } … … 107 104 protected override void SetEnabledStateOfControls() { 108 105 base.SetEnabledStateOfControls(); 109 bool enabled = Content != null && ! ReadOnly;106 bool enabled = Content != null && !Locked && !ReadOnly; 110 107 refreshButton.Enabled = enabled; 111 108 addButton.Enabled = enabled; … … 213 210 }; 214 211 215 selectedProject = project;212 SelectedProject = project; 216 213 Content.Add(project); 217 214 } … … 278 275 } 279 276 280 private void projectsTreeView_AfterSelect(object sender, TreeViewEventArgs e) { 281 ChangeSelectedProjectNode(e.Node); 282 283 //if (projectView.Content != null) 284 // projectView.Content.PropertyChanged -= ProjectViewContent_PropertyChanged; 285 286 projectView.Content = selectedProject; 287 projectPermissionsView.Content = selectedProject; 288 projectResourcesView.Content = selectedProject; 289 290 //if (selectedProject != null) 291 // selectedProject.PropertyChanged += ProjectViewContent_PropertyChanged; 277 private void projectsTreeView_MouseDown(object sender, MouseEventArgs e) { 278 var node = projectsTreeView.GetNodeAt(e.Location); 279 if(node != null) ChangeSelectedProjectNode(node); 280 } 281 282 private void projectsTreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e) { 283 e.Cancel = true; 292 284 } 293 285 … … 306 298 var targetNode = treeView.GetNodeAt(targetPoint); 307 299 308 if (sourceNode == targetNode) return;309 300 var targetProject = (targetNode != null) ? (Project)targetNode.Tag : null; 310 301 311 if (targetProject != null && targetProject.Id == Guid.Empty) {302 if (!HiveAdminClient.Instance.CheckParentChange(sourceProject, targetProject)) { 312 303 MessageBox.Show( 313 "You cannot drag projects to a not yet storedproject.",304 "You cannot drag projects to this project.", 314 305 "HeuristicLab Hive Administrator", 315 306 MessageBoxButtons.OK, 316 307 MessageBoxIcon.Information); 317 308 return; 318 }319 if(!HiveAdminClient.Instance.CheckParentChange(sourceProject, targetProject)) {320 MessageBox.Show(321 "You cannot drag to this project.",322 "HeuristicLab Hive Administrator",323 MessageBoxButtons.OK,324 MessageBoxIcon.Information);325 return;326 309 } 327 310 … … 340 323 } 341 324 342 selectedProject = sourceProject;325 SelectedProject = sourceProject; 343 326 OnContentChanged(); 344 327 } … … 364 347 || sourceProject == null 365 348 || sourceNode == targetNode 366 || (targetProject != null && targetProject.Id == Guid.Empty)367 || (targetProject != null && targetProject.Id == sourceProject.ParentProjectId)368 349 || !HiveAdminClient.Instance.CheckParentChange(sourceProject, targetProject)) { 369 350 e.Effect = DragDropEffects.None; … … 398 379 } 399 380 381 private void ChangeSelectedProject(Project project) { 382 projectView.Content = project; 383 projectPermissionsView.Content = project; 384 projectResourcesView.Content = project; 385 386 bool locked = project == null || (project != null && project.Id == Guid.Empty); 387 addButton.Enabled = !locked; 388 projectPermissionsView.Locked = locked; 389 projectResourcesView.Locked = locked; 390 selectedProject = project; 391 } 392 400 393 private void ChangeSelectedProjectNode(TreeNode projectNode) { 401 selectedProject = (Project)projectNode.Tag; 394 if (projectNode == null) return; 395 SelectedProject = (Project)projectNode.Tag; 402 396 ResetTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent, true); 403 397 projectNode.BackColor = selectedColor; … … 405 399 } 406 400 407 private ProjectBuildProjectTree(IEnumerable<Project> projects) {401 private void BuildProjectTree(IEnumerable<Project> projects) { 408 402 projectsTreeView.Nodes.Clear(); 409 if (!projects.Any()) return null;403 if (!projects.Any()) return; 410 404 411 405 var mainProjects = new HashSet<Project>(projects.Where(x => x.ParentProjectId == null)); … … 417 411 418 412 var stack = new Stack<Project>(mainProjects.OrderByDescending(x => x.Name)); 419 if (selectedProject != null) selectedProject = projects.Where(x => x.Id == selectedProject.Id).FirstOrDefault();413 if (selectedProject != null) SelectedProject = projects.Where(x => x.Id == selectedProject.Id).FirstOrDefault(); 420 414 bool nodeSelected = false; 421 415 … … 433 427 } 434 428 if (selectedProject == null) { 435 selectedProject = newProject;429 SelectedProject = newProject; 436 430 } 437 431 if (newProject.Id == selectedProject.Id && !nodeSelected) { … … 471 465 472 466 projectsTreeView.ExpandAll(); 473 474 return selectedProject;475 467 } 476 468 … … 485 477 486 478 private void RemoveProject(Project project) { 487 if (project == null || project.Id == Guid.Empty) return;479 if (project == null) return; 488 480 489 481 try { 490 HiveAdminClient.Delete(project);482 if(project.Id != Guid.Empty) HiveAdminClient.Delete(project); 491 483 Content.Remove(selectedProject); 492 484 } catch (AnonymousUserException) { … … 497 489 private bool IsAuthorized(Project project) { 498 490 return project != null && UserInformation.Instance.UserExists; 499 //&& (project.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());500 491 } 501 492 -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs
r15767 r15777 157 157 this.treeView.TabIndex = 0; 158 158 this.treeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeSlaveGroup_ItemDrag); 159 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeSlaveGroup_MouseDown); 159 160 this.treeView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeSlaveGroup_BeforeSelect); 160 this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterSelect);161 161 this.treeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragDrop); 162 162 this.treeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnterOver); -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15767 r15777 45 45 private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1 46 46 private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b 47 47 48 private Resource selectedResource = null; 49 public Resource SelectedResource { 50 get { return selectedResource; } 51 set { if (selectedResource != value) ChangeSelectedResource(value); } 52 } 48 53 49 54 private readonly object locker = new object(); … … 94 99 scheduleView.Content = null; 95 100 } else { 96 var top = BuildResourceTree(Content); 97 SetEnabledStateOfControlsForSelectedResource(); 98 99 viewHost.Content = top; 100 bool locked = !IsAdmin(); 101 viewHost.Locked = locked; 102 scheduleView.Locked = locked; 103 104 if (top != null && top.Id == Guid.Empty) { 105 scheduleView.SetEnabledStateOfSchedule(false); 106 } 101 BuildResourceTree(Content); 107 102 } 108 103 } … … 110 105 protected override void SetEnabledStateOfControls() { 111 106 base.SetEnabledStateOfControls(); 112 bool enabled = Content != null && !Locked && IsAdmin();107 bool enabled = Content != null && !Locked && !ReadOnly && IsAdmin(); 113 108 btnAddGroup.Enabled = enabled; 114 109 btnRemoveGroup.Enabled = enabled; … … 220 215 }; 221 216 222 selectedResource = group;217 SelectedResource = group; 223 218 Content.Add(group); 224 219 } … … 282 277 } 283 278 279 private void treeSlaveGroup_MouseDown(object sender, MouseEventArgs e) { 280 var node = treeView.GetNodeAt(e.Location); 281 if(node != null && node.Name != ungroupedGroupName) ChangeSelectedResourceNode(node); 282 } 283 284 284 private void treeSlaveGroup_BeforeSelect(object sender, TreeViewCancelEventArgs e) { 285 if (((Resource)e.Node.Tag).Name == ungroupedGroupName) e.Cancel = true; 286 } 287 288 private async void treeSlaveGroup_AfterSelect(object sender, TreeViewEventArgs e) { 289 ChangeSelectedResourceNode(e.Node); 290 SetEnabledStateOfControlsForSelectedResource(); 291 292 //if (viewHost.Content != null && viewHost.Content is SlaveGroup) 293 // ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged; 294 295 viewHost.Content = selectedResource; 296 HiveAdminClient.Instance.DowntimeForResourceId = selectedResource != null ? selectedResource.Id : Guid.Empty; 297 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 298 action: () => UpdateSchedule(), 299 finallyCallback: () => scheduleView.Content = HiveAdminClient.Instance.Downtimes); 300 301 //if (selectedResource != null && selectedResource is SlaveGroup) 302 // selectedResource.PropertyChanged += SlaveViewContent_PropertyChanged; 303 304 bool locked = !IsAdmin(); 305 viewHost.Locked = locked; 306 scheduleView.Locked = locked; 285 e.Cancel = true; 307 286 } 308 287 … … 321 300 var targetNode = treeView.GetNodeAt(targetPoint); 322 301 323 if (sourceNode == targetNode) return;324 302 var targetResource = (targetNode != null) ? (Resource)targetNode.Tag : null; 325 303 326 if (!IsAdmin()) { 327 MessageBox.Show( 328 "You cannot drag resources. This is solely granted for HeuristicLab Hive Administrators.", 329 "HeuristicLab Hive Administrator", 330 MessageBoxButtons.OK, 331 MessageBoxIcon.Information); 332 return; 333 } else if (targetResource != null && targetResource is Slave) { 334 MessageBox.Show( 335 "You cannot drag resources on to a slave.", 336 "HeuristicLab Hive Administrator", 337 MessageBoxButtons.OK, 338 MessageBoxIcon.Information); 339 return; 340 } else if (targetResource != null && targetResource.Id == Guid.Empty) { 341 MessageBox.Show( 342 "You cannot drag resources to a not yet stored resource group.", 343 "HeuristicLab Hive Administrator", 344 MessageBoxButtons.OK, 345 MessageBoxIcon.Information); 346 return; 347 } else if(!HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource)) { 304 if(!HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource)) { 348 305 MessageBox.Show( 349 306 "You cannot drag resources to this group.", … … 352 309 MessageBoxIcon.Information); 353 310 return; 354 } else if (targetNode != null && (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName)) {355 MessageBox.Show(356 string.Format(@"You cannot drag resources to group ""{0}"". This group only contains slaves which have not been assigned to a real group yet.", ungroupedGroupName),357 "HeuristicLab Hive Administrator",358 MessageBoxButtons.OK,359 MessageBoxIcon.Information);360 return;361 311 } 362 312 … … 375 325 } 376 326 377 selectedResource = sourceResource;327 SelectedResource = sourceResource; 378 328 OnContentChanged(); 379 329 } … … 399 349 || sourceResource == null 400 350 || sourceNode == targetNode 401 || (targetResource != null && targetResource is Slave)402 || (targetResource != null && targetResource.Id == Guid.Empty)403 || (targetResource != null && targetResource.Id == sourceResource.ParentResourceId)404 351 || !HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource) 405 352 || (targetNode != null && (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName))) { … … 435 382 } 436 383 437 private ResourceBuildResourceTree(IEnumerable<Resource> resources) {384 private void BuildResourceTree(IEnumerable<Resource> resources) { 438 385 treeView.Nodes.Clear(); 439 if (!resources.Any()) return null;386 if (!resources.Any()) return; 440 387 441 388 var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>() … … 447 394 448 395 var stack = new Stack<Resource>(mainResources.OrderByDescending(x => x.Name)); 449 if (selectedResource != null) selectedResource = resources.Where(x => x.Id == selectedResource.Id).FirstOrDefault();396 if (selectedResource != null) SelectedResource = resources.Where(x => x.Id == selectedResource.Id).FirstOrDefault(); 450 397 bool nodeSelected = false; 451 398 … … 463 410 } 464 411 if (selectedResource == null) { 465 selectedResource = newResource;412 SelectedResource = newResource; 466 413 } 467 414 if (newResource.Id == selectedResource.Id && !nodeSelected) { … … 517 464 ungroupedNode.Nodes.Add(slaveNode); 518 465 if(selectedResource == null) { 519 selectedResource = slave;466 SelectedResource = slave; 520 467 } 521 468 if (slave.Id == Guid.Empty) { … … 533 480 treeView.Nodes.Add(ungroupedNode); 534 481 treeView.ExpandAll(); 535 536 return selectedResource;537 482 } 538 483 … … 586 531 587 532 private void RemoveResource(Resource resource) { 588 if (resource == null || resource.Id == Guid.Empty) return;533 if (resource == null) return; 589 534 590 535 try { 591 HiveAdminClient.Delete(resource);536 if(resource.Id != Guid.Empty) HiveAdminClient.Delete(resource); 592 537 Content.Remove(selectedResource); 593 538 } catch(AnonymousUserException) { … … 617 562 } 618 563 564 private async void ChangeSelectedResource(Resource resource) { 565 selectedResource = resource; 566 viewHost.Content = selectedResource; 567 HiveAdminClient.Instance.DowntimeForResourceId = selectedResource != null ? selectedResource.Id : Guid.Empty; 568 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 569 action: () => UpdateSchedule(), 570 finallyCallback: () => scheduleView.Content = HiveAdminClient.Instance.Downtimes); 571 572 bool locked = !IsAdmin() || resource == null; 573 bool addLocked = locked || (resource != null && resource.Id == Guid.Empty); 574 575 btnAddGroup.Enabled = !addLocked; 576 btnRemoveGroup.Enabled = !locked; 577 btnSave.Enabled = !locked; 578 viewHost.Locked = locked; 579 scheduleView.Locked = locked; 580 scheduleView.SetEnabledStateOfSchedule(!addLocked); 581 } 582 619 583 private void ChangeSelectedResourceNode(TreeNode resourceNode) { 620 selectedResource = (Resource)resourceNode.Tag; 584 if (resourceNode == null) return; 585 SelectedResource = (Resource)resourceNode.Tag; 621 586 ResetTreeNodes(treeView.Nodes, selectedColor, Color.Transparent, true); 622 587 resourceNode.BackColor = selectedColor; … … 624 589 } 625 590 626 private void SetEnabledStateOfControlsForSelectedResource() {627 bool enabled = (IsAdmin()) ? true : false;628 btnAddGroup.Enabled = enabled;629 btnRemoveGroup.Enabled = enabled;630 btnSave.Enabled = enabled;631 }632 633 591 private void ShowHiveInformationDialog() { 634 592 if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog); -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r15768 r15777 305 305 306 306 public bool CheckParentChange(Project child, Project parent) { 307 bool changeGranted = true; 308 309 // change is not granted, if the moved project is null 310 // or the new parent is not stored yet 311 // or there is not parental change 307 bool changePossible = true; 308 309 // change is not possible... 310 // ... if the moved project is null 311 // ... or the new parent is not stored yet 312 // ... or there is not parental change 312 313 if (child == null 313 314 || (parent != null && parent.Id == Guid.Empty) 314 315 || (parent != null && parent.Id == child.ParentProjectId)) { 315 change Granted= false;316 changePossible = false; 316 317 } else if(parent != null && projectDescendants.ContainsKey(child.Id)) { 317 // change is not granted,if the new parent is among the moved project's descendants318 change Granted= !projectDescendants[child.Id].Where(x => x.Id == parent.Id).Any();319 } 320 321 return change Granted;318 // ... if the new parent is among the moved project's descendants 319 changePossible = !projectDescendants[child.Id].Where(x => x.Id == parent.Id).Any(); 320 } 321 322 return changePossible; 322 323 } 323 324 324 325 public bool CheckParentChange(Resource child, Resource parent) { 325 bool changeGranted = true; 326 327 // change is not granted, if the moved resource is null 328 // or the new parent is not stored yet 329 // or there is not parental change 326 bool changePossible = true; 327 328 // change is not possisble... 329 // ... if the moved resource is null 330 // ... or the new parent is not stored yet 331 // ... or the new parent is a slave 332 // ... or there is not parental change 330 333 if (child == null 331 334 || (parent != null && parent.Id == Guid.Empty) 335 || (parent != null && parent is Slave) 332 336 || (parent != null && parent.Id == child.ParentResourceId)) { 333 change Granted= false;337 changePossible = false; 334 338 } else if (parent != null && resourceDescendants.ContainsKey(child.Id)) { 335 // change is not granted,if the new parent is among the moved resource's descendants336 change Granted= !resourceDescendants[child.Id].Where(x => x.Id == parent.Id).Any();337 } 338 339 return change Granted;339 // ... or if the new parent is among the moved resource's descendants 340 changePossible = !resourceDescendants[child.Id].Where(x => x.Id == parent.Id).Any(); 341 } 342 343 return changePossible; 340 344 } 341 345 #endregion
Note: See TracChangeset
for help on using the changeset viewer.