#region License Information
/* HeuristicLab
* Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using HeuristicLab.Clients.Hive;
using HeuristicLab.Clients.Hive.JobManager.Views;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
namespace HeuristicLab.HiveEngine.Views {
[View("Hive Engine View")]
[Content(typeof(HiveEngine), IsDefaultView = true)]
public sealed partial class HiveEngineView : ItemView {
private readonly HiveResourceSelectorDialog hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Guid.Empty, Guid.Empty);
public new HiveEngine Content {
get { return (HiveEngine)base.Content; }
set { base.Content = value; }
}
public HiveEngineView() {
InitializeComponent();
}
protected override void DeregisterContentEvents() {
Content.ExecutionTimeOnHiveChanged -= new EventHandler(Content_ExecutionTimeOnHiveChanged);
Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
base.DeregisterContentEvents();
}
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.ExecutionTimeOnHiveChanged += new EventHandler(Content_ExecutionTimeOnHiveChanged);
Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
}
#region Event Handlers (Content)
private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
if (InvokeRequired) {
Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
} else {
executionTimeTextBox.Text = Content.ExecutionTime.ToString();
}
}
private void Content_ExecutionTimeOnHiveChanged(object sender, EventArgs e) {
if (InvokeRequired) {
Invoke(new EventHandler(Content_ExecutionTimeOnHiveChanged), sender, e);
} else {
executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString();
}
}
#endregion
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
projectNameTextBox.Text = string.Empty;
priorityComboBox.SelectedIndex = 1;
executionTimeOnHiveTextBox.Text = string.Empty;
hiveExperimentListView.Content = null;
logView.Content = null;
} else {
if (Content.ProjectId != null && Content.ProjectId != Guid.Empty) {
var project = HiveServiceLocator.Instance.CallHiveService(s => s.GetProject(Content.ProjectId));
if (project != null) projectNameTextBox.Text = project.Name;
} else {
projectNameTextBox.Text = string.Empty;
}
if (Content.Priority >= 0 && Content.Priority < priorityComboBox.Items.Count) {
priorityComboBox.SelectedIndex = Content.Priority;
} else {
priorityComboBox.SelectedIndex = 1;
}
executionTimeOnHiveTextBox.Text = Content.ExecutionTimeOnHive.ToString();
hiveExperimentListView.Content = Content.Jobs;
logView.Content = Content.Log;
}
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
searchButton.Enabled = Content != null && !ReadOnly && !Locked;
projectNameTextBox.Enabled = Content != null && !ReadOnly && !Locked;
priorityComboBox.Enabled = Content != null && !ReadOnly && !Locked;
}
private void searchButton_Click(object sender, EventArgs e) {
hiveResourceSelectorDialog.SelectedProjectId = Content != null ? Content.ProjectId : Guid.Empty;
hiveResourceSelectorDialog.SelectedResourceIds = Content != null ? Content.ResourceIds : new List();
var result = hiveResourceSelectorDialog.ShowDialog(this);
if (result == DialogResult.OK) {
var selectedProject = hiveResourceSelectorDialog.SelectedProject;
if (selectedProject != null) {
projectNameTextBox.Text = selectedProject.Name;
Content.ProjectId = selectedProject.Id;
Content.ResourceIds = hiveResourceSelectorDialog.SelectedResources.Select(x => x.Id).ToList();
} else {
projectNameTextBox.Text = string.Empty;
Content.ProjectId = Guid.Empty;
Content.ResourceIds = new List();
}
}
}
private void priorityComboBox_SelectedIndexChanged(object sender, EventArgs e) {
if (Content != null && Content.Priority != priorityComboBox.SelectedIndex) {
Content.Priority = priorityComboBox.SelectedIndex;
}
}
}
}