#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.Core.Views;
using HeuristicLab.MainForm;
using HeuristicLab.PluginInfrastructure;
namespace HeuristicLab.Clients.Hive.Views {
///
/// The base class for visual representations of items.
///
[View("Hive Experiment Manager View")]
[Content(typeof(HiveExperimentManagerClient), true)]
public sealed partial class HiveExperimentManagerView : ItemView {
private ProgressView progressView;
public new HiveExperimentManagerClient Content {
get { return (HiveExperimentManagerClient)base.Content; }
set { base.Content = value; }
}
///
/// Initializes a new instance of .
///
public HiveExperimentManagerView() {
InitializeComponent();
updateExperimentsPanel.Dock = DockStyle.Fill;
}
protected override void OnContentChanged() {
base.OnContentChanged();
Content_HiveExperimentsChanged(this, EventArgs.Empty);
Content_IsProgressingChanged(this, EventArgs.Empty);
if(Content != null) UpdateExperimentsAsync();
}
protected override void RegisterContentEvents() {
this.Content.HiveExperimentsChanged += new EventHandler(Content_HiveExperimentsChanged);
this.Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged);
}
protected override void DeregisterContentEvents() {
this.Content.HiveExperimentsChanged -= new EventHandler(Content_HiveExperimentsChanged);
this.Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged);
}
private void Content_HiveExperimentsChanged(object sender, EventArgs e) {
if (Content != null) {
this.hiveExperimentListView.Content = Content.HiveExperiments;
}
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
updateExperimentsPanel.Visible = Content != null && Content.HiveExperiments == null;
}
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();
}
}
private 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);
}
}
}