Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8692 was 8692, checked in by ascheibe, 12 years ago

#1882 fixed collecting runs in the OptimizerHiveTaskView

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