Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/11 14:08:11 (13 years ago)
Author:
ascheibe
Message:

#1233
Admin UI:

  • don't completely rebuild treeview on drag and drop
  • some bugfixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administration/3.4/Views/ResourcesView.cs

    r6464 r6492  
    116116        TreeNode stn = new TreeNode(r.Name);
    117117        if (r is Slave) {
    118           stn.ImageIndex = 0;
     118          stn.ImageIndex = slaveImageIndex;
    119119        } else if (r is SlaveGroup) {
    120120          stn.ImageIndex = slaveGroupImageIndex;
     
    125125
    126126        BuildSlaveGroupTree(r, stn);
     127        tn.ExpandAll();
    127128      }
    128129    }
     
    169170
    170171    private void btnRemoveGroup_Click(object sender, EventArgs e) {
    171       //TODO: display some warning?
    172172      if (treeSlaveGroup.SelectedNode != null && treeSlaveGroup.SelectedNode.Tag != null) {
    173173        Resource res = (Resource)treeSlaveGroup.SelectedNode.Tag;
    174174
    175         if (res is Slave) {
    176           Content.Remove(res);
    177           ServiceLocator.Instance.CallHiveService(service => service.DeleteSlave(res.Id));
    178         } else if (res is SlaveGroup) {
    179           //only delete empty groups
    180           if (Content.Where(s => s.ParentResourceId == res.Id).Count() < 1) {
     175        DialogResult diagRes = MessageBox.Show("Do you really want to delete " + res.Name + "?", "HeuristicLab Hive Administration", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     176        if (diagRes == DialogResult.Yes) {
     177          if (res is Slave) {
    181178            Content.Remove(res);
    182             ServiceLocator.Instance.CallHiveService(service => service.DeleteSlaveGroup(res.Id));
    183           } else {
    184             MessageBox.Show("Only empty groups can be deleted.", "HeuristicLab Hive Administration", MessageBoxButtons.OK, MessageBoxIcon.Error);
     179            ServiceLocator.Instance.CallHiveService(service => service.DeleteSlave(res.Id));
     180          } else if (res is SlaveGroup) {
     181            //only delete empty groups
     182            if (Content.Where(s => s.ParentResourceId == res.Id).Count() < 1) {
     183              Content.Remove(res);
     184              ServiceLocator.Instance.CallHiveService(service => service.DeleteSlaveGroup(res.Id));
     185            } else {
     186              MessageBox.Show("Only empty groups can be deleted.", "HeuristicLab Hive Administration", MessageBoxButtons.OK, MessageBoxIcon.Error);
     187            }
    185188          }
    186189        }
     
    218221
    219222          SlaveGroup sgrp = null;
     223          TreeNode parentNode = null;
    220224          if (destNode.Tag != null && destNode.Tag is SlaveGroup) {
    221225            sgrp = (SlaveGroup)destNode.Tag;
     226            parentNode = destNode;
    222227          } else if (destNode.Parent != null && destNode.Parent.Tag is SlaveGroup) {
    223228            sgrp = (SlaveGroup)destNode.Parent.Tag;
     229            parentNode = destNode.Parent;
     230          }
     231
     232          if (newNode.Tag is SlaveGroup && CheckParentsEqualsMovedNode(parentNode, newNode)) {
     233            return;
    224234          }
    225235
     
    234244              if (slave.ParentResourceId == null || (slave.ParentResourceId != null && slave.ParentResourceId != sgrp.Id)) {
    235245                slave.ParentResourceId = sgrp.Id;
     246                newNode.Remove();
     247                parentNode.Nodes.Clear();
     248                BuildSlaveGroupTree(sgrp, parentNode);
    236249              }
    237250            } else if (newNode.Tag is SlaveGroup) {
     
    239252              if (slaveGroup.ParentResourceId == null || (slaveGroup.ParentResourceId != null && slaveGroup.ParentResourceId != sgrp.Id)) {
    240253                slaveGroup.ParentResourceId = sgrp.Id;
     254                newNode.Remove();
     255                parentNode.Nodes.Clear();
     256                BuildSlaveGroupTree(sgrp, parentNode);
    241257              }
    242258            }
    243             OnContentChanged();
    244           }
    245         }
    246       }
     259          }
     260        }
     261      }
     262    }
     263
     264    private bool CheckParentsEqualsMovedNode(TreeNode dest, TreeNode movedNode) {
     265      TreeNode tmp = dest;
     266
     267      while (tmp != null) {
     268        if (tmp == movedNode) {
     269          return true;
     270        }
     271        tmp = tmp.Parent;
     272      }
     273      return false;
    247274    }
    248275
Note: See TracChangeset for help on using the changeset viewer.