#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.Linq; using System.Windows.Forms; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; namespace HeuristicLab.Clients.OKB { [View("OKBAlgorithm View")] [Content(typeof(OKBAlgorithm), true)] public sealed partial class OKBAlgorithmView : ItemView { public new OKBAlgorithm Content { get { return (OKBAlgorithm)base.Content; } set { base.Content = value; } } public OKBAlgorithmView() { InitializeComponent(); } protected override void OnInitialized(System.EventArgs e) { base.OnInitialized(e); OKBClient.Instance.Refreshing += new EventHandler(OKBClient_Refreshing); OKBClient.Instance.Refreshed += new EventHandler(OKBClient_Refreshed); PopulateComboBox(); } protected override void DeregisterContentEvents() { Content.AlgorithmChanged -= new EventHandler(Content_AlgorithmChanged); base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.AlgorithmChanged += new EventHandler(Content_AlgorithmChanged); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { algorithmComboBox.SelectedIndex = -1; viewHost.Content = null; } else { algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId); viewHost.Content = Content.Algorithm; } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); algorithmComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (algorithmComboBox.Items.Count > 0); refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked; } private void PopulateComboBox() { algorithmComboBox.DataSource = null; Platform platform = OKBClient.Instance.Platforms.FirstOrDefault(x => x.Name == "HeuristicLab 3.3"); if (platform != null) { algorithmComboBox.DataSource = OKBClient.Instance.Algorithms.Where(x => x.PlatformId == platform.Id).ToList(); algorithmComboBox.DisplayMember = "Name"; } } protected override void OnClosed(FormClosedEventArgs e) { OKBClient.Instance.Refreshing -= new EventHandler(OKBClient_Refreshing); OKBClient.Instance.Refreshed -= new EventHandler(OKBClient_Refreshed); base.OnClosed(e); } private void OKBClient_Refreshing(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(OKBClient_Refreshing), sender, e); } else { Cursor = Cursors.AppStarting; algorithmComboBox.Enabled = refreshButton.Enabled = viewHost.Enabled = false; } } private void OKBClient_Refreshed(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(OKBClient_Refreshed), sender, e); } else { PopulateComboBox(); SetEnabledStateOfControls(); Cursor = Cursors.Default; } } #region Content Events private void Content_AlgorithmChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_AlgorithmChanged), sender, e); else { algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId); viewHost.Content = Content.Algorithm; } } #endregion #region Control Events private void refreshButton_Click(object sender, System.EventArgs e) { OKBClient.Instance.Refresh(); } private void algorithmComboBox_SelectedValueChanged(object sender, System.EventArgs e) { Algorithm algorithm = algorithmComboBox.SelectedValue as Algorithm; if ((algorithm != null) && (Content != null)) { Content.Load(algorithm.Id); if (Content.AlgorithmId != algorithm.Id) // reset selected item if load was not successful algorithmComboBox.SelectedItem = OKBClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId); } } #endregion } }