Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/HiveTaskView.cs @ 6727

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

#1233 the last bunch of renames, hopefully

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