Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/HiveTaskView.cs @ 6977

Last change on this file since 6977 was 6976, checked in by ascheibe, 13 years ago

#1672 integrate the Hive client projects into trunk (Hive Job Manager and Administrator)

File size: 8.5 KB
Line 
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
22using System;
23using System.Windows.Forms;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26
27namespace 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          this.priorityComboBox.Text = Content.Task.Priority.ToString();
96          this.coresNeededComboBox.Text = Content.Task.CoresNeeded.ToString();
97          this.memoryNeededComboBox.Text = Content.Task.MemoryNeeded.ToString();
98        } else {
99          this.jobIdTextBox.Text = string.Empty;
100          this.dateCreatedTextBox.Text = string.Empty;
101          this.priorityComboBox.Text = "3";
102          this.coresNeededComboBox.Text = "1";
103          this.memoryNeededComboBox.Text = "256";
104        }
105      }
106    }
107
108    protected virtual void Content_TaskItemChanged(object sender, EventArgs e) {
109      RegisterTaskEvents();
110      Job_ItemChanged(this, e);
111    }
112
113    protected virtual void Job_ItemChanged(object sender, EventArgs e) {
114      if (Content != null && Content.Task != null && Content.ItemTask.Item != null) {
115      } else {
116      }
117    }
118
119    protected virtual void Content_TaskStateChanged(object sender, EventArgs e) {
120      if (InvokeRequired) {
121        Invoke(new EventHandler(Content_TaskStateChanged), sender, e);
122      } else {
123        if (Content != null && Content.Task != null) {
124          this.stateTextBox.Text = Content.Task.State.ToString();
125          this.commandTextBox.Text = Content.Task.Command.ToString();
126          this.executionTimeTextBox.Text = Content.Task.ExecutionTime.ToString();
127          this.dateFinishedTextBox.Text = Content.Task.DateFinished.ToString();
128          this.exceptionTextBox.Text = Content.Task.CurrentStateLog != null ? Content.Task.CurrentStateLog.Exception : string.Empty;
129          this.lastUpdatedTextBox.Text = Content.Task.LastTaskDataUpdate.ToString();
130        } else {
131          this.stateTextBox.Text = string.Empty;
132          this.commandTextBox.Text = string.Empty;
133          this.executionTimeTextBox.Text = string.Empty;
134          this.dateCalculatedText.Text = string.Empty;
135          this.dateFinishedTextBox.Text = string.Empty;
136          this.exceptionTextBox.Text = string.Empty;
137          this.lastUpdatedTextBox.Text = string.Empty;
138        }
139        Content_StateLogChanged(this, EventArgs.Empty);
140        SetEnabledStateOfControls();
141      }
142    }
143
144    protected virtual void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
145      if (InvokeRequired) {
146        Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
147      } else {
148        computeInParallelCheckBox.Checked = Content.ItemTask.ComputeInParallel;
149      }
150    }
151
152    protected virtual void Content_StateLogChanged(object sender, EventArgs e) {
153      if (Content != null) {
154        if (Content.ItemTask.ComputeInParallel) {
155          this.stateLogViewHost.Content = Content.ChildStateLogList;
156        } else {
157          this.stateLogViewHost.Content = Content.StateLog;
158        }
159      } else {
160        this.stateLogViewHost.Content = null;
161      }
162    }
163    #endregion
164
165    #region Child Control Events
166    protected virtual void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
167      if (Content != null && Content.ItemTask != null) {
168        this.Content.ItemTask.ComputeInParallel = this.computeInParallelCheckBox.Checked;
169      }
170    }
171
172    protected virtual void exceptionTextBox_DoubleClick(object sender, EventArgs e) {
173      using (TextDialog dialog = new TextDialog("Exception", exceptionTextBox.Text, ReadOnly || !Content.CanChangeDescription)) {
174        if (dialog.ShowDialog(this) == DialogResult.OK)
175          Content.Description = dialog.Content;
176      }
177    }
178
179    protected virtual void modifyItemButton_Click(object sender, EventArgs e) {
180      MainFormManager.MainForm.ShowContent(Content.ItemTask.Item);
181    }
182    #endregion
183
184    protected override void SetEnabledStateOfControls() {
185      base.SetEnabledStateOfControls();
186      this.jobIdTextBox.ReadOnly = true;
187      this.stateTextBox.ReadOnly = true;
188      this.commandTextBox.ReadOnly = true;
189      this.executionTimeTextBox.ReadOnly = true;
190      this.dateCreatedTextBox.ReadOnly = true;
191      this.dateCalculatedText.ReadOnly = true;
192      this.dateFinishedTextBox.ReadOnly = true;
193      this.exceptionTextBox.ReadOnly = true;
194      this.lastUpdatedTextBox.ReadOnly = true;
195
196      this.priorityComboBox.Enabled = !this.ReadOnly;
197      this.coresNeededComboBox.Enabled = !this.ReadOnly;
198      this.memoryNeededComboBox.Enabled = !this.ReadOnly;
199      this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.ItemTask != null && this.Content.ItemTask.IsParallelizable;
200
201      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));
202    }
203  }
204}
Note: See TracBrowser for help on using the repository browser.