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 HeuristicLab.Core.Views; |
---|
24 | using HeuristicLab.MainForm; |
---|
25 | |
---|
26 | namespace HeuristicLab.HiveEngine.Views { |
---|
27 | [View("Hive Engine View")] |
---|
28 | [Content(typeof(HiveEngine), IsDefaultView = true)] |
---|
29 | public sealed partial class HiveEngineView : ItemView { |
---|
30 | public new HiveEngine Content { |
---|
31 | get { return (HiveEngine)base.Content; } |
---|
32 | set { base.Content = value; } |
---|
33 | } |
---|
34 | |
---|
35 | public HiveEngineView() { |
---|
36 | InitializeComponent(); |
---|
37 | } |
---|
38 | |
---|
39 | protected override void DeregisterContentEvents() { |
---|
40 | Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); |
---|
41 | Content.ExecutionTimeOnHiveChanged -= new EventHandler(Content_ExecutionTimeOnHiveChanged); |
---|
42 | base.DeregisterContentEvents(); |
---|
43 | } |
---|
44 | |
---|
45 | protected override void RegisterContentEvents() { |
---|
46 | base.RegisterContentEvents(); |
---|
47 | Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); |
---|
48 | Content.ExecutionTimeOnHiveChanged += new EventHandler(Content_ExecutionTimeOnHiveChanged); |
---|
49 | } |
---|
50 | |
---|
51 | #region Event Handlers (Content) |
---|
52 | private void Content_ExecutionStateChanged(object sender, EventArgs e) { |
---|
53 | if (InvokeRequired) { |
---|
54 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); |
---|
55 | } else { |
---|
56 | executionTimeTextBox.Text = Content.ExecutionTime.ToString(); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | private void Content_ExecutionTimeOnHiveChanged(object sender, EventArgs e) { |
---|
61 | if (InvokeRequired) { |
---|
62 | Invoke(new EventHandler(Content_ExecutionTimeOnHiveChanged), sender, e); |
---|
63 | } else { |
---|
64 | executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString(); |
---|
65 | } |
---|
66 | } |
---|
67 | #endregion |
---|
68 | |
---|
69 | protected override void OnContentChanged() { |
---|
70 | base.OnContentChanged(); |
---|
71 | if (Content == null) { |
---|
72 | resourceIdsTextBox.Text = string.Empty; |
---|
73 | priorityTextBox.Text = string.Empty; |
---|
74 | executionTimeOnHiveTextBox.Text = string.Empty; |
---|
75 | isPrivilegedCheckBox.Checked = false; |
---|
76 | hiveExperimentListView.Content = null; |
---|
77 | logView.Content = null; |
---|
78 | } else { |
---|
79 | resourceIdsTextBox.Text = Content.ResourceNames; |
---|
80 | priorityTextBox.Text = Content.Priority.ToString(); |
---|
81 | executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString(); |
---|
82 | isPrivilegedCheckBox.Checked = Content.IsPrivileged; |
---|
83 | hiveExperimentListView.Content = Content.HiveExperiments; |
---|
84 | logView.Content = Content.Log; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | protected override void SetEnabledStateOfControls() { |
---|
89 | base.SetEnabledStateOfControls(); |
---|
90 | // Enable or disable controls based on whether the content is null or the view is set readonly |
---|
91 | if (Content != null) { |
---|
92 | resourceIdsTextBox.ReadOnly = this.ReadOnly; |
---|
93 | priorityTextBox.ReadOnly = this.ReadOnly; |
---|
94 | isPrivilegedCheckBox.Enabled = !this.ReadOnly; // TODO: check for user rights |
---|
95 | } else { |
---|
96 | resourceIdsTextBox.ReadOnly = false; |
---|
97 | priorityTextBox.ReadOnly = false; |
---|
98 | isPrivilegedCheckBox.Enabled = false; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | #region Event Handlers (child controls) |
---|
103 | private void resourceIdsTextBox_Validated(object sender, EventArgs e) { |
---|
104 | Content.ResourceNames = resourceIdsTextBox.Text; |
---|
105 | } |
---|
106 | |
---|
107 | private void priorityTextBox_Validated(object sender, EventArgs e) { |
---|
108 | Content.Priority = int.Parse(priorityTextBox.Text); |
---|
109 | } |
---|
110 | |
---|
111 | private void isPrivilegedCheckBox_CheckedChanged(object sender, EventArgs e) { |
---|
112 | Content.IsPrivileged = isPrivilegedCheckBox.Checked; |
---|
113 | } |
---|
114 | #endregion |
---|
115 | |
---|
116 | |
---|
117 | } |
---|
118 | } |
---|