Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | using HeuristicLab.PluginInfrastructure;
|
---|
5 |
|
---|
6 | namespace 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.