#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.Threading; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Clients.Hive.Views { [View("Updateable Hive Experiment Manager View")] [Content(typeof(HiveExperimentManagerClient), true)] public partial class UpdateableHiveExperimentManagerView : HiveExperimentManagerView { private ProgressView progressView; public UpdateableHiveExperimentManagerView() { InitializeComponent(); updateExperimentsPanel.Dock = DockStyle.Fill; } protected override void OnContentChanged() { base.OnContentChanged(); Content_IsProgressingChanged(this, EventArgs.Empty); if (Content != null) UpdateExperimentsAsync(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); this.Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged); } protected override void DeregisterContentEvents() { base.DeregisterContentEvents(); this.Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged); } private void updateExperimentsButton_Click(object sender, EventArgs e) { if (Content != null) UpdateExperimentsAsync(); } private void Content_IsProgressingChanged(object sender, EventArgs e) { if (this.InvokeRequired) { Invoke(new EventHandler(Content_IsProgressingChanged), sender, e); } else { if (Content != null && Content.IsProgressing) { SetProgressView(); } else { FinishProgressView(); } } } private void SetProgressView() { if (progressView == null) { progressView = new ProgressView(this, Content.Progress); } else { progressView.Progress = Content.Progress; } } private void FinishProgressView() { if (progressView != null) { progressView.Finish(); progressView = null; SetEnabledStateOfControls(); } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); updateExperimentsPanel.Visible = Content != null && Content.HiveExperiments == null; } protected void UpdateExperimentsAsync() { MethodInvoker invoker = new MethodInvoker(Content.UpdateExperimentList); invoker.BeginInvoke((ar) => { try { invoker.EndInvoke(ar); } catch (Exception ex) { ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex); } }, null); } } }