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.Threading.Tasks;
|
---|
9 | using System.Windows.Forms;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
12 | public partial class JsonItemValidValuesControl : UserControl {
|
---|
13 |
|
---|
14 | StringValueVM VM { get; set; }
|
---|
15 |
|
---|
16 | public JsonItemValidValuesControl(StringValueVM vm) {
|
---|
17 | InitializeComponent();
|
---|
18 | VM = vm;
|
---|
19 | if (VM.Item.ConcreteRestrictedItems != null) {
|
---|
20 | foreach (var i in VM.Item.ConcreteRestrictedItems)
|
---|
21 | SetupOption(i);
|
---|
22 | comboBoxValues.DataBindings.Add("SelectedItem", VM, nameof(StringValueVM.Value));
|
---|
23 | } else {
|
---|
24 | comboBoxValues.Hide();
|
---|
25 | groupBoxRange.Hide();
|
---|
26 | TextBox tb = new TextBox();
|
---|
27 | this.Controls.Add(tb);
|
---|
28 | tb.Location = comboBoxValues.Location;
|
---|
29 | tb.Size = comboBoxValues.Size;
|
---|
30 | tb.Anchor = comboBoxValues.Anchor;
|
---|
31 | tb.Dock = comboBoxValues.Dock;
|
---|
32 | tb.DataBindings.Add("Text", VM, nameof(StringValueVM.Value));
|
---|
33 | tb.Show();
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | private void SetupOption(string opt) {
|
---|
38 | AddComboOption(opt);
|
---|
39 | TextBox tb = new TextBox();
|
---|
40 | tb.Text = opt;
|
---|
41 | //tb.Size = new Size()
|
---|
42 | tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
---|
43 | //tb.Dock = DockStyle.Right | DockStyle.Left;
|
---|
44 | tb.ReadOnly = true;
|
---|
45 |
|
---|
46 | CheckBox checkBox = new CheckBox();
|
---|
47 | checkBox.Checked = true;
|
---|
48 |
|
---|
49 | checkBox.CheckStateChanged += (o, args) => {
|
---|
50 | if (checkBox.Checked)
|
---|
51 | AddComboOption(opt);
|
---|
52 | else
|
---|
53 | RemoveComboOption(opt);
|
---|
54 | };
|
---|
55 | tableOptions.Controls.Add(checkBox);
|
---|
56 | tableOptions.Controls.Add(tb);
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void AddComboOption(string opt) {
|
---|
60 | comboBoxValues.Items.Add(opt);
|
---|
61 | IList<string> items = new List<string>();
|
---|
62 | foreach (var i in comboBoxValues.Items) {
|
---|
63 | items.Add((string)i);
|
---|
64 | }
|
---|
65 | ((StringValueVM)VM).Range = items;
|
---|
66 | comboBoxValues.Enabled = true;
|
---|
67 | tableOptions.Refresh();
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void RemoveComboOption(string opt) {
|
---|
71 | comboBoxValues.Items.Remove(opt);
|
---|
72 | IList<string> items = new List<string>();
|
---|
73 | foreach (var i in comboBoxValues.Items) {
|
---|
74 | items.Add((string)i);
|
---|
75 | }
|
---|
76 | ((StringValueVM)VM).Range = items;
|
---|
77 | if (((StringValueVM)VM).Range.Count() <= 0) {
|
---|
78 | comboBoxValues.Enabled = false;
|
---|
79 | comboBoxValues.SelectedIndex = -1;
|
---|
80 | }
|
---|
81 | tableOptions.Refresh();
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|