#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 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.MainForm;
using HeuristicLab.MainForm.WindowsForms;
namespace HeuristicLab.Clients.OKB {
[View("Algorithm View")]
[Content(typeof(Algorithm), true)]
public partial class AlgorithmView : NamedOKBItemView {
private List platformComboBoxValues;
private List algorithmClassComboBoxValues;
public new Algorithm Content {
get { return (Algorithm)base.Content; }
set { base.Content = value; }
}
public AlgorithmView() {
InitializeComponent();
}
protected override void OnInitialized(System.EventArgs e) {
base.OnInitialized(e);
platformComboBoxValues = OKBClient.Instance.Platforms.ToList();
platformComboBox.DataSource = platformComboBoxValues;
algorithmClassComboBoxValues = OKBClient.Instance.AlgorithmClasses.ToList();
algorithmClassComboBox.DataSource = algorithmClassComboBoxValues;
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
platformComboBox.SelectedIndex = -1;
algorithmClassComboBox.SelectedIndex = -1;
algorithmDataView.AlgorithmId = 0;
} else {
platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
algorithmDataView.AlgorithmId = Content.Id;
}
usersListBox.DataSource = null;
algorithmDataView.Content = null;
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
platformComboBox.Enabled = (Content != null) && !ReadOnly;
algorithmClassComboBox.Enabled = (Content != null) && !ReadOnly;
refreshUsersButton.Enabled = Content != null;
storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly;
algorithmDataView.Enabled = Content != null;
}
protected override void OnContentPropertyChanged(string propertyName) {
switch (propertyName) {
case "Id":
algorithmDataView.AlgorithmId = Content.Id;
break;
case "PlatformId":
platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId);
break;
case "AlgorithmClassId":
algorithmClassComboBox.SelectedItem = algorithmClassComboBoxValues.FirstOrDefault(a => a.Id == Content.AlgorithmClassId);
break;
}
}
private void platformComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
if (Content != null) {
Platform selected = platformComboBox.SelectedItem as Platform;
if (selected != null) Content.PlatformId = selected.Id;
}
}
private void algorithmClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) {
if (Content != null) {
AlgorithmClass selected = algorithmClassComboBox.SelectedItem as AlgorithmClass;
if (selected != null) Content.AlgorithmClassId = selected.Id;
}
}
private void refreshUsersButton_Click(object sender, System.EventArgs e) {
List ids = OKBClient.Instance.GetAlgorithmUsers(Content.Id);
if (ids != null) {
List users = OKBClient.Instance.Users.ToList();
usersListBox.DataSource = users;
usersListBox.DisplayMember = "Name";
usersListBox.SelectedItems.Clear();
foreach (Guid id in ids)
usersListBox.SelectedItems.Add(users.First(u => u.Id == id));
usersListBox.Enabled = !ReadOnly;
storeUsersButton.Enabled = false;
}
}
private void storeUsersButton_Click(object sender, System.EventArgs e) {
if (OKBClient.Instance.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast().Select(u => u.Id).ToList()))
storeUsersButton.Enabled = false;
}
private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) {
storeUsersButton.Enabled = !ReadOnly;
}
private void refreshParametersButton_Click(object sender, EventArgs e) {
algorithmParameterCollectionView.Content = OKBClient.Instance.GetAlgorithmParameters(Content.Id);
}
private void refreshResultsButton_Click(object sender, EventArgs e) {
resultCollectionView.Content = OKBClient.Instance.GetResults(Content.Id);
}
private void refreshExperimentsButton_Click(object sender, EventArgs e) {
experimentCollectionView.Content = OKBClient.Instance.GetExperiments(Content.Id, 0);
}
}
}