Changeset 15742 for branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
- Timestamp:
- 02/09/18 07:56:01 (7 years ago)
- File:
-
- 1 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);
Note: See TracChangeset
for help on using the changeset viewer.