#region License Information /* HeuristicLab * Copyright (C) 2002-2010 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.Linq; using System.Windows.Forms; using HeuristicLab.Core; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; namespace HeuristicLab.Clients.Hive.Views { [View("HiveJob View")] [Content(typeof(HiveJob), true)] public partial class HiveJobView : ItemView { public new HiveJob Content { get { return (HiveJob)base.Content; } set { if (base.Content != value) { base.Content = value; } } } public HiveJobView() { InitializeComponent(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.OptimizerJobChanged += new EventHandler(Content_OptimizerJobChanged); Content.JobChanged += new EventHandler(Content_JobChanged); Content.JobStateChanged += new EventHandler(Content_JobStateChanged); } protected override void DeregisterContentEvents() { Content.OptimizerJobChanged -= new EventHandler(Content_OptimizerJobChanged); Content.JobChanged -= new EventHandler(Content_JobChanged); Content.JobStateChanged -= new EventHandler(Content_JobStateChanged); base.DeregisterContentEvents(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null && Content.Job != null) { logView.Content = Content.OptimizerJob.Log; childHiveJobView.Content = Content.ChildHiveJobs; computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel; } else { logView.Content = null; childHiveJobView.Content = null; computeInParallelCheckBox.Checked = false; } Content_OptimizerJobChanged(this, EventArgs.Empty); Content_JobChanged(this, EventArgs.Empty); Content_JobStateChanged(this, EventArgs.Empty); } void Content_OptimizerJobChanged(object sender, EventArgs e) { RegisterJobEvents(); Job_OptimizerChanged(this, e); } void Job_OptimizerChanged(object sender, EventArgs e) { if (Content != null && Content.Job != null && Content.OptimizerJob.Optimizer != null) { optimizerNamedItemView.Content = Content.OptimizerJob.Optimizer; runCollectionViewHost.Content = Content.OptimizerJob.Optimizer.Runs; } else { optimizerNamedItemView.Content = null; runCollectionViewHost.Content = null; } } private void RegisterJobEvents() { if (Content != null && Content.Job != null) { Content.OptimizerJob.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged); Content.OptimizerJob.OptimizerChanged += new EventHandler(Job_OptimizerChanged); } } private void DeregisterJobEvents() { if (Content != null && Content.Job != null) { Content.OptimizerJob.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged); Content.OptimizerJob.OptimizerChanged -= new EventHandler(Job_OptimizerChanged); } } #region Content Events private void Content_JobChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(Content_JobChanged), sender, e); } else { if (Content != null && Content.Job != null) { this.jobIdTextBox.Text = Content.Job.Id.ToString(); this.dateCreatedTextBox.Text = Content.Job.DateCreated.ToString(); this.priorityTextBox.Text = Content.Job.Priority.ToString(); this.coresNeededTextBox.Text = Content.Job.CoresNeeded.ToString(); this.memoryNeededTextBox.Text = Content.Job.MemoryNeeded.ToString(); } else { this.jobIdTextBox.Text = string.Empty; this.dateCreatedTextBox.Text = string.Empty; this.priorityTextBox.Text = string.Empty; this.coresNeededTextBox.Text = string.Empty; this.memoryNeededTextBox.Text = string.Empty; } } } private void Content_JobStateChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(Content_JobStateChanged), sender, e); } else { if (Content != null && Content.Job != null) { this.stateTextBox.Text = Content.Job.State.ToString(); this.executionTimeTextBox.Text = Content.Job.ExecutionTime.ToString(); //this.dateCalculatedText.Text = Content.Job.DateCalculated.ToString(); this.dateFinishedTextBox.Text = Content.Job.DateFinished.ToString(); this.exceptionTextBox.Text = Content.Job.CurrentStateLog.Exception; if (Content.OptimizerJob.ComputeInParallel) { this.stateLogViewHost.Content = new ItemList( this.Content.ChildHiveJobs.Select(child => new StateLogList(child.Job.StateLog) )); } else { this.stateLogViewHost.Content = new StateLogList(Content.Job.StateLog); } } else { this.stateTextBox.Text = string.Empty; this.executionTimeTextBox.Text = string.Empty; this.dateCalculatedText.Text = string.Empty; this.dateFinishedTextBox.Text = string.Empty; this.exceptionTextBox.Text = string.Empty; this.stateLogViewHost.Content = null; } } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); this.jobIdTextBox.ReadOnly = true; this.stateTextBox.ReadOnly = true; this.executionTimeTextBox.ReadOnly = true; this.dateCreatedTextBox.ReadOnly = true; this.dateCalculatedText.ReadOnly = true; this.dateFinishedTextBox.ReadOnly = true; this.exceptionTextBox.ReadOnly = true; this.priorityTextBox.ReadOnly = this.ReadOnly; this.coresNeededTextBox.ReadOnly = this.ReadOnly; this.memoryNeededTextBox.ReadOnly = this.ReadOnly; this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.OptimizerJob != null && this.Content.OptimizerJob.IsParallelizable; optimizerNamedItemView.ReadOnly = true; ShowOrHideChildJobTabPage(); } void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e); } else { computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel; ShowOrHideChildJobTabPage(); } } private void ShowOrHideChildJobTabPage() { if (Content != null && Content.OptimizerJob != null) { if (!Content.OptimizerJob.ComputeInParallel) { if (tabControl.TabPages.Contains(childJobsTabPage)) tabControl.TabPages.Remove(childJobsTabPage); } else { if (!tabControl.TabPages.Contains(childJobsTabPage)) tabControl.TabPages.Insert(1, childJobsTabPage); } } } #endregion private void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) { if (Content != null && Content.OptimizerJob != null) { this.Content.OptimizerJob.ComputeInParallel = this.computeInParallelCheckBox.Checked; } } } }