#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.Drawing; using System.Linq; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; using HeuristicLab.Core.Views; using HeuristicLab.Data.Views; using HeuristicLab.Data; namespace HeuristicLab.Clients.Hive.Administrator.Views { [View("ProjectView")] [Content(typeof(Project), IsDefaultView = false)] public partial class ProjectJobsView : ItemView { private const string JOB_ID = "Id"; private const string JOB_NAME = "Name"; private const string JOB_OWNER = "Owner"; private const string JOB_DATECREATED = "Date Created"; private const string JOB_STATE = "State"; private const string JOB_DESCRIPTION = "Description"; public new Project Content { get { return (Project)base.Content; } set { base.Content = value; } } public ProjectJobsView() /*: base()*/ { InitializeComponent(); } #region Overrides protected override void OnContentChanged() { base.OnContentChanged(); UpdateJobs(); } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); bool enabled = Content != null && !Locked && !ReadOnly; refreshButton.Enabled = enabled; removeButton.Enabled = enabled; matrixView.Enabled = enabled; } #endregion Overrides #region Event Handlers private void ProjectJobsView_Load(object sender, EventArgs e) { } private void refreshButton_Click(object sender, EventArgs e) { HiveAdminClient.Instance.Refresh(); // Update list/matrix } private async void removeButton_Click(object sender, EventArgs e) { // remove selected job(s) } #endregion Event Handlers #region Helpers private StringMatrix CreateValueMatrix() { var jobs = HiveAdminClient.Instance.Jobs[Content.Id]; string[,] values = new string[jobs.Count, 7]; for(int i = 0; i < jobs.Count; i++) { var job = jobs.ElementAt(i); values[i, 0] = job.Id.ToString(); values[i, 1] = job.Name; values[i, 2] = job.OwnerUserId.ToString(); values[i, 3] = job.OwnerUsername; values[i, 4] = job.DateCreated.ToString(); values[i, 5] = job.State.ToString(); values[i, 6] = job.Description; } var matrix = new StringMatrix(values); matrix.ColumnNames = new string[] { JOB_ID, JOB_NAME, JOB_OWNER, JOB_OWNER, JOB_DATECREATED, JOB_STATE, JOB_DESCRIPTION }; matrix.SortableView = true; return matrix; } private void UpdateJobs() { if (InvokeRequired) Invoke((Action)UpdateJobs); else { StringMatrix matrix = null; if(Content != null) { matrix = CreateValueMatrix(); } else { refreshButton.Enabled = false; removeButton.Enabled = false; } matrixView.Content = matrix; matrixView.DataGridView.AutoResizeColumns(); //foreach(DataGridViewColumn col in matrixView.DataGridView.Columns) { // col.Width = -2; //} } } #endregion Helpers } }