#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 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.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Clients.Access;
using HeuristicLab.Clients.Hive.Views;
using HeuristicLab.Collections;
using HeuristicLab.Common.Resources;
using HeuristicLab.Core;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
namespace HeuristicLab.Clients.Hive.Administrator.Views {
[View("Projects View")]
[Content(typeof(IItemList), false)]
public partial class ProjectsView : ItemView, IDisposable {
private const int greenFlagImageIndex = 0;
private const int redFlagImageIndex = 1;
private const string SELECTED_TAG = ""; // " [selected]";
private const string NOT_STORED_TAG = "*"; // " [not stored]";
private const string CHANGES_NOT_STORED_TAG = "*"; // " [changes not stored]";
private readonly Color selectedBackColor = Color.DodgerBlue;
private readonly Color selectedForeColor = Color.White;
private readonly Color grayTextColor = SystemColors.GrayText;
private Project selectedProject = null;
public Project SelectedProject {
get { return selectedProject; }
set { if (selectedProject != value) ChangeSelectedProject(value); }
}
private readonly object locker = new object();
public new IItemList Content {
get { return (IItemList)base.Content; }
set { base.Content = value; }
}
public ProjectsView() {
InitializeComponent();
projectsTreeView.ImageList.Images.Add(VSImageLibrary.FlagGreen);
projectsTreeView.ImageList.Images.Add(VSImageLibrary.FlagRed);
HiveAdminClient.Instance.Refreshing += HiveAdminClient_Instance_Refreshing;
HiveAdminClient.Instance.Refreshed += HiveAdminClient_Instance_Refreshed;
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;
HiveAdminClient.Instance.Refreshed -= HiveAdminClient_Instance_Refreshed;
HiveAdminClient.Instance.Refreshing -= HiveAdminClient_Instance_Refreshing;
base.OnClosing(e);
}
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.ItemsAdded += Content_ItemsAdded;
Content.ItemsRemoved += Content_ItemsRemoved;
}
protected override void DeregisterContentEvents() {
Content.ItemsRemoved -= Content_ItemsRemoved;
Content.ItemsAdded -= Content_ItemsAdded;
base.DeregisterContentEvents();
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
projectsTreeView.Nodes.Clear();
projectView.Content = null;
projectPermissionsView.Content = null;
projectResourcesView.Content = null;
projectJobsView.Content = null;
selectedProject = null;
} else {
BuildProjectTree(Content);
}
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
bool selectedProjectExists = selectedProject != null && selectedProject.Id != Guid.Empty && Content.Contains(selectedProject);
bool projectIsNew = selectedProject != null && selectedProject.Id == Guid.Empty;
bool locked = Content == null || selectedProject == null || Locked || ReadOnly;
bool parentOwner = HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id);
bool saveLocked = locked || (!IsAdmin() && selectedProject.OwnerUserId != UserInformation.Instance.User.Id && !parentOwner);
bool addLocked = saveLocked || projectIsNew || selectedProject.Id == Guid.Empty;
bool deleteLocked = locked || (!IsAdmin() && !parentOwner) || Content.Where(x => x.ParentProjectId == selectedProject.Id).Any();
var now = DateTime.Now;
if (!addLocked && (now < selectedProject.StartDate || now > selectedProject.EndDate)) addLocked = true;
addButton.Enabled = !addLocked;
removeButton.Enabled = !deleteLocked;
saveProjectButton.Enabled = !saveLocked;
projectView.Enabled = !locked;
projectPermissionsView.Enabled = !locked;
projectResourcesView.Enabled = !locked;
projectJobsView.Enabled = !locked;
projectView.Locked = locked;
projectPermissionsView.Locked = locked;
projectResourcesView.Locked = locked;
projectJobsView.Locked = locked;
}
#endregion
#region Event Handlers
private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs> e) {
if (InvokeRequired) Invoke((Action