[15401] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2017 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.ComponentModel;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Clients.Access;
|
---|
[15412] | 27 | using HeuristicLab.Clients.Hive.Views;
|
---|
[15401] | 28 | using HeuristicLab.Core.Views;
|
---|
| 29 | using HeuristicLab.MainForm;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Clients.Hive.Administrator.Views {
|
---|
| 32 | [View("ProjectView")]
|
---|
| 33 | [Content(typeof(Project), IsDefaultView = true)]
|
---|
| 34 | public partial class ProjectView : ItemView {
|
---|
| 35 | private readonly object locker = new object();
|
---|
| 36 |
|
---|
| 37 | public new Project Content {
|
---|
| 38 | get { return (Project)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public ProjectView() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 |
|
---|
| 45 | AccessClient.Instance.Refreshing += AccessClient_Instance_Refreshing;
|
---|
| 46 | AccessClient.Instance.Refreshed += AccessClient_Instance_Refreshed;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[15412] | 49 | #region Overrides
|
---|
[15401] | 50 | protected override void OnClosing(FormClosingEventArgs e) {
|
---|
| 51 | AccessClient.Instance.Refreshed -= AccessClient_Instance_Refreshed;
|
---|
| 52 | AccessClient.Instance.Refreshing -= AccessClient_Instance_Refreshing;
|
---|
| 53 | base.OnClosing(e);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | protected override void RegisterContentEvents() {
|
---|
| 57 | base.RegisterContentEvents();
|
---|
| 58 | Content.PropertyChanged += Content_PropertyChanged;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | protected override void DeregisterContentEvents() {
|
---|
| 62 | Content.PropertyChanged -= Content_PropertyChanged;
|
---|
| 63 | base.DeregisterContentEvents();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | protected override void OnContentChanged() {
|
---|
| 67 | base.OnContentChanged();
|
---|
| 68 | if (Content == null) {
|
---|
[15576] | 69 | idTextBox.Clear();
|
---|
[15401] | 70 | nameTextBox.Clear();
|
---|
| 71 | descriptionTextBox.Clear();
|
---|
| 72 | ownerComboBox.SelectedItem = null;
|
---|
| 73 | createdTextBox.Clear();
|
---|
| 74 | startDateTimePicker.Value = DateTime.Now;
|
---|
| 75 | endDateTimePicker.Value = startDateTimePicker.Value;
|
---|
| 76 | indefiniteCheckBox.Checked = false;
|
---|
| 77 | } else {
|
---|
[15576] | 78 | idTextBox.Text = Content.Id.ToString();
|
---|
[15401] | 79 | nameTextBox.Text = Content.Name;
|
---|
| 80 | descriptionTextBox.Text = Content.Description;
|
---|
| 81 | ownerComboBox.SelectedItem = AccessClient.Instance.UsersAndGroups.FirstOrDefault(x => x.Id == Content.OwnerUserId);
|
---|
| 82 | createdTextBox.Text = Content.DateCreated.ToString("ddd, dd.MM.yyyy, HH:mm:ss");
|
---|
| 83 | startDateTimePicker.Value = Content.StartDate;
|
---|
| 84 | if (indefiniteCheckBox.Checked = !Content.EndDate.HasValue) {
|
---|
| 85 | endDateTimePicker.Value = startDateTimePicker.Value;
|
---|
| 86 | } else {
|
---|
| 87 | endDateTimePicker.Value = Content.EndDate.Value;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | protected override void SetEnabledStateOfControls() {
|
---|
| 93 | base.SetEnabledStateOfControls();
|
---|
[15760] | 94 | bool enabled = Content != null && !Locked && !ReadOnly;
|
---|
[15401] | 95 | nameTextBox.Enabled = enabled;
|
---|
| 96 | descriptionTextBox.Enabled = enabled;
|
---|
[15412] | 97 | refreshButton.Enabled = enabled;
|
---|
[15401] | 98 | ownerComboBox.Enabled = enabled;
|
---|
| 99 | createdTextBox.Enabled = enabled;
|
---|
| 100 | startDateTimePicker.Enabled = enabled;
|
---|
| 101 | endDateTimePicker.Enabled = enabled && Content.EndDate.HasValue;
|
---|
| 102 | indefiniteCheckBox.Enabled = enabled;
|
---|
| 103 | }
|
---|
[15412] | 104 | #endregion
|
---|
[15401] | 105 |
|
---|
[15412] | 106 | #region Event Handlers
|
---|
| 107 | private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 108 | OnContentChanged();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[15401] | 111 | private void AccessClient_Instance_Refreshing(object sender, EventArgs e) {
|
---|
| 112 | if (InvokeRequired) Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshing, sender, e);
|
---|
| 113 | else {
|
---|
| 114 | var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
|
---|
| 115 | mainForm.AddOperationProgressToView(this, "Refreshing ...");
|
---|
| 116 | SetEnabledStateOfControls();
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | private void AccessClient_Instance_Refreshed(object sender, EventArgs e) {
|
---|
| 121 | if (InvokeRequired) Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshed, sender, e);
|
---|
| 122 | else {
|
---|
| 123 | var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
|
---|
| 124 | mainForm.RemoveOperationProgressFromView(this);
|
---|
| 125 | SetEnabledStateOfControls();
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | private async void ProjectView_Load(object sender, EventArgs e) {
|
---|
[15412] | 130 | await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
|
---|
| 131 | action: () => UpdateUsers(),
|
---|
| 132 | finallyCallback: () => {
|
---|
| 133 | ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged;
|
---|
| 134 | ownerComboBox.DataSource = AccessClient.Instance.UsersAndGroups.OfType<LightweightUser>().ToList();
|
---|
| 135 | ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged;
|
---|
| 136 | });
|
---|
[15401] | 137 | }
|
---|
| 138 |
|
---|
| 139 | private async void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 140 | lock (locker) {
|
---|
[15422] | 141 | if (!refreshButton.Enabled) return;
|
---|
| 142 | refreshButton.Enabled = false;
|
---|
[15401] | 143 | }
|
---|
| 144 |
|
---|
[15412] | 145 | await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
|
---|
| 146 | action: () => UpdateUsers(),
|
---|
| 147 | finallyCallback: () => {
|
---|
| 148 | ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged;
|
---|
| 149 | ownerComboBox.DataSource = AccessClient.Instance.UsersAndGroups.OfType<LightweightUser>().ToList();
|
---|
| 150 | ownerComboBox.SelectedItem = AccessClient.Instance.UsersAndGroups.FirstOrDefault(x => x.Id == Content.OwnerUserId);
|
---|
| 151 | ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged;
|
---|
[15422] | 152 | refreshButton.Enabled = true;
|
---|
[15412] | 153 | });
|
---|
[15401] | 154 | }
|
---|
| 155 |
|
---|
| 156 | private void nameTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 157 | if (string.IsNullOrEmpty(nameTextBox.Text)) {
|
---|
| 158 | MessageBox.Show(
|
---|
| 159 | "Project must have a name.",
|
---|
| 160 | "HeuristicLab Hive Administrator",
|
---|
| 161 | MessageBoxButtons.OK,
|
---|
| 162 | MessageBoxIcon.Error);
|
---|
| 163 | e.Cancel = true;
|
---|
[15422] | 164 | }
|
---|
[15401] | 165 | }
|
---|
| 166 |
|
---|
[15422] | 167 | private void nameTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 168 | if (Content != null && Content.Name != nameTextBox.Text)
|
---|
| 169 | Content.Name = nameTextBox.Text;
|
---|
[15401] | 170 | }
|
---|
| 171 |
|
---|
[15422] | 172 | private void descriptionTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 173 | if (Content != null && Content.Description != descriptionTextBox.Text)
|
---|
| 174 | Content.Description = descriptionTextBox.Text;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
[15401] | 177 | private void ownerComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 178 | var selectedItem = (LightweightUser)ownerComboBox.SelectedItem;
|
---|
[15422] | 179 | var selectedOwnerUserId = selectedItem != null ? selectedItem.Id : Guid.Empty;
|
---|
| 180 | if (Content != null && Content.OwnerUserId != selectedOwnerUserId)
|
---|
| 181 | Content.OwnerUserId = selectedOwnerUserId;
|
---|
[15401] | 182 | }
|
---|
| 183 |
|
---|
[15422] | 184 | private void startDateTimePicker_ValueChanged(object sender, EventArgs e) {
|
---|
| 185 | if (Content == null) return;
|
---|
[15401] | 186 | if (!Content.EndDate.HasValue || startDateTimePicker.Value > Content.EndDate)
|
---|
| 187 | endDateTimePicker.Value = startDateTimePicker.Value;
|
---|
[15422] | 188 | if (Content.StartDate != startDateTimePicker.Value)
|
---|
| 189 | Content.StartDate = startDateTimePicker.Value;
|
---|
[15401] | 190 | }
|
---|
| 191 |
|
---|
[15422] | 192 | private void endDateTimePicker_ValueChanged(object sender, EventArgs e) {
|
---|
| 193 | if (Content == null) return;
|
---|
[15401] | 194 | if (endDateTimePicker.Value < startDateTimePicker.Value)
|
---|
| 195 | endDateTimePicker.Value = startDateTimePicker.Value;
|
---|
[15422] | 196 | if (Content.EndDate != endDateTimePicker.Value)
|
---|
| 197 | Content.EndDate = endDateTimePicker.Value;
|
---|
[15401] | 198 | }
|
---|
| 199 |
|
---|
| 200 | private void indefiniteCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[15422] | 201 | if (Content == null) return;
|
---|
| 202 | var newEndDate = indefiniteCheckBox.Checked ? (DateTime?)null : Content.StartDate;
|
---|
| 203 | if (Content.EndDate != newEndDate)
|
---|
| 204 | Content.EndDate = newEndDate;
|
---|
[15401] | 205 | }
|
---|
[15412] | 206 | #endregion
|
---|
| 207 |
|
---|
| 208 | #region Helpers
|
---|
| 209 | private void UpdateUsers() {
|
---|
| 210 | try {
|
---|
| 211 | AccessClient.Instance.Refresh();
|
---|
| 212 | } catch (AnonymousUserException) {
|
---|
| 213 | ShowHiveInformationDialog();
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | private void ShowHiveInformationDialog() {
|
---|
| 218 | if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
|
---|
| 219 | else {
|
---|
| 220 | using (HiveInformationDialog dialog = new HiveInformationDialog()) {
|
---|
| 221 | dialog.ShowDialog(this);
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 | #endregion
|
---|
[15401] | 226 | }
|
---|
| 227 | }
|
---|