Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Clients.Hive.Views/3.3/ExperimentManager/HiveExperimentManagerView.cs @ 4949

Last change on this file since 4949 was 4905, checked in by cneumuel, 14 years ago

#1233

  • added plugin management features
  • took over client-GUI from old branch
  • merged with bugfixes from old branch
  • added hive-web (for IIS)
File size: 4.2 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.Clients.Hive.Views {
30  /// <summary>
31  /// The base class for visual representations of items.
32  /// </summary>
33  [View("Hive Experiment Manager View")]
34  [Content(typeof(HiveExperimentManagerClient), true)]
35  public sealed partial class HiveExperimentManagerView : ItemView {
36    private ProgressView progressView;
37
38    public new HiveExperimentManagerClient Content {
39      get { return (HiveExperimentManagerClient)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      if(Content != null) UpdateExperimentsAsync();
56    }
57
58    protected override void RegisterContentEvents() {
59      this.Content.HiveExperimentsChanged += new EventHandler(Content_HiveExperimentsChanged);
60      this.Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged);
61    }
62
63    protected override void DeregisterContentEvents() {
64      this.Content.HiveExperimentsChanged -= new EventHandler(Content_HiveExperimentsChanged);
65      this.Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged);
66    }
67
68    private void Content_HiveExperimentsChanged(object sender, EventArgs e) {
69      if (Content != null) {
70        this.hiveExperimentListView.Content = Content.HiveExperiments;
71      }
72    }
73
74    protected override void SetEnabledStateOfControls() {
75      base.SetEnabledStateOfControls();
76      updateExperimentsPanel.Visible = Content != null && Content.HiveExperiments == null;
77
78    }
79
80    private void updateExperimentsButton_Click(object sender, EventArgs e) {
81      if(Content != null) UpdateExperimentsAsync();
82    }
83
84    private void Content_IsProgressingChanged(object sender, EventArgs e) {
85      if (this.InvokeRequired) {
86        Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
87      } else {
88        if (Content != null && Content.IsProgressing) {
89          SetProgressView();
90        } else {
91          FinishProgressView();
92        }
93      }
94    }
95
96    private void SetProgressView() {
97      if (progressView == null) {
98        progressView = new ProgressView(this, Content.Progress);
99      } else {
100        progressView.Progress = Content.Progress;
101      }
102    }
103
104    private void FinishProgressView() {
105      if (progressView != null) {
106        progressView.Finish();
107        progressView = null;
108        SetEnabledStateOfControls();
109      }
110    }
111
112    private void UpdateExperimentsAsync() {
113      MethodInvoker invoker = new MethodInvoker(Content.UpdateExperimentList);
114      invoker.BeginInvoke((ar) => {
115        try {
116          invoker.EndInvoke(ar);
117        }
118        catch (Exception ex) {
119          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
120        }
121      }, null);
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.