Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/HiveJobView.cs @ 5779

Last change on this file since 5779 was 5779, checked in by cneumuel, 14 years ago

#1233

  • implemented pause, stop for single jobs
  • introduced Command property for jobs (to distinguish between state and command (abort vs. aborted))
  • improved behaviour of ItemTreeView (double click opens new window, selected item stays marked)
  • fixed bugs in StateLogGanttChartListView and HiveJobView
  • fixed cloning of client-side dtos
File size: 8.4 KB
Line 
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
22using System;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Clients.Hive.Views {
29  [View("HiveJob View")]
30  [Content(typeof(HiveJob), true)]
31  public partial class HiveJobView : ItemView {
32    public new HiveJob Content {
33      get { return (HiveJob)base.Content; }
34      set {
35        if (base.Content != value) {
36          base.Content = value;
37        }
38      }
39    }
40
41    public HiveJobView() {
42      InitializeComponent();
43    }
44
45    protected override void RegisterContentEvents() {
46      base.RegisterContentEvents();
47      Content.OptimizerJobChanged += new EventHandler(Content_OptimizerJobChanged);
48      Content.JobChanged += new EventHandler(Content_JobChanged);
49      Content.JobStateChanged += new EventHandler(Content_JobStateChanged);
50    }
51
52    protected override void DeregisterContentEvents() {
53      Content.OptimizerJobChanged -= new EventHandler(Content_OptimizerJobChanged);
54      Content.JobChanged -= new EventHandler(Content_JobChanged);
55      Content.JobStateChanged -= new EventHandler(Content_JobStateChanged);
56      base.DeregisterContentEvents();
57    }
58
59    protected override void OnContentChanged() {
60      base.OnContentChanged();
61      if (Content != null && Content.Job != null) {
62        logView.Content = Content.OptimizerJob.Log;
63        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
64      } else {
65        logView.Content = null;
66        computeInParallelCheckBox.Checked = false;
67      }
68      Content_OptimizerJobChanged(this, EventArgs.Empty);
69      Content_JobChanged(this, EventArgs.Empty);
70      Content_JobStateChanged(this, EventArgs.Empty);
71    }
72
73    void Content_OptimizerJobChanged(object sender, EventArgs e) {
74      RegisterJobEvents();
75      Job_OptimizerChanged(this, e);
76    }
77
78    void Job_OptimizerChanged(object sender, EventArgs e) {
79      if (Content != null && Content.Job != null && Content.OptimizerJob.Optimizer != null) {
80        optimizerNamedItemView.Content = Content.OptimizerJob.Optimizer;
81        runCollectionViewHost.Content = Content.OptimizerJob.Optimizer.Runs;
82      } else {
83        optimizerNamedItemView.Content = null;
84        runCollectionViewHost.Content = null;
85      }
86    }
87
88    private void RegisterJobEvents() {
89      if (Content != null && Content.Job != null) {
90        Content.OptimizerJob.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged);
91        Content.OptimizerJob.OptimizerChanged += new EventHandler(Job_OptimizerChanged);
92      }
93    }
94
95    private void DeregisterJobEvents() {
96      if (Content != null && Content.Job != null) {
97        Content.OptimizerJob.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged);
98        Content.OptimizerJob.OptimizerChanged -= new EventHandler(Job_OptimizerChanged);
99      }
100    }
101
102    #region Content Events
103    private void Content_JobChanged(object sender, EventArgs e) {
104      if (InvokeRequired) {
105        Invoke(new EventHandler(Content_JobChanged), sender, e);
106      } else {
107        if (Content != null && Content.Job != null) {
108          this.jobIdTextBox.Text = Content.Job.Id.ToString();
109          this.dateCreatedTextBox.Text = Content.Job.DateCreated.HasValue ? Content.Job.DateCreated.ToString() : string.Empty;
110          this.priorityTextBox.Text = Content.Job.Priority.ToString();
111          this.coresNeededTextBox.Text = Content.Job.CoresNeeded.ToString();
112          this.memoryNeededTextBox.Text = Content.Job.MemoryNeeded.ToString();
113        } else {
114          this.jobIdTextBox.Text = string.Empty;
115          this.dateCreatedTextBox.Text = string.Empty;
116          this.priorityTextBox.Text = string.Empty;
117          this.coresNeededTextBox.Text = string.Empty;
118          this.memoryNeededTextBox.Text = string.Empty;
119        }
120      }
121    }
122
123    private void Content_JobStateChanged(object sender, EventArgs e) {
124      if (InvokeRequired) {
125        Invoke(new EventHandler(Content_JobStateChanged), sender, e);
126      } else {
127        if (Content != null && Content.Job != null) {
128          this.stateTextBox.Text = Content.Job.State.ToString();
129          this.executionTimeTextBox.Text = Content.Job.ExecutionTime.ToString();
130          this.dateFinishedTextBox.Text = Content.Job.DateFinished.ToString();
131          this.exceptionTextBox.Text = Content.Job.CurrentStateLog != null ? Content.Job.CurrentStateLog.Exception : string.Empty;
132          if (Content.OptimizerJob.ComputeInParallel) {
133            this.stateLogViewHost.Content = new StateLogListList(
134                this.Content.ChildHiveJobs.Select(child => new StateLogList(child.Job.StateLog)
135              ));
136          } else {
137            this.stateLogViewHost.Content = new StateLogList(Content.Job.StateLog);
138          }
139        } else {
140          this.stateTextBox.Text = string.Empty;
141          this.executionTimeTextBox.Text = string.Empty;
142          this.dateCalculatedText.Text = string.Empty;
143          this.dateFinishedTextBox.Text = string.Empty;
144          this.exceptionTextBox.Text = string.Empty;
145          this.stateLogViewHost.Content = null;
146        }
147        SetEnabledStateOfControls();
148      }
149    }
150
151    protected override void SetEnabledStateOfControls() {
152      base.SetEnabledStateOfControls();
153      this.jobIdTextBox.ReadOnly = true;
154      this.stateTextBox.ReadOnly = true;
155      this.executionTimeTextBox.ReadOnly = true;
156      this.dateCreatedTextBox.ReadOnly = true;
157      this.dateCalculatedText.ReadOnly = true;
158      this.dateFinishedTextBox.ReadOnly = true;
159      this.exceptionTextBox.ReadOnly = true;
160
161      this.priorityTextBox.ReadOnly = this.ReadOnly;
162      this.coresNeededTextBox.ReadOnly = this.ReadOnly;
163      this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
164      this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.OptimizerJob != null && this.Content.OptimizerJob.IsParallelizable;
165
166      this.restartButton.Enabled = Content != null && Content.Job.State == JobState.Paused;
167      this.pauseButton.Enabled = Content != null && Content.Job.State == JobState.Calculating;
168      this.stopButton.Enabled = Content != null && (Content.Job.State == JobState.Calculating || Content.Job.State == JobState.Waiting || Content.Job.State == JobState.Paused);
169
170      optimizerNamedItemView.ReadOnly = true;
171    }
172
173    void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
174      if (InvokeRequired) {
175        Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
176      } else {
177        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
178      }
179    }
180    #endregion
181
182    private void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
183      if (Content != null && Content.OptimizerJob != null) {
184        this.Content.OptimizerJob.ComputeInParallel = this.computeInParallelCheckBox.Checked;
185      }
186    }
187
188    private void exceptionTextBox_DoubleClick(object sender, EventArgs e) {
189      using (TextDialog dialog = new TextDialog("Exception", exceptionTextBox.Text, ReadOnly || !Content.CanChangeDescription)) {
190        if (dialog.ShowDialog(this) == DialogResult.OK)
191          Content.Description = dialog.Content;
192      }
193    }
194
195    private void restartButton_Click(object sender, EventArgs e) {
196      Content.Restart();
197    }
198
199    private void pauseButton_Click(object sender, EventArgs e) {
200      Content.Pause();
201    }
202
203    private void stopButton_Click(object sender, EventArgs e) {
204      Content.Stop();
205    }
206  }
207}
Note: See TracBrowser for help on using the repository browser.