1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 | using HeuristicLab.Core;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.CEDMA.Server {
|
---|
12 | public partial class DispatcherView : ViewBase {
|
---|
13 | private SimpleDispatcher dispatcher;
|
---|
14 | public DispatcherView(SimpleDispatcher 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 | algorithmsListBox.Items.Clear();
|
---|
29 | targetVariableList.Items.Clear();
|
---|
30 | inputVariableList.Items.Clear();
|
---|
31 |
|
---|
32 | foreach (string targetVar in dispatcher.TargetVariables) {
|
---|
33 | targetVariableList.Items.Add(targetVar, false);
|
---|
34 | }
|
---|
35 |
|
---|
36 | foreach (string inputVar in dispatcher.InputVariables) {
|
---|
37 | inputVariableList.Items.Add(inputVar, false);
|
---|
38 | }
|
---|
39 |
|
---|
40 | foreach (HeuristicLab.Modeling.IAlgorithm algo in dispatcher.Algorithms) {
|
---|
41 | algorithmsListBox.Items.Add(algo, false);
|
---|
42 | }
|
---|
43 | targetVariableList.ClearSelected();
|
---|
44 | inputVariableList.Enabled = false;
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | private void targetVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
|
---|
49 | if (e.NewValue == CheckState.Checked) {
|
---|
50 | dispatcher.EnableTargetVariable((string)targetVariableList.Items[e.Index]);
|
---|
51 | } else if (e.NewValue == CheckState.Unchecked) {
|
---|
52 | dispatcher.DisableTargetVariable((string)targetVariableList.Items[e.Index]);
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
|
---|
57 | string selectedTarget = (string)targetVariableList.SelectedItem;
|
---|
58 | if (e.NewValue == CheckState.Checked) {
|
---|
59 | dispatcher.EnableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
|
---|
60 | } else if (e.NewValue == CheckState.Unchecked) {
|
---|
61 | dispatcher.DisableInputVariable(selectedTarget, (string)inputVariableList.Items[e.Index]);
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) {
|
---|
66 | string selectedTarget = (string)targetVariableList.SelectedItem;
|
---|
67 | UpdateInputVariableList(selectedTarget);
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void UpdateInputVariableList(string target) {
|
---|
71 | inputVariableList.Items.Clear();
|
---|
72 | var activatedInputVariables = dispatcher.GetInputVariables(target);
|
---|
73 | foreach (string inputVar in dispatcher.InputVariables) {
|
---|
74 | inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar));
|
---|
75 | }
|
---|
76 | inputVariableList.Enabled = true;
|
---|
77 | }
|
---|
78 |
|
---|
79 | private void setAllButton_Click(object sender, EventArgs e) {
|
---|
80 | foreach (string targetVar in dispatcher.TargetVariables) {
|
---|
81 | for (int i = 0; i < inputVariableList.Items.Count; i++) {
|
---|
82 | if (inputVariableList.GetItemChecked(i)) {
|
---|
83 | dispatcher.EnableInputVariable(targetVar, (string)inputVariableList.Items[i]);
|
---|
84 | } else {
|
---|
85 | dispatcher.DisableInputVariable(targetVar, (string)inputVariableList.Items[i]);
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | private void algorithmsListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
|
---|
92 | if(e.NewValue == CheckState.Checked) {
|
---|
93 | dispatcher.EnableAlgorithm((HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
|
---|
94 | } else if(e.NewValue == CheckState.Unchecked) {
|
---|
95 | dispatcher.DisableAlgorithm((HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|