[4905] | 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 |
|
---|
| 22 | using System;
|
---|
[5597] | 23 | using System.Linq;
|
---|
[4905] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
| 28 | namespace 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 |
|
---|
[5793] | 73 | protected void Content_OptimizerJobChanged(object sender, EventArgs e) {
|
---|
[4905] | 74 | RegisterJobEvents();
|
---|
| 75 | Job_OptimizerChanged(this, e);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[5793] | 78 | protected void Job_OptimizerChanged(object sender, EventArgs e) {
|
---|
[4905] | 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();
|
---|
[5779] | 109 | this.dateCreatedTextBox.Text = Content.Job.DateCreated.HasValue ? Content.Job.DateCreated.ToString() : string.Empty;
|
---|
[4905] | 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) {
|
---|
[5511] | 128 | this.stateTextBox.Text = Content.Job.State.ToString();
|
---|
[4905] | 129 | this.executionTimeTextBox.Text = Content.Job.ExecutionTime.ToString();
|
---|
| 130 | this.dateFinishedTextBox.Text = Content.Job.DateFinished.ToString();
|
---|
[5779] | 131 | this.exceptionTextBox.Text = Content.Job.CurrentStateLog != null ? Content.Job.CurrentStateLog.Exception : string.Empty;
|
---|
[5793] | 132 | this.lastUpdatedTextBox.Text = Content.Job.LastJobDataUpdate.ToString();
|
---|
[5597] | 133 | if (Content.OptimizerJob.ComputeInParallel) {
|
---|
[5718] | 134 | this.stateLogViewHost.Content = new StateLogListList(
|
---|
[5636] | 135 | this.Content.ChildHiveJobs.Select(child => new StateLogList(child.Job.StateLog)
|
---|
[5597] | 136 | ));
|
---|
| 137 | } else {
|
---|
[5636] | 138 | this.stateLogViewHost.Content = new StateLogList(Content.Job.StateLog);
|
---|
[5597] | 139 | }
|
---|
[4905] | 140 | } else {
|
---|
| 141 | this.stateTextBox.Text = string.Empty;
|
---|
| 142 | this.executionTimeTextBox.Text = string.Empty;
|
---|
| 143 | this.dateCalculatedText.Text = string.Empty;
|
---|
| 144 | this.dateFinishedTextBox.Text = string.Empty;
|
---|
| 145 | this.exceptionTextBox.Text = string.Empty;
|
---|
[5597] | 146 | this.stateLogViewHost.Content = null;
|
---|
[5793] | 147 | this.lastUpdatedTextBox.Text = string.Empty;
|
---|
[4905] | 148 | }
|
---|
[5779] | 149 | SetEnabledStateOfControls();
|
---|
[4905] | 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | protected override void SetEnabledStateOfControls() {
|
---|
| 154 | base.SetEnabledStateOfControls();
|
---|
| 155 | this.jobIdTextBox.ReadOnly = true;
|
---|
| 156 | this.stateTextBox.ReadOnly = true;
|
---|
| 157 | this.executionTimeTextBox.ReadOnly = true;
|
---|
| 158 | this.dateCreatedTextBox.ReadOnly = true;
|
---|
| 159 | this.dateCalculatedText.ReadOnly = true;
|
---|
| 160 | this.dateFinishedTextBox.ReadOnly = true;
|
---|
| 161 | this.exceptionTextBox.ReadOnly = true;
|
---|
[5793] | 162 | this.lastUpdatedTextBox.ReadOnly = true;
|
---|
[4905] | 163 |
|
---|
| 164 | this.priorityTextBox.ReadOnly = this.ReadOnly;
|
---|
| 165 | this.coresNeededTextBox.ReadOnly = this.ReadOnly;
|
---|
| 166 | this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
|
---|
| 167 | this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.OptimizerJob != null && this.Content.OptimizerJob.IsParallelizable;
|
---|
| 168 |
|
---|
[5779] | 169 | this.restartButton.Enabled = Content != null && Content.Job.State == JobState.Paused;
|
---|
| 170 | this.pauseButton.Enabled = Content != null && Content.Job.State == JobState.Calculating;
|
---|
| 171 | this.stopButton.Enabled = Content != null && (Content.Job.State == JobState.Calculating || Content.Job.State == JobState.Waiting || Content.Job.State == JobState.Paused);
|
---|
[5793] | 172 | this.showOptimizerButton.Enabled = Content != null && Content.Job.State == JobState.Paused && Content.OptimizerJob != null && Content.OptimizerJob.Optimizer != null;
|
---|
[5779] | 173 |
|
---|
[4905] | 174 | optimizerNamedItemView.ReadOnly = true;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
|
---|
| 178 | if (InvokeRequired) {
|
---|
| 179 | Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
|
---|
| 180 | } else {
|
---|
| 181 | computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | #endregion
|
---|
| 185 |
|
---|
| 186 | private void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 187 | if (Content != null && Content.OptimizerJob != null) {
|
---|
| 188 | this.Content.OptimizerJob.ComputeInParallel = this.computeInParallelCheckBox.Checked;
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
[5779] | 191 |
|
---|
| 192 | private void exceptionTextBox_DoubleClick(object sender, EventArgs e) {
|
---|
| 193 | using (TextDialog dialog = new TextDialog("Exception", exceptionTextBox.Text, ReadOnly || !Content.CanChangeDescription)) {
|
---|
| 194 | if (dialog.ShowDialog(this) == DialogResult.OK)
|
---|
| 195 | Content.Description = dialog.Content;
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | private void restartButton_Click(object sender, EventArgs e) {
|
---|
| 200 | Content.Restart();
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
| 204 | Content.Pause();
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
| 208 | Content.Stop();
|
---|
| 209 | }
|
---|
[5793] | 210 | private void showOptimizerButton_Click(object sender, EventArgs e) {
|
---|
| 211 | MainFormManager.MainForm.ShowContent(Content.OptimizerJob.Optimizer);
|
---|
| 212 | }
|
---|
[4905] | 213 | }
|
---|
| 214 | }
|
---|