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 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Core.Views;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Hive.ExperimentManager.Views {
|
---|
28 | [View("HiveJob View")]
|
---|
29 | [Content(typeof(HiveJob), true)]
|
---|
30 | public partial class HiveJobView : ItemView {
|
---|
31 | public new HiveJob Content {
|
---|
32 | get { return (HiveJob)base.Content; }
|
---|
33 | set {
|
---|
34 | if (base.Content != value) {
|
---|
35 | base.Content = value;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public HiveJobView() {
|
---|
41 | InitializeComponent();
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected override void RegisterContentEvents() {
|
---|
45 | base.RegisterContentEvents();
|
---|
46 | Content.JobChanged += new EventHandler(Content_JobChanged);
|
---|
47 | Content.JobDtoChanged += new EventHandler(Content_JobDtoChanged);
|
---|
48 | Content.JobStateChanged += new EventHandler(Content_JobStateChanged);
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void DeregisterContentEvents() {
|
---|
52 | Content.JobChanged -= new EventHandler(Content_JobChanged);
|
---|
53 | Content.JobDtoChanged -= new EventHandler(Content_JobDtoChanged);
|
---|
54 | Content.JobStateChanged -= new EventHandler(Content_JobStateChanged);
|
---|
55 | base.DeregisterContentEvents();
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void OnContentChanged() {
|
---|
59 | base.OnContentChanged();
|
---|
60 | if (Content != null && Content.Job != null) {
|
---|
61 | logView.Content = Content.Job.Log;
|
---|
62 | childHiveJobView.Content = Content.ChildHiveJobs;
|
---|
63 | computeInParallelCheckBox.Checked = Content.Job.ComputeInParallel;
|
---|
64 | } else {
|
---|
65 | logView.Content = null;
|
---|
66 | childHiveJobView.Content = null;
|
---|
67 | computeInParallelCheckBox.Checked = false;
|
---|
68 | }
|
---|
69 | Content_JobChanged(this, EventArgs.Empty);
|
---|
70 | Content_JobDtoChanged(this, EventArgs.Empty);
|
---|
71 | Content_JobStateChanged(this, EventArgs.Empty);
|
---|
72 | }
|
---|
73 |
|
---|
74 | void Content_JobChanged(object sender, EventArgs e) {
|
---|
75 | RegisterJobEvents();
|
---|
76 | Job_OptimizerChanged(this, e);
|
---|
77 | }
|
---|
78 |
|
---|
79 | void Job_OptimizerChanged(object sender, EventArgs e) {
|
---|
80 | if (Content != null && Content.Job != null && Content.Job.Optimizer != null) {
|
---|
81 | optimizerNamedItemView.Content = Content.Job.Optimizer;
|
---|
82 | runCollectionViewHost.Content = Content.Job.Optimizer.Runs;
|
---|
83 | } else {
|
---|
84 | optimizerNamedItemView.Content = null;
|
---|
85 | runCollectionViewHost.Content = null;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | private void RegisterJobEvents() {
|
---|
90 | if (Content != null && Content.Job != null) {
|
---|
91 | Content.Job.ComputeInParallelChanged += new EventHandler(Job_ComputeInParallelChanged);
|
---|
92 | Content.Job.OptimizerChanged += new EventHandler(Job_OptimizerChanged);
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | private void DeregisterJobEvents() {
|
---|
97 | if (Content != null && Content.Job != null) {
|
---|
98 | Content.Job.ComputeInParallelChanged -= new EventHandler(Job_ComputeInParallelChanged);
|
---|
99 | Content.Job.OptimizerChanged -= new EventHandler(Job_OptimizerChanged);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | #region Content Events
|
---|
104 | private void Content_JobDtoChanged(object sender, EventArgs e) {
|
---|
105 | if (InvokeRequired) {
|
---|
106 | Invoke(new EventHandler(Content_JobDtoChanged), sender, e);
|
---|
107 | } else {
|
---|
108 | if (Content != null && Content.JobDto != null) {
|
---|
109 | this.jobIdTextBox.Text = Content.JobDto.Id.ToString();
|
---|
110 | this.dateCreatedTextBox.Text = Content.JobDto.DateCreated.ToString();
|
---|
111 | this.priorityTextBox.Text = Content.JobDto.Priority.ToString();
|
---|
112 | this.coresNeededTextBox.Text = Content.JobDto.CoresNeeded.ToString();
|
---|
113 | this.memoryNeededTextBox.Text = Content.JobDto.MemoryNeeded.ToString();
|
---|
114 | } else {
|
---|
115 | this.jobIdTextBox.Text = string.Empty;
|
---|
116 | this.dateCreatedTextBox.Text = string.Empty;
|
---|
117 | this.priorityTextBox.Text = string.Empty;
|
---|
118 | this.coresNeededTextBox.Text = string.Empty;
|
---|
119 | this.memoryNeededTextBox.Text = string.Empty;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | private void Content_JobStateChanged(object sender, EventArgs e) {
|
---|
125 | if (InvokeRequired) {
|
---|
126 | Invoke(new EventHandler(Content_JobStateChanged), sender, e);
|
---|
127 | } else {
|
---|
128 | if (Content != null && Content.JobDto != null) {
|
---|
129 | this.stateTextBox.Text = Content.JobDto.State.ToString();
|
---|
130 | this.executionTimeTextBox.Text = Content.JobDto.ExecutionTime.ToString();
|
---|
131 | this.dateCalculatedText.Text = Content.JobDto.DateCalculated.ToString();
|
---|
132 | this.dateFinishedTextBox.Text = Content.JobDto.DateFinished.ToString();
|
---|
133 | this.exceptionTextBox.Text = Content.JobDto.Exception;
|
---|
134 | } else {
|
---|
135 | this.stateTextBox.Text = string.Empty;
|
---|
136 | this.executionTimeTextBox.Text = string.Empty;
|
---|
137 | this.dateCalculatedText.Text = string.Empty;
|
---|
138 | this.dateFinishedTextBox.Text = string.Empty;
|
---|
139 | this.exceptionTextBox.Text = string.Empty;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | protected override void SetEnabledStateOfControls() {
|
---|
145 | if (InvokeRequired) {
|
---|
146 | this.InvokeIfRequired(c => { SetEnabledStateOfControls(); });
|
---|
147 | } else {
|
---|
148 | base.SetEnabledStateOfControls();
|
---|
149 | this.jobIdTextBox.ReadOnly = true;
|
---|
150 | this.stateTextBox.ReadOnly = true;
|
---|
151 | this.executionTimeTextBox.ReadOnly = true;
|
---|
152 | this.dateCreatedTextBox.ReadOnly = true;
|
---|
153 | this.dateCalculatedText.ReadOnly = true;
|
---|
154 | this.dateFinishedTextBox.ReadOnly = true;
|
---|
155 | this.exceptionTextBox.ReadOnly = true;
|
---|
156 |
|
---|
157 | this.priorityTextBox.ReadOnly = this.ReadOnly;
|
---|
158 | this.coresNeededTextBox.ReadOnly = this.ReadOnly;
|
---|
159 | this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
|
---|
160 | this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.Job != null && this.Content.Job.IsParallelizable;
|
---|
161 |
|
---|
162 | optimizerNamedItemView.ReadOnly = true;
|
---|
163 | ShowOrHideChildJobTabPage();
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | void Job_ComputeInParallelChanged(object sender, EventArgs e) {
|
---|
168 | if (InvokeRequired) {
|
---|
169 | Invoke(new EventHandler(Job_ComputeInParallelChanged), sender, e);
|
---|
170 | } else {
|
---|
171 | computeInParallelCheckBox.Checked = Content.Job.ComputeInParallel;
|
---|
172 | ShowOrHideChildJobTabPage();
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | private void ShowOrHideChildJobTabPage() {
|
---|
177 | if (Content != null && Content.Job != null) {
|
---|
178 | if (!Content.Job.ComputeInParallel) {
|
---|
179 | if (tabControl.TabPages.Contains(childJobsTabPage))
|
---|
180 | tabControl.TabPages.Remove(childJobsTabPage);
|
---|
181 | } else {
|
---|
182 | if (!tabControl.TabPages.Contains(childJobsTabPage))
|
---|
183 | tabControl.TabPages.Insert(1, childJobsTabPage);
|
---|
184 | }
|
---|
185 | }
|
---|
186 | }
|
---|
187 | #endregion
|
---|
188 |
|
---|
189 | private void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
190 | if (Content != null) {
|
---|
191 | this.Content.Job.ComputeInParallel = this.computeInParallelCheckBox.Checked;
|
---|
192 | }
|
---|
193 | }
|
---|
194 | }
|
---|
195 | }
|
---|