#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("Problem View")] [Content(typeof(Problem), true)] public partial class ProblemView : NamedOKBItemView { private List platformComboBoxValues; private List problemClassComboBoxValues; public new Problem Content { get { return (Problem)base.Content; } set { base.Content = value; } } public ProblemView() { InitializeComponent(); } protected override void OnInitialized(System.EventArgs e) { base.OnInitialized(e); platformComboBoxValues = OKBClient.Instance.Platforms.ToList(); platformComboBox.DataSource = platformComboBoxValues; problemClassComboBoxValues = OKBClient.Instance.ProblemClasses.ToList(); problemClassComboBox.DataSource = problemClassComboBoxValues; } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { platformComboBox.SelectedIndex = -1; problemClassComboBox.SelectedIndex = -1; problemDataView.ProblemId = 0; } else { platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId); problemClassComboBox.SelectedItem = problemClassComboBoxValues.FirstOrDefault(a => a.Id == Content.ProblemClassId); problemDataView.ProblemId = Content.Id; } usersListBox.DataSource = null; problemDataView.Content = null; } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); platformComboBox.Enabled = (Content != null) && !ReadOnly; problemClassComboBox.Enabled = (Content != null) && !ReadOnly; refreshUsersButton.Enabled = Content != null; storeUsersButton.Enabled = (usersListBox.DataSource != null) && !ReadOnly; usersListBox.Enabled = (usersListBox.DataSource != null) && !ReadOnly; problemDataView.Enabled = Content != null; } protected override void OnContentPropertyChanged(string propertyName) { switch (propertyName) { case "Id": problemDataView.ProblemId = Content.Id; break; case "PlatformId": platformComboBox.SelectedItem = platformComboBoxValues.FirstOrDefault(p => p.Id == Content.PlatformId); break; case "ProblemClassId": problemClassComboBox.SelectedItem = problemClassComboBoxValues.FirstOrDefault(a => a.Id == Content.ProblemClassId); 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 problemClassComboBox_SelectedValueChanged(object sender, System.EventArgs e) { if (Content != null) { ProblemClass selected = problemClassComboBox.SelectedItem as ProblemClass; if (selected != null) Content.ProblemClassId = selected.Id; } } private void refreshUsersButton_Click(object sender, System.EventArgs e) { List ids = OKBClient.Instance.GetProblemUsers(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.UpdateProblemUsers(Content.Id, usersListBox.SelectedItems.Cast().Select(u => u.Id).ToList())) storeUsersButton.Enabled = false; } private void usersListBox_SelectedIndexChanged(object sender, EventArgs e) { storeUsersButton.Enabled = !ReadOnly; } } }