Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.Communication.Data/3.2/StateTransitionView.cs @ 3025

Last change on this file since 3025 was 2474, checked in by swagner, 15 years ago

Implemented generic EventArgs (#796)

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