Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs @ 9893

Last change on this file since 9893 was 9893, checked in by ascheibe, 11 years ago

#1042

  • applied mkommends progress view patch
  • adapted Hive views accordingly
  • made some minor improvements (more to come...)
File size: 5.1 KB
RevLine 
[6976]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6976]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;
[7582]23using System.Threading.Tasks;
[6976]24using System.Windows.Forms;
25using HeuristicLab.MainForm;
[7582]26using HeuristicLab.MainForm.WindowsForms;
[7156]27using HeuristicLab.PluginInfrastructure;
[6976]28
29namespace HeuristicLab.Clients.Hive.Views {
30  [View("OptimizerHiveTask View")]
31  [Content(typeof(OptimizerHiveTask), true)]
32  public partial class OptimizerHiveTaskView : HiveTaskView {
[8165]33    private Progress progress;
[8181]34    private ProgressView progressView;
[7156]35
[6976]36    public new OptimizerHiveTask Content {
37      get { return (OptimizerHiveTask)base.Content; }
38      set {
39        if (base.Content != value) {
40          base.Content = value;
41        }
42      }
43    }
44
45    public OptimizerHiveTaskView() {
46      InitializeComponent();
[9893]47      progress = new Progress();
[6976]48    }
49
50    protected override void Job_ItemChanged(object sender, EventArgs e) {
51      if (Content != null && Content.Task != null && Content.ItemTask.Item != null) {
[8939]52        Content.ExecuteReadActionOnItemTask(new Action(delegate() {
53          runCollectionViewHost.Content = Content.ItemTask.Item.Runs;
54        }));
[6976]55      } else {
56        runCollectionViewHost.Content = null;
57      }
58    }
59    #region Content Events
60    protected override void RegisterContentEvents() {
61      base.RegisterContentEvents();
62      Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged);
[8181]63      progressView = new ProgressView(this, progress);
[6976]64    }
65
66    protected override void DeregisterContentEvents() {
67      Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged);
[8181]68      if (progressView != null) {
69        progressView.Dispose();
70        progressView = null;
71      }
[6976]72      base.DeregisterContentEvents();
73    }
74
75    protected virtual void Content_IsControllableChanged(object sender, EventArgs e) {
76      SetEnabledStateOfControls();
77    }
78
79    #endregion
80
81    #region Child Control Events
82    private void restartButton_Click(object sender, EventArgs e) {
[7156]83      var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeTaskAsync);
84      task.ContinueWith((t) => {
[8165]85        progress.Finish();
[7156]86        ErrorHandling.ShowErrorDialog(this, "An error occured while resuming the task.", t.Exception);
[7582]87      }, TaskContinuationOptions.OnlyOnFaulted);
[6976]88    }
89
90    private void pauseButton_Click(object sender, EventArgs e) {
[7156]91      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseTaskAsync);
92      task.ContinueWith((t) => {
[8165]93        progress.Finish();
[7156]94        ErrorHandling.ShowErrorDialog(this, "An error occured while pausing the task.", t.Exception);
95      }, TaskContinuationOptions.OnlyOnFaulted);
[6976]96    }
97
98    private void stopButton_Click(object sender, EventArgs e) {
[7156]99      var task = System.Threading.Tasks.Task.Factory.StartNew(StopTaskAsync);
100      task.ContinueWith((t) => {
[8165]101        progress.Finish();
[7156]102        ErrorHandling.ShowErrorDialog(this, "An error occured while stopping the task.", t.Exception);
103      }, TaskContinuationOptions.OnlyOnFaulted);
[6976]104    }
105    #endregion
106
[7156]107    private void PauseTaskAsync() {
[9893]108      progress.Start("Pausing task. Please be patient for the command to take effect.");
[8181]109      Content.Pause();
[8186]110      progress.Finish();
[7156]111    }
112
113    private void StopTaskAsync() {
[9893]114      progress.Start("Stopping task. Please be patient for the command to take effect.");
[8181]115      Content.Stop();
[8186]116      progress.Finish();
[7156]117    }
118
119    private void ResumeTaskAsync() {
[9893]120      progress.Start("Resuming task. Please be patient for the command to take effect.");
[8181]121      Content.Restart();
[8186]122      progress.Finish();
[7156]123    }
124
[6976]125    protected override void SetEnabledStateOfControls() {
126      base.SetEnabledStateOfControls();
127
128      this.restartButton.Enabled = Content != null && Content.IsControllable && !Content.Task.Command.HasValue && (Content.Task.State == TaskState.Paused || Content.Task.State == TaskState.Failed || Content.Task.State == TaskState.Aborted);
129      this.pauseButton.Enabled = Content != null && Content.IsControllable && !Content.Task.Command.HasValue && Content.Task.State == TaskState.Calculating;
130      this.stopButton.Enabled = Content != null && Content.IsControllable && !Content.Task.Command.HasValue && (Content.Task.State == TaskState.Calculating || Content.Task.State == TaskState.Waiting || Content.Task.State == TaskState.Paused);
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.