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 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 |
|
---|
28 |
|
---|
29 | namespace 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 | lastSlaveDisplayStat = e.Value;
|
---|
79 |
|
---|
80 | if (e.Value == SlaveDisplayStat.Asleep || e.Value == SlaveDisplayStat.NoService) {
|
---|
81 | btnStart.Enabled = true;
|
---|
82 | btnStop.Enabled = false;
|
---|
83 | }
|
---|
84 |
|
---|
85 | if (e.Value == SlaveDisplayStat.Busy || e.Value == SlaveDisplayStat.Idle || e.Value == SlaveDisplayStat.Offline) {
|
---|
86 | btnStart.Enabled = false;
|
---|
87 | btnStop.Enabled = true;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected virtual void Content_CoreConnectionChanged(object sender, EventArgs<CoreConnection> e) {
|
---|
92 | if (e.Value == CoreConnection.Offline) {
|
---|
93 | btnStart.Enabled = false;
|
---|
94 | btnStop.Enabled = false;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | #endregion
|
---|
98 |
|
---|
99 | protected virtual void btnStop_Click(object sender, EventArgs e) {
|
---|
100 | if (Content != null) {
|
---|
101 | Content.Sleep();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | protected virtual void btnStart_Click(object sender, EventArgs e) {
|
---|
106 | if (Content != null) {
|
---|
107 | if (lastSlaveDisplayStat == SlaveDisplayStat.Asleep) {
|
---|
108 | Content.RestartCore();
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|