#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.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 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;
} else {
var top = BuildProjectTree(Content);
projectView.Content = top;
projectPermissionsView.Content = top;
projectResourcesView.Content = top;
}
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
bool enabled = Content != null && !ReadOnly;
refreshButton.Enabled = enabled;
addButton.Enabled = enabled;
removeButton.Enabled = enabled;
saveProjectButton.Enabled = enabled;
projectView.Enabled = enabled;
projectPermissionsView.Enabled = enabled;
projectResourcesView.Enabled = enabled;
}
#endregion
#region Event Handlers
private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs> e) {
if (InvokeRequired) Invoke((Action