Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Clients.Hive.Views/3.3/ExperimentManager/HiveJobView.cs @ 4949

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

#1233

  • added plugin management features
  • took over client-GUI from old branch
  • merged with bugfixes from old branch
  • added hive-web (for IIS)
File size: 7.6 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.Windows.Forms;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.Clients.Hive.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.OptimizerJobChanged += new EventHandler(Content_OptimizerJobChanged);
47      Content.JobChanged += new EventHandler(Content_JobChanged);
48      Content.JobStateChanged += new EventHandler(Content_JobStateChanged);
49    }
50
51    protected override void DeregisterContentEvents() {
52      Content.OptimizerJobChanged -= new EventHandler(Content_OptimizerJobChanged);
53      Content.JobChanged -= new EventHandler(Content_JobChanged);
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.OptimizerJob.Log;
62        childHiveJobView.Content = Content.ChildHiveJobs;
63        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
64      } else {
65        logView.Content = null;
66        childHiveJobView.Content = null;
67        computeInParallelCheckBox.Checked = false;
68      }
69      Content_OptimizerJobChanged(this, EventArgs.Empty);
70      Content_JobChanged(this, EventArgs.Empty);
71      Content_JobStateChanged(this, EventArgs.Empty);
72    }
73
74    void Content_OptimizerJobChanged(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.OptimizerJob.Optimizer != null) {
81        optimizerNamedItemView.Content = Content.OptimizerJob.Optimizer;
82        runCollectionViewHost.Content = Content.OptimizerJob.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.OptimizerJob.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged);
92        Content.OptimizerJob.OptimizerChanged += new EventHandler(Job_OptimizerChanged);
93      }
94    }
95
96    private void DeregisterJobEvents() {
97      if (Content != null && Content.Job != null) {
98        Content.OptimizerJob.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged);
99        Content.OptimizerJob.OptimizerChanged -= new EventHandler(Job_OptimizerChanged);
100      }
101    }
102
103    #region Content Events
104    private void Content_JobChanged(object sender, EventArgs e) {
105      if (InvokeRequired) {
106        Invoke(new EventHandler(Content_JobChanged), sender, e);
107      } else {
108        if (Content != null && Content.Job != null) {
109          this.jobIdTextBox.Text = Content.Job.Id.ToString();
110          this.dateCreatedTextBox.Text = Content.Job.DateCreated.ToString();
111          this.priorityTextBox.Text = Content.Job.Priority.ToString();
112          this.coresNeededTextBox.Text = Content.Job.CoresNeeded.ToString();
113          this.memoryNeededTextBox.Text = Content.Job.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.Job != null) {
129          this.stateTextBox.Text = Content.Job.JobState.ToString();
130          this.executionTimeTextBox.Text = Content.Job.ExecutionTime.ToString();
131          this.dateCalculatedText.Text = Content.Job.DateCalculated.ToString();
132          this.dateFinishedTextBox.Text = Content.Job.DateFinished.ToString();
133          this.exceptionTextBox.Text = Content.Job.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      base.SetEnabledStateOfControls();
146      this.jobIdTextBox.ReadOnly = true;
147      this.stateTextBox.ReadOnly = true;
148      this.executionTimeTextBox.ReadOnly = true;
149      this.dateCreatedTextBox.ReadOnly = true;
150      this.dateCalculatedText.ReadOnly = true;
151      this.dateFinishedTextBox.ReadOnly = true;
152      this.exceptionTextBox.ReadOnly = true;
153
154      this.priorityTextBox.ReadOnly = this.ReadOnly;
155      this.coresNeededTextBox.ReadOnly = this.ReadOnly;
156      this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
157      this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.OptimizerJob != null && this.Content.OptimizerJob.IsParallelizable;
158
159      optimizerNamedItemView.ReadOnly = true;
160      ShowOrHideChildJobTabPage();
161    }
162
163    void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
164      if (InvokeRequired) {
165        Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
166      } else {
167        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
168        ShowOrHideChildJobTabPage();
169      }
170    }
171
172    private void ShowOrHideChildJobTabPage() {
173      if (Content != null && Content.OptimizerJob != null) {
174        if (!Content.OptimizerJob.ComputeInParallel) {
175          if (tabControl.TabPages.Contains(childJobsTabPage))
176            tabControl.TabPages.Remove(childJobsTabPage);
177        } else {
178          if (!tabControl.TabPages.Contains(childJobsTabPage))
179            tabControl.TabPages.Insert(1, childJobsTabPage);
180        }
181      }
182    }
183    #endregion
184
185    private void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
186      if (Content != null && Content.OptimizerJob != null) {
187        this.Content.OptimizerJob.ComputeInParallel = this.computeInParallelCheckBox.Checked;
188      }
189    }
190  }
191}
Note: See TracBrowser for help on using the repository browser.