Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/04/18 11:16:36 (6 years ago)
Author:
jkarder
Message:

#2839: worked on hive project management

  • fixed handling of enabled states in ResourcesView
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r16117 r16122  
    112112        BuildResourceTree(Content);
    113113      }
     114      SetEnabledStateOfControls();
    114115    }
    115116
     
    117118      base.SetEnabledStateOfControls();
    118119
    119       bool locked = Content == null || selectedResource == null || Locked || ReadOnly;
    120       bool adminLocked = locked || !IsAdmin();
    121       bool addLocked = adminLocked || selectedResource.Id == Guid.Empty || selectedResource is Slave;
    122       bool deleteLocked = adminLocked || HiveAdminClient.Instance.ResourceDescendants[selectedResource.Id].Any();
     120      bool locked = Content == null || Locked || ReadOnly;
     121      bool addLocked = locked
     122                    || !IsAdmin()
     123                    || (selectedResource is Slave && selectedResource.ParentResourceId != null)
     124                    || (selectedResource != null && selectedResource.Id == Guid.Empty);
     125
     126      HashSet<Guid> descendantResources = null;
     127
     128      bool deleteLocked = locked
     129                       || !IsAdmin()
     130                       || !Content.Any()
     131                       || selectedResource == null
     132                       || (selectedResource.Id != Guid.Empty && (!HiveAdminClient.Instance.ResourceDescendants.TryGetValue(selectedResource.Id, out descendantResources) || descendantResources.Any()));
     133
     134      bool saveLocked = locked
     135                       || !IsAdmin()
     136                       || !Content.Any()
     137                       || selectedResource == null;
    123138
    124139      btnAddGroup.Enabled = !addLocked;
    125140      btnRemoveGroup.Enabled = !deleteLocked;
    126       btnSave.Enabled = !locked;
    127       scheduleView.Locked = adminLocked;
     141      btnSave.Enabled = !saveLocked;
     142      viewHost.Locked = locked || !IsAdmin();
     143      scheduleView.Locked = locked || !IsAdmin();
    128144    }
    129145    #endregion
     
    207223
    208224    private void btnAddGroup_Click(object sender, EventArgs e) {
    209       Guid? parentResourceId = null;
    210       if (!IsAdmin()) {
    211         MessageBox.Show(
    212           "You have no permission to add a resource group.",
    213           "HeuristicLab Hive Administrator",
    214           MessageBoxButtons.OK,
    215           MessageBoxIcon.Information);
    216         return;
    217       } else if (selectedResource != null && selectedResource.Id == Guid.Empty) {
    218         MessageBox.Show(
    219           "You cannot add a resource group to a not yet stored group.",
    220           "HeuristicLab Hive Administrator",
    221           MessageBoxButtons.OK,
    222           MessageBoxIcon.Information);
    223         return;
    224       }
    225 
    226       if (selectedResource != null && selectedResource is SlaveGroup) {
    227         parentResourceId = selectedResource.Id;
    228       } else {
    229         MessageBox.Show(
    230           "You cannot add a resource group to a slave.",
    231           "HeuristicLab Hive Administrator",
    232           MessageBoxButtons.OK,
    233           MessageBoxIcon.Information);
    234         return;
    235       }
     225      var parentResourceId = selectedResource is SlaveGroup ? selectedResource.Id : (Guid?)null;
    236226
    237227      var group = new SlaveGroup {
     
    241231      };
    242232
    243       //HiveAdminClient.Instance.UpdateResourceGenealogy(Content);
    244233      SelectedResource = group;
    245234      Content.Add(group);
     
    252241        if (!btnRemoveGroup.Enabled) return;
    253242        btnRemoveGroup.Enabled = false;
    254       }
    255 
    256       if (!IsAdmin()) {
    257         MessageBox.Show(
    258           "You have no permission to delete resource groups.",
    259           "HeuristicLab Hive Administrator",
    260           MessageBoxButtons.OK,
    261           MessageBoxIcon.Information);
    262         return;
    263       }
    264 
    265       if (Content.Any(x => x.ParentResourceId == selectedResource.Id)) {
    266         MessageBox.Show(
    267           "Only empty resource groups can be deleted.",
    268           "HeuristicLab Hive Administrator",
    269           MessageBoxButtons.OK,
    270           MessageBoxIcon.Error);
    271         return;
    272243      }
    273244
     
    281252          action: () => {
    282253            RemoveResource(selectedResource);
    283           },
    284           finallyCallback: () => {
    285             btnRemoveGroup.Enabled = true;
    286254          });
    287       } else {
    288         btnRemoveGroup.Enabled = true;
     255
     256        OnContentChanged();
     257        SetEnabledStateOfControls();
    289258      }
    290259    }
     
    302271            resource.Store();
    303272          UpdateResources();
    304         },
    305         finallyCallback: () => btnSave.Enabled = true);
     273        });
    306274
    307275      OnContentChanged();
     276      SetEnabledStateOfControls();
    308277    }
    309278
     
    483452      ungroupedGroupNode = new TreeNode(UNGROUPED_GROUP_NAME) {
    484453        ForeColor = SystemColors.GrayText,
     454        ImageIndex = slaveGroupImageIndex,
    485455        Tag = new SlaveGroup() {
    486456          Name = UNGROUPED_GROUP_NAME,
     
    508478        ungroupedGroupNode.Text += " [" + ungroupedGroupNode.Nodes.Count.ToString() + "]";
    509479        ungroupedGroupNode.Expand();
    510       }
    511       treeView.Nodes.Add(ungroupedGroupNode);
     480        treeView.Nodes.Add(ungroupedGroupNode);
     481      }
    512482    }
    513483
     
    564534      try {
    565535        if (resource.Id != Guid.Empty) {
    566           var resourcesToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified);
    567           foreach (var r in resourcesToSave)
    568             r.Store();
    569 
    570536          SelectedResource = HiveAdminClient.Instance.GetAvailableResourceAncestors(resource.Id).LastOrDefault();
    571537          HiveAdminClient.Delete(resource);
    572538          UpdateResources();
    573539        } else {
    574           Content.Remove(selectedResource);
     540          SelectedResource = null;
     541          Content.Remove(resource);
    575542        }
    576543      } catch (AnonymousUserException) {
Note: See TracChangeset for help on using the changeset viewer.