1 | using System.Collections.Generic;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Windows.Forms;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
7 | public partial class JsonItemValidValuesControl : UserControl {
|
---|
8 |
|
---|
9 | StringValueVM VM { get; set; }
|
---|
10 |
|
---|
11 | public JsonItemValidValuesControl(StringValueVM vm) {
|
---|
12 | InitializeComponent();
|
---|
13 | VM = vm;
|
---|
14 | if (VM.Item.ConcreteRestrictedItems != null) {
|
---|
15 | concreteItemsRestrictor.OnChecked += AddComboOption;
|
---|
16 | concreteItemsRestrictor.OnUnchecked += RemoveComboOption;
|
---|
17 | concreteItemsRestrictor.Init(VM.Item.ConcreteRestrictedItems);
|
---|
18 | comboBoxValues.DataBindings.Add("SelectedItem", VM, nameof(StringValueVM.Value));
|
---|
19 | } else {
|
---|
20 | groupBoxRange.Hide();
|
---|
21 | TextBox tb = new TextBox();
|
---|
22 | tableLayoutPanel2.Controls.Remove(comboBoxValues);
|
---|
23 | tableLayoutPanel2.Controls.Add(tb, 1, 0);
|
---|
24 |
|
---|
25 | tb.Location = comboBoxValues.Location;
|
---|
26 | tb.Margin = new Padding(0);
|
---|
27 | tb.Size = new Size(comboBoxValues.Size.Width, 20);
|
---|
28 | tb.Anchor = AnchorStyles.Top | AnchorStyles.Left;
|
---|
29 | tb.Dock = DockStyle.Fill;
|
---|
30 |
|
---|
31 | tb.DataBindings.Add("Text", VM, nameof(StringValueVM.Value));
|
---|
32 | tb.Show();
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | private void AddComboOption(object opt) {
|
---|
37 | comboBoxValues.Items.Add(opt);
|
---|
38 | IList<string> items = new List<string>();
|
---|
39 | foreach (var i in comboBoxValues.Items) {
|
---|
40 | items.Add((string)i);
|
---|
41 | }
|
---|
42 | VM.Range = items;
|
---|
43 | comboBoxValues.Enabled = true;
|
---|
44 | }
|
---|
45 |
|
---|
46 | private void RemoveComboOption(object opt) {
|
---|
47 | comboBoxValues.Items.Remove(opt);
|
---|
48 | IList<string> items = new List<string>();
|
---|
49 | foreach (var i in comboBoxValues.Items) {
|
---|
50 | items.Add((string)i);
|
---|
51 | }
|
---|
52 | VM.Range = items;
|
---|
53 | if (VM.Range.Count() <= 0) {
|
---|
54 | comboBoxValues.Enabled = false;
|
---|
55 | comboBoxValues.SelectedIndex = -1;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|