Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs @ 2244

Last change on this file since 2244 was 2223, checked in by mkommend, 15 years ago

reintegrated branch new heuristic.modeling database backend (ticket #712)

File size: 2.7 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)
15      : base() {
16      this.dispatcher = dispatcher;
17      InitializeComponent();
18      UpdateControls();
19      dispatcher.Changed += (sender, args) => UpdateControls();
20      this.inputVariableList.CheckOnClick = true;
21    }
22
23    protected override void UpdateControls() {
24      if (InvokeRequired) {
25        Invoke((Action)UpdateControls);
26      } else {
27        base.UpdateControls();
28        targetVariableList.Items.Clear();
29        inputVariableList.Items.Clear();
30
31        foreach (string targetVar in dispatcher.TargetVariables) {
32          targetVariableList.Items.Add(targetVar, false);
33        }
34
35        foreach (string inputVar in dispatcher.InputVariables) {
36          inputVariableList.Items.Add(inputVar, false);
37        }
38        targetVariableList.ClearSelected();
39        inputVariableList.Enabled = false;
40      }
41    }
42
43    private void targetVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
44      if (e.NewValue == CheckState.Checked) {
45        dispatcher.EnableTargetVariable((string)targetVariableList.Items[e.Index]);
46      } else if (e.NewValue == CheckState.Unchecked) {
47        dispatcher.DisableTargetVariable((string)targetVariableList.Items[e.Index]);
48      }
49    }
50
51    private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
52      string selectedTarget = (string)targetVariableList.SelectedItem;
53      if (e.NewValue == CheckState.Checked) {
54        dispatcher.EnableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
55      } else if (e.NewValue == CheckState.Unchecked) {
56        dispatcher.DisableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
57      }
58    }
59
60    private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) {
61      string selectedTarget = (string)targetVariableList.SelectedItem;
62      UpdateInputVariableList(selectedTarget);
63    }
64
65    private void UpdateInputVariableList(string target) {
66      inputVariableList.Items.Clear();
67      var activatedInputVariables = dispatcher.GetInputVariables(target);
68      foreach (string inputVar in dispatcher.InputVariables) {
69        inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar));
70      }
71      inputVariableList.Enabled = true;
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.