Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelectorDialog.cs @ 15642

Last change on this file since 15642 was 15642, checked in by jzenisek, 6 years ago

#2839

  • adapted handling of cascading revocations of project-user permissions and project-resource assignments: from deleting all AssignedJobResource (formerly) to deleting only entries which are effected by the previously mentioned revocations (now)
  • implemented job update (client side)
  • corrected & improved stateful project/resource selection dialog
  • corrected resource statistic calculation in project/resource selection dialog
File size: 6.1 KB
RevLine 
[7910]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[7910]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[15412]22using System;
[7910]23using System.Collections.Generic;
[15412]24using System.ComponentModel;
25using System.Linq;
[7910]26using System.Windows.Forms;
[15412]27using HeuristicLab.Clients.Hive.Views;
28using HeuristicLab.MainForm;
[15627]29using HeuristicLab.Core;
[7910]30
31namespace HeuristicLab.Clients.Hive.JobManager.Views {
32  public partial class HiveResourceSelectorDialog : Form {
[15412]33    private readonly object locker = new object();
34    private bool updatingProjects = false;
35
36    public Project SelectedProject {
37      get { return hiveResourceSelector.SelectedProject; }
38    }
39
40    public IEnumerable<Resource> SelectedResources {
[15627]41      get { return hiveResourceSelector.AssignedResources; }
[15412]42    }
43
[15627]44    private Guid jobId;
45    public Guid JobId {
46      get { return hiveResourceSelector.JobId; }
47      set { jobId = value; }
48    }
49
50    // persisted projectId
51    private Guid? projectId;
52    public Guid? ProjectId {
53      get { return hiveResourceSelector.ProjectId; }
54      set { projectId = value; }
55    }
56
[15642]57    // currently selected projectId (initially the persisted projectId)
[15627]58    private Guid? selectedProjectId;
59    public Guid? SelectedProjectId {
60      get { return selectedProjectId; }
61      set { selectedProjectId = value; }
62    }
63
[15642]64    // currently selected resourceIds (if null, perform lookup in HiveResourceSelector)
65    private IEnumerable<Guid> selectedResourceIds;
66    public IEnumerable<Guid> SelectedResourceIds {
67      get { return selectedResourceIds; }
68      set { selectedResourceIds = value; }
69    }
[15627]70
[15642]71
72
[15627]73    public HiveResourceSelectorDialog(Guid jobId, Guid projectId) {
74      this.jobId = jobId;
75      this.projectId = projectId;
76      this.selectedProjectId = projectId;
[7910]77      InitializeComponent();
78    }
79
[15412]80    #region Overrides
81    protected override void OnLoad(EventArgs e) {
82      HiveAdminClient.Instance.Refreshing += HiveAdminClient_Instance_Refreshing;
83      HiveAdminClient.Instance.Refreshed += HiveAdminClient_Instance_Refreshed;
84      base.OnLoad(e);
85    }
[7910]86
[15412]87    protected override void OnClosing(CancelEventArgs e) {
88      HiveAdminClient.Instance.Refreshed -= HiveAdminClient_Instance_Refreshed;
89      HiveAdminClient.Instance.Refreshing -= HiveAdminClient_Instance_Refreshing;
90      base.OnClosing(e);
[7910]91    }
[15412]92    #endregion
[7910]93
[15412]94    #region Event Handlers
95    private void HiveAdminClient_Instance_Refreshing(object sender, EventArgs e) {
96      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshing, sender, e);
97      else {
98        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
99        mainForm.AddOperationProgressToView(this, "Refreshing ...");
100        refreshButton.Enabled = false;
101      }
[7910]102    }
103
[15412]104    private void HiveAdminClient_Instance_Refreshed(object sender, EventArgs e) {
105      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshed, sender, e);
106      else {
107        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
108        mainForm.RemoveOperationProgressFromView(this);
109        refreshButton.Enabled = true;
110      }
[7910]111    }
112
[15412]113    private async void HiveResourceSelectorDialog_Load(object sender, EventArgs e) {
114      lock (locker) {
115        if (updatingProjects) return;
116        updatingProjects = true;
117      }
118
119      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
120        action: () => UpdateProjects(),
121        finallyCallback: () => updatingProjects = false);
[7910]122    }
123
[15412]124    private async void refreshButton_Click(object sender, EventArgs e) {
125      lock (locker) {
126        if (updatingProjects) return;
127        updatingProjects = true;
128      }
129
130      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
131        action: () => UpdateProjects(),
132        finallyCallback: () => updatingProjects = false);
[7910]133    }
134
[15412]135    private void hiveResourceSelector_SelectedProjectChanged(object sender, EventArgs e) {
136      okButton.Enabled = hiveResourceSelector.SelectedProject != null;
137    }
138
139    private void hiveResourceSelector_SelectedResourcesChanged(object sender, EventArgs e) {
[15627]140      okButton.Enabled = hiveResourceSelector.AssignedResources.Any();
[15412]141    }
142
143    private void hiveResourceSelector_ProjectsTreeViewDoubleClicked(object sender, EventArgs e) {
144      if (hiveResourceSelector.SelectedProject == null) return;
[15642]145      if (!hiveResourceSelector.AssignedResources.Any()) return;
[15412]146
147      DialogResult = DialogResult.OK;
148      Close();
149    }
150    #endregion
151
152    #region Helpers
153    private void UpdateProjects() {
[7910]154      HiveAdminClient.Instance.Refresh();
[15627]155      hiveResourceSelector.JobId = jobId;
156      hiveResourceSelector.ProjectId = projectId;
157      hiveResourceSelector.SelectedProjectId = selectedProjectId;
[15642]158      hiveResourceSelector.SelectedResourceIds = selectedResourceIds;
[15627]159      var projectList = new ItemList<Project>(HiveServiceLocator.Instance.CallHiveService(s => s.GetProjects()));
160      hiveResourceSelector.Content = projectList;
[7910]161    }
[15412]162
163    private void ShowHiveInformationDialog() {
164      if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
165      else {
166        using (HiveInformationDialog dialog = new HiveInformationDialog()) {
167          dialog.ShowDialog(this);
168        }
169      }
170    }
171    #endregion
[7910]172  }
173}
Note: See TracBrowser for help on using the repository browser.