[17404] | 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 {
|
---|
[17464] | 12 | public partial class JsonItemValidValuesControl : UserControl {
|
---|
[17404] | 13 |
|
---|
[17473] | 14 | StringValueVM VM { get; set; }
|
---|
[17464] | 15 |
|
---|
| 16 | public JsonItemValidValuesControl(StringValueVM vm) {
|
---|
[17404] | 17 | InitializeComponent();
|
---|
[17464] | 18 | VM = vm;
|
---|
[17473] | 19 | if (VM.Item.ConcreteRestrictedItems != null) {
|
---|
| 20 | foreach (var i in VM.Item.ConcreteRestrictedItems)
|
---|
| 21 | SetupOption(i);
|
---|
[17443] | 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 | }
|
---|
[17404] | 35 | }
|
---|
[17417] | 36 |
|
---|
| 37 | private void SetupOption(string opt) {
|
---|
[17405] | 38 | AddComboOption(opt);
|
---|
[17404] | 39 | TextBox tb = new TextBox();
|
---|
| 40 | tb.Text = opt;
|
---|
[17443] | 41 | //tb.Size = new Size()
|
---|
[17404] | 42 | tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
---|
[17443] | 43 | //tb.Dock = DockStyle.Right | DockStyle.Left;
|
---|
[17404] | 44 | tb.ReadOnly = true;
|
---|
[17405] | 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);
|
---|
[17404] | 54 | };
|
---|
[17405] | 55 | tableOptions.Controls.Add(checkBox);
|
---|
[17404] | 56 | tableOptions.Controls.Add(tb);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[17405] | 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 | }
|
---|
[17417] | 65 | ((StringValueVM)VM).Range = items;
|
---|
| 66 | comboBoxValues.Enabled = true;
|
---|
[17405] | 67 | tableOptions.Refresh();
|
---|
[17404] | 68 | }
|
---|
| 69 |
|
---|
[17405] | 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 | }
|
---|
[17417] | 76 | ((StringValueVM)VM).Range = items;
|
---|
| 77 | if (((StringValueVM)VM).Range.Count() <= 0) {
|
---|
| 78 | comboBoxValues.Enabled = false;
|
---|
| 79 | comboBoxValues.SelectedIndex = -1;
|
---|
| 80 | }
|
---|
[17405] | 81 | tableOptions.Refresh();
|
---|
| 82 | }
|
---|
[17404] | 83 | }
|
---|
| 84 | }
|
---|