[4116] | 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;
|
---|
| 23 | using System.Windows.Forms;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.PluginInfrastructure;
|
---|
| 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Optimization.Views;
|
---|
[4305] | 31 | using HeuristicLab.Hive.Experiment.Properties;
|
---|
[4116] | 32 |
|
---|
| 33 | namespace HeuristicLab.Hive.Experiment.Views {
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// The base class for visual representations of items.
|
---|
| 36 | /// </summary>
|
---|
| 37 | [View("Experiment View")]
|
---|
| 38 | [Content(typeof(HiveExperiment), true)]
|
---|
| 39 | public sealed partial class HiveExperimentView : NamedItemView {
|
---|
| 40 | public new HiveExperiment Content {
|
---|
| 41 | get { return (HiveExperiment)base.Content; }
|
---|
| 42 | set { base.Content = value; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | /// <summary>
|
---|
| 46 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 47 | /// </summary>
|
---|
| 48 | public HiveExperimentView() {
|
---|
| 49 | InitializeComponent();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void DeregisterContentEvents() {
|
---|
| 53 | Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
| 54 | Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
|
---|
| 55 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
| 56 | Content.Prepared -= new EventHandler(Content_Prepared);
|
---|
| 57 | Content.Started -= new EventHandler(Content_Started);
|
---|
| 58 | Content.Paused -= new EventHandler(Content_Paused);
|
---|
| 59 | Content.Stopped -= new EventHandler(Content_Stopped);
|
---|
| 60 | Content.ExperimentChanged -= new EventHandler(Content_ExperimentChanged);
|
---|
[4133] | 61 | Content.IsResultsPollingChanged -= new EventHandler(Content_IsResultsPollingChanged);
|
---|
[4116] | 62 | base.DeregisterContentEvents();
|
---|
| 63 | }
|
---|
[4133] | 64 |
|
---|
[4116] | 65 | protected override void RegisterContentEvents() {
|
---|
| 66 | base.RegisterContentEvents();
|
---|
| 67 | Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
| 68 | Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
|
---|
| 69 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
| 70 | Content.Prepared += new EventHandler(Content_Prepared);
|
---|
| 71 | Content.Started += new EventHandler(Content_Started);
|
---|
| 72 | Content.Paused += new EventHandler(Content_Paused);
|
---|
| 73 | Content.Stopped += new EventHandler(Content_Stopped);
|
---|
[4133] | 74 | Content.IsResultsPollingChanged += new EventHandler(Content_IsResultsPollingChanged);
|
---|
[4116] | 75 | Content.ExperimentChanged += new EventHandler(Content_ExperimentChanged);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | protected override void OnContentChanged() {
|
---|
| 79 | base.OnContentChanged();
|
---|
| 80 | if (Content == null) {
|
---|
[4119] | 81 | executionTimeTextBox.Text = string.Empty;
|
---|
[4116] | 82 | } else {
|
---|
| 83 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
[4119] | 84 | resourceIdsTextBox.Text = Content.ResourceIds;
|
---|
[4305] | 85 | serverIpTextBox.Text = Settings.Default.HiveServerIp;
|
---|
[4119] | 86 | experimentNamedItemView.Content = Content.Experiment;
|
---|
[4120] | 87 | logView.Content = Content.Log;
|
---|
| 88 | jobListView.Content = Content.JobItems;
|
---|
[4144] | 89 | Content_ExperimentChanged(this, EventArgs.Empty);
|
---|
[4116] | 90 | }
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | protected override void SetEnabledStateOfControls() {
|
---|
| 94 | base.SetEnabledStateOfControls();
|
---|
| 95 | executionTimeTextBox.Enabled = Content != null;
|
---|
[4119] | 96 | if (Content != null) {
|
---|
[4144] | 97 | viewExperimentButton.Enabled = Content.Experiment != null;
|
---|
[4119] | 98 | experimentNamedItemView.Locked = Content.Experiment == null;
|
---|
| 99 | }
|
---|
[4116] | 100 | SetEnabledStateOfExecutableButtons();
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
| 104 | if ((Content != null) && (Content.ExecutionState == ExecutionState.Started)) Content.Stop();
|
---|
| 105 | base.OnClosed(e);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | private void Content_ExperimentChanged(object sender, EventArgs e) {
|
---|
| 109 | experimentNamedItemView.Content = Content.Experiment;
|
---|
[4119] | 110 | if (Content.Experiment != null) {
|
---|
[4144] | 111 | runCollectionView.Content = Content.Experiment.Runs;
|
---|
[4170] | 112 | if (Content.ExecutionState == ExecutionState.Stopped) {
|
---|
| 113 | Content.Prepare();
|
---|
| 114 | }
|
---|
[4119] | 115 | }
|
---|
[4120] | 116 | SetEnabledStateOfControls();
|
---|
[4116] | 117 | }
|
---|
| 118 |
|
---|
| 119 | #region Content Events
|
---|
| 120 | private void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
| 121 | if (InvokeRequired)
|
---|
| 122 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
| 123 | else
|
---|
| 124 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
|
---|
| 125 | }
|
---|
| 126 | private void Content_Prepared(object sender, EventArgs e) {
|
---|
| 127 | if (InvokeRequired)
|
---|
| 128 | Invoke(new EventHandler(Content_Prepared), sender, e);
|
---|
| 129 | else {
|
---|
| 130 | nameTextBox.Enabled = descriptionTextBox.Enabled = true;
|
---|
| 131 | Locked = false;
|
---|
| 132 | SetEnabledStateOfExecutableButtons();
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 | private void Content_Started(object sender, EventArgs e) {
|
---|
| 136 | if (InvokeRequired)
|
---|
| 137 | Invoke(new EventHandler(Content_Started), sender, e);
|
---|
| 138 | else {
|
---|
| 139 | nameTextBox.Enabled = descriptionTextBox.Enabled = false;
|
---|
| 140 | SetEnabledStateOfExecutableButtons();
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | private void Content_Paused(object sender, EventArgs e) {
|
---|
| 144 | if (InvokeRequired)
|
---|
| 145 | Invoke(new EventHandler(Content_Paused), sender, e);
|
---|
| 146 | else {
|
---|
| 147 | nameTextBox.Enabled = descriptionTextBox.Enabled = true;
|
---|
| 148 | SetEnabledStateOfExecutableButtons();
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | private void Content_Stopped(object sender, EventArgs e) {
|
---|
| 152 | if (InvokeRequired)
|
---|
| 153 | Invoke(new EventHandler(Content_Stopped), sender, e);
|
---|
| 154 | else {
|
---|
| 155 | nameTextBox.Enabled = descriptionTextBox.Enabled = true;
|
---|
| 156 | Locked = false;
|
---|
| 157 | SetEnabledStateOfExecutableButtons();
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
| 161 | if (InvokeRequired)
|
---|
| 162 | Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
|
---|
| 163 | else
|
---|
| 164 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
| 165 | }
|
---|
| 166 | private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
| 167 | if (InvokeRequired)
|
---|
| 168 | Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
|
---|
| 169 | else
|
---|
| 170 | ErrorHandling.ShowErrorDialog(this, e.Value);
|
---|
| 171 | }
|
---|
[4133] | 172 | private void Content_IsResultsPollingChanged(object sender, EventArgs e) {
|
---|
| 173 | if (InvokeRequired)
|
---|
| 174 | Invoke(new EventHandler(Content_IsResultsPollingChanged), sender, e);
|
---|
| 175 | else {
|
---|
| 176 | SetEnabledStateOfControls();
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
[4116] | 179 | #endregion
|
---|
| 180 |
|
---|
| 181 | #region Control events
|
---|
| 182 | private void startButton_Click(object sender, EventArgs e) {
|
---|
| 183 | Content.Start();
|
---|
| 184 | }
|
---|
| 185 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
| 186 | Content.Pause();
|
---|
| 187 | }
|
---|
| 188 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
| 189 | Content.Stop();
|
---|
| 190 | }
|
---|
| 191 | private void resetButton_Click(object sender, EventArgs e) {
|
---|
| 192 | Content.Prepare();
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | private void serverUrlTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
[4305] | 196 | if (string.IsNullOrEmpty(serverIpTextBox.Text)) {
|
---|
[4116] | 197 | e.Cancel = true;
|
---|
[4305] | 198 | errorProvider.SetError(serverIpTextBox, "ServerUrl cannot be empty");
|
---|
| 199 | serverIpTextBox.SelectAll();
|
---|
[4116] | 200 | return;
|
---|
| 201 | }
|
---|
[4305] | 202 | Settings.Default.HiveServerIp = serverIpTextBox.Text;
|
---|
[4116] | 203 | }
|
---|
| 204 |
|
---|
| 205 | private void serverUrlTextBox_Validated(object sender, EventArgs e) {
|
---|
[4305] | 206 | errorProvider.SetError(serverIpTextBox, string.Empty);
|
---|
[4116] | 207 | }
|
---|
| 208 |
|
---|
| 209 | private void resourceIdsTextBox_Validated(object sender, EventArgs e) {
|
---|
[4119] | 210 | Content.ResourceIds = resourceIdsTextBox.Text;
|
---|
[4116] | 211 | }
|
---|
| 212 |
|
---|
| 213 | private void newExperimentButton_Click(object sender, EventArgs e) {
|
---|
| 214 | Content.Experiment = new HeuristicLab.Optimization.Experiment();
|
---|
| 215 | }
|
---|
| 216 |
|
---|
[4144] | 217 | private void openExperimentButton_Click(object sender, EventArgs e) {
|
---|
[4116] | 218 | OpenFileDialog openFileDialog = new OpenFileDialog();
|
---|
| 219 | openFileDialog.Title = "Open Experimenter";
|
---|
| 220 | openFileDialog.FileName = "Item";
|
---|
| 221 | openFileDialog.Multiselect = false;
|
---|
| 222 | openFileDialog.DefaultExt = "hl";
|
---|
| 223 | openFileDialog.Filter = "HeuristicLab Files|*.hl|All Files|*.*";
|
---|
| 224 |
|
---|
| 225 | if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
| 226 | Content.Experiment = (HeuristicLab.Optimization.Experiment)ContentManager.Load(openFileDialog.FileName);
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[4144] | 230 | private void showExperimentButton_Click(object sender, EventArgs e) {
|
---|
[4116] | 231 | MainFormManager.MainForm.ShowContent(Content.Experiment);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[4133] | 234 | private void disconnectButton_Click(object sender, EventArgs e) {
|
---|
| 235 | if (Content != null) {
|
---|
| 236 | Content.StopResultPolling();
|
---|
| 237 | SetEnabledStateOfControls();
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | private void reconnectButton_Click(object sender, EventArgs e) {
|
---|
| 242 | if (Content != null) {
|
---|
| 243 | Content.StartResultPolling();
|
---|
| 244 | SetEnabledStateOfControls();
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | #endregion
|
---|
| 248 |
|
---|
| 249 | #region Helpers
|
---|
| 250 | private void SetEnabledStateOfExecutableButtons() {
|
---|
| 251 | if (Content == null) {
|
---|
| 252 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = reconnectButton.Enabled = disconnectButton.Enabled = false;
|
---|
| 253 | } else {
|
---|
| 254 | startButton.Enabled = Content.ExecutionState == ExecutionState.Prepared;
|
---|
| 255 | pauseButton.Enabled = false; // disabled for now
|
---|
| 256 | stopButton.Enabled = Content.ExecutionState == ExecutionState.Started && Content.IsPollingResults;
|
---|
| 257 | resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
| 258 | reconnectButton.Enabled = (Content.ExecutionState == ExecutionState.Started) && !Content.IsPollingResults;
|
---|
| 259 | disconnectButton.Enabled = (Content.ExecutionState == ExecutionState.Started) && Content.IsPollingResults;
|
---|
| 260 |
|
---|
| 261 | this.Locked = Content.ExecutionState == ExecutionState.Started && Content.IsPollingResults;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | #endregion
|
---|
[4116] | 265 | }
|
---|
| 266 | }
|
---|