1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Text;
|
---|
7 | using System.Windows.Forms;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Data;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.Communication.Data {
|
---|
12 | public partial class ProtocolStateView : ViewBase {
|
---|
13 | public ProtocolState ProtocolState {
|
---|
14 | get { return (ProtocolState)Item; }
|
---|
15 | set { base.Item = value; }
|
---|
16 | }
|
---|
17 |
|
---|
18 | public ProtocolStateView() {
|
---|
19 | InitializeComponent();
|
---|
20 | }
|
---|
21 | public ProtocolStateView(ProtocolState protocolState)
|
---|
22 | : this() {
|
---|
23 | ProtocolState = protocolState;
|
---|
24 | }
|
---|
25 |
|
---|
26 | protected override void RemoveItemEvents() {
|
---|
27 | ProtocolState.Changed -= new EventHandler(ProtocolState_Changed);
|
---|
28 | ProtocolState.Protocol.StatesChanged -= new EventHandler(States_Changed);
|
---|
29 | if (ProtocolState.StateTransitions != null) {
|
---|
30 | for (int i = 0 ; i < ProtocolState.StateTransitions.Count ; i++) {
|
---|
31 | ProtocolState.StateTransitions[i].Changed -= new EventHandler(StateTransitions_Changed);
|
---|
32 | }
|
---|
33 | }
|
---|
34 | base.RemoveItemEvents();
|
---|
35 | }
|
---|
36 | protected override void AddItemEvents() {
|
---|
37 | base.AddItemEvents();
|
---|
38 | ProtocolState.Changed += new EventHandler(ProtocolState_Changed);
|
---|
39 | ProtocolState.Protocol.StatesChanged += new EventHandler(States_Changed);
|
---|
40 | if (ProtocolState.StateTransitions != null) {
|
---|
41 | for (int i = 0 ; i < ProtocolState.StateTransitions.Count ; i++) {
|
---|
42 | ProtocolState.StateTransitions[i].Changed += new EventHandler(StateTransitions_Changed);
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | protected override void UpdateControls() {
|
---|
48 | base.UpdateControls();
|
---|
49 | if (ProtocolState == null) {
|
---|
50 | nameStringDataView.Enabled = false;
|
---|
51 | nameStringDataView.StringData = null;
|
---|
52 | acceptingStateBoolDataView.Enabled = false;
|
---|
53 | acceptingStateBoolDataView.BoolData = null;
|
---|
54 | outboundCommunicationDataView.Enabled = false;
|
---|
55 | outboundCommunicationDataView.ConstrainedItemList = null;
|
---|
56 | inboundCommunicationDataView.Enabled = false;
|
---|
57 | inboundCommunicationDataView.ConstrainedItemList = null;
|
---|
58 | stateTransitionTabControl.Controls.Clear();
|
---|
59 | } else {
|
---|
60 | nameStringDataView.StringData = ProtocolState.Name;
|
---|
61 | nameStringDataView.Enabled = true;
|
---|
62 | acceptingStateBoolDataView.Enabled = true;
|
---|
63 | acceptingStateBoolDataView.BoolData = ProtocolState.AcceptingState;
|
---|
64 | outboundCommunicationDataView.ConstrainedItemList = ProtocolState.SendingData;
|
---|
65 | outboundCommunicationDataView.Enabled = true;
|
---|
66 | inboundCommunicationDataView.ConstrainedItemList = ProtocolState.ReceivingData;
|
---|
67 | inboundCommunicationDataView.Enabled = true;
|
---|
68 |
|
---|
69 | addTransitionButton.Enabled = (ProtocolState.Protocol.States.Count > 1);
|
---|
70 | removeTransitionButton.Enabled = (ProtocolState.StateTransitions != null && ProtocolState.StateTransitions.Count > 0);
|
---|
71 |
|
---|
72 | stateTransitionTabControl.Controls.Clear();
|
---|
73 | ItemList<StateTransition> stateTransitions = ProtocolState.StateTransitions;
|
---|
74 | if (stateTransitions != null) {
|
---|
75 | for (int i = 0 ; i < stateTransitions.Count ; i++) {
|
---|
76 | StateTransition stateTransition = (StateTransition)stateTransitions[i];
|
---|
77 | TabPage newTransitionTabPage = new TabPage((stateTransition.TargetState == null) ? ("no target") : (stateTransition.TargetState.Name.ToString()));
|
---|
78 | Control stateTransitionView = (Control)stateTransition.CreateView();
|
---|
79 | stateTransitionTabControl.Controls.Add(newTransitionTabPage);
|
---|
80 |
|
---|
81 | newTransitionTabPage.Controls.Add(stateTransitionView);
|
---|
82 | newTransitionTabPage.Location = new Point(4, 22);
|
---|
83 | newTransitionTabPage.Padding = new Padding(3);
|
---|
84 | newTransitionTabPage.Size = stateTransitionTabControl.ClientSize;
|
---|
85 | newTransitionTabPage.UseVisualStyleBackColor = true;
|
---|
86 |
|
---|
87 | stateTransitionView.Location = new Point(0, 0);
|
---|
88 | stateTransitionView.Size = newTransitionTabPage.ClientSize;
|
---|
89 | stateTransitionView.Dock = DockStyle.Fill;
|
---|
90 | stateTransitionView.Anchor = (AnchorStyles)(AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | #region ProtocolState change handling (main underlying object)
|
---|
97 | void ProtocolState_Changed(object sender, EventArgs e) {
|
---|
98 | Refresh();
|
---|
99 | }
|
---|
100 | #endregion
|
---|
101 |
|
---|
102 | #region Protocol.States change handling (parent object)
|
---|
103 | void States_Changed(object sender, EventArgs e) {
|
---|
104 | for (int i = 0 ; i < stateTransitionTabControl.TabCount ; i++)
|
---|
105 | stateTransitionTabControl.TabPages[i].Controls[0].Refresh();
|
---|
106 | addTransitionButton.Enabled = (ProtocolState.Protocol.States.Count > 1);
|
---|
107 | }
|
---|
108 | #endregion
|
---|
109 |
|
---|
110 | #region StateTransitions change handling (child object)
|
---|
111 | void StateTransitions_Changed(object sender, EventArgs e) {
|
---|
112 | for (int i = 0 ; i < stateTransitionTabControl.TabCount ; i++) {
|
---|
113 | if (((StateTransition)ProtocolState.StateTransitions[i]).TargetState != null)
|
---|
114 | stateTransitionTabControl.TabPages[i].Text = ((StateTransition)ProtocolState.StateTransitions[i]).TargetState.Name.ToString();
|
---|
115 | }
|
---|
116 | }
|
---|
117 | #endregion
|
---|
118 |
|
---|
119 | #region Button events
|
---|
120 | private void addTransitionButton_Click(object sender, EventArgs e) {
|
---|
121 | //ProtocolState.AcceptingState = new BoolData(false);
|
---|
122 | StateTransition stateTransition = new StateTransition();
|
---|
123 | stateTransition.Changed += new EventHandler(StateTransitions_Changed);
|
---|
124 | stateTransition.SourceState = ProtocolState;
|
---|
125 |
|
---|
126 | if (ProtocolState.StateTransitions == null) {
|
---|
127 | ItemList<StateTransition> temp = new ItemList<StateTransition>();
|
---|
128 | temp.Add(stateTransition);
|
---|
129 | ProtocolState.StateTransitions = temp;
|
---|
130 | } else {
|
---|
131 | ProtocolState.StateTransitions.Add(stateTransition);
|
---|
132 | Refresh();
|
---|
133 | }
|
---|
134 | removeTransitionButton.Enabled = true;
|
---|
135 | }
|
---|
136 |
|
---|
137 | private void removeTransitionButton_Click(object sender, EventArgs e) {
|
---|
138 | if (stateTransitionTabControl.TabCount > 0) {
|
---|
139 | int selIdx = stateTransitionTabControl.SelectedIndex;
|
---|
140 | ProtocolState.StateTransitions[selIdx].Changed -= new EventHandler(StateTransitions_Changed);
|
---|
141 | stateTransitionTabControl.Controls.RemoveAt(selIdx);
|
---|
142 | ProtocolState.StateTransitions.RemoveAt(selIdx);
|
---|
143 | if (ProtocolState.StateTransitions.Count == 0) {
|
---|
144 | //ProtocolState.AcceptingState = new BoolData(true);
|
---|
145 | ProtocolState.StateTransitions = null;
|
---|
146 | removeTransitionButton.Enabled = false;
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 | #endregion
|
---|
151 | }
|
---|
152 | }
|
---|