#region License Information /* HeuristicLab * Copyright (C) 2002-2014 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 HeuristicLab.Common; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using System; using System.Windows.Forms; namespace HeuristicLab.Optimization.Networks.Views { [View("ServiceParameter View")] [Content(typeof(ServiceParameter<>), true)] [Content(typeof(IServiceParameter<>), false)] [Content(typeof(IServiceParameter), false)] public partial class ServiceParameterView : EntityView { public new IServiceParameter Content { get { return (IServiceParameter)base.Content; } set { base.Content = value; } } public ServiceParameterView() { InitializeComponent(); } protected override void DeregisterContentEvents() { Content.TypeChanged -= Content_TypeChanged; Content.ValueChanged -= Content_ValueChanged; base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.TypeChanged += Content_TypeChanged; Content.ValueChanged += Content_ValueChanged; } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { dataTypeTextBox.Text = string.Empty; typeComboBox.SelectedIndex = 0; valueViewHost.Content = null; } else { dataTypeTextBox.Text = Content.DataType.GetPrettyName(); typeComboBox.SelectedIndex = Content.Type == ServiceParameterType.Input ? 0 : 1; valueViewHost.ViewType = null; valueViewHost.Content = Content.Value as IContent; } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); dataTypeTextBox.Enabled = Content != null; typeComboBox.Enabled = Content != null && !ReadOnly; valueGroupBox.Enabled = (Content as IContent) != null; } protected virtual void Content_TypeChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_TypeChanged), sender, e); else { typeComboBox.SelectedIndex = Content.Type == ServiceParameterType.Input ? 0 : 1; } } protected virtual void Content_ValueChanged(object sender, System.EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_ValueChanged), sender, e); else { valueViewHost.ViewType = null; valueViewHost.Content = Content.Value as IContent; } } protected virtual void typeComboBox_SelectedIndexChanged(object sender, EventArgs e) { Content.Type = typeComboBox.SelectedIndex == 0 ? ServiceParameterType.Input : ServiceParameterType.Output; } } }