Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/ConcreteItemsRestrictor.cs @ 17828

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

#3026:

  • added error output for failed runner initialization
  • reorganised some final view models
  • TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
  • code cleanup
  • refactored RegressionProblemDataConverter
  • added lots of comments
  • added new view for StringArrayJsonItem
  • added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
File size: 1.5 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 ConcreteItemsRestrictor : UserControl {
13
14    public event Action<object> OnChecked;
15    public event Action<object> OnUnchecked;
16
17    public ConcreteItemsRestrictor() {
18      InitializeComponent();
19    }
20
21    public void Init<T>(IEnumerable<T> objs) {
22      if(objs != null) {
23        foreach(var obj in objs) {
24          SetupOption(obj);
25        }
26      }
27    }
28
29    private void SetupOption(object opt) {
30      AddComboOption(opt);
31      TextBox tb = new TextBox();
32      tb.Text = opt.ToString();
33      tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
34      tb.ReadOnly = true;
35
36      CheckBox checkBox = new CheckBox();
37      checkBox.Checked = true;
38
39      checkBox.CheckStateChanged += (o, args) => {
40        if (checkBox.Checked)
41          AddComboOption(opt);
42        else
43          RemoveComboOption(opt);
44      };
45      tableOptions.Controls.Add(checkBox);
46      tableOptions.Controls.Add(tb);
47    }
48
49    private void AddComboOption(object obj) {
50      OnChecked?.Invoke(obj);
51      tableOptions.Refresh();
52    }
53
54    private void RemoveComboOption(object obj) {
55      OnUnchecked?.Invoke(obj);
56      tableOptions.Refresh();
57    }
58  }
59}
Note: See TracBrowser for help on using the repository browser.