Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/GenericPortView.cs @ 11500

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

#2205: Worked on optimization networks

File size: 5.6 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("GenericPort View")]
29  [Content(typeof(GenericPort), true)]
30  [Content(typeof(IGenericPort), false)]
31  public partial class GenericPortView : ParameterizedPortView {
32    protected EntitySelectorDialog entitySelectorDialog;
33
34    public new IGenericPort Content {
35      get { return (IGenericPort)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public GenericPortView() {
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 (entitySelectorDialog != null) entitySelectorDialog.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      base.DeregisterContentEvents();
56    }
57    protected override void RegisterContentEvents() {
58      base.RegisterContentEvents();
59      Content.ConnectedPortChanged += Content_ConnectedPortChanged;
60    }
61
62    protected override void OnContentChanged() {
63      base.OnContentChanged();
64      connectedPortView.Content = Content == null ? null : Content.ConnectedPort;
65      errorProvider.SetError(connectedPortView, ((Content == null) || Content.PortConnectionValid) ? string.Empty : "Port connection is not valid");
66    }
67
68    protected override void SetEnabledStateOfControls() {
69      base.SetEnabledStateOfControls();
70      connectedPortGroupBox.Enabled = Content != null && !ReadOnly;
71      setConnectedPortButton.Enabled = Content != null && !ReadOnly;
72      clearConnectedPortButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly;
73      cloneConnectedPortParametersButton.Enabled = Content != null && Content.ConnectedPort != null && !ReadOnly;
74    }
75
76    protected virtual void Content_ConnectedPortChanged(object sender, EventArgs e) {
77      if (InvokeRequired)
78        Invoke(new EventHandler(Content_ConnectedPortChanged), sender, e);
79      else {
80        clearConnectedPortButton.Enabled = Content.ConnectedPort != null && !ReadOnly;
81        cloneConnectedPortParametersButton.Enabled = Content.ConnectedPort != null && !ReadOnly;
82        connectedPortView.Content = Content.ConnectedPort;
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(connectedPortView, Content.PortConnectionValid ? string.Empty : "Port connection is not valid");
91      }
92    }
93
94    protected virtual void setConnectedPortButton_Click(object sender, EventArgs e) {
95      if (entitySelectorDialog == null) {
96        entitySelectorDialog = new EntitySelectorDialog();
97        entitySelectorDialog.Caption = "Select Connected Port";
98        entitySelectorDialog.EntitySelector.Caption = "Available 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.ConnectedPort,
108          typeof(IConnectedPort)
109        );
110
111        if (entitySelectorDialog.ShowDialog(this) == DialogResult.OK) {
112          Content.ConnectedPort = entitySelectorDialog.EntitySelector.SelectedEntity as IConnectedPort;
113        }
114      }
115      catch (Exception ex) {
116        ErrorHandling.ShowErrorDialog(this, ex);
117      }
118    }
119    protected virtual void clearConnectedPortButton_Click(object sender, EventArgs e) {
120      Content.ConnectedPort = null;
121    }
122
123    protected virtual void connectedPortView_DragEnterOver(object sender, DragEventArgs e) {
124      e.Effect = DragDropEffects.None;
125      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IConnectedPort;
126
127      if (!ReadOnly && (data != null) && (Content.CanConnectToPort(data))) {
128        e.Effect = DragDropEffects.Link;
129      }
130    }
131    protected virtual void connectedPortView_DragDrop(object sender, DragEventArgs e) {
132      if (e.Effect != DragDropEffects.None) {
133        var port = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IConnectedPort;
134        Content.ConnectedPort = port;
135      }
136    }
137    protected virtual void cloneConnectedPortParametersButton_Click(object sender, EventArgs e) {
138      Content.CloneConnectedPortParameters();
139    }
140  }
141}
Note: See TracBrowser for help on using the repository browser.