Changeset 15631


Ignore:
Timestamp:
01/19/18 02:12:20 (19 months ago)
Author:
swagner
Message:

#2877: Improved groups/slaves treeview of Hive Administrator

  • enabled selecting and moving multiple slaves at once
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  
    6060      this.btnRemoveGroup = new System.Windows.Forms.Button();
    6161      this.btnAddGroup = new System.Windows.Forms.Button();
    62       this.btnPermissionsSave = new System.Windows.Forms.Button();
    6362      this.treeSlaveGroup = new System.Windows.Forms.TreeView();
    6463      this.tabSlaveGroup = new System.Windows.Forms.TabControl();
     
    6766      this.tabSchedule = new System.Windows.Forms.TabPage();
    6867      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();
    6971      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();
    7272      ((System.ComponentModel.ISupportInitialize)(this.splitSlaves)).BeginInit();
    7373      this.splitSlaves.Panel1.SuspendLayout();
     
    8888      // splitSlaves
    8989      //
    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) 
    9292            | System.Windows.Forms.AnchorStyles.Right)));
    9393      this.splitSlaves.Location = new System.Drawing.Point(3, 3);
     
    165165      //
    166166      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;
    170171      this.treeSlaveGroup.ImageIndex = 0;
    171172      this.treeSlaveGroup.ImageList = this.imageListSlaveGroups;
     
    178179      this.treeSlaveGroup.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterSelect);
    179180      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);
    183183      //
    184184      // tabSlaveGroup
    185185      //
    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) 
    188188            | System.Windows.Forms.AnchorStyles.Right)));
    189189      this.tabSlaveGroup.Controls.Add(this.tabDetails);
     
    210210      // slaveView
    211211      //
    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) 
    214214            | System.Windows.Forms.AnchorStyles.Right)));
    215215      this.slaveView.Caption = "SlaveView";
     
    234234      // scheduleView
    235235      //
    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) 
    238238            | System.Windows.Forms.AnchorStyles.Right)));
    239239      this.scheduleView.Caption = "ScheduleView";
     
    271271      // permissionView
    272272      //
    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) 
    275275            | System.Windows.Forms.AnchorStyles.Right)));
    276276      this.permissionView.Caption = "RefreshableLightweightUser View";
  • branches/2877_HiveImprovements/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r15620 r15631  
    4444    }
    4545
    46     public const string UngroupedGroupName = "UNGROUPED";
     46    public const string UNGROUPED_GROUP_NAME = "UNGROUPED";
     47    private TreeNode ungroupedGroupNode;
    4748    private const int slaveImageIndex = 0;
    4849    private const int slaveGroupImageIndex = 1;
     
    140141        var ungroupedSlaves = new SlaveGroup {
    141142          Id = Guid.NewGuid(),
    142           Name = UngroupedGroupName,
     143          Name = UNGROUPED_GROUP_NAME,
    143144          Description = "Slaves without a group"
    144145        };
    145         var ungroupedSlavesCount = 0;
    146         var ungroupedNode = CreateTreeNodeFromResource(ungroupedSlaves);
     146        ungroupedGroupNode = CreateTreeNode(ungroupedSlaves);
    147147
    148148        var parentlessResources = from r in Content
     
    152152        foreach (Resource r in parentlessResources) {
    153153          if (r.GetType() == typeof(SlaveGroup)) {  // root node
    154             var root = CreateTreeNodeFromResource(r);
     154            var root = CreateTreeNode(r);
    155155            treeSlaveGroup.Nodes.Add(root);
    156156            BuildSlaveGroupTree((SlaveGroup)r, root);
    157157          } else if (r.GetType() == typeof(Slave)) {  // ungrouped slaves
    158             ungroupedNode.Nodes.Add(CreateTreeNodeFromResource(r));
    159             ungroupedSlavesCount++;
     158            ungroupedGroupNode.Nodes.Add(CreateTreeNode(r));
    160159          }
    161160        }
    162         if (ungroupedSlavesCount > 0)
    163           ungroupedNode.Text += "   [" + ungroupedSlavesCount.ToString() + "]";
    164         treeSlaveGroup.Nodes.Add(ungroupedNode);
     161        if (ungroupedGroupNode.Nodes.Count > 0)
     162          ungroupedGroupNode.Text += "   [" + ungroupedGroupNode.Nodes.Count.ToString() + "]";
     163        treeSlaveGroup.Nodes.Add(ungroupedGroupNode);
    165164      }
    166165    }
     
    172171                        select r;
    173172      foreach (var g in childGroups) {
    174         var childNode = CreateTreeNodeFromResource(g);
     173        var childNode = CreateTreeNode(g);
    175174        node.Nodes.Add(childNode);
    176175        BuildSlaveGroupTree(g, childNode);
     
    183182      var childSlavesCount = 0;
    184183      foreach (var s in childSlaves) {
    185         node.Nodes.Add(CreateTreeNodeFromResource(s));
     184        node.Nodes.Add(CreateTreeNode(s));
    186185        childSlavesCount++;
    187186      }
     
    190189    }
    191190
    192     private TreeNode CreateTreeNodeFromResource(Resource r) {
     191    private TreeNode CreateTreeNode(Resource r) {
    193192      var node = new TreeNode();
    194193      node.Text = r.Name;
     
    239238    private bool IsAuthorized(Resource resource) {
    240239      return resource != null
    241           && resource.Name != UngroupedGroupName
     240          && resource != ungroupedGroupNode.Tag
    242241          && resource.Id != Guid.Empty
    243242          && UserInformation.Instance.UserExists
     
    347346    }
    348347
     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
    349390    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      }
    440400    }
    441401
Note: See TracChangeset for help on using the changeset viewer.