Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026

  • code cleanup
File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Windows.Forms;
4using HeuristicLab.PluginInfrastructure;
5
6namespace HeuristicLab.JsonInterface.OptimizerIntegration {
7  public partial class ValueLookupJsonItemControl : UserControl {
8
9    private static IDictionary<Type, Type> ji2vm = null;
10    private static IDictionary<Type, Type> JI2VM {
11      get {
12        if (ji2vm == null) {
13          ji2vm = new Dictionary<Type, Type>();
14          foreach (var vmType in ApplicationManager.Manager.GetTypes(typeof(IJsonItemVM))) {
15            IJsonItemVM vm = (IJsonItemVM)Activator.CreateInstance(vmType);
16            ji2vm.Add(vm.TargetedJsonItemType, vmType);
17          }
18        }
19        return ji2vm;
20      }
21    }
22
23    private ValueLookupJsonItemControl() {
24      InitializeComponent();
25    }
26
27    protected ValueLookupJsonItemControl(IValueLookupJsonItemVM vm) {
28      InitializeComponent();
29      if (vm.JsonItemReference != null && JI2VM.TryGetValue(vm.JsonItemReference.GetType(), out Type vmType)) {
30        IJsonItemVM tmp = (IJsonItemVM)Activator.CreateInstance(vmType);
31        tmp.Item = vm.JsonItemReference;
32        content.Controls.Clear();
33        UserControl control = tmp.Control;
34        if(control != null) {
35          content.Controls.Add(control);
36          control.Dock = DockStyle.Fill;
37        }
38      }
39    }
40
41    public static ValueLookupJsonItemControl Create(IValueLookupJsonItemVM vm) => new ValueLookupJsonItemControl(vm);
42  }
43}
Note: See TracBrowser for help on using the repository browser.