Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.HiveEngine.Views/3.3/HiveEngineView.cs @ 16824

Last change on this file since 16824 was 16173, checked in by jkarder, 6 years ago

#2839:

  • fixed compilation errors in HiveEngine
  • minor changes
File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Collections.Generic;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Clients.Hive;
27using HeuristicLab.Clients.Hive.JobManager.Views;
28using HeuristicLab.Core.Views;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.HiveEngine.Views {
32  [View("Hive Engine View")]
33  [Content(typeof(HiveEngine), IsDefaultView = true)]
34  public sealed partial class HiveEngineView : ItemView {
35    private readonly HiveResourceSelectorDialog hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Guid.Empty, Guid.Empty);
36
37    public new HiveEngine Content {
38      get { return (HiveEngine)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public HiveEngineView() {
43      InitializeComponent();
44    }
45
46    protected override void DeregisterContentEvents() {
47      Content.ExecutionTimeOnHiveChanged -= new EventHandler(Content_ExecutionTimeOnHiveChanged);
48      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
49      base.DeregisterContentEvents();
50    }
51
52    protected override void RegisterContentEvents() {
53      base.RegisterContentEvents();
54      Content.ExecutionTimeOnHiveChanged += new EventHandler(Content_ExecutionTimeOnHiveChanged);
55      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
56    }
57
58    #region Event Handlers (Content)
59    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
60      if (InvokeRequired) {
61        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
62      } else {
63        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
64      }
65    }
66
67    private void Content_ExecutionTimeOnHiveChanged(object sender, EventArgs e) {
68      if (InvokeRequired) {
69        Invoke(new EventHandler(Content_ExecutionTimeOnHiveChanged), sender, e);
70      } else {
71        executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString();
72      }
73    }
74    #endregion
75
76    protected override void OnContentChanged() {
77      base.OnContentChanged();
78      if (Content == null) {
79        projectNameTextBox.Text = string.Empty;
80        priorityComboBox.SelectedIndex = 1;
81        executionTimeOnHiveTextBox.Text = string.Empty;
82        hiveExperimentListView.Content = null;
83        logView.Content = null;
84      } else {
85        if (Content.ProjectId != null && Content.ProjectId != Guid.Empty) {
86          var project = HiveServiceLocator.Instance.CallHiveService(s => s.GetProject(Content.ProjectId));
87          if (project != null) projectNameTextBox.Text = project.Name;
88        } else {
89          projectNameTextBox.Text = string.Empty;
90        }
91
92        if (Content.Priority >= 0 && Content.Priority < priorityComboBox.Items.Count) {
93          priorityComboBox.SelectedIndex = Content.Priority;
94        } else {
95          priorityComboBox.SelectedIndex = 1;
96        }
97
98        executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString();
99        hiveExperimentListView.Content = Content.Jobs;
100        logView.Content = Content.Log;
101      }
102    }
103
104    protected override void SetEnabledStateOfControls() {
105      base.SetEnabledStateOfControls();
106
107      searchButton.Enabled = Content != null && !ReadOnly && !Locked;
108      projectNameTextBox.Enabled = Content != null && !ReadOnly && !Locked;
109      priorityComboBox.Enabled = Content != null && !ReadOnly && !Locked;
110    }
111
112    private void searchButton_Click(object sender, EventArgs e) {
113      hiveResourceSelectorDialog.SelectedProjectId = Content != null ? Content.ProjectId : Guid.Empty;
114      hiveResourceSelectorDialog.SelectedResourceIds = Content != null ? Content.ResourceIds : new List<Guid>();
115
116      var result = hiveResourceSelectorDialog.ShowDialog(this);
117      if (result == DialogResult.OK) {
118        var selectedProject = hiveResourceSelectorDialog.SelectedProject;
119        if (selectedProject != null) {
120          projectNameTextBox.Text = selectedProject.Name;
121          Content.ProjectId = selectedProject.Id;
122          Content.ResourceIds = hiveResourceSelectorDialog.SelectedResources.Select(x => x.Id).ToList();
123        } else {
124          projectNameTextBox.Text = string.Empty;
125          Content.ProjectId = Guid.Empty;
126          Content.ResourceIds = new List<Guid>();
127        }
128      }
129    }
130
131    private void priorityComboBox_SelectedIndexChanged(object sender, EventArgs e) {
132      if (Content != null && Content.Priority != priorityComboBox.SelectedIndex) {
133        Content.Priority = priorityComboBox.SelectedIndex;
134      }
135    }
136  }
137}
Note: See TracBrowser for help on using the repository browser.