Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/ServiceParameterView.cs @ 11463

Last change on this file since 11463 was 11454, checked in by swagner, 10 years ago

#2205: Worked on optimization networks

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25using System;
26using System.Windows.Forms;
27
28namespace HeuristicLab.Optimization.Networks.Views {
29  [View("ServiceParameter View")]
30  [Content(typeof(ServiceParameter<>), true)]
31  [Content(typeof(IServiceParameter<>), false)]
32  [Content(typeof(IServiceParameter), false)]
33  public partial class ServiceParameterView : EntityView {
34    public new IServiceParameter Content {
35      get { return (IServiceParameter)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public ServiceParameterView() {
40      InitializeComponent();
41    }
42
43    protected override void DeregisterContentEvents() {
44      Content.TypeChanged -= Content_TypeChanged;
45      Content.ValueChanged -= Content_ValueChanged;
46      base.DeregisterContentEvents();
47    }
48
49    protected override void RegisterContentEvents() {
50      base.RegisterContentEvents();
51      Content.TypeChanged += Content_TypeChanged;
52      Content.ValueChanged += Content_ValueChanged;
53    }
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        dataTypeTextBox.Text = string.Empty;
59        typeComboBox.SelectedIndex = 0;
60        valueViewHost.Content = null;
61      } else {
62        dataTypeTextBox.Text = Content.DataType.GetPrettyName();
63        typeComboBox.SelectedIndex = Content.Type == ServiceParameterType.Input ? 0 : 1;
64        valueViewHost.ViewType = null;
65        valueViewHost.Content = Content.Value as IContent;
66      }
67    }
68
69    protected override void SetEnabledStateOfControls() {
70      base.SetEnabledStateOfControls();
71      dataTypeTextBox.Enabled = Content != null;
72      typeComboBox.Enabled = Content != null && !ReadOnly;
73      valueGroupBox.Enabled = (Content as IContent) != null;
74    }
75    protected virtual void Content_TypeChanged(object sender, EventArgs e) {
76      if (InvokeRequired)
77        Invoke(new EventHandler(Content_TypeChanged), sender, e);
78      else {
79        typeComboBox.SelectedIndex = Content.Type == ServiceParameterType.Input ? 0 : 1;
80      }
81    }
82    protected virtual void Content_ValueChanged(object sender, System.EventArgs e) {
83      if (InvokeRequired)
84        Invoke(new EventHandler(Content_ValueChanged), sender, e);
85      else {
86        valueViewHost.ViewType = null;
87        valueViewHost.Content = Content.Value as IContent;
88      }
89    }
90
91    protected virtual void typeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
92      Content.Type = typeComboBox.SelectedIndex == 0 ? ServiceParameterType.Input : ServiceParameterType.Output;
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.