[4905] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[6033] | 23 | using System.Linq;
|
---|
[4905] | 24 | using System.Windows.Forms;
|
---|
[6033] | 25 | using HeuristicLab.Collections;
|
---|
[4905] | 26 | using HeuristicLab.MainForm;
|
---|
[5955] | 27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 28 | using HeuristicLab.PluginInfrastructure;
|
---|
[4905] | 29 |
|
---|
| 30 | namespace HeuristicLab.Clients.Hive.Views {
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// The base class for visual representations of items.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [View("Hive Experiment Manager View")]
|
---|
[5955] | 35 | [Content(typeof(ExperimentManagerClient), true)]
|
---|
| 36 | public partial class HiveExperimentManagerView : AsynchronousContentView {
|
---|
[4905] | 37 |
|
---|
[5955] | 38 | public new ExperimentManagerClient Content {
|
---|
| 39 | get { return (ExperimentManagerClient)base.Content; }
|
---|
[4905] | 40 | set { base.Content = value; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /// <summary>
|
---|
| 44 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 45 | /// </summary>
|
---|
| 46 | public HiveExperimentManagerView() {
|
---|
| 47 | InitializeComponent();
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[5955] | 50 | protected override void RegisterContentEvents() {
|
---|
| 51 | base.RegisterContentEvents();
|
---|
| 52 | Content.Refreshing += new EventHandler(Content_Refreshing);
|
---|
| 53 | Content.Refreshed += new EventHandler(Content_Refreshed);
|
---|
[6033] | 54 | Content.HiveExperimentsChanged += new EventHandler(Content_HiveExperimentsChanged);
|
---|
| 55 |
|
---|
[5955] | 56 | }
|
---|
| 57 |
|
---|
| 58 | protected override void DeregisterContentEvents() {
|
---|
| 59 | Content.Refreshing -= new EventHandler(Content_Refreshing);
|
---|
| 60 | Content.Refreshed -= new EventHandler(Content_Refreshed);
|
---|
[6033] | 61 | Content.HiveExperimentsChanged -= new EventHandler(Content_HiveExperimentsChanged);
|
---|
[5955] | 62 | base.DeregisterContentEvents();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[4905] | 65 | protected override void OnContentChanged() {
|
---|
| 66 | base.OnContentChanged();
|
---|
[5955] | 67 | if (Content == null) {
|
---|
| 68 | hiveExperimentListView.Content = null;
|
---|
| 69 | } else {
|
---|
| 70 | hiveExperimentListView.Content = Content.HiveExperiments;
|
---|
| 71 | if(Content != null)
|
---|
| 72 | Content.RefreshAsync(new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
|
---|
| 73 | }
|
---|
[4905] | 74 | }
|
---|
| 75 |
|
---|
[5512] | 76 | protected override void SetEnabledStateOfControls() {
|
---|
| 77 | base.SetEnabledStateOfControls();
|
---|
[5955] | 78 | refreshButton.Enabled = Content != null;
|
---|
| 79 | hiveExperimentListView.Enabled = Content != null;
|
---|
[5512] | 80 | }
|
---|
| 81 |
|
---|
[5955] | 82 | private void Content_Refreshing(object sender, EventArgs e) {
|
---|
| 83 | if (InvokeRequired) {
|
---|
| 84 | Invoke(new EventHandler(Content_Refreshing), sender, e);
|
---|
| 85 | } else {
|
---|
| 86 | Cursor = Cursors.AppStarting;
|
---|
| 87 | refreshButton.Enabled = false;
|
---|
| 88 | hiveExperimentListView.Enabled = false;
|
---|
| 89 | }
|
---|
[4905] | 90 | }
|
---|
[5955] | 91 | private void Content_Refreshed(object sender, EventArgs e) {
|
---|
| 92 | if (InvokeRequired) {
|
---|
| 93 | Invoke(new EventHandler(Content_Refreshed), sender, e);
|
---|
| 94 | } else {
|
---|
| 95 | hiveExperimentListView.Content = Content.HiveExperiments;
|
---|
| 96 | refreshButton.Enabled = true;
|
---|
| 97 | hiveExperimentListView.Enabled = true;
|
---|
| 98 | Cursor = Cursors.Default;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
[4905] | 101 |
|
---|
[5955] | 102 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 103 | Content.RefreshAsync(new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
|
---|
[4905] | 104 | }
|
---|
| 105 |
|
---|
[5955] | 106 | protected override void OnClosing(FormClosingEventArgs e) {
|
---|
| 107 | base.OnClosing(e);
|
---|
[6033] | 108 | if (Content != null && Content.HiveExperiments != null) {
|
---|
| 109 | foreach (var exp in Content.HiveExperiments.OfType<RefreshableHiveExperiment>()) {
|
---|
[5955] | 110 | if (exp.RefreshAutomatically) {
|
---|
| 111 | exp.RefreshAutomatically = false; // stop result polling
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
[4905] | 114 | }
|
---|
| 115 | }
|
---|
[6033] | 116 |
|
---|
| 117 | private void HiveExperiments_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableHiveExperiment> e) {
|
---|
| 118 | foreach (var item in e.Items) {
|
---|
| 119 | ExperimentManagerClient.Delete(item);
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | private void Content_HiveExperimentsChanged(object sender, EventArgs e) {
|
---|
| 124 | Content.HiveExperiments.ItemsRemoved += new CollectionItemsChangedEventHandler<RefreshableHiveExperiment>(HiveExperiments_ItemsRemoved);
|
---|
| 125 | }
|
---|
[4905] | 126 | }
|
---|
| 127 | }
|
---|