Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2115 merged r11170 (copyright update) into trunk

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