- Timestamp:
- 01/19/18 02:12:20 (7 years ago)
- Location:
- branches/2877_HiveImprovements/HeuristicLab.Clients.Hive.Administrator/3.3/Views
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2877_HiveImprovements/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs
r15583 r15631 60 60 this.btnRemoveGroup = new System.Windows.Forms.Button(); 61 61 this.btnAddGroup = new System.Windows.Forms.Button(); 62 this.btnPermissionsSave = new System.Windows.Forms.Button();63 62 this.treeSlaveGroup = new System.Windows.Forms.TreeView(); 64 63 this.tabSlaveGroup = new System.Windows.Forms.TabControl(); … … 67 66 this.tabSchedule = new System.Windows.Forms.TabPage(); 68 67 this.scheduleView = new HeuristicLab.Clients.Hive.Administrator.Views.ScheduleView(); 68 this.tabPermissions = new System.Windows.Forms.TabPage(); 69 this.btnPermissionsSave = new System.Windows.Forms.Button(); 70 this.permissionView = new HeuristicLab.Clients.Access.Views.RefreshableLightweightUserView(); 69 71 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 70 this.tabPermissions = new System.Windows.Forms.TabPage();71 this.permissionView = new HeuristicLab.Clients.Access.Views.RefreshableLightweightUserView();72 72 ((System.ComponentModel.ISupportInitialize)(this.splitSlaves)).BeginInit(); 73 73 this.splitSlaves.Panel1.SuspendLayout(); … … 88 88 // splitSlaves 89 89 // 90 this.splitSlaves.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 91 | System.Windows.Forms.AnchorStyles.Left) 90 this.splitSlaves.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 91 | System.Windows.Forms.AnchorStyles.Left) 92 92 | System.Windows.Forms.AnchorStyles.Right))); 93 93 this.splitSlaves.Location = new System.Drawing.Point(3, 3); … … 165 165 // 166 166 this.treeSlaveGroup.AllowDrop = true; 167 this.treeSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 168 | System.Windows.Forms.AnchorStyles.Left) 169 | System.Windows.Forms.AnchorStyles.Right))); 167 this.treeSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 168 | System.Windows.Forms.AnchorStyles.Left) 169 | System.Windows.Forms.AnchorStyles.Right))); 170 this.treeSlaveGroup.CheckBoxes = true; 170 171 this.treeSlaveGroup.ImageIndex = 0; 171 172 this.treeSlaveGroup.ImageList = this.imageListSlaveGroups; … … 178 179 this.treeSlaveGroup.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterSelect); 179 180 this.treeSlaveGroup.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragDrop); 180 this.treeSlaveGroup.DragEnter += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnter); 181 this.treeSlaveGroup.DragOver += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragOver); 182 this.treeSlaveGroup.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.treeSlaveGroup_QueryContinueDrag); 181 this.treeSlaveGroup.DragEnter += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnterOver); 182 this.treeSlaveGroup.DragOver += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnterOver); 183 183 // 184 184 // tabSlaveGroup 185 185 // 186 this.tabSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 187 | System.Windows.Forms.AnchorStyles.Left) 186 this.tabSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 187 | System.Windows.Forms.AnchorStyles.Left) 188 188 | System.Windows.Forms.AnchorStyles.Right))); 189 189 this.tabSlaveGroup.Controls.Add(this.tabDetails); … … 210 210 // slaveView 211 211 // 212 this.slaveView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 213 | System.Windows.Forms.AnchorStyles.Left) 212 this.slaveView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 213 | System.Windows.Forms.AnchorStyles.Left) 214 214 | System.Windows.Forms.AnchorStyles.Right))); 215 215 this.slaveView.Caption = "SlaveView"; … … 234 234 // scheduleView 235 235 // 236 this.scheduleView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 237 | System.Windows.Forms.AnchorStyles.Left) 236 this.scheduleView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 237 | System.Windows.Forms.AnchorStyles.Left) 238 238 | System.Windows.Forms.AnchorStyles.Right))); 239 239 this.scheduleView.Caption = "ScheduleView"; … … 271 271 // permissionView 272 272 // 273 this.permissionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 274 | System.Windows.Forms.AnchorStyles.Left) 273 this.permissionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 274 | System.Windows.Forms.AnchorStyles.Left) 275 275 | System.Windows.Forms.AnchorStyles.Right))); 276 276 this.permissionView.Caption = "RefreshableLightweightUser View"; -
branches/2877_HiveImprovements/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15620 r15631 44 44 } 45 45 46 public const string UngroupedGroupName = "UNGROUPED"; 46 public const string UNGROUPED_GROUP_NAME = "UNGROUPED"; 47 private TreeNode ungroupedGroupNode; 47 48 private const int slaveImageIndex = 0; 48 49 private const int slaveGroupImageIndex = 1; … … 140 141 var ungroupedSlaves = new SlaveGroup { 141 142 Id = Guid.NewGuid(), 142 Name = U ngroupedGroupName,143 Name = UNGROUPED_GROUP_NAME, 143 144 Description = "Slaves without a group" 144 145 }; 145 var ungroupedSlavesCount = 0; 146 var ungroupedNode = CreateTreeNodeFromResource(ungroupedSlaves); 146 ungroupedGroupNode = CreateTreeNode(ungroupedSlaves); 147 147 148 148 var parentlessResources = from r in Content … … 152 152 foreach (Resource r in parentlessResources) { 153 153 if (r.GetType() == typeof(SlaveGroup)) { // root node 154 var root = CreateTreeNode FromResource(r);154 var root = CreateTreeNode(r); 155 155 treeSlaveGroup.Nodes.Add(root); 156 156 BuildSlaveGroupTree((SlaveGroup)r, root); 157 157 } else if (r.GetType() == typeof(Slave)) { // ungrouped slaves 158 ungroupedNode.Nodes.Add(CreateTreeNodeFromResource(r)); 159 ungroupedSlavesCount++; 158 ungroupedGroupNode.Nodes.Add(CreateTreeNode(r)); 160 159 } 161 160 } 162 if (ungrouped SlavesCount > 0)163 ungrouped Node.Text += " [" + ungroupedSlavesCount.ToString() + "]";164 treeSlaveGroup.Nodes.Add(ungrouped Node);161 if (ungroupedGroupNode.Nodes.Count > 0) 162 ungroupedGroupNode.Text += " [" + ungroupedGroupNode.Nodes.Count.ToString() + "]"; 163 treeSlaveGroup.Nodes.Add(ungroupedGroupNode); 165 164 } 166 165 } … … 172 171 select r; 173 172 foreach (var g in childGroups) { 174 var childNode = CreateTreeNode FromResource(g);173 var childNode = CreateTreeNode(g); 175 174 node.Nodes.Add(childNode); 176 175 BuildSlaveGroupTree(g, childNode); … … 183 182 var childSlavesCount = 0; 184 183 foreach (var s in childSlaves) { 185 node.Nodes.Add(CreateTreeNode FromResource(s));184 node.Nodes.Add(CreateTreeNode(s)); 186 185 childSlavesCount++; 187 186 } … … 190 189 } 191 190 192 private TreeNode CreateTreeNode FromResource(Resource r) {191 private TreeNode CreateTreeNode(Resource r) { 193 192 var node = new TreeNode(); 194 193 node.Text = r.Name; … … 239 238 private bool IsAuthorized(Resource resource) { 240 239 return resource != null 241 && resource .Name != UngroupedGroupName240 && resource != ungroupedGroupNode.Tag 242 241 && resource.Id != Guid.Empty 243 242 && UserInformation.Instance.UserExists … … 347 346 } 348 347 348 private void treeSlaveGroup_ItemDrag(object sender, ItemDragEventArgs e) { 349 var nodes = GetCheckedNodes(treeSlaveGroup.Nodes).ToList(); 350 var draggedNode = (TreeNode)e.Item; 351 if (!draggedNode.Checked) nodes.Add(draggedNode); 352 nodes.Remove(ungroupedGroupNode); 353 var resources = nodes.Select(x => x.Tag).OfType<Resource>().ToList(); 354 355 if ((resources.Count > 0) && resources.TrueForAll((r) => IsAuthorized(r))) { 356 DataObject data = new DataObject(); 357 data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, resources); 358 var action = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move); 359 if (action.HasFlag(DragDropEffects.Move)) { 360 foreach (var node in nodes) node.Remove(); 361 ungroupedGroupNode.Text = ((Resource)ungroupedGroupNode.Tag).Name; 362 if (ungroupedGroupNode.Nodes.Count > 0) 363 ungroupedGroupNode.Text += " [" + ungroupedGroupNode.Nodes.Count.ToString() + "]"; 364 365 } 366 } 367 } 368 369 private IEnumerable<TreeNode> GetCheckedNodes(TreeNodeCollection nodes) { 370 if (nodes != null) { 371 foreach (var node in nodes.OfType<TreeNode>()) { 372 if (node.Checked) yield return node; 373 foreach (var child in GetCheckedNodes(node.Nodes)) 374 yield return child; 375 } 376 } 377 } 378 379 private void treeSlaveGroup_DragEnterOver(object sender, DragEventArgs e) { 380 e.Effect = DragDropEffects.None; 381 var resources = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IEnumerable<Resource>; 382 var node = treeSlaveGroup.GetNodeAt(treeSlaveGroup.PointToClient(new Point(e.X, e.Y))); 383 var group = node?.Tag as SlaveGroup; 384 385 if ((resources != null) && (node != null) && (group != null) && IsAuthorized(group) && (!resources.Contains(group))) { 386 if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move; 387 } 388 } 389 349 390 private void treeSlaveGroup_DragDrop(object sender, DragEventArgs e) { 350 if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false)) { 351 Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y)); 352 TreeNode destNode = ((TreeView)sender).GetNodeAt(pt); 353 TreeNode newNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode"); 354 355 if (destNode.TreeView == newNode.TreeView) { 356 if (destNode.Text == UngroupedGroupName || (destNode.Parent != null && destNode.Parent.Text == UngroupedGroupName)) { 357 MessageBox.Show(string.Format("You can't drag items to the group \"{0}\".{1}This group only contains slaves which haven't yet been assigned to a real group.", 358 UngroupedGroupName, Environment.NewLine), "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Information); 359 return; 360 } 361 362 SlaveGroup sgrp = null; 363 TreeNode parentNode = null; 364 if (destNode.Tag != null && destNode.Tag is SlaveGroup) { 365 sgrp = (SlaveGroup)destNode.Tag; 366 parentNode = destNode; 367 } else if (destNode.Parent != null && destNode.Parent.Tag is SlaveGroup) { 368 sgrp = (SlaveGroup)destNode.Parent.Tag; 369 parentNode = destNode.Parent; 370 } 371 372 if (newNode.Tag is SlaveGroup && CheckParentsEqualsMovedNode(parentNode, newNode)) { 373 return; 374 } 375 376 SlaveGroup parent = (SlaveGroup)parentNode.Tag; 377 378 if (parent.OwnerUserId != null && !IsAuthorized(parent)) { 379 MessageBox.Show(string.Format("You don't have the permissions to drag items to the group \"{0}\".", ((Resource)parentNode.Tag).Name), 380 "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 381 return; 382 } 383 384 if (sgrp != null && newNode.Tag != null) { 385 //save parent group to get an id 386 if (sgrp.Id == Guid.Empty) { 387 sgrp.Store(); 388 } 389 390 if (newNode.Tag is Slave) { 391 Slave slave = (Slave)newNode.Tag; 392 if (slave.ParentResourceId == null || (slave.ParentResourceId != null && slave.ParentResourceId != sgrp.Id)) { 393 slave.ParentResourceId = sgrp.Id; 394 newNode.Remove(); 395 parentNode.Nodes.Clear(); 396 BuildSlaveGroupTree(sgrp, parentNode); 397 } 398 } else if (newNode.Tag is SlaveGroup) { 399 SlaveGroup slaveGroup = (SlaveGroup)newNode.Tag; 400 if (slaveGroup.ParentResourceId == null || (slaveGroup.ParentResourceId != null && slaveGroup.ParentResourceId != sgrp.Id)) { 401 slaveGroup.ParentResourceId = sgrp.Id; 402 newNode.Remove(); 403 parentNode.Nodes.Clear(); 404 BuildSlaveGroupTree(sgrp, parentNode); 405 } 406 } 407 } 408 } 409 } 410 } 411 412 private bool CheckParentsEqualsMovedNode(TreeNode dest, TreeNode movedNode) { 413 TreeNode tmp = dest; 414 415 while (tmp != null) { 416 if (tmp == movedNode) { 417 return true; 418 } 419 tmp = tmp.Parent; 420 } 421 return false; 422 } 423 424 private void treeSlaveGroup_ItemDrag(object sender, ItemDragEventArgs e) { 425 TreeNode sourceNode = (TreeNode)e.Item; 426 if (IsAuthorized((Resource)sourceNode.Tag)) 427 DoDragDrop(sourceNode, DragDropEffects.All); 428 } 429 430 private void treeSlaveGroup_DragEnter(object sender, DragEventArgs e) { 431 e.Effect = DragDropEffects.Move; 432 } 433 434 private void treeSlaveGroup_DragOver(object sender, DragEventArgs e) { 435 e.Effect = DragDropEffects.Move; 436 } 437 438 private void treeSlaveGroup_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) { 439 e.Action = DragAction.Continue; 391 if (e.Effect != DragDropEffects.None) { 392 var node = treeSlaveGroup.GetNodeAt(treeSlaveGroup.PointToClient(new Point(e.X, e.Y))); 393 var group = (SlaveGroup)node.Tag; // drop is only allowed on slave groups, validity of drop target is check in treeSlaveGroup_DragEnterOver 394 var resources = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IEnumerable<Resource>; 395 396 foreach (var r in resources) r.ParentResourceId = group.Id; 397 node.Nodes.Clear(); 398 BuildSlaveGroupTree(group, node); 399 } 440 400 } 441 401
Note: See TracChangeset
for help on using the changeset viewer.