Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Networks.Views/3.3/### obsolete/InputPortView.cs @ 11733

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

#2205: Worked on optimization networks

File size: 4.7 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("InputPort View")]
29  [Content(typeof(InputPort<>), true)]
30  [Content(typeof(IInputPort<>), false)]
31  [Content(typeof(IInputPort), false)]
32  public partial class InputPortView : ValuePortView {
33    protected EntitySelectorDialog entitySelectorDialog;
34
35    public new IInputPort Content {
36      get { return (IInputPort)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public InputPortView() {
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.OutputPortChanged -= Content_OutputPortChanged;
54      base.DeregisterContentEvents();
55    }
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.OutputPortChanged += Content_OutputPortChanged;
59    }
60
61    protected override void OnContentChanged() {
62      base.OnContentChanged();
63      outputPortView.Content = Content == null ? null : Content.OutputPort;
64    }
65
66    protected override void SetEnabledStateOfControls() {
67      base.SetEnabledStateOfControls();
68      outputPortGroupBox.Enabled = Content != null && !ReadOnly;
69      setOutputPortButton.Enabled = Content != null && !ReadOnly;
70      clearOutputPortButton.Enabled = Content != null && Content.OutputPort != null && !ReadOnly;
71    }
72
73    protected virtual void Content_OutputPortChanged(object sender, EventArgs e) {
74      if (InvokeRequired)
75        Invoke(new EventHandler(Content_OutputPortChanged), sender, e);
76      else {
77        clearOutputPortButton.Enabled = Content.OutputPort != null && !ReadOnly;
78        outputPortView.Content = Content.OutputPort;
79      }
80    }
81
82    protected virtual void setOutputPortButton_Click(object sender, EventArgs e) {
83      if (entitySelectorDialog == null) {
84        entitySelectorDialog = new EntitySelectorDialog();
85        entitySelectorDialog.Caption = "Select Output Port";
86        entitySelectorDialog.EntitySelector.Caption = "Available Output 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.OutputPort,
96          typeof(IOutputPort<>).MakeGenericType(Content.GetType().GetGenericArguments()[0])
97        );
98
99        if (entitySelectorDialog.ShowDialog(this) == DialogResult.OK) {
100          Content.OutputPort = entitySelectorDialog.EntitySelector.SelectedEntity as IOutputPort;
101        }
102      }
103      catch (Exception ex) {
104        ErrorHandling.ShowErrorDialog(this, ex);
105      }
106    }
107    protected virtual void clearOutputPortButton_Click(object sender, EventArgs e) {
108      Content.OutputPort = null;
109    }
110
111    protected virtual void outputPortView_DragEnterOver(object sender, DragEventArgs e) {
112      e.Effect = DragDropEffects.None;
113      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
114      var type = typeof(IOutputPort<>).MakeGenericType(Content.GetType().GetGenericArguments()[0]);
115
116      if (!ReadOnly && (type.IsAssignableFrom(data.GetType()))) {
117        e.Effect = DragDropEffects.Link;
118      }
119    }
120    protected virtual void outputPortView_DragDrop(object sender, DragEventArgs e) {
121      if (e.Effect != DragDropEffects.None) {
122        IOutputPort port = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IOutputPort;
123        Content.OutputPort = port;
124      }
125    }
126  }
127}
Note: See TracBrowser for help on using the repository browser.