#region License Information /* HeuristicLab * Copyright (C) 2002-2011 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 HeuristicLab.Core.Views; using HeuristicLab.MainForm; namespace HeuristicLab.HiveEngine.Views { [View("Hive Engine View")] [Content(typeof(HiveEngine), IsDefaultView = true)] public sealed partial class HiveEngineView : ItemView { public new HiveEngine Content { get { return (HiveEngine)base.Content; } set { base.Content = value; } } public HiveEngineView() { InitializeComponent(); } protected override void DeregisterContentEvents() { Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); Content.ExecutionTimeOnHiveChanged -= new EventHandler(Content_ExecutionTimeOnHiveChanged); base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); Content.ExecutionTimeOnHiveChanged += new EventHandler(Content_ExecutionTimeOnHiveChanged); } #region Event Handlers (Content) private void Content_ExecutionStateChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); } else { executionTimeTextBox.Text = Content.ExecutionTime.ToString(); } } private void Content_ExecutionTimeOnHiveChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(Content_ExecutionTimeOnHiveChanged), sender, e); } else { executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString(); } } #endregion protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { resourceIdsTextBox.Text = string.Empty; priorityTextBox.Text = string.Empty; executionTimeOnHiveTextBox.Text = string.Empty; isPrivilegedCheckBox.Checked = false; hiveExperimentListView.Content = null; logView.Content = null; } else { resourceIdsTextBox.Text = Content.ResourceNames; priorityTextBox.Text = Content.Priority.ToString(); executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString(); isPrivilegedCheckBox.Checked = Content.IsPrivileged; hiveExperimentListView.Content = Content.HiveExperiments; logView.Content = Content.Log; } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); // Enable or disable controls based on whether the content is null or the view is set readonly if (Content != null) { resourceIdsTextBox.ReadOnly = this.ReadOnly; priorityTextBox.ReadOnly = this.ReadOnly; isPrivilegedCheckBox.Enabled = !this.ReadOnly; // TODO: check for user rights } else { resourceIdsTextBox.ReadOnly = false; priorityTextBox.ReadOnly = false; isPrivilegedCheckBox.Enabled = false; } } #region Event Handlers (child controls) private void resourceIdsTextBox_Validated(object sender, EventArgs e) { Content.ResourceNames = resourceIdsTextBox.Text; } private void priorityTextBox_Validated(object sender, EventArgs e) { Content.Priority = int.Parse(priorityTextBox.Text); } private void isPrivilegedCheckBox_CheckedChanged(object sender, EventArgs e) { Content.IsPrivileged = isPrivilegedCheckBox.Checked; } #endregion } }