#region License Information
/* HeuristicLab
* Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Clients.Access;
using HeuristicLab.Clients.Hive.Views;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
namespace HeuristicLab.Clients.Hive.Administrator.Views {
[View("ProjectView")]
[Content(typeof(Project), IsDefaultView = true)]
public partial class ProjectView : ItemView {
private readonly object locker = new object();
public new Project Content {
get { return (Project)base.Content; }
set { base.Content = value; }
}
public ProjectView() {
InitializeComponent();
AccessClient.Instance.Refreshing += AccessClient_Instance_Refreshing;
AccessClient.Instance.Refreshed += AccessClient_Instance_Refreshed;
}
#region Overrides
protected override void OnClosing(FormClosingEventArgs e) {
AccessClient.Instance.Refreshed -= AccessClient_Instance_Refreshed;
AccessClient.Instance.Refreshing -= AccessClient_Instance_Refreshing;
base.OnClosing(e);
}
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.PropertyChanged += Content_PropertyChanged;
}
protected override void DeregisterContentEvents() {
Content.PropertyChanged -= Content_PropertyChanged;
base.DeregisterContentEvents();
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
nameTextBox.Clear();
descriptionTextBox.Clear();
ownerComboBox.SelectedItem = null;
createdTextBox.Clear();
startDateTimePicker.Value = DateTime.Now;
endDateTimePicker.Value = startDateTimePicker.Value;
indefiniteCheckBox.Checked = false;
} else {
nameTextBox.Text = Content.Name;
descriptionTextBox.Text = Content.Description;
ownerComboBox.SelectedItem = AccessClient.Instance.UsersAndGroups.FirstOrDefault(x => x.Id == Content.OwnerUserId);
createdTextBox.Text = Content.DateCreated.ToString("ddd, dd.MM.yyyy, HH:mm:ss");
startDateTimePicker.Value = Content.StartDate;
if (indefiniteCheckBox.Checked = !Content.EndDate.HasValue) {
endDateTimePicker.Value = startDateTimePicker.Value;
} else {
endDateTimePicker.Value = Content.EndDate.Value;
}
}
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
bool enabled = Content != null && !ReadOnly;
nameTextBox.Enabled = enabled;
descriptionTextBox.Enabled = enabled;
refreshButton.Enabled = enabled;
ownerComboBox.Enabled = enabled;
createdTextBox.Enabled = enabled;
startDateTimePicker.Enabled = enabled;
endDateTimePicker.Enabled = enabled && Content.EndDate.HasValue;
indefiniteCheckBox.Enabled = enabled;
}
#endregion
#region Event Handlers
private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
OnContentChanged();
}
private void AccessClient_Instance_Refreshing(object sender, EventArgs e) {
if (InvokeRequired) Invoke((Action