Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Networks.Views/3.3/### obsolete/InputOutputPortView.cs @ 13136

Last change on this file since 13136 was 11500, checked in by swagner, 10 years ago

#2205: Worked on optimization networks

File size: 4.9 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.MainForm;
23using HeuristicLab.PluginInfrastructure;
24using System;
25using System.Windows.Forms;
26
27namespace HeuristicLab.Optimization.Networks.Views {
28  [View("InputOutputPort View")]
29  [Content(typeof(InputOutputPort<,>), true)]
30  [Content(typeof(IInputOutputPort<,>), false)]
31  [Content(typeof(IInputOutputPort), false)]
32  public partial class InputOutputPortView : ValuePortView {
33    protected EntitySelectorDialog entitySelectorDialog;
34
35    public new IInputOutputPort Content {
36      get { return (IInputOutputPort)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public InputOutputPortView() {
41      InitializeComponent();
42    }
43
44    protected override void Dispose(bool disposing) {
45      if (disposing) {
46        if (entitySelectorDialog != null) entitySelectorDialog.Dispose();
47        if (components != null) components.Dispose();
48      }
49      base.Dispose(disposing);
50    }
51
52    protected override void DeregisterContentEvents() {
53      Content.OutputInputPortChanged -= Content_OutputInputPortChanged;
54      base.DeregisterContentEvents();
55    }
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.OutputInputPortChanged += Content_OutputInputPortChanged;
59    }
60
61    protected override void OnContentChanged() {
62      base.OnContentChanged();
63      outputInputPortView.Content = Content == null ? null : Content.OutputInputPort;
64    }
65
66    protected override void SetEnabledStateOfControls() {
67      base.SetEnabledStateOfControls();
68      outputInputPortGroupBox.Enabled = Content != null && !ReadOnly;
69      setOutputInputPortButton.Enabled = Content != null && !ReadOnly;
70      clearOutputInputPortButton.Enabled = Content != null && Content.OutputInputPort != null && !ReadOnly;
71    }
72
73    protected virtual void Content_OutputInputPortChanged(object sender, EventArgs e) {
74      if (InvokeRequired)
75        Invoke(new EventHandler(Content_OutputInputPortChanged), sender, e);
76      else {
77        clearOutputInputPortButton.Enabled = Content.OutputInputPort != null && !ReadOnly;
78        outputInputPortView.Content = Content.OutputInputPort;
79      }
80    }
81
82    protected virtual void setOutputInputPortButton_Click(object sender, EventArgs e) {
83      if (entitySelectorDialog == null) {
84        entitySelectorDialog = new EntitySelectorDialog();
85        entitySelectorDialog.Caption = "Select Output/Input Port";
86        entitySelectorDialog.EntitySelector.Caption = "Available Output/Input Ports";
87      }
88
89      try {
90        IEntity root = Content;
91        while (root.Parent != null)
92          root = root.Parent;
93        entitySelectorDialog.EntitySelector.Configure(
94          root,
95          Content.OutputInputPort,
96          typeof(IOutputInputPort<,>).MakeGenericType(Content.GetType().GetGenericArguments()[0], Content.GetType().GetGenericArguments()[1])
97        );
98
99        if (entitySelectorDialog.ShowDialog(this) == DialogResult.OK) {
100          Content.OutputInputPort = entitySelectorDialog.EntitySelector.SelectedEntity as IOutputInputPort;
101        }
102      }
103      catch (Exception ex) {
104        ErrorHandling.ShowErrorDialog(this, ex);
105      }
106    }
107    protected virtual void clearOutputInputPortButton_Click(object sender, EventArgs e) {
108      Content.OutputInputPort = null;
109    }
110
111    protected virtual void outputInputPortView_DragEnterOver(object sender, DragEventArgs e) {
112      e.Effect = DragDropEffects.None;
113      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
114      var type = typeof(IOutputInputPort<,>).MakeGenericType(Content.GetType().GetGenericArguments()[0], Content.GetType().GetGenericArguments()[1]);
115
116      if (!ReadOnly && (type.IsAssignableFrom(data.GetType()))) {
117        e.Effect = DragDropEffects.Link;
118      }
119    }
120    protected virtual void outputInputPortView_DragDrop(object sender, DragEventArgs e) {
121      if (e.Effect != DragDropEffects.None) {
122        IOutputInputPort port = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IOutputInputPort;
123        Content.OutputInputPort = port;
124      }
125    }
126  }
127}
Note: See TracBrowser for help on using the repository browser.