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 |
|
---|
22 | using HeuristicLab.MainForm;
|
---|
23 | using System;
|
---|
24 | using System.Windows.Forms;
|
---|
25 |
|
---|
26 | namespace HeuristicLab.Optimization.Networks.Views {
|
---|
27 | [View("InputPort View")]
|
---|
28 | [Content(typeof(InputPort<>), true)]
|
---|
29 | [Content(typeof(IInputPort<>), false)]
|
---|
30 | [Content(typeof(IInputPort), false)]
|
---|
31 | public partial class InputPortView : ValuePortView {
|
---|
32 | protected EntitySelectorDialog entitySelectorDialog;
|
---|
33 |
|
---|
34 | public new IInputPort Content {
|
---|
35 | get { return (IInputPort)base.Content; }
|
---|
36 | set { base.Content = value; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public InputPortView() {
|
---|
40 | InitializeComponent();
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void Dispose(bool disposing) {
|
---|
44 | if (disposing) {
|
---|
45 | if (entitySelectorDialog != null) entitySelectorDialog.Dispose();
|
---|
46 | if (components != null) components.Dispose();
|
---|
47 | }
|
---|
48 | base.Dispose(disposing);
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void DeregisterContentEvents() {
|
---|
52 | Content.OutputPortChanged -= Content_OutputPortChanged;
|
---|
53 | base.DeregisterContentEvents();
|
---|
54 | }
|
---|
55 | protected override void RegisterContentEvents() {
|
---|
56 | base.RegisterContentEvents();
|
---|
57 | Content.OutputPortChanged += Content_OutputPortChanged;
|
---|
58 | }
|
---|
59 |
|
---|
60 | protected override void OnContentChanged() {
|
---|
61 | base.OnContentChanged();
|
---|
62 | outputPortView.Content = Content == null ? null : Content.OutputPort;
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void SetEnabledStateOfControls() {
|
---|
66 | base.SetEnabledStateOfControls();
|
---|
67 | outputPortGroupBox.Enabled = Content != null && !ReadOnly;
|
---|
68 | setOutputPortButton.Enabled = Content != null && !ReadOnly;
|
---|
69 | clearOutputPortButton.Enabled = Content != null && Content.OutputPort != null && !ReadOnly;
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected virtual void Content_OutputPortChanged(object sender, EventArgs e) {
|
---|
73 | if (InvokeRequired)
|
---|
74 | Invoke(new EventHandler(Content_OutputPortChanged), sender, e);
|
---|
75 | else {
|
---|
76 | clearOutputPortButton.Enabled = Content.OutputPort != null && !ReadOnly;
|
---|
77 | outputPortView.Content = Content.OutputPort;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected virtual void setOutputPortButton_Click(object sender, EventArgs e) {
|
---|
82 | if (entitySelectorDialog == null) {
|
---|
83 | entitySelectorDialog = new EntitySelectorDialog();
|
---|
84 | entitySelectorDialog.Caption = "Select Output Port";
|
---|
85 | }
|
---|
86 |
|
---|
87 | IEntity root = Content;
|
---|
88 | while (root.Parent != null)
|
---|
89 | root = root.Parent;
|
---|
90 | entitySelectorDialog.EntitySelector.Root = root;
|
---|
91 |
|
---|
92 | if (entitySelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
93 | Content.OutputPort = entitySelectorDialog.EntitySelector.SelectedEntity as IOutputPort;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | protected virtual void clearOutputPortButton_Click(object sender, EventArgs e) {
|
---|
97 | Content.OutputPort = null;
|
---|
98 | }
|
---|
99 |
|
---|
100 | protected virtual void outputPortView_DragEnterOver(object sender, DragEventArgs e) {
|
---|
101 | e.Effect = DragDropEffects.None;
|
---|
102 | if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IOutputPort)) {
|
---|
103 | e.Effect = DragDropEffects.Link;
|
---|
104 | }
|
---|
105 | }
|
---|
106 | protected virtual void outputPortView_DragDrop(object sender, DragEventArgs e) {
|
---|
107 | if (e.Effect != DragDropEffects.None) {
|
---|
108 | IOutputPort port = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IOutputPort;
|
---|
109 | Content.OutputPort = port;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|