Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-MoveOperators/HeuristicLab.Clients.Hive.Slave.Views/3.3/SlaveCmdsBase.cs @ 8309

Last change on this file since 8309 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Windows.Forms;
24using HeuristicLab.Common;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28
29namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
30
31  [View("HeuristicLab Slave Cmds View")]
32  [Content(typeof(SlaveItem), IsDefaultView = false)]
33  public partial class SlaveCmdsBase : ItemView {
34    protected SlaveDisplayStat lastSlaveDisplayStat;
35
36    public new SlaveItem Content {
37      get { return (SlaveItem)base.Content; }
38      set {
39        if (base.Content != value) {
40          base.Content = value;
41        }
42      }
43    }
44
45    public SlaveCmdsBase() {
46      InitializeComponent();
47    }
48
49    #region Register Content Events
50    protected override void DeregisterContentEvents() {
51
52      Content.SlaveDisplayStateChanged -= new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
53      Content.CoreConnectionChanged -= new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
54
55      base.DeregisterContentEvents();
56    }
57
58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
60
61      Content.SlaveDisplayStateChanged += new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
62      Content.CoreConnectionChanged += new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
63    }
64    #endregion
65
66    protected override void OnContentChanged() {
67      base.OnContentChanged();
68      btnStart.Enabled = false;
69      btnStop.Enabled = false;
70    }
71
72    protected override void SetEnabledStateOfControls() {
73      base.SetEnabledStateOfControls();
74    }
75
76    #region Event Handlers
77    protected virtual void Content_SlaveDisplayStateChanged(object sender, EventArgs<SlaveDisplayStat> e) {
78      if (this.InvokeRequired) {
79        Action<object, EventArgs<SlaveDisplayStat>> action = new Action<object, EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
80        Invoke(action, sender, e);
81      } else {
82        lastSlaveDisplayStat = e.Value;
83        if (e.Value == SlaveDisplayStat.Asleep || e.Value == SlaveDisplayStat.NoService) {
84          btnStart.Enabled = true;
85          btnStop.Enabled = false;
86        }
87
88        if (e.Value == SlaveDisplayStat.Busy || e.Value == SlaveDisplayStat.Idle || e.Value == SlaveDisplayStat.Offline) {
89          btnStart.Enabled = false;
90          btnStop.Enabled = true;
91        }
92      }
93    }
94
95    protected virtual void Content_CoreConnectionChanged(object sender, EventArgs<CoreConnection> e) {
96      if (e.Value == CoreConnection.Offline) {
97        btnStart.Enabled = false;
98        btnStop.Enabled = false;
99      }
100    }
101    #endregion
102
103    protected virtual void btnStop_Click(object sender, EventArgs e) {
104      if (Content != null) {
105        Content.Sleep();
106      }
107    }
108
109    protected virtual void btnStart_Click(object sender, EventArgs e) {
110      if (Content != null) {
111        if (lastSlaveDisplayStat == SlaveDisplayStat.Asleep) {
112          Content.RestartCore();
113        }
114      }
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.