Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6168 was 6033, checked in by cneumuel, 14 years ago

#1233

  • created baseclass for jobs (ItemJob) which derives OperatorJobs and EngineJobs
  • created special view for OptimizerJobs which derives from a more general view
  • removed logic from domain class HiveExperiment and moved it into RefreshableHiveExperiment
  • improved ItemTreeView
  • corrected plugin dependencies
  • fixed bug in database trigger when deleting HiveExperiments
  • added delete cascade for Plugin and PluginData
  • lots of fixes
File size: 4.7 KB
RevLine 
[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
22using System;
[6033]23using System.Linq;
[4905]24using System.Windows.Forms;
[6033]25using HeuristicLab.Collections;
[4905]26using HeuristicLab.MainForm;
[5955]27using HeuristicLab.MainForm.WindowsForms;
28using HeuristicLab.PluginInfrastructure;
[4905]29
30namespace 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}
Note: See TracBrowser for help on using the repository browser.