Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/### obsolete/ServiceParameterView.cs @ 11519

Last change on this file since 11519 was 11519, checked in by swagner, 9 years ago

#2205: Worked on optimization networks

File size: 5.8 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;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.PluginInfrastructure;
27using System;
28using System.Windows.Forms;
29
30namespace HeuristicLab.Optimization.Networks.Views {
31  [View("ServiceParameter View")]
32  [Content(typeof(ServiceParameter<>), true)]
33  [Content(typeof(IServiceParameter<>), false)]
34  [Content(typeof(IServiceParameter), false)]
35  public partial class ServiceParameterView : EntityView {
36    protected TypeSelectorDialog typeSelectorDialog;
37
38    public new IServiceParameter Content {
39      get { return (IServiceParameter)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public ServiceParameterView() {
44      InitializeComponent();
45    }
46
47    protected override void Dispose(bool disposing) {
48      if (disposing) {
49        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
50        if (components != null) components.Dispose();
51      }
52      base.Dispose(disposing);
53    }
54
55    protected override void DeregisterContentEvents() {
56      Content.TypeChanged -= Content_TypeChanged;
57      Content.ValueChanged -= Content_ValueChanged;
58      base.DeregisterContentEvents();
59    }
60
61    protected override void RegisterContentEvents() {
62      base.RegisterContentEvents();
63      Content.TypeChanged += Content_TypeChanged;
64      Content.ValueChanged += Content_ValueChanged;
65    }
66
67    protected override void OnContentChanged() {
68      base.OnContentChanged();
69      if (Content == null) {
70        dataTypeTextBox.Text = string.Empty;
71        typeComboBox.SelectedIndex = 0;
72        valueViewHost.Content = null;
73      } else {
74        dataTypeTextBox.Text = Content.DataType.GetPrettyName();
75        typeComboBox.SelectedIndex = Content.Type == ServiceParameterType.Input ? 0 : 1;
76        valueViewHost.ViewType = null;
77        valueViewHost.Content = Content.Value;
78      }
79    }
80
81    protected override void SetEnabledStateOfControls() {
82      base.SetEnabledStateOfControls();
83      dataTypeTextBox.Enabled = Content != null;
84      typeComboBox.Enabled = Content != null && !ReadOnly;
85      valueGroupBox.Enabled = Content != null;
86      setValueButton.Enabled = Content != null && !ReadOnly;
87      clearValueButton.Enabled = Content != null && Content.Value != null && !ReadOnly;
88    }
89    protected virtual void Content_TypeChanged(object sender, EventArgs e) {
90      if (InvokeRequired)
91        Invoke(new EventHandler(Content_TypeChanged), sender, e);
92      else {
93        typeComboBox.SelectedIndex = Content.Type == ServiceParameterType.Input ? 0 : 1;
94      }
95    }
96    protected virtual void Content_ValueChanged(object sender, System.EventArgs e) {
97      if (InvokeRequired)
98        Invoke(new EventHandler(Content_ValueChanged), sender, e);
99      else {
100        clearValueButton.Enabled = Content.Value != null;
101        valueViewHost.ViewType = null;
102        valueViewHost.Content = Content.Value;
103      }
104    }
105
106    protected virtual void typeComboBox_SelectedIndexChanged(object sender, EventArgs e) {
107      Content.Type = typeComboBox.SelectedIndex == 0 ? ServiceParameterType.Input : ServiceParameterType.Output;
108    }
109
110    protected virtual void setValueButton_Click(object sender, EventArgs e) {
111      if (typeSelectorDialog == null) {
112        typeSelectorDialog = new TypeSelectorDialog();
113        typeSelectorDialog.Caption = "Select Value";
114      }
115      typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);
116      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
117        try {
118          Content.Value = (IItem)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
119        }
120        catch (Exception ex) {
121          ErrorHandling.ShowErrorDialog(this, ex);
122        }
123      }
124    }
125    protected virtual void clearValueButton_Click(object sender, EventArgs e) {
126      Content.Value = null;
127    }
128    protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {
129      e.Effect = DragDropEffects.None;
130      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IItem)) {
131        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
132        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
133        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
134        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
135        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
136      }
137    }
138    protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
139      if (e.Effect != DragDropEffects.None) {
140        IItem item = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IItem;
141        if (e.Effect.HasFlag(DragDropEffects.Copy)) item = (IItem)item.Clone();
142        Content.Value = item;
143      }
144    }
145  }
146}
Note: See TracBrowser for help on using the repository browser.