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.Optimization.Networks.Views {
|
---|
28 | [View("ClientPort View")]
|
---|
29 | [Content(typeof(ClientPort), true)]
|
---|
30 | [Content(typeof(IClientPort), false)]
|
---|
31 | public partial class ClientPortView : ClientServicePortView {
|
---|
32 | protected EntitySelectorDialog entitySelectorDialog;
|
---|
33 |
|
---|
34 | public new IClientPort Content {
|
---|
35 | get { return (IClientPort)base.Content; }
|
---|
36 | set { base.Content = value; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public ClientPortView() {
|
---|
40 | InitializeComponent();
|
---|
41 | errorProvider.SetIconAlignment(servicePortView, ErrorIconAlignment.MiddleRight);
|
---|
42 | errorProvider.SetIconPadding(servicePortView, 2);
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void Dispose(bool disposing) {
|
---|
46 | if (disposing) {
|
---|
47 | if (entitySelectorDialog != null) entitySelectorDialog.Dispose();
|
---|
48 | if (components != null) components.Dispose();
|
---|
49 | }
|
---|
50 | base.Dispose(disposing);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void DeregisterContentEvents() {
|
---|
54 | Content.ServicePortChanged -= Content_ServicePortChanged;
|
---|
55 | base.DeregisterContentEvents();
|
---|
56 | }
|
---|
57 | protected override void RegisterContentEvents() {
|
---|
58 | base.RegisterContentEvents();
|
---|
59 | Content.ServicePortChanged += Content_ServicePortChanged;
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override void OnContentChanged() {
|
---|
63 | base.OnContentChanged();
|
---|
64 | servicePortView.Content = Content == null ? null : Content.ServicePort;
|
---|
65 | errorProvider.SetError(servicePortView, ((Content == null) || Content.Valid) ? string.Empty : "Port configurations do not match");
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected override void SetEnabledStateOfControls() {
|
---|
69 | base.SetEnabledStateOfControls();
|
---|
70 | servicePortGroupBox.Enabled = Content != null && !ReadOnly;
|
---|
71 | setServicePortButton.Enabled = Content != null && !ReadOnly;
|
---|
72 | clearServicePortButton.Enabled = Content != null && Content.ServicePort != null && !ReadOnly;
|
---|
73 | cloneServicePortParametersButton.Enabled = Content != null && Content.ServicePort != null && !ReadOnly;
|
---|
74 | }
|
---|
75 |
|
---|
76 | protected virtual void Content_ServicePortChanged(object sender, EventArgs e) {
|
---|
77 | if (InvokeRequired)
|
---|
78 | Invoke(new EventHandler(Content_ServicePortChanged), sender, e);
|
---|
79 | else {
|
---|
80 | clearServicePortButton.Enabled = Content.ServicePort != null && !ReadOnly;
|
---|
81 | cloneServicePortParametersButton.Enabled = Content.ServicePort != null && !ReadOnly;
|
---|
82 | servicePortView.Content = Content.ServicePort;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | protected override void Content_InterfaceChanged(object sender, EventArgs e) {
|
---|
86 | if (InvokeRequired)
|
---|
87 | Invoke(new EventHandler(Content_InterfaceChanged), sender, e);
|
---|
88 | else {
|
---|
89 | base.Content_InterfaceChanged(sender, e);
|
---|
90 | errorProvider.SetError(servicePortView, Content.Valid ? string.Empty : "Port configurations do not match");
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | protected virtual void setServicePortButton_Click(object sender, EventArgs e) {
|
---|
95 | if (entitySelectorDialog == null) {
|
---|
96 | entitySelectorDialog = new EntitySelectorDialog();
|
---|
97 | entitySelectorDialog.Caption = "Select Service Port";
|
---|
98 | entitySelectorDialog.EntitySelector.Caption = "Available Service Ports";
|
---|
99 | }
|
---|
100 |
|
---|
101 | try {
|
---|
102 | IEntity root = Content;
|
---|
103 | while (root.Parent != null)
|
---|
104 | root = root.Parent;
|
---|
105 | entitySelectorDialog.EntitySelector.Configure(
|
---|
106 | root,
|
---|
107 | Content.ServicePort,
|
---|
108 | typeof(IServicePort)
|
---|
109 | );
|
---|
110 |
|
---|
111 | if (entitySelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
112 | Content.ServicePort = entitySelectorDialog.EntitySelector.SelectedEntity as IServicePort;
|
---|
113 | }
|
---|
114 | }
|
---|
115 | catch (Exception ex) {
|
---|
116 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
117 | }
|
---|
118 | }
|
---|
119 | protected virtual void clearServicePortButton_Click(object sender, EventArgs e) {
|
---|
120 | Content.ServicePort = null;
|
---|
121 | }
|
---|
122 |
|
---|
123 | protected virtual void servicePortView_DragEnterOver(object sender, DragEventArgs e) {
|
---|
124 | e.Effect = DragDropEffects.None;
|
---|
125 | var data = (IServicePort)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
126 |
|
---|
127 | if (!ReadOnly && (Content.IsValidServicePort(data))) {
|
---|
128 | e.Effect = DragDropEffects.Link;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | protected virtual void servicePortView_DragDrop(object sender, DragEventArgs e) {
|
---|
132 | if (e.Effect != DragDropEffects.None) {
|
---|
133 | IServicePort port = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IServicePort;
|
---|
134 | Content.ServicePort = port;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | protected virtual void cloneServicePortParametersButton_Click(object sender, EventArgs e) {
|
---|
138 | Content.CloneServicePortParameters();
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|