Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValidValuesControl.cs @ 17473

Last change on this file since 17473 was 17473, checked in by dpiringe, 4 years ago

#3026:

  • refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
  • updated view models for new json item structure
  • updated SingleLineArrayJsonWriter
File size: 2.6 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.Threading.Tasks;
9using System.Windows.Forms;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.