[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;
|
---|
[5955] | 23 | using System.ComponentModel;
|
---|
[4905] | 24 | using System.Threading;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Core.Views;
|
---|
| 29 | using HeuristicLab.MainForm;
|
---|
| 30 | using HeuristicLab.PluginInfrastructure;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Clients.Hive.Views {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// The base class for visual representations of items.
|
---|
| 35 | /// </summary>
|
---|
| 36 | [View("Experiment View")]
|
---|
[5955] | 37 | [Content(typeof(HiveExperiment), true)]
|
---|
| 38 | public sealed partial class HiveExperimentView : ItemView {
|
---|
[4905] | 39 | private ProgressView progressView;
|
---|
| 40 |
|
---|
[5955] | 41 | public new HiveExperiment Content {
|
---|
| 42 | get { return (HiveExperiment)base.Content; }
|
---|
[4905] | 43 | set { base.Content = value; }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | /// <summary>
|
---|
| 47 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 48 | /// </summary>
|
---|
| 49 | public HiveExperimentView() {
|
---|
| 50 | InitializeComponent();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | protected override void DeregisterContentEvents() {
|
---|
[5955] | 54 | //Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
[4905] | 55 | Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
|
---|
| 56 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
[5955] | 57 | //Content.Prepared -= new EventHandler(Content_Prepared);
|
---|
| 58 | //Content.Started -= new EventHandler(Content_Started);
|
---|
| 59 | //Content.Paused -= new EventHandler(Content_Paused);
|
---|
| 60 | //Content.Stopped -= new EventHandler(Content_Stopped);
|
---|
| 61 | Content.RefreshAutomaticallyChanged -= new EventHandler(Content_RefreshAutomaticallyChanged);
|
---|
[4905] | 62 | Content.HiveJobChanged -= new EventHandler(Content_HiveJobChanged);
|
---|
| 63 | Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged);
|
---|
[5955] | 64 | Content.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(Content_PropertyChanged);
|
---|
[4905] | 65 | base.DeregisterContentEvents();
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | protected override void RegisterContentEvents() {
|
---|
| 69 | base.RegisterContentEvents();
|
---|
[5955] | 70 | //Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
[4905] | 71 | Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
|
---|
| 72 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
[5955] | 73 | //Content.Prepared += new EventHandler(Content_Prepared);
|
---|
| 74 | //Content.Started += new EventHandler(Content_Started);
|
---|
| 75 | //Content.Paused += new EventHandler(Content_Paused);
|
---|
| 76 | //Content.Stopped += new EventHandler(Content_Stopped);
|
---|
| 77 | Content.RefreshAutomaticallyChanged += new EventHandler(Content_RefreshAutomaticallyChanged);
|
---|
[4905] | 78 | Content.HiveJobChanged += new EventHandler(Content_HiveJobChanged);
|
---|
| 79 | Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged);
|
---|
[5955] | 80 | Content.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Content_PropertyChanged);
|
---|
[4905] | 81 | }
|
---|
| 82 |
|
---|
| 83 | protected override void OnContentChanged() {
|
---|
| 84 | base.OnContentChanged();
|
---|
| 85 | if (Content == null) {
|
---|
[5955] | 86 | nameTextBox.Text = string.Empty;
|
---|
[4905] | 87 | executionTimeTextBox.Text = string.Empty;
|
---|
[5458] | 88 | resourceNamesTextBox.Text = string.Empty;
|
---|
[5402] | 89 | useLocalPluginsCheckBox.Checked = false;
|
---|
[4905] | 90 | logView.Content = null;
|
---|
[5955] | 91 | //includeJobsCheckBox.Checked = false;
|
---|
| 92 | refreshAutomaticallyCheckBox.Checked = false;
|
---|
| 93 | jobsTextBox.Text = "0";
|
---|
| 94 | calculatingTextBox.Text = "0";
|
---|
| 95 | finishedTextBox.Text = "0";
|
---|
[4905] | 96 | } else {
|
---|
[5955] | 97 | nameTextBox.Text = Content.Name;
|
---|
[4905] | 98 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
[5458] | 99 | resourceNamesTextBox.Text = Content.ResourceNames;
|
---|
[5402] | 100 | useLocalPluginsCheckBox.Checked = Content.UseLocalPlugins;
|
---|
[5955] | 101 | //includeJobsCheckBox.Checked = Content.IncludeJobs;
|
---|
| 102 | refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically;
|
---|
| 103 | jobsTextBox.Text = Content.JobCount.ToString();
|
---|
| 104 | calculatingTextBox.Text = Content.CalculatingCount.ToString();
|
---|
| 105 | finishedTextBox.Text = Content.FinishedCount.ToString();
|
---|
[4905] | 106 | }
|
---|
| 107 | Content_HiveJobChanged(this, EventArgs.Empty);
|
---|
| 108 | Content_IsProgressingChanged(this, EventArgs.Empty);
|
---|
| 109 | SetEnabledStateOfControls();
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | protected override void SetEnabledStateOfControls() {
|
---|
| 113 | base.SetEnabledStateOfControls();
|
---|
| 114 | executionTimeTextBox.Enabled = Content != null;
|
---|
| 115 | experimentNamedItemView.ReadOnly = true;
|
---|
[5955] | 116 | jobsTextBox.ReadOnly = true;
|
---|
| 117 | calculatingTextBox.ReadOnly = true;
|
---|
| 118 | finishedTextBox.ReadOnly = true;
|
---|
| 119 |
|
---|
[4905] | 120 | if (Content != null) {
|
---|
[5955] | 121 | bool alreadyUploaded = Content.RootJobId != null && Content.Id != Guid.Empty;
|
---|
| 122 | bool jobsLoaded = Content.HiveJob != null && Content.HiveJob.Job.Id != Guid.Empty;
|
---|
[4905] | 123 |
|
---|
[5955] | 124 | this.nameTextBox.ReadOnly = Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded;
|
---|
| 125 | this.resourceNamesTextBox.ReadOnly = Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded;
|
---|
| 126 | this.jobsTreeView.ReadOnly = Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded;
|
---|
| 127 | this.useLocalPluginsCheckBox.Enabled = !(Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded);
|
---|
| 128 | this.refreshAutomaticallyCheckBox.Enabled = alreadyUploaded && jobsLoaded && Content.ExecutionState == ExecutionState.Started;
|
---|
| 129 | this.viewExperimentButton.Enabled = Content.GetExperiment() != null;
|
---|
| 130 | this.openExperimentButton.Enabled = !alreadyUploaded && Content.ExecutionState == ExecutionState.Prepared;
|
---|
| 131 | this.newExperimentButton.Enabled = !alreadyUploaded && Content.ExecutionState == ExecutionState.Prepared;
|
---|
| 132 | this.refreshButton.Enabled = alreadyUploaded;
|
---|
[4905] | 133 |
|
---|
[5955] | 134 | this.Locked = Content.ExecutionState == ExecutionState.Started;
|
---|
[4905] | 135 | }
|
---|
| 136 | SetEnabledStateOfExecutableButtons();
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
| 140 | if (Content != null) {
|
---|
[5955] | 141 | if (Content.RefreshAutomatically)
|
---|
[4905] | 142 | Content.StopResultPolling();
|
---|
| 143 | }
|
---|
| 144 | base.OnClosed(e);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | #region Content Events
|
---|
| 148 | private void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
| 149 | if (InvokeRequired)
|
---|
| 150 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
| 151 | else
|
---|
| 152 | SetEnabledStateOfControls();
|
---|
| 153 | }
|
---|
| 154 | private void Content_Prepared(object sender, EventArgs e) {
|
---|
| 155 | if (InvokeRequired)
|
---|
| 156 | Invoke(new EventHandler(Content_Prepared), sender, e);
|
---|
| 157 | else {
|
---|
[5852] | 158 | nameTextBox.Enabled = true;
|
---|
[4905] | 159 | Locked = false;
|
---|
| 160 | SetEnabledStateOfControls();
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | private void Content_Started(object sender, EventArgs e) {
|
---|
| 164 | if (InvokeRequired)
|
---|
| 165 | Invoke(new EventHandler(Content_Started), sender, e);
|
---|
| 166 | else {
|
---|
[5852] | 167 | nameTextBox.Enabled = false;
|
---|
[4905] | 168 | SetEnabledStateOfControls();
|
---|
| 169 | }
|
---|
| 170 | }
|
---|
| 171 | private void Content_Paused(object sender, EventArgs e) {
|
---|
| 172 | if (InvokeRequired)
|
---|
| 173 | Invoke(new EventHandler(Content_Paused), sender, e);
|
---|
| 174 | else {
|
---|
[5852] | 175 | nameTextBox.Enabled = true;
|
---|
[4905] | 176 | SetEnabledStateOfControls();
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 | private void Content_Stopped(object sender, EventArgs e) {
|
---|
| 180 | if (InvokeRequired)
|
---|
| 181 | Invoke(new EventHandler(Content_Stopped), sender, e);
|
---|
| 182 | else {
|
---|
[5852] | 183 | nameTextBox.Enabled = true;
|
---|
[4905] | 184 | Locked = false;
|
---|
| 185 | SetEnabledStateOfControls();
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 | private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
| 189 | if (InvokeRequired)
|
---|
| 190 | Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
|
---|
| 191 | else
|
---|
| 192 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
| 193 | }
|
---|
| 194 | private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
| 195 | if (InvokeRequired)
|
---|
| 196 | Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
|
---|
| 197 | else
|
---|
| 198 | ErrorHandling.ShowErrorDialog(this, e.Value);
|
---|
| 199 | }
|
---|
[5955] | 200 | private void Content_RefreshAutomaticallyChanged(object sender, EventArgs e) {
|
---|
[4905] | 201 | if (InvokeRequired)
|
---|
[5955] | 202 | Invoke(new EventHandler(Content_RefreshAutomaticallyChanged), sender, e);
|
---|
[4905] | 203 | else {
|
---|
[5955] | 204 | refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically;
|
---|
[4905] | 205 | SetEnabledStateOfControls();
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
[5955] | 208 | private void Content_HiveJobChanged(object sender, EventArgs e) {
|
---|
[4905] | 209 | if (InvokeRequired)
|
---|
| 210 | Invoke(new EventHandler(Content_HiveJobChanged), sender, e);
|
---|
| 211 | else {
|
---|
| 212 | if (Content != null) {
|
---|
[5675] | 213 | jobsTreeView.Content = Content.HiveJob;
|
---|
[4905] | 214 | experimentNamedItemView.Content = Content.GetExperiment();
|
---|
| 215 | } else {
|
---|
[5675] | 216 | jobsTreeView.Content = null;
|
---|
[4905] | 217 | experimentNamedItemView.Content = null;
|
---|
| 218 | }
|
---|
| 219 | SetEnabledStateOfControls();
|
---|
| 220 | }
|
---|
| 221 | }
|
---|
[5955] | 222 | private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 223 | if (InvokeRequired)
|
---|
| 224 | Invoke(new PropertyChangedEventHandler(Content_PropertyChanged), sender, e);
|
---|
| 225 | else {
|
---|
| 226 | jobsTextBox.Text = Content.JobCount.ToString();
|
---|
| 227 | calculatingTextBox.Text = Content.CalculatingCount.ToString();
|
---|
| 228 | finishedTextBox.Text = Content.FinishedCount.ToString();
|
---|
| 229 | }
|
---|
| 230 | }
|
---|
[4905] | 231 | #endregion
|
---|
| 232 |
|
---|
| 233 | #region Control events
|
---|
| 234 | private void startButton_Click(object sender, EventArgs e) {
|
---|
[5955] | 235 | ExperimentManagerClient.StartExperiment(new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex)), Content);
|
---|
[4905] | 236 | }
|
---|
| 237 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
[5955] | 238 | ExperimentManagerClient.PauseExperiment(Content);
|
---|
[4905] | 239 | }
|
---|
| 240 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
[5955] | 241 | ExperimentManagerClient.StopExperiment(Content);
|
---|
[4905] | 242 | }
|
---|
[5955] | 243 | private void resetButton_Click(object sender, EventArgs e) { }
|
---|
| 244 |
|
---|
| 245 | private void nameTextBox_Validated(object sender, EventArgs e) {
|
---|
| 246 | if (Content.Name != nameTextBox.Text)
|
---|
| 247 | Content.Name = nameTextBox.Text;
|
---|
[4905] | 248 | }
|
---|
| 249 |
|
---|
[5458] | 250 | private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
|
---|
[5955] | 251 | if (Content.ResourceNames != resourceNamesTextBox.Text)
|
---|
| 252 | Content.ResourceNames = resourceNamesTextBox.Text;
|
---|
[4905] | 253 | }
|
---|
| 254 |
|
---|
| 255 | private void newExperimentButton_Click(object sender, EventArgs e) {
|
---|
| 256 | Content.SetExperiment(new HeuristicLab.Optimization.Experiment());
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | private void openExperimentButton_Click(object sender, EventArgs e) {
|
---|
| 260 | OpenFileDialog openFileDialog = new OpenFileDialog();
|
---|
| 261 | openFileDialog.Title = "Open Experimenter";
|
---|
| 262 | openFileDialog.FileName = "Item";
|
---|
| 263 | openFileDialog.Multiselect = false;
|
---|
| 264 | openFileDialog.DefaultExt = "hl";
|
---|
| 265 | openFileDialog.Filter = "HeuristicLab Files|*.hl|All Files|*.*";
|
---|
| 266 |
|
---|
| 267 | if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
| 268 | Content.SetExperiment((HeuristicLab.Optimization.Experiment)ContentManager.Load(openFileDialog.FileName));
|
---|
| 269 | }
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | private void showExperimentButton_Click(object sender, EventArgs e) {
|
---|
| 273 | MainFormManager.MainForm.ShowContent(Content.GetExperiment());
|
---|
| 274 | }
|
---|
| 275 |
|
---|
[5955] | 276 | private void viewExperimentButton_Click(object sender, EventArgs e) {
|
---|
| 277 | MainFormManager.MainForm.ShowContent(Content.GetExperiment());
|
---|
[4905] | 278 | }
|
---|
| 279 |
|
---|
[5955] | 280 | private void includeJobsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 281 | //if (Content != null) Content.IncludeJobs = includeJobsCheckBox.Checked;
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | private void refreshAutomaticallyCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[4905] | 285 | if (Content != null) {
|
---|
[5955] | 286 | Content.RefreshAutomatically = refreshAutomaticallyCheckBox.Checked;
|
---|
[4905] | 287 | }
|
---|
| 288 | }
|
---|
[5402] | 289 |
|
---|
| 290 | private void useLocalPluginsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[5955] | 291 | if (Content != null) Content.UseLocalPlugins = useLocalPluginsCheckBox.Checked;
|
---|
[5402] | 292 | }
|
---|
[5955] | 293 |
|
---|
| 294 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 295 | var invoker = new Action<HiveExperiment>(ExperimentManagerClient.LoadExperiment);
|
---|
| 296 | invoker.BeginInvoke(Content, (ar) => {
|
---|
| 297 | try {
|
---|
| 298 | invoker.EndInvoke(ar);
|
---|
| 299 | }
|
---|
| 300 | catch (Exception ex) {
|
---|
| 301 | ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
|
---|
| 302 | }
|
---|
| 303 | }, null);
|
---|
| 304 | }
|
---|
[4905] | 305 | #endregion
|
---|
| 306 |
|
---|
| 307 | #region Helpers
|
---|
| 308 | private void SetEnabledStateOfExecutableButtons() {
|
---|
| 309 | if (Content == null) {
|
---|
[5955] | 310 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
|
---|
[4905] | 311 | } else {
|
---|
| 312 | startButton.Enabled = Content.GetExperiment() != null && Content.ExecutionState == ExecutionState.Prepared;
|
---|
[5955] | 313 | pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;
|
---|
| 314 | stopButton.Enabled = Content.ExecutionState == ExecutionState.Started;
|
---|
[4905] | 315 | resetButton.Enabled = false;
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 | #endregion
|
---|
| 319 |
|
---|
[5955] | 320 | #region Progress reporting
|
---|
[4905] | 321 | private void Content_IsProgressingChanged(object sender, EventArgs e) {
|
---|
| 322 | if (this.InvokeRequired) {
|
---|
| 323 | Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
|
---|
| 324 | } else {
|
---|
| 325 | if (Content != null && Content.IsProgressing) {
|
---|
| 326 | SetProgressView();
|
---|
| 327 | } else {
|
---|
| 328 | FinishProgressView();
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | private void SetProgressView() {
|
---|
| 334 | if (progressView == null) {
|
---|
| 335 | progressView = new ProgressView(this, Content.Progress);
|
---|
| 336 | }
|
---|
| 337 | progressView.Progress = Content.Progress;
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | private void FinishProgressView() {
|
---|
| 341 | if (progressView != null) {
|
---|
| 342 | progressView.Finish();
|
---|
| 343 | progressView = null;
|
---|
| 344 | SetEnabledStateOfControls();
|
---|
| 345 | }
|
---|
| 346 | }
|
---|
[5955] | 347 | #endregion
|
---|
| 348 |
|
---|
[4905] | 349 | }
|
---|
| 350 | }
|
---|