1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 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 System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Text;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.Core;
|
---|
30 | using HeuristicLab.Data;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Communication.Data {
|
---|
33 | public partial class StateTransitionView : ViewBase {
|
---|
34 |
|
---|
35 | public StateTransition StateTransition {
|
---|
36 | get { return (StateTransition)Item; }
|
---|
37 | set { base.Item = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public StateTransitionView() {
|
---|
41 | InitializeComponent();
|
---|
42 | }
|
---|
43 |
|
---|
44 | public StateTransitionView(StateTransition stateTransition)
|
---|
45 | : this() {
|
---|
46 | StateTransition = stateTransition;
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected override void RemoveItemEvents() {
|
---|
50 | StateTransition.Changed -= new EventHandler(StateTransition_Changed);
|
---|
51 | base.RemoveItemEvents();
|
---|
52 | }
|
---|
53 | protected override void AddItemEvents() {
|
---|
54 | base.AddItemEvents();
|
---|
55 | StateTransition.Changed += new EventHandler(StateTransition_Changed);
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void UpdateControls() {
|
---|
59 | base.UpdateControls();
|
---|
60 | if (StateTransition == null) {
|
---|
61 | transitionFunctionProgrammableOperatorView.Enabled = false;
|
---|
62 | targetStateComboBox.Enabled = false;
|
---|
63 | targetStateComboBox.DataSource = null;
|
---|
64 | targetStateComboBox.Items.Clear();
|
---|
65 | } else {
|
---|
66 | targetStateComboBox.Enabled = true;
|
---|
67 | transitionFunctionProgrammableOperatorView.ProgrammableOperator = StateTransition.TransitionCondition;
|
---|
68 | transitionFunctionProgrammableOperatorView.Enabled = true;
|
---|
69 | BuildTargetStateComboBox();
|
---|
70 | BuildVariablesListBox();
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | void StateTransition_Changed(object sender, EventArgs e) {
|
---|
75 | Refresh();
|
---|
76 | }
|
---|
77 |
|
---|
78 | void VariablesList_Changed(object sender, EventArgs e) {
|
---|
79 | BuildVariablesListBox();
|
---|
80 | }
|
---|
81 |
|
---|
82 | #region Events to synchronize changes in request/response variables to state transition
|
---|
83 | void Parameter_Changed(object sender, EventArgs e) {
|
---|
84 | BuildVariablesListBox();
|
---|
85 | }
|
---|
86 | void Parameter_Added(object sender, ItemIndexEventArgs e) {
|
---|
87 | ((IItem)e.Item).Changed += new EventHandler(Parameter_Changed);
|
---|
88 | }
|
---|
89 | void Parameter_Removed(object sender, ItemIndexEventArgs e) {
|
---|
90 | ((IItem)e.Item).Changed -= new EventHandler(Parameter_Changed);
|
---|
91 | }
|
---|
92 | #endregion
|
---|
93 |
|
---|
94 | private void BuildTargetStateComboBox() {
|
---|
95 | ComboBox comboBox = targetStateComboBox;
|
---|
96 | ItemList<ProtocolState> states = null;
|
---|
97 | /*if (StateTransition.SourceState == null || StateTransition.SourceState.Protocol == null)
|
---|
98 | states = null;
|
---|
99 | else
|
---|
100 | states = StateTransition.SourceState.Protocol.States;*/
|
---|
101 | ProtocolState selected = StateTransition.TargetState;
|
---|
102 | ProtocolState forbidden = StateTransition.SourceState;
|
---|
103 |
|
---|
104 | if (states != null && states.Count > 0) {
|
---|
105 | IList<ProtocolState> sourceList = new List<ProtocolState>(states.Count);
|
---|
106 | int selectedIndex = -1, counter = -1;
|
---|
107 | for (int i = 0 ; i < states.Count ; i++) {
|
---|
108 | if (forbidden == null || !states[i].Guid.Equals(forbidden.Guid)) {
|
---|
109 | sourceList.Add((ProtocolState)states[i]);
|
---|
110 | counter++;
|
---|
111 | }
|
---|
112 | if (selected != null && states[i].Guid.Equals(selected.Guid))
|
---|
113 | selectedIndex = counter;
|
---|
114 | }
|
---|
115 | comboBox.SelectedIndexChanged -= new EventHandler(targetStateComboBox_SelectedIndexChanged);
|
---|
116 | BindingList<ProtocolState> bl = new BindingList<ProtocolState>(sourceList);
|
---|
117 | comboBox.DataSource = bl;
|
---|
118 | comboBox.DisplayMember = "Name";
|
---|
119 | comboBox.ValueMember = "Guid";
|
---|
120 | comboBox.SelectedIndex = selectedIndex;
|
---|
121 | comboBox.SelectedIndexChanged += new EventHandler(targetStateComboBox_SelectedIndexChanged);
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void BuildVariablesListBox() {
|
---|
126 | ListBox variables = variablesListBox;
|
---|
127 | /*ConstrainedItemList request = StateTransition.SourceState.SendingData;
|
---|
128 | ConstrainedItemList response = StateTransition.SourceState.ReceivingData;*/
|
---|
129 | variables.Items.Clear();
|
---|
130 | variables.Items.Add("==Sending==");
|
---|
131 | /*for (int i = 0 ; i < request.Count ; i++) {
|
---|
132 | variables.Items.Add(request[i]);
|
---|
133 | }*/
|
---|
134 | variables.Items.Add("==Receiving==");
|
---|
135 | /*for (int i = 0 ; i < response.Count ; i++) {
|
---|
136 | variables.Items.Add(response[i]);
|
---|
137 | }*/
|
---|
138 | }
|
---|
139 |
|
---|
140 | private void targetStateComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
141 | if (targetStateComboBox.SelectedIndex >= 0) {
|
---|
142 | StateTransition.TargetState = (ProtocolState)targetStateComboBox.SelectedItem;
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|