Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Exporter-715/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs @ 3199

Last change on this file since 3199 was 2153, checked in by gkronber, 15 years ago

Changed CEDMA dispatcher to allow different input variable sets for each target variable. #676 (Cockpit for the CEDMA Server to control algorithm settings)

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Core;
10
11namespace HeuristicLab.CEDMA.Server {
12  public partial class DispatcherView : ViewBase {
13    private DispatcherBase dispatcher;
14    public DispatcherView(DispatcherBase dispatcher) : base() {
15      this.dispatcher = dispatcher;
16      InitializeComponent();
17      UpdateControls();
18      dispatcher.Changed += (sender, args) => UpdateControls();
19    }
20
21    protected override void UpdateControls() {
22      if (InvokeRequired) {
23        Invoke((Action)UpdateControls);
24      } else {
25        base.UpdateControls();
26        targetVariableList.Items.Clear();
27        inputVariableList.Items.Clear();
28
29        foreach (string targetVar in dispatcher.TargetVariables) {
30          targetVariableList.Items.Add(targetVar, false);
31        }
32
33        foreach (string inputVar in dispatcher.InputVariables) {
34          inputVariableList.Items.Add(inputVar, false);
35        }
36        targetVariableList.ClearSelected();
37        inputVariableList.Enabled = false;
38      }
39    }
40
41    private void targetVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
42      if (e.NewValue == CheckState.Checked) {
43        dispatcher.EnableTargetVariable((string)targetVariableList.Items[e.Index]);
44      } else if (e.NewValue == CheckState.Unchecked) {
45        dispatcher.DisableTargetVariable((string)targetVariableList.Items[e.Index]);
46      }
47    }
48
49    private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
50      string selectedTarget = (string)targetVariableList.SelectedItem;
51      if (e.NewValue == CheckState.Checked) {
52        dispatcher.EnableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
53      } else if (e.NewValue == CheckState.Unchecked) {
54        dispatcher.DisableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
55      }
56    }
57
58    private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) {
59      string selectedTarget = (string)targetVariableList.SelectedItem;
60      UpdateInputVariableList(selectedTarget);
61    }
62
63    private void UpdateInputVariableList(string target) {
64      inputVariableList.Items.Clear();
65      var activatedInputVariables = dispatcher.GetInputVariables(target);
66      foreach (string inputVar in dispatcher.InputVariables) {
67        inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar));
68      }
69      inputVariableList.Enabled = true;
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.