#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 { 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); platformComboBox.DataSource = Administrator.Instance.Platforms.ToList(); algorithmClassComboBox.DataSource = Administrator.Instance.AlgorithmClasses.ToList(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { platformComboBox.SelectedIndex = -1; algorithmClassComboBox.SelectedIndex = -1; algorithmDataView.AlgorithmId = 0; } else { platformComboBox.SelectedItem = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId); algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.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 = Administrator.Instance.Platforms.FirstOrDefault(p => p.Id == Content.PlatformId); break; case "AlgorithmClassId": algorithmClassComboBox.SelectedItem = Administrator.Instance.AlgorithmClasses.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) { Guid[] ids = Administrator.Instance.GetAlgorithmUsers(Content.Id); if (ids != null) { List users = Administrator.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 (Administrator.Instance.UpdateAlgorithmUsers(Content.Id, usersListBox.SelectedItems.Cast().Select(u => u.Id).ToArray())) storeUsersButton.Enabled = false; } private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) { storeUsersButton.Enabled = !ReadOnly; } } }