1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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.Clients.Hive.Views {
|
---|
28 | [View("HiveTask View")]
|
---|
29 | [Content(typeof(HiveTask), true)]
|
---|
30 | [Content(typeof(HiveTask<>), false)]
|
---|
31 | public partial class HiveTaskView : ItemView {
|
---|
32 | public new HiveTask Content {
|
---|
33 | get { return (HiveTask)base.Content; }
|
---|
34 | set {
|
---|
35 | if (base.Content != value) {
|
---|
36 | base.Content = value;
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public HiveTaskView() {
|
---|
42 | InitializeComponent();
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void RegisterContentEvents() {
|
---|
46 | base.RegisterContentEvents();
|
---|
47 | Content.ItemTaskChanged += new EventHandler(Content_TaskItemChanged);
|
---|
48 | Content.TaskChanged += new EventHandler(Content_TaskChanged);
|
---|
49 | Content.TaskStateChanged += new EventHandler(Content_TaskStateChanged);
|
---|
50 | Content.StateLogChanged += new EventHandler(Content_StateLogChanged);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void DeregisterContentEvents() {
|
---|
54 | Content.ItemTaskChanged -= new EventHandler(Content_TaskItemChanged);
|
---|
55 | Content.TaskChanged -= new EventHandler(Content_TaskChanged);
|
---|
56 | Content.TaskStateChanged -= new EventHandler(Content_TaskStateChanged);
|
---|
57 | Content.StateLogChanged -= new EventHandler(Content_StateLogChanged);
|
---|
58 | base.DeregisterContentEvents();
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override void OnContentChanged() {
|
---|
62 | base.OnContentChanged();
|
---|
63 | if (Content != null && Content.Task != null) {
|
---|
64 | computeInParallelCheckBox.Checked = Content.ItemTask.ComputeInParallel;
|
---|
65 | } else {
|
---|
66 | computeInParallelCheckBox.Checked = false;
|
---|
67 | }
|
---|
68 | Content_TaskItemChanged(this, EventArgs.Empty);
|
---|
69 | Content_TaskChanged(this, EventArgs.Empty);
|
---|
70 | Content_TaskStateChanged(this, EventArgs.Empty);
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected virtual void RegisterTaskEvents() {
|
---|
74 | if (Content != null && Content.Task != null) {
|
---|
75 | Content.ItemTask.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged);
|
---|
76 | Content.ItemTask.ItemChanged += new EventHandler(Job_ItemChanged);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | protected virtual void DeregisterTaskEvents() {
|
---|
81 | if (Content != null && Content.Task != null) {
|
---|
82 | Content.ItemTask.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged);
|
---|
83 | Content.ItemTask.ItemChanged -= new EventHandler(Job_ItemChanged);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | #region Content Events
|
---|
88 | protected virtual void Content_TaskChanged(object sender, EventArgs e) {
|
---|
89 | if (InvokeRequired) {
|
---|
90 | Invoke(new EventHandler(Content_TaskChanged), sender, e);
|
---|
91 | } else {
|
---|
92 | if (Content != null && Content.Task != null) {
|
---|
93 | this.jobIdTextBox.Text = Content.Task.Id.ToString();
|
---|
94 | this.dateCreatedTextBox.Text = Content.Task.DateCreated.HasValue ? Content.Task.DateCreated.ToString() : string.Empty;
|
---|
95 | if (Content.Task.Priority >= 0 && Content.Task.Priority < priorityComboBox.Items.Count) {
|
---|
96 | this.priorityComboBox.SelectedIndex = Content.Task.Priority;
|
---|
97 | } else {
|
---|
98 | this.priorityComboBox.SelectedIndex = 0;
|
---|
99 | }
|
---|
100 | this.coresNeededComboBox.Text = Content.Task.CoresNeeded.ToString();
|
---|
101 | this.memoryNeededComboBox.Text = Content.Task.MemoryNeeded.ToString();
|
---|
102 | } else {
|
---|
103 | this.jobIdTextBox.Text = string.Empty;
|
---|
104 | this.dateCreatedTextBox.Text = string.Empty;
|
---|
105 | this.priorityComboBox.SelectedIndex = 0;
|
---|
106 | this.coresNeededComboBox.Text = "1";
|
---|
107 | this.memoryNeededComboBox.Text = "128";
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | protected virtual void Content_TaskItemChanged(object sender, EventArgs e) {
|
---|
113 | RegisterTaskEvents();
|
---|
114 | Job_ItemChanged(this, e);
|
---|
115 | }
|
---|
116 |
|
---|
117 | protected virtual void Job_ItemChanged(object sender, EventArgs e) {
|
---|
118 | if (Content != null && Content.Task != null && Content.ItemTask.Item != null) {
|
---|
119 | } else {
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | protected virtual void Content_TaskStateChanged(object sender, EventArgs e) {
|
---|
124 | if (InvokeRequired) {
|
---|
125 | Invoke(new EventHandler(Content_TaskStateChanged), sender, e);
|
---|
126 | } else {
|
---|
127 | if (Content != null && Content.Task != null) {
|
---|
128 | this.stateTextBox.Text = Content.Task.State.ToString();
|
---|
129 | this.commandTextBox.Text = Content.Task.Command.ToString();
|
---|
130 | this.executionTimeTextBox.Text = Content.Task.ExecutionTime.ToString();
|
---|
131 | this.dateFinishedTextBox.Text = Content.Task.DateFinished.ToString();
|
---|
132 | this.exceptionTextBox.Text = Content.Task.CurrentStateLog != null ? Content.Task.CurrentStateLog.Exception : string.Empty;
|
---|
133 | this.lastUpdatedTextBox.Text = Content.Task.LastTaskDataUpdate.ToString();
|
---|
134 | } else {
|
---|
135 | this.stateTextBox.Text = string.Empty;
|
---|
136 | this.commandTextBox.Text = string.Empty;
|
---|
137 | this.executionTimeTextBox.Text = string.Empty;
|
---|
138 | this.dateCalculatedText.Text = string.Empty;
|
---|
139 | this.dateFinishedTextBox.Text = string.Empty;
|
---|
140 | this.exceptionTextBox.Text = string.Empty;
|
---|
141 | this.lastUpdatedTextBox.Text = string.Empty;
|
---|
142 | }
|
---|
143 | Content_StateLogChanged(this, EventArgs.Empty);
|
---|
144 | SetEnabledStateOfControls();
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | protected virtual void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
|
---|
149 | if (InvokeRequired) {
|
---|
150 | Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
|
---|
151 | } else {
|
---|
152 | computeInParallelCheckBox.Checked = Content.ItemTask.ComputeInParallel;
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | protected virtual void Content_StateLogChanged(object sender, EventArgs e) {
|
---|
157 | if (Content != null) {
|
---|
158 | if (Content.ItemTask.ComputeInParallel) {
|
---|
159 | this.stateLogViewHost.Content = Content.ChildStateLogList;
|
---|
160 | } else {
|
---|
161 | this.stateLogViewHost.Content = Content.StateLog;
|
---|
162 | }
|
---|
163 | } else {
|
---|
164 | this.stateLogViewHost.Content = null;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | #endregion
|
---|
168 |
|
---|
169 | #region Child Control Events
|
---|
170 | protected virtual void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
171 | if (Content != null && Content.ItemTask != null) {
|
---|
172 | this.Content.ItemTask.ComputeInParallel = this.computeInParallelCheckBox.Checked;
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | protected virtual void exceptionTextBox_DoubleClick(object sender, EventArgs e) {
|
---|
177 | using (TextDialog dialog = new TextDialog("Exception", exceptionTextBox.Text, ReadOnly || !Content.CanChangeDescription)) {
|
---|
178 | if (dialog.ShowDialog(this) == DialogResult.OK)
|
---|
179 | Content.Description = dialog.Content;
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | protected virtual void modifyItemButton_Click(object sender, EventArgs e) {
|
---|
184 | MainFormManager.MainForm.ShowContent(Content.ItemTask.Item);
|
---|
185 | }
|
---|
186 | #endregion
|
---|
187 |
|
---|
188 | protected override void SetEnabledStateOfControls() {
|
---|
189 | base.SetEnabledStateOfControls();
|
---|
190 | this.jobIdTextBox.ReadOnly = true;
|
---|
191 | this.stateTextBox.ReadOnly = true;
|
---|
192 | this.commandTextBox.ReadOnly = true;
|
---|
193 | this.executionTimeTextBox.ReadOnly = true;
|
---|
194 | this.dateCreatedTextBox.ReadOnly = true;
|
---|
195 | this.dateCalculatedText.ReadOnly = true;
|
---|
196 | this.dateFinishedTextBox.ReadOnly = true;
|
---|
197 | this.exceptionTextBox.ReadOnly = true;
|
---|
198 | this.lastUpdatedTextBox.ReadOnly = true;
|
---|
199 |
|
---|
200 | this.priorityComboBox.Enabled = !this.ReadOnly;
|
---|
201 | this.coresNeededComboBox.Enabled = !this.ReadOnly;
|
---|
202 | this.memoryNeededComboBox.Enabled = !this.ReadOnly;
|
---|
203 | this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.ItemTask != null && this.Content.ItemTask.IsParallelizable;
|
---|
204 |
|
---|
205 | this.modifyItemButton.Enabled = (Content != null && Content.ItemTask.Item != null && (Content.Task.State == TaskState.Paused || Content.Task.State == TaskState.Offline || Content.Task.State == TaskState.Finished || Content.Task.State == TaskState.Failed || Content.Task.State == TaskState.Aborted));
|
---|
206 | }
|
---|
207 |
|
---|
208 | private void priorityComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
209 | if (Content != null && Content.Task != null && Content.Task.Priority != priorityComboBox.SelectedIndex) {
|
---|
210 | Content.Task.Priority = priorityComboBox.SelectedIndex;
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|