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