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 HeuristicLab.PluginInfrastructure;
|
---|
24 | using System;
|
---|
25 | using System.Windows.Forms;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Core.Networks.Views {
|
---|
28 | [View("MessagePort View")]
|
---|
29 | [Content(typeof(MessagePort), true)]
|
---|
30 | [Content(typeof(IMessagePort), false)]
|
---|
31 | public partial class MessagePortView : PortView {
|
---|
32 | protected NetworkItemSelectorDialog networkItemSelectorDialog;
|
---|
33 |
|
---|
34 | public new IMessagePort Content {
|
---|
35 | get { return (IMessagePort)base.Content; }
|
---|
36 | set { base.Content = value; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public MessagePortView() {
|
---|
40 | InitializeComponent();
|
---|
41 | errorProvider.SetIconAlignment(connectedPortView, ErrorIconAlignment.MiddleRight);
|
---|
42 | errorProvider.SetIconPadding(connectedPortView, 2);
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void Dispose(bool disposing) {
|
---|
46 | if (disposing) {
|
---|
47 | if (networkItemSelectorDialog != null) networkItemSelectorDialog.Dispose();
|
---|
48 | if (components != null) components.Dispose();
|
---|
49 | }
|
---|
50 | base.Dispose(disposing);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void DeregisterContentEvents() {
|
---|
54 | Content.ConnectedPortChanged -= Content_ConnectedPortChanged;
|
---|
55 | Content.PortConnectionValidChanged -= Content_PortConnectionValidChanged;
|
---|
56 | Content.LogMessagesChanged -= Content_LogMessagesChanged;
|
---|
57 | base.DeregisterContentEvents();
|
---|
58 | }
|
---|
59 | protected override void RegisterContentEvents() {
|
---|
60 | base.RegisterContentEvents();
|
---|
61 | Content.ConnectedPortChanged += Content_ConnectedPortChanged;
|
---|
62 | Content.PortConnectionValidChanged += Content_PortConnectionValidChanged;
|
---|
63 | Content.LogMessagesChanged += Content_LogMessagesChanged;
|
---|
64 | }
|
---|
65 |
|
---|
66 | protected override void OnContentChanged() {
|
---|
67 | base.OnContentChanged();
|
---|
68 | portParameterCollectionView.Content = Content == null ? null : Content.Parameters;
|
---|
69 | connectedPortView.Content = Content == null ? null : Content.ConnectedPort;
|
---|
70 | portParameterCollectionView.Content = Content == null ? null : Content.Parameters;
|
---|
71 | logMessagesCheckBox.Checked = Content == null ? false : Content.LogMessages;
|
---|
72 | messageCollectionView.Content = Content == null ? null : Content.Messages;
|
---|
73 | errorProvider.SetError(connectedPortView, ((Content == null) || Content.PortConnectionValid) ? string.Empty : "Port connection is not valid");
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected override void SetEnabledStateOfControls() {
|
---|
77 | base.SetEnabledStateOfControls();
|
---|
78 | sendMessageButton.Enabled = Content != null;
|
---|
79 | connectedPortGroupBox.Enabled = Content != null && !ReadOnly;
|
---|
80 | setConnectedPortButton.Enabled = Content != null && !ReadOnly;
|
---|
81 | clearConnectedPortButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly;
|
---|
82 | portParameterCollectionView.Enabled = Content != null && !ReadOnly;
|
---|
83 | cloneConnectedPortParametersButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly;
|
---|
84 | logMessagesCheckBox.Enabled = Content != null && !ReadOnly;
|
---|
85 | messageCollectionView.Enabled = Content != null && !ReadOnly;
|
---|
86 | }
|
---|
87 |
|
---|
88 | protected virtual void Content_ConnectedPortChanged(object sender, EventArgs e) {
|
---|
89 | if (InvokeRequired)
|
---|
90 | Invoke(new EventHandler(Content_ConnectedPortChanged), sender, e);
|
---|
91 | else {
|
---|
92 | clearConnectedPortButton.Enabled = Content.ConnectedPort != null && !ReadOnly;
|
---|
93 | cloneConnectedPortParametersButton.Enabled = Content.ConnectedPort != null && !ReadOnly;
|
---|
94 | connectedPortView.Content = Content.ConnectedPort;
|
---|
95 | }
|
---|
96 | }
|
---|
97 | protected virtual void Content_PortConnectionValidChanged(object sender, EventArgs e) {
|
---|
98 | if (InvokeRequired)
|
---|
99 | Invoke(new EventHandler(Content_PortConnectionValidChanged), sender, e);
|
---|
100 | else {
|
---|
101 | errorProvider.SetError(connectedPortView, Content.PortConnectionValid ? string.Empty : "Port connection is not valid");
|
---|
102 | }
|
---|
103 | }
|
---|
104 | protected virtual void Content_LogMessagesChanged(object sender, EventArgs e) {
|
---|
105 | if (InvokeRequired)
|
---|
106 | Invoke(new EventHandler(Content_LogMessagesChanged), sender, e);
|
---|
107 | else {
|
---|
108 | logMessagesCheckBox.Checked = Content.LogMessages;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | protected virtual void sendMessageButton_Click(object sender, EventArgs e) {
|
---|
113 | Content.SendMessageAsync(Content.PrepareMessage());
|
---|
114 | }
|
---|
115 |
|
---|
116 | protected virtual void setConnectedPortButton_Click(object sender, EventArgs e) {
|
---|
117 | if (networkItemSelectorDialog == null) {
|
---|
118 | networkItemSelectorDialog = new NetworkItemSelectorDialog();
|
---|
119 | networkItemSelectorDialog.Caption = "Select Connected Port";
|
---|
120 | networkItemSelectorDialog.NetworkItemSelector.Caption = "Available Ports";
|
---|
121 | }
|
---|
122 |
|
---|
123 | try {
|
---|
124 | INetworkItem root = Content;
|
---|
125 | while (root.Parent != null)
|
---|
126 | root = root.Parent;
|
---|
127 | networkItemSelectorDialog.NetworkItemSelector.Configure(
|
---|
128 | root,
|
---|
129 | Content.ConnectedPort,
|
---|
130 | typeof(IMessagePort)
|
---|
131 | );
|
---|
132 |
|
---|
133 | if (networkItemSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
134 | Content.ConnectedPort = networkItemSelectorDialog.NetworkItemSelector.SelectedNetworkItem as IMessagePort;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | catch (Exception ex) {
|
---|
138 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | protected virtual void clearConnectedPortButton_Click(object sender, EventArgs e) {
|
---|
142 | Content.ConnectedPort = null;
|
---|
143 | }
|
---|
144 |
|
---|
145 | protected virtual void connectedPortView_DragEnterOver(object sender, DragEventArgs e) {
|
---|
146 | e.Effect = DragDropEffects.None;
|
---|
147 | var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IMessagePort;
|
---|
148 |
|
---|
149 | if (!ReadOnly && (data != null) && (Content.CanConnectToPort(data))) {
|
---|
150 | e.Effect = DragDropEffects.Link;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | protected virtual void connectedPortView_DragDrop(object sender, DragEventArgs e) {
|
---|
154 | if (e.Effect != DragDropEffects.None) {
|
---|
155 | var port = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IMessagePort;
|
---|
156 | Content.ConnectedPort = port;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | protected virtual void cloneConnectedPortParametersButton_Click(object sender, EventArgs e) {
|
---|
160 | Content.CloneParametersFromPort(Content.ConnectedPort);
|
---|
161 | }
|
---|
162 | protected virtual void logMessagesCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
163 | Content.LogMessages = logMessagesCheckBox.Checked;
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|