#region License Information
/* HeuristicLab
* Copyright (C) 2002-2019 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 const string INACTIVE_TAG = " [inactive]";
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();
private bool refreshingInternal = false;
private bool refreshingExternal = false;
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;
}
#region Overrides
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);
}
SetEnabledStateOfControls();
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
bool locked = Content == null || Locked || ReadOnly;
bool parentOwner = selectedProject != null && HiveAdminClient.Instance.CheckOwnershipOfParentProject(selectedProject, UserInformation.Instance.User.Id);
bool selectedProjectDisabled = selectedProject == null
|| selectedProject != null && selectedProject.Id == Guid.Empty;
bool selectedProjectHasJobs =
!selectedProjectDisabled && HiveAdminClient.Instance.Jobs.ContainsKey(selectedProject.Id)
&& HiveAdminClient.Instance.Jobs[selectedProject.Id] != null
&& HiveAdminClient.Instance.Jobs[selectedProject.Id].Any();
bool addLocked = locked
|| (selectedProject == null && !IsAdmin())
|| (selectedProject != null && selectedProject.Id == Guid.Empty)
|| (selectedProject != null && !IsAdmin() && !parentOwner && selectedProject.OwnerUserId != UserInformation.Instance.User.Id)
|| (selectedProject != null && (DateTime.Now < selectedProject.StartDate || DateTime.Now > selectedProject.EndDate));
bool deleteLocked = locked
|| !Content.Any()
|| selectedProject == null
|| Content.Any(x => x.ParentProjectId == selectedProject.Id)
|| selectedProjectHasJobs
|| (!IsAdmin() && !parentOwner);
bool saveLocked = locked
|| !Content.Any()
|| selectedProject == null
|| (!IsAdmin() && !parentOwner && selectedProject.OwnerUserId != UserInformation.Instance.User.Id);
addButton.Enabled = !addLocked;
removeButton.Enabled = !deleteLocked;
saveProjectButton.Enabled = !saveLocked;
projectView.Enabled = !locked;
projectPermissionsView.Enabled = !locked && !selectedProjectDisabled;
projectResourcesView.Enabled = !locked && !selectedProjectDisabled;
projectJobsView.Enabled = !locked && !selectedProjectDisabled;
projectView.Locked = locked;
projectPermissionsView.Locked = locked || selectedProjectDisabled;
projectResourcesView.Locked = locked || selectedProjectDisabled;
projectJobsView.Locked = locked || selectedProjectDisabled;
}
#endregion
#region Event Handlers
private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs> e) {
if (InvokeRequired) Invoke((Action