Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs @ 9893

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

#1042

  • applied mkommends progress view patch
  • adapted Hive views accordingly
  • made some minor improvements (more to come...)
File size: 24.7 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;
23using System.ComponentModel;
24using System.Linq;
[7910]25using System.Text;
[6976]26using System.Threading;
[7162]27using System.Threading.Tasks;
[6976]28using System.Windows.Forms;
29using HeuristicLab.Collections;
30using HeuristicLab.Common;
31using HeuristicLab.Core;
32using HeuristicLab.MainForm;
[7582]33using HeuristicLab.MainForm.WindowsForms;
[6976]34using HeuristicLab.Optimization;
35using HeuristicLab.PluginInfrastructure;
36
37namespace HeuristicLab.Clients.Hive.JobManager.Views {
38  /// <summary>
39  /// The base class for visual representations of items.
40  /// </summary>
41  [View("Hive Job View")]
42  [Content(typeof(RefreshableJob), true)]
43  public partial class RefreshableHiveJobView : HeuristicLab.Core.Views.ItemView {
44    private ProgressView progressView;
[7910]45    private HiveResourceSelectorDialog hiveResourceSelectorDialog;
[8914]46    private bool SuppressEvents { get; set; }
[8994]47    private object runCollectionViewLocker = new object();
[6976]48
49    public new RefreshableJob Content {
50      get { return (RefreshableJob)base.Content; }
51      set { base.Content = value; }
52    }
53
54    /// <summary>
55    /// Initializes a new instance of <see cref="ItemBaseView"/>.
56    /// </summary>
57    public RefreshableHiveJobView() {
58      InitializeComponent();
59    }
60
61    protected override void RegisterContentEvents() {
62      base.RegisterContentEvents();
63      Content.RefreshAutomaticallyChanged += new EventHandler(Content_RefreshAutomaticallyChanged);
64      Content.JobChanged += new EventHandler(Content_HiveExperimentChanged);
65      Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged);
66      Content.JobStatisticsChanged += new EventHandler(Content_JobStatisticsChanged);
67      Content.ExceptionOccured += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured);
68      Content.StateLogListChanged += new EventHandler(Content_StateLogListChanged);
69      Content.HiveTasksChanged += new EventHandler(Content_HiveTasksChanged);
70      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
71      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
72      Content.Loaded += new EventHandler(Content_Loaded);
[7782]73      Content.TaskReceived += new EventHandler(Content_TaskReceived);
[9893]74      progressView = new ProgressView(this, Content.Progress);
[6976]75    }
76
77    protected override void DeregisterContentEvents() {
78      Content.RefreshAutomaticallyChanged -= new EventHandler(Content_RefreshAutomaticallyChanged);
79      Content.JobChanged -= new EventHandler(Content_HiveExperimentChanged);
80      Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged);
81      Content.JobStatisticsChanged -= new EventHandler(Content_JobStatisticsChanged);
82      Content.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured);
83      Content.StateLogListChanged -= new EventHandler(Content_StateLogListChanged);
84      Content.HiveTasksChanged -= new EventHandler(Content_HiveTasksChanged);
85      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
86      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
87      Content.Loaded -= new EventHandler(Content_Loaded);
[7782]88      Content.TaskReceived -= new EventHandler(Content_TaskReceived);
[8165]89      if (progressView != null) {
90        progressView.Dispose();
91        progressView = null;
92      }
[9219]93      DeregisterHiveExperimentEvents();
94      DeregisterHiveTasksEvents();
[6976]95      base.DeregisterContentEvents();
96    }
97
98    private void RegisterHiveExperimentEvents() {
99      Content.Job.PropertyChanged += new PropertyChangedEventHandler(HiveExperiment_PropertyChanged);
100    }
101
102    private void DeregisterHiveExperimentEvents() {
103      Content.Job.PropertyChanged -= new PropertyChangedEventHandler(HiveExperiment_PropertyChanged);
104    }
105
[9219]106    private void RegisterHiveTasksEvents() {
[6976]107      Content.HiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded);
108      Content.HiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved);
109      Content.HiveTasks.CollectionReset += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_CollectionReset);
110    }
[9219]111    private void DeregisterHiveTasksEvents() {
[6976]112      Content.HiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded);
113      Content.HiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved);
114      Content.HiveTasks.CollectionReset -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_CollectionReset);
115    }
116
117    protected override void OnContentChanged() {
118      base.OnContentChanged();
[8914]119      SuppressEvents = true;
120      try {
121        if (Content == null) {
122          nameTextBox.Text = string.Empty;
123          executionTimeTextBox.Text = string.Empty;
124          resourceNamesTextBox.Text = string.Empty;
125          isPrivilegedCheckBox.Checked = false;
126          refreshAutomaticallyCheckBox.Checked = false;
[8994]127          lock (runCollectionViewLocker) {
128            runCollectionViewHost.Content = null;
129          }
[9219]130          logView.Content = null;
131          jobsTreeView.Content = null;
132          hiveExperimentPermissionListView.Content = null;
133          stateLogViewHost.Content = null;
[8914]134        } else {
135          nameTextBox.Text = Content.Job.Name;
136          executionTimeTextBox.Text = Content.ExecutionTime.ToString();
137          resourceNamesTextBox.Text = Content.Job.ResourceNames;
[9436]138          isPrivilegedCheckBox.Checked = Content.Job.IsPrivileged;
[8914]139          refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically;
140          logView.Content = Content.Log;
[8994]141          lock (runCollectionViewLocker) {
142            runCollectionViewHost.Content = GetAllRunsFromJob(Content);
143          }
[8914]144        }
[6976]145      }
[8914]146      finally {
147        SuppressEvents = false;
148      }
[6976]149      hiveExperimentPermissionListView.Content = null; // has to be filled by refresh button
150      Content_JobStatisticsChanged(this, EventArgs.Empty);
151      Content_HiveExperimentChanged(this, EventArgs.Empty);
152      Content_HiveTasksChanged(this, EventArgs.Empty);
153      Content_StateLogListChanged(this, EventArgs.Empty);
154      HiveExperiment_PropertyChanged(this, new PropertyChangedEventArgs("Id"));
155      SetEnabledStateOfControls();
156    }
157
[9223]158    protected override void OnLockedChanged() {
159      base.OnLockedChanged();
160      executionTimeTextBox.Enabled = !Locked;
161      jobsTextBox.Enabled = !Locked;
162      calculatingTextBox.Enabled = !Locked;
163      finishedTextBox.Enabled = !Locked;
164      tabControl.Enabled = !Locked;
165      nameTextBox.Enabled = !Locked;
166      resourceNamesTextBox.Enabled = !Locked;
167      searchButton.Enabled = !Locked;
168      jobsTreeView.Enabled = !Locked;
169      isPrivilegedCheckBox.Enabled = !Locked;
170      refreshAutomaticallyCheckBox.Enabled = !Locked;
171      refreshButton.Enabled = !Locked;
172      UnloadButton.Enabled = !Locked;
173      startButton.Enabled = !Locked;
174      pauseButton.Enabled = !Locked;
175      stopButton.Enabled = !Locked;
176      resetButton.Enabled = !Locked;
177    }
178
[6976]179    protected override void SetEnabledStateOfControls() {
180      base.SetEnabledStateOfControls();
[9223]181      if (!Locked) {
182        executionTimeTextBox.Enabled = Content != null;
183        jobsTextBox.ReadOnly = true;
184        calculatingTextBox.ReadOnly = true;
185        finishedTextBox.ReadOnly = true;
[6976]186
[9223]187        if (Content != null) {
188          bool alreadyUploaded = Content.Id != Guid.Empty;
189          bool jobsLoaded = Content.HiveTasks != null && Content.HiveTasks.All(x => x.Task.Id != Guid.Empty);
190          tabControl.Enabled = !Content.IsProgressing;
[6976]191
[9223]192          this.nameTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
193          this.resourceNamesTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
194          this.searchButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Prepared && !alreadyUploaded && !Content.IsProgressing;
195          this.jobsTreeView.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
[6976]196
[9223]197          this.isPrivilegedCheckBox.Enabled = HiveClient.Instance.IsAllowedPrivileged && Content.IsControllable && !(Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded) && !Content.IsProgressing;
198          this.refreshAutomaticallyCheckBox.Enabled = Content.IsControllable && alreadyUploaded && jobsLoaded && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
199          this.refreshButton.Enabled = Content.IsDownloadable && alreadyUploaded && !Content.IsProgressing;
[9219]200
[9223]201          this.UnloadButton.Enabled = Content.HiveTasks != null && Content.HiveTasks.Count > 0 && alreadyUploaded && !Content.IsProgressing;
202        }
203        SetEnabledStateOfExecutableButtons();
204        tabControl_SelectedIndexChanged(this, EventArgs.Empty); // ensure sharing tabpage is disabled
[6976]205      }
206    }
207
208    protected override void OnClosed(FormClosedEventArgs e) {
209      if (Content != null) {
210        if (Content.RefreshAutomatically)
211          Content.StopResultPolling();
212      }
213      base.OnClosed(e);
214    }
215
216    #region Content Events
[7782]217    void Content_TaskReceived(object sender, EventArgs e) {
[8994]218      lock (runCollectionViewLocker) {
219        runCollectionViewHost.Content = GetAllRunsFromJob(Content);
220      }
[7782]221    }
222
[6976]223    private void HiveTasks_ItemsAdded(object sender, CollectionItemsChangedEventArgs<HiveTask> e) {
224      if (InvokeRequired)
225        Invoke(new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded), sender, e);
226      else {
227        SetEnabledStateOfControls();
228      }
229    }
230
231    private void HiveTasks_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<HiveTask> e) {
232      if (InvokeRequired)
233        Invoke(new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved), sender, e);
234      else {
235        SetEnabledStateOfControls();
236      }
237    }
238
239    private void HiveTasks_CollectionReset(object sender, CollectionItemsChangedEventArgs<HiveTask> e) {
240      if (InvokeRequired)
241        Invoke(new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_CollectionReset), sender, e);
242      else {
243        SetEnabledStateOfControls();
244      }
245    }
246
247    private void Content_ExecutionStateChanged(object sender, EventArgs e) {
248      if (InvokeRequired)
249        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
250      else
251        SetEnabledStateOfControls();
252    }
253    private void Content_Prepared(object sender, EventArgs e) {
254      if (InvokeRequired)
255        Invoke(new EventHandler(Content_Prepared), sender, e);
256      else {
257        nameTextBox.Enabled = true;
258        Locked = false;
259        SetEnabledStateOfControls();
260      }
261    }
262    private void Content_Started(object sender, EventArgs e) {
263      if (InvokeRequired)
264        Invoke(new EventHandler(Content_Started), sender, e);
265      else {
266        nameTextBox.Enabled = false;
267        SetEnabledStateOfControls();
268      }
269    }
270    private void Content_Paused(object sender, EventArgs e) {
271      if (InvokeRequired)
272        Invoke(new EventHandler(Content_Paused), sender, e);
273      else {
274        nameTextBox.Enabled = true;
275        SetEnabledStateOfControls();
276      }
277    }
278    private void Content_Stopped(object sender, EventArgs e) {
279      if (InvokeRequired)
280        Invoke(new EventHandler(Content_Stopped), sender, e);
281      else {
282        nameTextBox.Enabled = true;
283        Locked = false;
284        SetEnabledStateOfControls();
285      }
286    }
287    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
288      if (InvokeRequired)
289        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
290      else
291        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
292    }
293    private void Content_RefreshAutomaticallyChanged(object sender, EventArgs e) {
294      if (InvokeRequired)
295        Invoke(new EventHandler(Content_RefreshAutomaticallyChanged), sender, e);
296      else {
297        refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically;
298        SetEnabledStateOfControls();
299      }
300    }
301    private void Content_HiveTasksChanged(object sender, EventArgs e) {
302      if (InvokeRequired)
303        Invoke(new EventHandler(Content_HiveTasksChanged), sender, e);
304      else {
305        if (Content != null && Content.HiveTasks != null) {
306          jobsTreeView.Content = Content.HiveTasks;
[9219]307          RegisterHiveTasksEvents();
[6976]308        } else {
309          jobsTreeView.Content = null;
310        }
311        SetEnabledStateOfControls();
312      }
313    }
314
315    void Content_Loaded(object sender, EventArgs e) {
[8994]316      lock (runCollectionViewLocker) {
317        runCollectionViewHost.Content = GetAllRunsFromJob(Content);
318      }
[9710]319      if (InvokeRequired) {
320        Invoke(new Action(() => { isPrivilegedCheckBox.Checked = Content.Job.IsPrivileged; }));
321      } else {
322        isPrivilegedCheckBox.Checked = Content.Job.IsPrivileged;
323      }
[6976]324    }
325
326    private void Content_HiveExperimentChanged(object sender, EventArgs e) {
327      if (Content != null && Content.Job != null) {
328        RegisterHiveExperimentEvents();
329      }
330    }
331    private void Content_IsControllableChanged(object sender, EventArgs e) {
332      SetEnabledStateOfControls();
333    }
334    private void Content_JobStatisticsChanged(object sender, EventArgs e) {
335      if (InvokeRequired)
336        Invoke(new EventHandler(Content_JobStatisticsChanged), sender, e);
337      else {
338        if (Content != null) {
339          jobsTextBox.Text = (Content.Job.JobCount - Content.Job.CalculatingCount - Content.Job.FinishedCount).ToString();
340          calculatingTextBox.Text = Content.Job.CalculatingCount.ToString();
341          finishedTextBox.Text = Content.Job.FinishedCount.ToString();
342        } else {
343          jobsTextBox.Text = "0";
344          calculatingTextBox.Text = "0";
345          finishedTextBox.Text = "0";
346        }
347      }
348    }
349    private void Content_ExceptionOccured(object sender, EventArgs<Exception> e) {
[7409]350      if (InvokeRequired)
351        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured), sender, e);
352      else {
353        //don't show the error dialog when downloading tasks, the HiveClient will throw an exception and the dialog will be shown then
354        if (sender.GetType() != typeof(ConcurrentTaskDownloader<ItemTask>) && sender.GetType() != typeof(TaskDownloader)) {
355          ErrorHandling.ShowErrorDialog(this, e.Value);
356        }
357      }
[6976]358    }
359    private void Content_StateLogListChanged(object sender, EventArgs e) {
360      if (InvokeRequired)
361        Invoke(new EventHandler(Content_StateLogListChanged), sender, e);
362      else {
363        UpdateStateLogList();
364      }
365    }
366
367    private void UpdateStateLogList() {
368      if (Content != null && this.Content.Job != null) {
369        stateLogViewHost.Content = this.Content.StateLogList;
370      } else {
371        stateLogViewHost.Content = null;
372      }
373    }
374
375    private void HiveExperiment_PropertyChanged(object sender, PropertyChangedEventArgs e) {
376      if (this.Content != null && e.PropertyName == "Id") this.hiveExperimentPermissionListView.HiveExperimentId = this.Content.Job.Id;
377    }
378    #endregion
379
380    #region Control events
[7910]381    private void searchButton_Click(object sender, EventArgs e) {
382      if (hiveResourceSelectorDialog == null)
383        hiveResourceSelectorDialog = new HiveResourceSelectorDialog();
384      if (hiveResourceSelectorDialog.ShowDialog(this) == DialogResult.OK) {
385        StringBuilder sb = new StringBuilder();
386        foreach (Resource resource in hiveResourceSelectorDialog.GetSelectedResources()) {
387          sb.Append(resource.Name);
[8109]388          sb.Append(";");
[7910]389        }
390        resourceNamesTextBox.Text = sb.ToString();
[8690]391        if (Content.Job.ResourceNames != resourceNamesTextBox.Text)
392          Content.Job.ResourceNames = resourceNamesTextBox.Text;
[7910]393      }
394    }
395
[6976]396    private void startButton_Click(object sender, EventArgs e) {
[7068]397      if (nameTextBox.Text.Trim() == string.Empty) {
398        MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
[7162]399      } else if (Content.ExecutionState == ExecutionState.Paused) {
[7156]400        var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content);
401        task.ContinueWith((t) => {
[9893]402          Content.Progress.Finish();
[7156]403          MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
404          Content.Log.LogException(t.Exception);
405        }, TaskContinuationOptions.OnlyOnFaulted);
[7068]406      } else {
407        HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken());
408      }
[6976]409    }
[7156]410
[6976]411    private void pauseButton_Click(object sender, EventArgs e) {
[7156]412      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content);
[7162]413      task.ContinueWith((t) => {
[9893]414        Content.Progress.Finish();
[7156]415        MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
416        Content.Log.LogException(t.Exception);
417      }, TaskContinuationOptions.OnlyOnFaulted);
[7162]418    }
[7156]419
[6976]420    private void stopButton_Click(object sender, EventArgs e) {
[7156]421      var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content);
422      task.ContinueWith((t) => {
[9893]423        Content.Progress.Finish();
[7156]424        MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
425        Content.Log.LogException(t.Exception);
426      }, TaskContinuationOptions.OnlyOnFaulted);
[6976]427    }
428    private void resetButton_Click(object sender, EventArgs e) { }
429
[7156]430    private void PauseJobAsync(object job) {
[9893]431      Content.Progress.Start("Pausing job...");
[7156]432      HiveClient.PauseJob((RefreshableJob)job);
[9893]433      Content.Progress.Finish();
[7156]434    }
435
436    private void StopJobAsync(object job) {
[9893]437      Content.Progress.Start("Stopping job...");
[7156]438      HiveClient.StopJob((RefreshableJob)job);
[9893]439      Content.Progress.Finish();
[7156]440    }
441
442    private void ResumeJobAsync(object job) {
[9893]443      Content.Progress.Start("Resuming job...");
[7156]444      HiveClient.ResumeJob((RefreshableJob)job);
[9893]445      Content.Progress.Finish();
[7156]446    }
447
[6976]448    private void nameTextBox_Validated(object sender, EventArgs e) {
[9219]449      if (!SuppressEvents && Content.Job != null && Content.Job.Name != nameTextBox.Text)
[6976]450        Content.Job.Name = nameTextBox.Text;
451    }
452
453    private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
[9219]454      if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text)
[6976]455        Content.Job.ResourceNames = resourceNamesTextBox.Text;
456    }
457
[8090]458    private void refreshAutomaticallyCheckBox_CheckedChanged(object sender, EventArgs e) {
[8914]459      if (Content != null && !SuppressEvents) Content.RefreshAutomatically = refreshAutomaticallyCheckBox.Checked;
[6976]460    }
461
[9107]462    private void isPrivilegedCheckBox_CheckChanged(object sender, EventArgs e) {
[9436]463      if (Content != null && !SuppressEvents) Content.Job.IsPrivileged = isPrivilegedCheckBox.Checked;
[6976]464    }
465
466    private void refreshButton_Click(object sender, EventArgs e) {
467      var invoker = new Action<RefreshableJob>(HiveClient.LoadJob);
468      invoker.BeginInvoke(Content, (ar) => {
469        try {
470          invoker.EndInvoke(ar);
471        }
472        catch (Exception ex) {
473          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
474        }
475      }, null);
476    }
477
478    private void refreshPermissionsButton_Click(object sender, EventArgs e) {
[7029]479      if (this.Content.Job.Id == Guid.Empty) {
480        MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
481      } else {
482        hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id);
483      }
[6976]484    }
485    #endregion
486
487    #region Helpers
488    private void SetEnabledStateOfExecutableButtons() {
489      if (Content == null) {
490        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
491      } else {
[8159]492        startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
493        pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
494        stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
[6976]495        resetButton.Enabled = false;
496      }
497    }
498    #endregion
499
500    #region Drag & Drop
501    private void jobsTreeView_DragOver(object sender, DragEventArgs e) {
502      jobsTreeView_DragEnter(sender, e);
503    }
504
505    private void jobsTreeView_DragEnter(object sender, DragEventArgs e) {
506      e.Effect = DragDropEffects.None;
507      var obj = e.Data.GetData(Constants.DragDropDataFormat);
508      if (obj is IOptimizer) {
[7067]509        if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None;
510        else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
[6976]511        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
512      }
513    }
514
515    private void jobsTreeView_DragDrop(object sender, DragEventArgs e) {
516      if (e.Effect != DragDropEffects.None) {
517        var obj = e.Data.GetData(Constants.DragDropDataFormat);
518
519        var optimizer = obj as IOptimizer;
520        if (optimizer != null) {
[7067]521          IOptimizer newOptimizer = null;
522          if (e.Effect.HasFlag(DragDropEffects.Copy)) {
523            newOptimizer = (IOptimizer)optimizer.Clone();
[8341]524            newOptimizer.Runs.Clear();
[7067]525          } else {
526            newOptimizer = optimizer;
527          }
528          if (newOptimizer.ExecutionState != ExecutionState.Prepared) {
529            newOptimizer.Prepare();
530          }
531
532          Content.HiveTasks.Add(new OptimizerHiveTask(newOptimizer));
[6976]533        }
534      }
535    }
536    #endregion
537
538    private void tabControl_SelectedIndexChanged(object sender, EventArgs e) {
539      if (tabControl.SelectedTab == permissionTabPage) {
540        if (!Content.IsSharable) {
[7162]541          MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
[6976]542          tabControl.SelectedTab = tasksTabPage;
543        }
544      }
545    }
546
547    private RunCollection GetAllRunsFromJob(RefreshableJob job) {
548      if (job != null) {
[8962]549        RunCollection runs = new RunCollection() { OptimizerName = job.ItemName };
[6976]550
[8700]551        foreach (HiveTask subTask in job.HiveTasks) {
552          if (subTask is OptimizerHiveTask) {
553            OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
[8939]554            ohTask.ExecuteReadActionOnItemTask(new Action(delegate() {
555              runs.AddRange(ohTask.ItemTask.Item.Runs);
556            }));
[8700]557          }
[6976]558        }
559        return runs;
560      } else {
561        return null;
562      }
563    }
[9219]564
565    private void UnloadButton_Click(object sender, EventArgs e) {
566      Content.Unload();
567      runCollectionViewHost.Content = null;
568      stateLogViewHost.Content = null;
569      hiveExperimentPermissionListView.Content = null;
570      jobsTreeView.Content = null;
571
572      SetEnabledStateOfControls();
573    }
[6976]574  }
575}
Note: See TracBrowser for help on using the repository browser.