1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using HeuristicLab.Clients.Hive.Views;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Clients.Hive.JobManager.Views {
|
---|
31 | public partial class HiveResourceSelectorDialog : Form {
|
---|
32 | private readonly object locker = new object();
|
---|
33 | private bool updatingProjects = false;
|
---|
34 |
|
---|
35 | public Project SelectedProject {
|
---|
36 | get { return hiveResourceSelector.SelectedProject; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public IEnumerable<Resource> SelectedResources {
|
---|
40 | get { return hiveResourceSelector.SelectedResources; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public HiveResourceSelectorDialog() {
|
---|
44 | InitializeComponent();
|
---|
45 | }
|
---|
46 |
|
---|
47 | #region Overrides
|
---|
48 | protected override void OnLoad(EventArgs e) {
|
---|
49 | HiveAdminClient.Instance.Refreshing += HiveAdminClient_Instance_Refreshing;
|
---|
50 | HiveAdminClient.Instance.Refreshed += HiveAdminClient_Instance_Refreshed;
|
---|
51 | base.OnLoad(e);
|
---|
52 | }
|
---|
53 |
|
---|
54 | protected override void OnClosing(CancelEventArgs e) {
|
---|
55 | HiveAdminClient.Instance.Refreshed -= HiveAdminClient_Instance_Refreshed;
|
---|
56 | HiveAdminClient.Instance.Refreshing -= HiveAdminClient_Instance_Refreshing;
|
---|
57 | base.OnClosing(e);
|
---|
58 | }
|
---|
59 | #endregion
|
---|
60 |
|
---|
61 | #region Event Handlers
|
---|
62 | private void HiveAdminClient_Instance_Refreshing(object sender, EventArgs e) {
|
---|
63 | if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshing, sender, e);
|
---|
64 | else {
|
---|
65 | var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
|
---|
66 | mainForm.AddOperationProgressToView(this, "Refreshing ...");
|
---|
67 | refreshButton.Enabled = false;
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void HiveAdminClient_Instance_Refreshed(object sender, EventArgs e) {
|
---|
72 | if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshed, sender, e);
|
---|
73 | else {
|
---|
74 | var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
|
---|
75 | mainForm.RemoveOperationProgressFromView(this);
|
---|
76 | refreshButton.Enabled = true;
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | private async void HiveResourceSelectorDialog_Load(object sender, EventArgs e) {
|
---|
81 | lock (locker) {
|
---|
82 | if (updatingProjects) return;
|
---|
83 | updatingProjects = true;
|
---|
84 | }
|
---|
85 |
|
---|
86 | await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
|
---|
87 | action: () => UpdateProjects(),
|
---|
88 | finallyCallback: () => updatingProjects = false);
|
---|
89 | }
|
---|
90 |
|
---|
91 | private async void refreshButton_Click(object sender, EventArgs e) {
|
---|
92 | lock (locker) {
|
---|
93 | if (updatingProjects) return;
|
---|
94 | updatingProjects = true;
|
---|
95 | }
|
---|
96 |
|
---|
97 | await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
|
---|
98 | action: () => UpdateProjects(),
|
---|
99 | finallyCallback: () => updatingProjects = false);
|
---|
100 | }
|
---|
101 |
|
---|
102 | private void hiveResourceSelector_SelectedProjectChanged(object sender, EventArgs e) {
|
---|
103 | okButton.Enabled = hiveResourceSelector.SelectedProject != null;
|
---|
104 | }
|
---|
105 |
|
---|
106 | private void hiveResourceSelector_SelectedResourcesChanged(object sender, EventArgs e) {
|
---|
107 | okButton.Enabled = hiveResourceSelector.SelectedResources.Any();
|
---|
108 | }
|
---|
109 |
|
---|
110 | private void hiveResourceSelector_ProjectsTreeViewDoubleClicked(object sender, EventArgs e) {
|
---|
111 | if (hiveResourceSelector.SelectedProject == null) return;
|
---|
112 |
|
---|
113 | DialogResult = DialogResult.OK;
|
---|
114 | Close();
|
---|
115 | }
|
---|
116 | #endregion
|
---|
117 |
|
---|
118 | #region Helpers
|
---|
119 | private void UpdateProjects() {
|
---|
120 | HiveAdminClient.Instance.Refresh();
|
---|
121 | hiveResourceSelector.Content = HiveAdminClient.Instance.Projects;
|
---|
122 | }
|
---|
123 |
|
---|
124 | private void ShowHiveInformationDialog() {
|
---|
125 | if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
|
---|
126 | else {
|
---|
127 | using (HiveInformationDialog dialog = new HiveInformationDialog()) {
|
---|
128 | dialog.ShowDialog(this);
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 | #endregion
|
---|
133 | }
|
---|
134 | }
|
---|