Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ConcreteItemsRestrictor.cs

Last change on this file was 18043, checked in by dpiringe, 3 years ago

#3026

  • code cleanup
File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Windows.Forms;
4
5namespace HeuristicLab.JsonInterface.OptimizerIntegration {
6  public partial class ConcreteItemsRestrictor : UserControl {
7
8    public event Action<object> OnChecked;
9    public event Action<object> OnUnchecked;
10
11    protected ConcreteItemsRestrictor() {
12      InitializeComponent();
13    }
14
15    public static ConcreteItemsRestrictor Create<T>(IEnumerable<T> objs) {
16      ConcreteItemsRestrictor ctrl = new ConcreteItemsRestrictor();
17      ctrl.Init<T>(objs);
18      return ctrl;
19    }
20
21    protected void Init<T>(IEnumerable<T> objs) {
22      if(objs != null)
23        foreach(var obj in objs)
24          SetupOption(obj);
25    }
26
27    private void SetupOption(object opt) {
28      AddComboOption(opt);
29      TextBox tb = new TextBox();
30      tb.Text = opt.ToString();
31      tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
32      tb.ReadOnly = true;
33
34      CheckBox checkBox = new CheckBox();
35      checkBox.Checked = true;
36      checkBox.Margin = new Padding(0);
37
38      checkBox.CheckStateChanged += (o, args) => {
39        if (checkBox.Checked)
40          AddComboOption(opt);
41        else
42          RemoveComboOption(opt);
43      };
44      tableOptions.Controls.Add(checkBox);
45      tableOptions.Controls.Add(tb);
46    }
47
48    private void AddComboOption(object obj) {
49      OnChecked?.Invoke(obj);
50      tableOptions.Refresh();
51    }
52
53    private void RemoveComboOption(object obj) {
54      OnUnchecked?.Invoke(obj);
55      tableOptions.Refresh();
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.