Free cookie consent management tool by TermsFeed Policy Generator

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

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

Put the GPL license in the files from the communication framework and simulation optimization project (branch 3.1)

File size: 4.2 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.Core;
30using HeuristicLab.Operators;
31using HeuristicLab.Data;
32using HeuristicLab.Communication.Data;
33
34namespace HeuristicLab.Communication.Operators {
35  public partial class ProtocolInjectorView : ViewBase {
36    public ProtocolInjector ProtocolInjector {
37      get { return (ProtocolInjector)Item; }
38      set {
39        Item = value;
40      }
41    }
42
43    public ProtocolInjectorView() {
44      InitializeComponent(); // killed self included code regarding ItemDictionaryView
45      dictionaryTabPage.SuspendLayout();
46      SuspendLayout();
47      itemDictionaryView = new ItemDictionaryView<StringData, StringData>();
48      itemDictionaryView.Location = new Point(6, 6);
49      itemDictionaryView.Dock = DockStyle.Fill;
50      itemDictionaryView.Name = "itemDictionaryView";
51      dictionaryTabPage.Controls.Add(itemDictionaryView);
52      dictionaryTabPage.ResumeLayout(false);
53      ResumeLayout(false);
54    }
55
56    public ProtocolInjectorView(ProtocolInjector protocolInjector)
57      : this() {
58      ProtocolInjector = protocolInjector;
59    }
60
61    protected override void RemoveItemEvents() {
62      operatorBaseVariableInfosView.Operator = null;
63      base.RemoveItemEvents();
64    }
65    protected override void AddItemEvents() {
66      base.AddItemEvents();
67      operatorBaseVariableInfosView.Operator = ProtocolInjector;
68    }
69
70    protected override void UpdateControls() {
71      base.UpdateControls();
72      if (ProtocolInjector == null) {
73        loadProtocolButton.Enabled = false;
74        protocolEditor.Enabled = false;
75        protocolEditor.Protocol = null;
76        itemDictionaryView.Enabled = false;
77        itemDictionaryView.ItemDictionary = null;
78      } else {
79        loadProtocolButton.Enabled = true;
80        protocolEditor.Protocol = (Protocol)ProtocolInjector.GetVariable("Protocol").Value;
81        protocolEditor.Enabled = true;
82        IVariable dict = ProtocolInjector.GetVariable("Dictionary");
83        if (dict == null) { // BACKWARDS COMPATIBLE CODE for versions prior to 3.0.0.40
84          dict = new Variable("Dictionary", new ItemDictionary<StringData, StringData>());
85          ProtocolInjector.AddVariable(dict);
86          ProtocolInjector.AddVariableInfo(new VariableInfo("Dictionary", "The received value translation dictionary", typeof(Dictionary<StringData, StringData>), VariableKind.New));
87        }
88        itemDictionaryView.ItemDictionary = (ItemDictionary<StringData, StringData>)dict.Value;
89        itemDictionaryView.Enabled = true;
90      }
91    }
92
93    private void loadProtocolButton_Click(object sender, EventArgs e) {
94      if (protocolOpenFileDialog.ShowDialog() == DialogResult.OK) {
95        Protocol protocol = null;
96        try {
97          protocol = (Protocol)PersistenceManager.Load(protocolOpenFileDialog.FileName);
98        } catch (InvalidCastException) {
99          throw new InvalidOperationException("Document is not a protocol");
100        } catch (Exception ex) {
101          throw new InvalidOperationException("An exception has occured:\n"+ex.Message.ToString());
102        }
103        ProtocolInjector.GetVariable("Protocol").Value = protocol;
104        UpdateControls();
105      }
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.