Changeset 15742 for branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views
- Timestamp:
- 02/09/18 07:56:01 (7 years ago)
- Location:
- branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
r15658 r15742 40 40 private const int greenFlagImageIndex = 0; 41 41 private const int redFlagImageIndex = 1; 42 42 43 private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1 43 44 private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b 45 private Project selectedProject = null; 44 46 45 47 private readonly object locker = new object(); 46 47 private Project selectedProject = null;48 48 49 49 public new IItemList<Project> Content { … … 173 173 private async void ProjectsView_Load(object sender, EventArgs e) { 174 174 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 175 action: () => UpdateProjects(), 176 finallyCallback: () => Content = HiveAdminClient.Instance.Projects); 175 action: () => UpdateProjects()); 177 176 } 178 177 … … 186 185 action: () => UpdateProjects(), 187 186 finallyCallback: () => { 188 Content = HiveAdminClient.Instance.Projects;189 187 refreshButton.Enabled = true; 190 188 }); … … 193 191 private void addButton_Click(object sender, EventArgs e) { 194 192 Guid? parentProjectId = null; 193 194 if (selectedProject != null && selectedProject.Id == Guid.Empty) { 195 MessageBox.Show( 196 "You cannot add a project to a not yet stored project.", 197 "HeuristicLab Hive Administrator", 198 MessageBoxButtons.OK, 199 MessageBoxIcon.Information); 200 return; 201 } 202 195 203 if (selectedProject != null) parentProjectId = selectedProject.Id; 196 204 var project = new Project { … … 199 207 ParentProjectId = parentProjectId 200 208 }; 209 210 selectedProject = project; 201 211 Content.Add(project); 202 212 } 203 213 204 214 private async void removeButton_Click(object sender, EventArgs e) { 215 if (selectedProject == null) return; 216 205 217 lock (locker) { 206 218 if (!removeButton.Enabled) return; … … 208 220 } 209 221 210 var selectedNode = projectsTreeView.SelectedNode; 211 if (selectedNode == null || selectedNode.Tag == null) return; 212 213 var project = (Project)selectedNode.Tag; 222 if(!IsAdmin() 223 && HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, 224 UserInformation.Instance.User.Id)) { 225 MessageBox.Show( 226 "Only subprojects of owned projects can be deleted.", 227 "HeuristicLab Hive Administrator", 228 MessageBoxButtons.OK, 229 MessageBoxIcon.Error); 230 return; 231 } 232 233 if (!IsAdmin() && Content.Any(x => x.ParentProjectId == selectedProject.Id)) { 234 MessageBox.Show( 235 "Only empty projects can be deleted.", 236 "HeuristicLab Hive Administrator", 237 MessageBoxButtons.OK, 238 MessageBoxIcon.Error); 239 return; 240 } 241 214 242 var result = MessageBox.Show( 215 "Do you really want to delete " + project.Name + "?",243 "Do you really want to delete " + selectedProject.Name + "?", 216 244 "HeuristicLab Hive Administrator", 217 245 MessageBoxButtons.YesNo, … … 219 247 220 248 if (result == DialogResult.Yes) { 221 if (Content.Any(x => x.ParentProjectId == project.Id)) { 222 MessageBox.Show( 223 "Only empty projects can be deleted.", 224 "HeuristicLab Hive Administrator", 225 MessageBoxButtons.OK, 226 MessageBoxIcon.Error); 227 } else { 228 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 229 action: () => RemoveProject(project), 230 finallyCallback: () => { 231 Content.Remove(project); 232 removeButton.Enabled = true; 233 }); 234 } 249 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 250 action: () => RemoveProject(selectedProject), 251 finallyCallback: () => { 252 removeButton.Enabled = true; 253 }); 235 254 } 236 255 } … … 247 266 foreach (var project in projectsToSave) 248 267 project.Store(); 268 UpdateProjects(); 249 269 }, 250 270 finallyCallback: () => saveProjectButton.Enabled = true); … … 254 274 255 275 private void projectsTreeView_AfterSelect(object sender, TreeViewEventArgs e) { 256 selectedProject = (Project)e.Node.Tag; 257 ReColorTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent, true); 258 e.Node.BackColor = selectedColor; 259 e.Node.Text += " [selected]"; 260 276 ChangeSelectedProjectNode(e.Node); 261 277 262 278 //if (projectView.Content != null) … … 269 285 //if (selectedProject != null) 270 286 // selectedProject.PropertyChanged += ProjectViewContent_PropertyChanged; 271 272 //if (IsAuthorized(selectedProject)) {273 // if (!tabControl.TabPages.Contains(permissionsTabPage))274 // tabControl.TabPages.Add(permissionsTabPage);275 // if (!tabControl.TabPages.Contains(resourcesTabPage))276 // tabControl.TabPages.Add(resourcesTabPage);277 //} else {278 // if (tabControl.TabPages.Contains(permissionsTabPage))279 // tabControl.TabPages.Remove(permissionsTabPage);280 // if (tabControl.TabPages.Contains(resourcesTabPage))281 // tabControl.TabPages.Remove(resourcesTabPage);282 //}283 287 } 284 288 … … 286 290 var sourceNode = (TreeNode)e.Data.GetData(typeof(TreeNode)); 287 291 if (sourceNode == null) return; 292 var sourceResource = ((Project)sourceNode.Tag); 293 if (sourceResource == null) return; 288 294 289 295 var treeView = (TreeView)sender; … … 294 300 295 301 if (sourceNode == targetNode) return; 296 297 if (sourceNode.Parent == null) 302 var targetProject = (targetNode != null) ? (Project)targetNode.Tag : null; 303 304 if(targetProject != null && targetProject.Id == Guid.Empty) { 305 MessageBox.Show( 306 "You cannot drag projects to a not yet stored project.", 307 "HeuristicLab Hive Administrator", 308 MessageBoxButtons.OK, 309 MessageBoxIcon.Information); 310 return; 311 } 312 313 if (sourceNode.Parent == null) { 298 314 treeView.Nodes.Remove(sourceNode); 299 else {315 } else { 300 316 sourceNode.Parent.Nodes.Remove(sourceNode); 301 ((Project)sourceNode.Tag).ParentProjectId = null;317 sourceResource.ParentProjectId = null; 302 318 } 303 319 304 320 if (targetNode == null) { 305 321 treeView.Nodes.Add(sourceNode); 306 } else {322 } else if(targetProject.Id != Guid.Empty) { 307 323 targetNode.Nodes.Add(sourceNode); 308 ((Project)sourceNode.Tag).ParentProjectId = ((Project)targetNode.Tag).Id; 309 } 324 sourceResource.ParentProjectId = targetProject.Id; 325 } 326 327 selectedProject = sourceResource; 328 OnContentChanged(); 310 329 } 311 330 … … 330 349 331 350 #region Helpers 332 private void ReColorTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) { 333 foreach(TreeNode n in nodes) { 334 if(n.BackColor.Equals(c1)) { 351 private void ResetTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) { 352 foreach (TreeNode n in nodes) { 353 var pro = ((Project)n.Tag); 354 if (n.BackColor.Equals(c1)) { 335 355 n.BackColor = c2; 336 if (resetText) n.Text = ((Project)n.Tag).Name; 356 } 357 if (resetText) { 358 n.Text = pro.Name; 359 360 if (pro.Id == Guid.Empty) { 361 n.Text += " [not stored]"; 362 } else if (pro.Modified) { 363 n.Text += " [changes not stored]"; 364 } 337 365 } 338 366 if (n.Nodes.Count > 0) { 339 ReColorTreeNodes(n.Nodes, c1, c2, resetText); 340 } 341 } 367 ResetTreeNodes(n.Nodes, c1, c2, resetText); 368 } 369 } 370 } 371 372 private void ChangeSelectedProjectNode(TreeNode projectNode) { 373 selectedProject = (Project)projectNode.Tag; 374 ResetTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent, true); 375 projectNode.BackColor = selectedColor; 376 projectNode.Text += " [selected]"; 342 377 } 343 378 … … 354 389 355 390 var stack = new Stack<Project>(mainProjects.OrderByDescending(x => x.Name)); 356 Project top = null;391 if (selectedProject != null) selectedProject = projects.Where(x => x.Id == selectedProject.Id).FirstOrDefault(); 357 392 358 393 TreeNode currentNode = null; … … 362 397 var newProject = stack.Pop(); 363 398 var newNode = new TreeNode(newProject.Name) { Tag = newProject }; 364 if (top == null) { 365 top = newProject; 399 400 if (newProject.Id == Guid.Empty) { 401 newNode.Text += " [not stored]"; 402 } else if(newProject.Modified) { 403 newNode.Text += " [changes not stored]"; 404 } 405 if (selectedProject == null) { 406 selectedProject = newProject; 407 } 408 if (newProject.Id == selectedProject.Id) { 366 409 newNode.BackColor = selectedColor; 367 410 newNode.Text += " [selected]"; 368 411 } 369 412 413 // search for parent node of newNode and save in currentNode 414 // necessary since newNodes (stack top items) might be siblings 415 // or grand..grandparents of previous node (currentNode) 370 416 while (currentNode != null && newProject.ParentProjectId != currentProject.Id) { 371 417 currentNode = currentNode.Parent; … … 396 442 projectsTreeView.ExpandAll(); 397 443 398 return top;444 return selectedProject; 399 445 } 400 446 … … 402 448 try { 403 449 HiveAdminClient.Instance.Refresh(); 450 Content = HiveAdminClient.Instance.Projects; 404 451 } catch (AnonymousUserException) { 405 452 ShowHiveInformationDialog(); … … 408 455 409 456 private void RemoveProject(Project project) { 457 if (project == null || project.Id == Guid.Empty) return; 458 410 459 try { 411 460 HiveAdminClient.Delete(project); 461 Content.Remove(selectedProject); 412 462 } catch (AnonymousUserException) { 413 463 ShowHiveInformationDialog(); … … 420 470 } 421 471 472 private bool IsAdmin() { 473 return HiveRoles.CheckAdminUserPermissions(); 474 } 475 422 476 private void ShowHiveInformationDialog() { 423 477 if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog); -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourceView.cs
r15576 r15742 59 59 base.SetEnabledStateOfControls(); 60 60 bool enabled = Content != null && !Locked; 61 idTextBox.ReadOnly = true; 61 62 nameTextBox.ReadOnly = !enabled; 62 63 descriptionTextBox.ReadOnly = !enabled; -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs
r15422 r15742 157 157 this.treeView.TabIndex = 0; 158 158 this.treeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeSlaveGroup_ItemDrag); 159 this.treeView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeSlaveGroup_BeforeSelect); 159 160 this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterSelect); 160 161 this.treeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragDrop); -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15658 r15742 43 43 public const string ungroupedGroupDescription = "Contains slaves that are not assigned to any group."; 44 44 45 private readonly Color ownedResourceColor = Color.LightGreen; 45 private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1 46 private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b 47 private Resource selectedResource = null; 48 46 49 private readonly object locker = new object(); 47 50 … … 98 101 protected override void SetEnabledStateOfControls() { 99 102 base.SetEnabledStateOfControls(); 100 bool enabled = Content != null && !Locked ;103 bool enabled = Content != null && !Locked && IsAdmin(); 101 104 btnAddGroup.Enabled = enabled; 102 105 btnRemoveGroup.Enabled = enabled; 103 106 btnSave.Enabled = enabled; 104 scheduleView.SetEnabledStateOfSchedule(enabled && IsA uthorized((Resource)viewHost.Content));107 scheduleView.SetEnabledStateOfSchedule(enabled && IsAdmin()); // IsAuthorized((Resource)viewHost.Content)); 105 108 } 106 109 #endregion … … 184 187 185 188 private void btnAddGroup_Click(object sender, EventArgs e) { 189 Guid? parentResourceId = null; 190 if(!IsAdmin()) { 191 MessageBox.Show( 192 "You have no permission to add a resource group.", 193 "HeuristicLab Hive Administrator", 194 MessageBoxButtons.OK, 195 MessageBoxIcon.Information); 196 return; 197 } else if(selectedResource != null && selectedResource.Id == Guid.Empty) { 198 MessageBox.Show( 199 "You cannot add a resource group to a not yet stored group.", 200 "HeuristicLab Hive Administrator", 201 MessageBoxButtons.OK, 202 MessageBoxIcon.Information); 203 return; 204 } 205 206 if (selectedResource != null && selectedResource is SlaveGroup) parentResourceId = selectedResource.Id; 186 207 var group = new SlaveGroup { 187 208 Name = "New Group", 188 OwnerUserId = UserInformation.Instance.User.Id 209 OwnerUserId = UserInformation.Instance.User.Id, 210 ParentResourceId = parentResourceId 189 211 }; 212 213 selectedResource = group; 190 214 Content.Add(group); 191 215 } 192 216 193 217 private async void btnRemoveGroup_Click(object sender, EventArgs e) { 218 if (selectedResource == null) return; 219 194 220 lock (locker) { 195 221 if (!btnRemoveGroup.Enabled) return; … … 197 223 } 198 224 199 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 200 action: () => RemoveResource(), 201 finallyCallback: () => btnRemoveGroup.Enabled = true); 225 if (!IsAdmin()) { 226 MessageBox.Show( 227 "You have no permission to delete resources.", 228 "HeuristicLab Hive Administrator", 229 MessageBoxButtons.OK, 230 MessageBoxIcon.Information); 231 return; 232 } 233 234 if (Content.Any(x => x.ParentResourceId == selectedResource.Id)) { 235 MessageBox.Show( 236 "Only empty resources can be deleted.", 237 "HeuristicLab Hive Administrator", 238 MessageBoxButtons.OK, 239 MessageBoxIcon.Error); 240 return; 241 } 242 243 var result = MessageBox.Show( 244 "Do you really want to delete " + selectedResource.Name + "?", 245 "HeuristicLab Hive Administrator", 246 MessageBoxButtons.YesNo, 247 MessageBoxIcon.Question); 248 if (result == DialogResult.Yes) { 249 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 250 action: () => RemoveResource(selectedResource), 251 finallyCallback: () => { 252 btnRemoveGroup.Enabled = true; 253 }); 254 } 202 255 } 203 256 … … 213 266 foreach (var resource in resourcesToSave) 214 267 resource.Store(); 268 UpdateResources(); 215 269 }, 216 270 finallyCallback: () => btnSave.Enabled = true); 271 272 OnContentChanged(); 273 } 274 275 private void treeSlaveGroup_BeforeSelect(object sender, TreeViewCancelEventArgs e) { 276 if (((Resource)e.Node.Tag).Name == ungroupedGroupName) e.Cancel = true; 217 277 } 218 278 219 279 private async void treeSlaveGroup_AfterSelect(object sender, TreeViewEventArgs e) { 220 var selectedResource = (Resource)e.Node.Tag; 221 222 if (viewHost.Content != null && viewHost.Content is SlaveGroup) 223 ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged; 280 ChangeSelectedResourceNode(e.Node); 281 SetEnabledStateOfControlsForSelectedResource(); 282 283 //if (viewHost.Content != null && viewHost.Content is SlaveGroup) 284 // ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged; 224 285 225 286 viewHost.Content = selectedResource; … … 229 290 finallyCallback: () => scheduleView.Content = HiveAdminClient.Instance.Downtimes); 230 291 231 if (selectedResource != null && selectedResource is SlaveGroup) 232 selectedResource.PropertyChanged += SlaveViewContent_PropertyChanged; 233 234 if (IsAuthorized(selectedResource)) { 235 if (!tabSlaveGroup.TabPages.Contains(tabSchedule)) 236 tabSlaveGroup.TabPages.Add(tabSchedule); 237 } else { 238 if (tabSlaveGroup.TabPages.Contains(tabSchedule)) 239 tabSlaveGroup.TabPages.Remove(tabSchedule); 240 } 292 //if (selectedResource != null && selectedResource is SlaveGroup) 293 // selectedResource.PropertyChanged += SlaveViewContent_PropertyChanged; 294 295 bool locked = !IsAdmin(); 296 viewHost.Locked = locked; 297 scheduleView.Locked = locked; 241 298 } 242 299 … … 244 301 var sourceNode = (TreeNode)e.Data.GetData(typeof(TreeNode)); 245 302 if (sourceNode == null) return; 303 var sourceResource = ((Resource)sourceNode.Tag); 304 if (sourceResource == null) return; 246 305 247 306 var treeView = (TreeView)sender; … … 252 311 253 312 if (sourceNode == targetNode) return; 254 255 if (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName) { 256 MessageBox.Show( 257 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), 313 var targetResource = (targetNode != null) ? (Resource)targetNode.Tag : null; 314 315 if (!IsAdmin()) { 316 MessageBox.Show( 317 "You cannot drag resources. This is solely granted for HeuristicLab Hive Administrators.", 258 318 "HeuristicLab Hive Administrator", 259 319 MessageBoxButtons.OK, 260 320 MessageBoxIcon.Information); 261 321 return; 322 } else if (targetResource != null && targetResource is Slave) { 323 MessageBox.Show( 324 "You cannot drag resources on to a slave.", 325 "HeuristicLab Hive Administrator", 326 MessageBoxButtons.OK, 327 MessageBoxIcon.Information); 328 return; 329 } else if(targetResource != null && targetResource.Id == Guid.Empty) { 330 MessageBox.Show( 331 "You cannot drag resources to a not yet stored resource group.", 332 "HeuristicLab Hive Administrator", 333 MessageBoxButtons.OK, 334 MessageBoxIcon.Information); 335 return; 336 } else if (targetNode != null && (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName)) { 337 MessageBox.Show( 338 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), 339 "HeuristicLab Hive Administrator", 340 MessageBoxButtons.OK, 341 MessageBoxIcon.Information); 342 return; 262 343 } 263 344 … … 266 347 else { 267 348 sourceNode.Parent.Nodes.Remove(sourceNode); 268 ((Resource)sourceNode.Tag).ParentResourceId = null;349 sourceResource.ParentResourceId = null; 269 350 } 270 351 271 352 if (targetNode == null) { 272 353 treeView.Nodes.Add(sourceNode); 273 } else {354 } else if(targetResource.Id != Guid.Empty) { 274 355 targetNode.Nodes.Add(sourceNode); 275 ((Resource)sourceNode.Tag).ParentResourceId = ((Project)targetNode.Tag).Id; 276 } 356 sourceResource.ParentResourceId = targetResource.Id; 357 } 358 359 selectedResource = sourceResource; 360 OnContentChanged(); 277 361 } 278 362 279 363 private void treeSlaveGroup_ItemDrag(object sender, ItemDragEventArgs e) { 280 364 TreeNode sourceNode = (TreeNode)e.Item; 281 if (IsA uthorized((Resource)sourceNode.Tag))365 if (IsAdmin()) 282 366 DoDragDrop(sourceNode, DragDropEffects.All); 283 367 } … … 297 381 298 382 #region Helpers 383 private void ResetTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) { 384 foreach (TreeNode n in nodes) { 385 var res = ((Resource)n.Tag); 386 if (n.BackColor.Equals(c1)) { 387 n.BackColor = c2; 388 } 389 if (resetText) { 390 n.Text = res.Name; 391 392 if (res.Id == Guid.Empty && res.Name != ungroupedGroupName) { 393 n.Text += " [not stored]"; 394 } else if (res.Modified && res.Name != ungroupedGroupName) { 395 n.Text += " [changes not stored]"; 396 } 397 } 398 if (n.Nodes.Count > 0) { 399 ResetTreeNodes(n.Nodes, c1, c2, resetText); 400 } 401 } 402 } 403 299 404 private Resource BuildResourceTree(IEnumerable<Resource> resources) { 300 405 treeView.Nodes.Clear(); 301 406 if (!resources.Any()) return null; 302 407 303 var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>().Where(x => x.ParentResourceId == null)); 408 var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>() 409 .Where(x => x.ParentResourceId == null)); 304 410 var parentedMainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>() 305 411 .Where(x => x.ParentResourceId.HasValue && !resources.Select(y => y.Id).Contains(x.ParentResourceId.Value))); … … 308 414 309 415 var stack = new Stack<Resource>(mainResources.OrderByDescending(x => x.Name)); 310 Resource top = null; 416 if (selectedResource != null) selectedResource = resources.Where(x => x.Id == selectedResource.Id).FirstOrDefault(); 417 //bool nodeSelected = false; 311 418 312 419 TreeNode currentNode = null; … … 314 421 315 422 while(stack.Any()) { 316 if (top == null) top = stack.Peek();317 423 var newResource = stack.Pop(); 318 424 var newNode = new TreeNode(newResource.Name) { Tag = newResource }; 425 426 if(newResource.Id == Guid.Empty) { 427 newNode.Text += " [not stored]"; 428 } else if(newResource.Modified) { 429 newNode.Text += " [changes not stored]"; 430 } 431 if (selectedResource == null) { 432 selectedResource = newResource; 433 } 434 if (newResource.Id == selectedResource.Id) { 435 newNode.BackColor = selectedColor; 436 newNode.Text += " [selected]"; 437 } 319 438 320 439 // search for parent node of newNode and save in currentNode 321 440 // necessary since newNodes (stack top items) might be siblings 322 441 // or grand..grandparents of previous node (currentNode) 323 while (currentNode != null && newResource.ParentResourceId != currentResource.Id) {442 while (currentNode != null && newResource.ParentResourceId != currentResource.Id) { 324 443 currentNode = currentNode.Parent; 325 444 currentResource = currentNode == null ? null : (Resource)currentNode.Tag; … … 363 482 var slaveNode = new TreeNode(slave.Name) { Tag = slave }; 364 483 ungroupedNode.Nodes.Add(slaveNode); 484 if(selectedResource == null) { 485 selectedResource = slave; 486 } 487 if (slave.Id == Guid.Empty) { 488 slaveNode.Text += " [not stored]"; 489 } else if (slave.Modified) { 490 slaveNode.Text += " [changes not stored]"; 491 } 492 if (slave.Id == selectedResource.Id) { 493 slaveNode.BackColor = selectedColor; 494 slaveNode.Text += " [selected]"; 495 } 365 496 } 366 497 … … 368 499 treeView.ExpandAll(); 369 500 370 return top;501 return selectedResource; 371 502 } 372 503 … … 411 542 412 543 private void UpdateResources() { 413 HiveAdminClient.Instance.Refresh(); 414 Content = HiveAdminClient.Instance.Resources; 415 } 416 417 private void RemoveResource() { 418 var selectedNode = treeView.SelectedNode; 419 if (selectedNode == null || selectedNode.Tag == null) return; 420 421 var resource = (Resource)selectedNode.Tag; 422 var result = MessageBox.Show( 423 "Do you really want to delete " + resource.Name + "?", 424 "HeuristicLab Hive Administrator", 425 MessageBoxButtons.YesNo, 426 MessageBoxIcon.Question); 427 428 if (result == DialogResult.Yes) { 429 if (resource is Slave) { 430 Content.Remove(resource); 431 HiveAdminClient.Delete(resource); 432 } else if (resource is SlaveGroup) { 433 if (Content.Any(x => x.ParentResourceId == resource.Id)) { 434 MessageBox.Show( 435 "Only empty resources can be deleted.", 436 "HeuristicLab Hive Administrator", 437 MessageBoxButtons.OK, 438 MessageBoxIcon.Error); 439 } else { 440 Content.Remove(resource); 441 HiveAdminClient.Delete(resource); 442 } 443 } 544 try { 545 HiveAdminClient.Instance.Refresh(); 546 Content = HiveAdminClient.Instance.Resources; 547 } catch(AnonymousUserException) { 548 ShowHiveInformationDialog(); 549 } 550 } 551 552 private void RemoveResource(Resource resource) { 553 if (resource == null || resource.Id == Guid.Empty) return; 554 555 try { 556 HiveAdminClient.Delete(resource); 557 Content.Remove(selectedResource); 558 } catch(AnonymousUserException) { 559 ShowHiveInformationDialog(); 444 560 } 445 561 } … … 456 572 return resource != null 457 573 && resource.Name != ungroupedGroupName 458 && resource.Id != Guid.Empty574 //&& resource.Id != Guid.Empty 459 575 && UserInformation.Instance.UserExists 460 && (resource.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions()); 576 && (HiveRoles.CheckAdminUserPermissions() 577 || HiveAdminClient.Instance.CheckOwnershipOfResource(resource, UserInformation.Instance.User.Id)); 578 } 579 580 private bool IsAdmin() { 581 return HiveRoles.CheckAdminUserPermissions(); 582 } 583 584 private void ChangeSelectedResourceNode(TreeNode resourceNode) { 585 selectedResource = (Resource)resourceNode.Tag; 586 ResetTreeNodes(treeView.Nodes, selectedColor, Color.Transparent, true); 587 resourceNode.BackColor = selectedColor; 588 resourceNode.Text += " [selected]"; 589 } 590 591 private void SetEnabledStateOfControlsForSelectedResource() { 592 bool enabled = (IsAdmin()) ? true : false; 593 btnAddGroup.Enabled = enabled; 594 btnRemoveGroup.Enabled = enabled; 595 btnSave.Enabled = enabled; 461 596 } 462 597 -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ScheduleView.cs
r14185 r15742 222 222 protected override void SetEnabledStateOfControls() { 223 223 base.SetEnabledStateOfControls(); 224 bool enabled = Content != null && !Locked; 225 btCreate.Enabled = enabled; 226 btbDelete.Enabled = enabled; 227 btnClearCal.Enabled = enabled; 228 btnRecurrence.Enabled = enabled; 229 btnSaveCal.Enabled = enabled; 224 230 } 225 231
Note: See TracChangeset
for help on using the changeset viewer.