Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.ExperimentManager.Views/3.3/HiveExperimentManagerView.cs @ 4760

Last change on this file since 4760 was 4760, checked in by cneumuel, 13 years ago

#1260

  • finished renaming of Hive.Experiment to Hive.ExperimentManager
  • renamed HiveClient to HiveExperimentManager
  • restructured menuitems in optimizer
File size: 4.1 KB
Line 
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
22using System;
23using System.Threading;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.PluginInfrastructure;
28
29namespace HeuristicLab.Hive.ExperimentManager.Views {
30  /// <summary>
31  /// The base class for visual representations of items.
32  /// </summary>
33  [View("Hive Experiment Manager View")]
34  [Content(typeof(HiveExperimentManager), true)]
35  public sealed partial class HiveExperimentManagerView : ItemView {
36    private ProgressView progressView;
37
38    public new HiveExperimentManager Content {
39      get { return (HiveExperimentManager)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      updateExperimentsPanel.Dock = DockStyle.Fill;
49    }
50
51    protected override void OnContentChanged() {
52      base.OnContentChanged();
53      Content_HiveExperimentsChanged(this, EventArgs.Empty);
54      Content_IsProgressingChanged(this, EventArgs.Empty);
55    }
56
57    protected override void RegisterContentEvents() {
58      this.Content.HiveExperimentsChanged += new EventHandler(Content_HiveExperimentsChanged);
59      this.Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged);
60    }
61
62    protected override void DeregisterContentEvents() {
63      this.Content.HiveExperimentsChanged -= new EventHandler(Content_HiveExperimentsChanged);
64      this.Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged);
65    }
66
67    private void Content_HiveExperimentsChanged(object sender, EventArgs e) {
68      if (Content != null) {
69        this.hiveExperimentListView.Content = Content.HiveExperiments;
70      }
71    }
72
73    protected override void SetEnabledStateOfControls() {
74      base.SetEnabledStateOfControls();
75      updateExperimentsPanel.Visible = Content != null && Content.HiveExperiments == null;
76
77    }
78
79    private void updateExperimentsButton_Click(object sender, EventArgs e) {
80      MethodInvoker invoker = new MethodInvoker(Content.UpdateExperimentList);
81      invoker.BeginInvoke((ar) => {
82        try {
83          invoker.EndInvoke(ar);
84        }
85        catch (Exception ex) {
86          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
87        }
88      }, null);
89    }
90
91    private void Content_IsProgressingChanged(object sender, EventArgs e) {
92      if (this.InvokeRequired) {
93        Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
94      } else {
95        if (Content != null && Content.IsProgressing) {
96          SetProgressView();
97        } else {
98          FinishProgressView();
99        }
100      }
101    }
102
103    private void SetProgressView() {
104      if (progressView == null) {
105        progressView = new ProgressView(this, Content.Progress);
106      } else {
107        progressView.Progress = Content.Progress;
108      }
109    }
110
111    private void FinishProgressView() {
112      if (progressView != null) {
113        progressView.Finish();
114        progressView = null;
115        SetEnabledStateOfControls();
116      }
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.