Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.ExperimentManager/3.3/Views/HiveExperimentManagerView.cs @ 6725

Last change on this file since 6725 was 6725, checked in by ascheibe, 13 years ago

#1233 more renaming for more consistency

File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Collections;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Clients.Hive.ExperimentManager.Views {
31  /// <summary>
32  /// The base class for visual representations of items.
33  /// </summary>
34  [View("Hive Experiment Manager View")]
35  [Content(typeof(HiveClient), true)]
36  public partial class HiveExperimentManagerView : AsynchronousContentView {
37
38    public new HiveClient Content {
39      get { return (HiveClient)base.Content; }
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
50    protected override void RegisterContentEvents() {
51      base.RegisterContentEvents();
52      Content.Refreshing += new EventHandler(Content_Refreshing);
53      Content.Refreshed += new EventHandler(Content_Refreshed);
54      Content.HiveExperimentsChanged += new EventHandler(Content_HiveExperimentsChanged);
55
56    }
57
58    protected override void DeregisterContentEvents() {
59      Content.Refreshing -= new EventHandler(Content_Refreshing);
60      Content.Refreshed -= new EventHandler(Content_Refreshed);
61      Content.HiveExperimentsChanged -= new EventHandler(Content_HiveExperimentsChanged);
62      base.DeregisterContentEvents();
63    }
64
65    protected override void OnContentChanged() {
66      base.OnContentChanged();
67      if (Content == null) {
68        hiveExperimentListView.Content = null;
69      } else {
70        hiveExperimentListView.Content = Content.Jobs;
71        if (Content != null)
72          Content.RefreshAsync(new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
73      }
74    }
75
76    protected override void SetEnabledStateOfControls() {
77      base.SetEnabledStateOfControls();
78      refreshButton.Enabled = Content != null;
79      hiveExperimentListView.Enabled = Content != null;
80    }
81
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      }
90    }
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.Jobs;
96        refreshButton.Enabled = true;
97        hiveExperimentListView.Enabled = true;
98        Cursor = Cursors.Default;
99      }
100    }
101
102    private void refreshButton_Click(object sender, EventArgs e) {
103      Content.RefreshAsync(new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
104    }
105
106    protected override void OnClosing(FormClosingEventArgs e) {
107      base.OnClosing(e);
108      if (Content != null && Content.Jobs != null) {
109        foreach (var exp in Content.Jobs.OfType<RefreshableJob>()) {
110          if (exp.RefreshAutomatically) {
111            exp.RefreshAutomatically = false; // stop result polling
112          }
113        }
114      }
115    }
116
117    private void HiveExperiments_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableJob> e) {
118      foreach (var item in e.Items) {
119        HiveClient.Delete(item);
120      }
121    }
122
123    private void Content_HiveExperimentsChanged(object sender, EventArgs e) {
124      Content.Jobs.ItemsRemoved += new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved);
125    }
126  }
127}
Note: See TracBrowser for help on using the repository browser.