Changeset 15777


Ignore:
Timestamp:
02/14/18 11:19:55 (18 months ago)
Author:
jzenisek
Message:

#2839 improved project- & resource selection handling

Location:
branches/2839_HiveProjectManagement
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.Designer.cs

    r15767 r15777  
    126126      this.projectsTreeView.TabIndex = 9;
    127127      this.projectsTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.projectsTreeView_ItemDrag);
    128       this.projectsTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.projectsTreeView_AfterSelect);
     128      this.projectsTreeView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.projectsTreeView_BeforeSelect);
     129      this.projectsTreeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.projectsTreeView_MouseDown);
    129130      this.projectsTreeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.projectsTreeView_DragDrop);
    130131      this.projectsTreeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.projectsTreeView_DragEnterOver);
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs

    r15767 r15777  
    4343    private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1
    4444    private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b
     45
    4546    private Project selectedProject = null;
     47    public Project SelectedProject {
     48      get { return selectedProject; }
     49      set { if (selectedProject != value) ChangeSelectedProject(value); }
     50    }
    4651
    4752    private readonly object locker = new object();
     
    9398        projectResourcesView.Content = null;
    9499      } else {
    95         var top = BuildProjectTree(Content);
    96         projectView.Content = top;
    97         projectPermissionsView.Content = top;
    98         projectResourcesView.Content = top;
    99 
    100         if(top != null && top.Id == Guid.Empty) {
    101           projectPermissionsView.Locked = true;
    102           projectResourcesView.Locked = true;
    103         }
     100        BuildProjectTree(Content);
    104101      }
    105102    }
     
    107104    protected override void SetEnabledStateOfControls() {
    108105      base.SetEnabledStateOfControls();
    109       bool enabled = Content != null && !ReadOnly;
     106      bool enabled = Content != null && !Locked && !ReadOnly;
    110107      refreshButton.Enabled = enabled;
    111108      addButton.Enabled = enabled;
     
    213210      };
    214211
    215       selectedProject = project;
     212      SelectedProject = project;
    216213      Content.Add(project);
    217214    }
     
    278275    }
    279276
    280     private void projectsTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
    281       ChangeSelectedProjectNode(e.Node);
    282 
    283       //if (projectView.Content != null)
    284       //  projectView.Content.PropertyChanged -= ProjectViewContent_PropertyChanged;
    285 
    286       projectView.Content = selectedProject;
    287       projectPermissionsView.Content = selectedProject;
    288       projectResourcesView.Content = selectedProject;
    289 
    290       //if (selectedProject != null)
    291       //  selectedProject.PropertyChanged += ProjectViewContent_PropertyChanged;
     277    private void projectsTreeView_MouseDown(object sender, MouseEventArgs e) {
     278      var node = projectsTreeView.GetNodeAt(e.Location);
     279      if(node != null) ChangeSelectedProjectNode(node);
     280    }
     281
     282    private void projectsTreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e) {
     283      e.Cancel = true;
    292284    }
    293285
     
    306298      var targetNode = treeView.GetNodeAt(targetPoint);
    307299
    308       if (sourceNode == targetNode) return;
    309300      var targetProject = (targetNode != null) ? (Project)targetNode.Tag : null;
    310301
    311       if(targetProject != null && targetProject.Id == Guid.Empty) {
     302      if (!HiveAdminClient.Instance.CheckParentChange(sourceProject, targetProject)) {
    312303        MessageBox.Show(
    313           "You cannot drag projects to a not yet stored project.",
     304          "You cannot drag projects to this project.",
    314305          "HeuristicLab Hive Administrator",
    315306          MessageBoxButtons.OK,
    316307          MessageBoxIcon.Information);
    317308        return;
    318       }
    319       if(!HiveAdminClient.Instance.CheckParentChange(sourceProject, targetProject)) {
    320         MessageBox.Show(
    321           "You cannot drag to this project.",
    322           "HeuristicLab Hive Administrator",
    323           MessageBoxButtons.OK,
    324           MessageBoxIcon.Information);
    325       return;
    326309      }
    327310
     
    340323      }
    341324
    342       selectedProject = sourceProject;
     325      SelectedProject = sourceProject;
    343326      OnContentChanged();
    344327    }
     
    364347      || sourceProject == null
    365348      || sourceNode == targetNode
    366       || (targetProject != null && targetProject.Id == Guid.Empty)
    367       || (targetProject != null && targetProject.Id == sourceProject.ParentProjectId)
    368349      || !HiveAdminClient.Instance.CheckParentChange(sourceProject, targetProject)) {
    369350        e.Effect = DragDropEffects.None;
     
    398379    }
    399380
     381    private void ChangeSelectedProject(Project project) {
     382      projectView.Content = project;
     383      projectPermissionsView.Content = project;
     384      projectResourcesView.Content = project;
     385
     386      bool locked = project == null || (project != null && project.Id == Guid.Empty);
     387      addButton.Enabled = !locked;
     388      projectPermissionsView.Locked = locked;
     389      projectResourcesView.Locked = locked;
     390      selectedProject = project;
     391    }
     392
    400393    private void ChangeSelectedProjectNode(TreeNode projectNode) {
    401       selectedProject = (Project)projectNode.Tag;
     394      if (projectNode == null) return;
     395      SelectedProject = (Project)projectNode.Tag;
    402396      ResetTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent, true);
    403397      projectNode.BackColor = selectedColor;
     
    405399    }
    406400
    407     private Project BuildProjectTree(IEnumerable<Project> projects) {
     401    private void BuildProjectTree(IEnumerable<Project> projects) {
    408402      projectsTreeView.Nodes.Clear();
    409       if (!projects.Any()) return null;
     403      if (!projects.Any()) return;
    410404
    411405      var mainProjects = new HashSet<Project>(projects.Where(x => x.ParentProjectId == null));
     
    417411
    418412      var stack = new Stack<Project>(mainProjects.OrderByDescending(x => x.Name));
    419       if (selectedProject != null) selectedProject = projects.Where(x => x.Id == selectedProject.Id).FirstOrDefault();
     413      if (selectedProject != null) SelectedProject = projects.Where(x => x.Id == selectedProject.Id).FirstOrDefault();
    420414      bool nodeSelected = false;
    421415
     
    433427        }
    434428        if (selectedProject == null) {
    435           selectedProject = newProject;
     429          SelectedProject = newProject;
    436430        }
    437431        if (newProject.Id == selectedProject.Id && !nodeSelected) {
     
    471465
    472466      projectsTreeView.ExpandAll();
    473 
    474       return selectedProject;
    475467    }
    476468
     
    485477
    486478    private void RemoveProject(Project project) {
    487       if (project == null || project.Id == Guid.Empty) return;
     479      if (project == null) return;
    488480
    489481      try {
    490         HiveAdminClient.Delete(project);
     482        if(project.Id != Guid.Empty) HiveAdminClient.Delete(project);
    491483        Content.Remove(selectedProject);
    492484      } catch (AnonymousUserException) {
     
    497489    private bool IsAuthorized(Project project) {
    498490      return project != null && UserInformation.Instance.UserExists;
    499           //&& (project.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());
    500491    }
    501492
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs

    r15767 r15777  
    157157      this.treeView.TabIndex = 0;
    158158      this.treeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeSlaveGroup_ItemDrag);
     159      this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeSlaveGroup_MouseDown);
    159160      this.treeView.BeforeSelect += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeSlaveGroup_BeforeSelect);
    160       this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeSlaveGroup_AfterSelect);
    161161      this.treeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragDrop);
    162162      this.treeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.treeSlaveGroup_DragEnterOver);
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r15767 r15777  
    4545    private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1
    4646    private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b
     47
    4748    private Resource selectedResource = null;
     49    public Resource SelectedResource {
     50      get { return selectedResource; }
     51      set { if (selectedResource != value) ChangeSelectedResource(value); }
     52    }
    4853
    4954    private readonly object locker = new object();
     
    9499        scheduleView.Content = null;
    95100      } else {
    96         var top = BuildResourceTree(Content);
    97         SetEnabledStateOfControlsForSelectedResource();
    98 
    99         viewHost.Content = top;
    100         bool locked = !IsAdmin();
    101         viewHost.Locked = locked;
    102         scheduleView.Locked = locked;
    103 
    104         if (top != null && top.Id == Guid.Empty) {
    105           scheduleView.SetEnabledStateOfSchedule(false);
    106         }
     101        BuildResourceTree(Content);
    107102      }
    108103    }
     
    110105    protected override void SetEnabledStateOfControls() {
    111106      base.SetEnabledStateOfControls();
    112       bool enabled = Content != null && !Locked && IsAdmin();
     107      bool enabled = Content != null && !Locked && !ReadOnly && IsAdmin();
    113108      btnAddGroup.Enabled = enabled;
    114109      btnRemoveGroup.Enabled = enabled;
     
    220215      };
    221216
    222       selectedResource = group;
     217      SelectedResource = group;
    223218      Content.Add(group);
    224219    }
     
    282277    }
    283278
     279    private void treeSlaveGroup_MouseDown(object sender, MouseEventArgs e) {
     280      var node = treeView.GetNodeAt(e.Location);
     281      if(node != null && node.Name != ungroupedGroupName) ChangeSelectedResourceNode(node);
     282    }
     283
    284284    private void treeSlaveGroup_BeforeSelect(object sender, TreeViewCancelEventArgs e) {
    285       if (((Resource)e.Node.Tag).Name == ungroupedGroupName) e.Cancel = true;
    286     }
    287 
    288     private async void treeSlaveGroup_AfterSelect(object sender, TreeViewEventArgs e) {
    289       ChangeSelectedResourceNode(e.Node);
    290       SetEnabledStateOfControlsForSelectedResource();
    291 
    292       //if (viewHost.Content != null && viewHost.Content is SlaveGroup)
    293       //  ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged;
    294 
    295       viewHost.Content = selectedResource;
    296       HiveAdminClient.Instance.DowntimeForResourceId = selectedResource != null ? selectedResource.Id : Guid.Empty;
    297       await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
    298         action: () => UpdateSchedule(),
    299         finallyCallback: () => scheduleView.Content = HiveAdminClient.Instance.Downtimes);
    300 
    301       //if (selectedResource != null && selectedResource is SlaveGroup)
    302       //  selectedResource.PropertyChanged += SlaveViewContent_PropertyChanged;
    303 
    304       bool locked = !IsAdmin();
    305       viewHost.Locked = locked;
    306       scheduleView.Locked = locked;
     285      e.Cancel = true;
    307286    }
    308287
     
    321300      var targetNode = treeView.GetNodeAt(targetPoint);
    322301
    323       if (sourceNode == targetNode) return;
    324302      var targetResource = (targetNode != null) ? (Resource)targetNode.Tag : null;
    325303
    326       if (!IsAdmin()) {
    327         MessageBox.Show(
    328           "You cannot drag resources. This is solely granted for HeuristicLab Hive Administrators.",
    329           "HeuristicLab Hive Administrator",
    330           MessageBoxButtons.OK,
    331           MessageBoxIcon.Information);
    332         return;
    333       } else if (targetResource != null && targetResource is Slave) {
    334         MessageBox.Show(
    335           "You cannot drag resources on to a slave.",
    336           "HeuristicLab Hive Administrator",
    337           MessageBoxButtons.OK,
    338           MessageBoxIcon.Information);
    339         return;
    340       } else if (targetResource != null && targetResource.Id == Guid.Empty) {
    341         MessageBox.Show(
    342           "You cannot drag resources to a not yet stored resource group.",
    343           "HeuristicLab Hive Administrator",
    344           MessageBoxButtons.OK,
    345           MessageBoxIcon.Information);
    346         return;
    347       } else if(!HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource)) {
     304      if(!HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource)) {
    348305        MessageBox.Show(
    349306          "You cannot drag resources to this group.",
     
    352309          MessageBoxIcon.Information);
    353310        return;
    354       } else if (targetNode != null && (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName)) {
    355         MessageBox.Show(
    356           string.Format(@"You cannot drag resources to group ""{0}"". This group only contains slaves which have not been assigned to a real group yet.", ungroupedGroupName),
    357           "HeuristicLab Hive Administrator",
    358           MessageBoxButtons.OK,
    359           MessageBoxIcon.Information);
    360         return;
    361311      }
    362312
     
    375325      }
    376326
    377       selectedResource = sourceResource;
     327      SelectedResource = sourceResource;
    378328      OnContentChanged();
    379329    }
     
    399349        || sourceResource == null
    400350        || sourceNode == targetNode
    401         || (targetResource != null && targetResource is Slave)
    402         || (targetResource != null && targetResource.Id == Guid.Empty)
    403         || (targetResource != null && targetResource.Id == sourceResource.ParentResourceId)
    404351        || !HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource)
    405352        || (targetNode != null && (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName))) {
     
    435382    }
    436383
    437     private Resource BuildResourceTree(IEnumerable<Resource> resources) {
     384    private void BuildResourceTree(IEnumerable<Resource> resources) {
    438385      treeView.Nodes.Clear();
    439       if (!resources.Any()) return null;
     386      if (!resources.Any()) return;
    440387
    441388      var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>()
     
    447394
    448395      var stack = new Stack<Resource>(mainResources.OrderByDescending(x => x.Name));
    449       if (selectedResource != null) selectedResource = resources.Where(x => x.Id == selectedResource.Id).FirstOrDefault();
     396      if (selectedResource != null) SelectedResource = resources.Where(x => x.Id == selectedResource.Id).FirstOrDefault();
    450397      bool nodeSelected = false;
    451398
     
    463410        }
    464411        if (selectedResource == null) {
    465           selectedResource = newResource;
     412          SelectedResource = newResource;
    466413        }
    467414        if (newResource.Id == selectedResource.Id && !nodeSelected) {
     
    517464        ungroupedNode.Nodes.Add(slaveNode);
    518465        if(selectedResource == null) {
    519           selectedResource = slave;
     466          SelectedResource = slave;
    520467        }
    521468        if (slave.Id == Guid.Empty) {
     
    533480      treeView.Nodes.Add(ungroupedNode);
    534481      treeView.ExpandAll();
    535 
    536       return selectedResource;
    537482    }
    538483
     
    586531
    587532    private void RemoveResource(Resource resource) {
    588       if (resource == null || resource.Id == Guid.Empty) return;
     533      if (resource == null) return;
    589534
    590535      try {
    591         HiveAdminClient.Delete(resource);
     536        if(resource.Id != Guid.Empty) HiveAdminClient.Delete(resource);
    592537        Content.Remove(selectedResource);
    593538      } catch(AnonymousUserException) {
     
    617562    }
    618563
     564    private async void ChangeSelectedResource(Resource resource) {
     565      selectedResource = resource;
     566      viewHost.Content = selectedResource;
     567      HiveAdminClient.Instance.DowntimeForResourceId = selectedResource != null ? selectedResource.Id : Guid.Empty;
     568      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     569        action: () => UpdateSchedule(),
     570        finallyCallback: () => scheduleView.Content = HiveAdminClient.Instance.Downtimes);
     571
     572      bool locked = !IsAdmin() || resource == null;
     573      bool addLocked = locked || (resource != null && resource.Id == Guid.Empty);
     574
     575      btnAddGroup.Enabled = !addLocked;
     576      btnRemoveGroup.Enabled = !locked;
     577      btnSave.Enabled = !locked;
     578      viewHost.Locked = locked;
     579      scheduleView.Locked = locked;
     580      scheduleView.SetEnabledStateOfSchedule(!addLocked);
     581    }
     582
    619583    private void ChangeSelectedResourceNode(TreeNode resourceNode) {
    620       selectedResource = (Resource)resourceNode.Tag;
     584      if (resourceNode == null) return;
     585      SelectedResource = (Resource)resourceNode.Tag;
    621586      ResetTreeNodes(treeView.Nodes, selectedColor, Color.Transparent, true);
    622587      resourceNode.BackColor = selectedColor;
     
    624589    }
    625590
    626     private void SetEnabledStateOfControlsForSelectedResource() {
    627       bool enabled = (IsAdmin()) ? true : false;
    628       btnAddGroup.Enabled = enabled;
    629       btnRemoveGroup.Enabled = enabled;
    630       btnSave.Enabled = enabled;
    631     }
    632 
    633591    private void ShowHiveInformationDialog() {
    634592      if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r15768 r15777  
    305305
    306306    public bool CheckParentChange(Project child, Project parent) {
    307       bool changeGranted = true;
    308 
    309       // change is not granted, if the moved project is null
    310       // or the new parent is not stored yet
    311       // or there is not parental change
     307      bool changePossible = true;
     308
     309      // change is not possible...
     310      // ... if the moved project is null
     311      // ... or the new parent is not stored yet
     312      // ... or there is not parental change
    312313      if (child == null
    313314        || (parent != null && parent.Id == Guid.Empty)
    314315        || (parent != null && parent.Id == child.ParentProjectId)) {
    315         changeGranted = false;
     316        changePossible = false;
    316317      } else if(parent != null && projectDescendants.ContainsKey(child.Id)) {
    317         // change is not granted, if the new parent is among the moved project's descendants
    318         changeGranted = !projectDescendants[child.Id].Where(x => x.Id == parent.Id).Any();
    319       }
    320 
    321       return changeGranted;
     318        // ... if the new parent is among the moved project's descendants
     319        changePossible = !projectDescendants[child.Id].Where(x => x.Id == parent.Id).Any();
     320      }
     321
     322      return changePossible;
    322323    }
    323324
    324325    public bool CheckParentChange(Resource child, Resource parent) {
    325       bool changeGranted = true;
    326 
    327       // change is not granted, if the moved resource is null
    328       // or the new parent is not stored yet
    329       // or there is not parental change
     326      bool changePossible = true;
     327
     328      // change is not possisble...
     329      // ... if the moved resource is null
     330      // ... or the new parent is not stored yet
     331      // ... or the new parent is a slave
     332      // ... or there is not parental change
    330333      if (child == null
    331334        || (parent != null && parent.Id == Guid.Empty)
     335        || (parent != null && parent is Slave)
    332336        || (parent != null && parent.Id == child.ParentResourceId)) {
    333         changeGranted = false;
     337        changePossible = false;
    334338      } else if (parent != null && resourceDescendants.ContainsKey(child.Id)) {
    335         // change is not granted, if the new parent is among the moved resource's descendants
    336         changeGranted = !resourceDescendants[child.Id].Where(x => x.Id == parent.Id).Any();
    337       }
    338 
    339       return changeGranted;
     339        // ... or if the new parent is among the moved resource's descendants
     340        changePossible = !resourceDescendants[child.Id].Where(x => x.Id == parent.Id).Any();
     341      }
     342
     343      return changePossible;
    340344    }
    341345    #endregion
Note: See TracChangeset for help on using the changeset viewer.