Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.Communication.Operators/ProtocolInjectorView.cs @ 583

Last change on this file since 583 was 583, checked in by abeham, 16 years ago

Adding communication framework to branch 3.1 (ticket #278)

File size: 3.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Text;
7using System.Windows.Forms;
8using HeuristicLab.Core;
9using HeuristicLab.Operators;
10using HeuristicLab.Data;
11using HeuristicLab.Communication.Data;
12
13namespace HeuristicLab.Communication.Operators {
14  public partial class ProtocolInjectorView : ViewBase {
15    public ProtocolInjector ProtocolInjector {
16      get { return (ProtocolInjector)Item; }
17      set {
18        Item = value;
19      }
20    }
21
22    public ProtocolInjectorView() {
23      InitializeComponent(); // killed self included code regarding ItemDictionaryView
24      dictionaryTabPage.SuspendLayout();
25      SuspendLayout();
26      itemDictionaryView = new ItemDictionaryView<StringData, StringData>();
27      itemDictionaryView.Location = new Point(6, 6);
28      itemDictionaryView.Dock = DockStyle.Fill;
29      itemDictionaryView.Name = "itemDictionaryView";
30      dictionaryTabPage.Controls.Add(itemDictionaryView);
31      dictionaryTabPage.ResumeLayout(false);
32      ResumeLayout(false);
33    }
34
35    public ProtocolInjectorView(ProtocolInjector protocolInjector)
36      : this() {
37      ProtocolInjector = protocolInjector;
38    }
39
40    protected override void RemoveItemEvents() {
41      operatorBaseVariableInfosView.Operator = null;
42      base.RemoveItemEvents();
43    }
44    protected override void AddItemEvents() {
45      base.AddItemEvents();
46      operatorBaseVariableInfosView.Operator = ProtocolInjector;
47    }
48
49    protected override void UpdateControls() {
50      base.UpdateControls();
51      if (ProtocolInjector == null) {
52        loadProtocolButton.Enabled = false;
53        protocolEditor.Enabled = false;
54        protocolEditor.Protocol = null;
55        itemDictionaryView.Enabled = false;
56        itemDictionaryView.ItemDictionary = null;
57      } else {
58        loadProtocolButton.Enabled = true;
59        protocolEditor.Protocol = (Protocol)ProtocolInjector.GetVariable("Protocol").Value;
60        protocolEditor.Enabled = true;
61        IVariable dict = ProtocolInjector.GetVariable("Dictionary");
62        if (dict == null) { // BACKWARDS COMPATIBLE CODE for versions prior to 3.0.0.40
63          dict = new Variable("Dictionary", new ItemDictionary<StringData, StringData>());
64          ProtocolInjector.AddVariable(dict);
65          ProtocolInjector.AddVariableInfo(new VariableInfo("Dictionary", "The received value translation dictionary", typeof(Dictionary<StringData, StringData>), VariableKind.New));
66        }
67        itemDictionaryView.ItemDictionary = (ItemDictionary<StringData, StringData>)dict.Value;
68        itemDictionaryView.Enabled = true;
69      }
70    }
71
72    private void loadProtocolButton_Click(object sender, EventArgs e) {
73      if (protocolOpenFileDialog.ShowDialog() == DialogResult.OK) {
74        Protocol protocol = null;
75        try {
76          protocol = (Protocol)PersistenceManager.Load(protocolOpenFileDialog.FileName);
77        } catch (InvalidCastException) {
78          throw new InvalidOperationException("Document is not a protocol");
79        } catch (Exception ex) {
80          throw new InvalidOperationException("An exception has occured:\n"+ex.Message.ToString());
81        }
82        ProtocolInjector.GetVariable("Protocol").Value = protocol;
83        UpdateControls();
84      }
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.