Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/23/21 16:36:44 (4 years ago)
Author:
dpiringe
Message:

#3026

  • removed property ConvertableType from all converters
  • removed the option to fixate or loosen the path of JsonItems (obsolete)
  • added a abstract formatter SymbolicRegressionSolutionFormatterBase as base formatter for ISymbolicRegressionSolution
  • unified the construction of exporter controls
  • code cleanup
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Interfaces/IArrayJsonItemVM.cs

    r17446 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 
    7 namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     1namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    82  public interface IArrayJsonItemVM : IJsonItemVM {
    93    bool Resizable { get; set; }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Interfaces/IJsonItemVM.cs

    r17473 r17843  
    11using System;
    2 using System.Collections.Generic;
    32using System.ComponentModel;
    4 using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    73using System.Windows.Forms;
    84
    95namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    10   public interface IJsonItemVM : INotifyPropertyChanged, IDisposable
     6  public interface IJsonItemVM : INotifyPropertyChanged
    117  {
    128    event Action ItemChanged;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Interfaces/ILookupJsonItemVM.cs

    r17471 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 
    7 namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    8   public interface ILookupJsonItemVM : IJsonItemVM {
    9     string ActualName { get; set; }
    10   }
     1namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     2  public interface ILookupJsonItemVM : IJsonItemVM { }
    113}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Interfaces/IMatrixJsonItemVM.cs

    r17471 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
     1using System.Collections.Generic;
    62
    73namespace HeuristicLab.JsonInterface.OptimizerIntegration {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Interfaces/IValueLookupJsonItemVM.cs

    r17471 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 
    7 namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     1namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    82  public interface IValueLookupJsonItemVM : ILookupJsonItemVM {
    93    IJsonItem JsonItemReference { get; }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ArrayValueVM.cs

    r17828 r17843  
    11using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    72using System.Windows.Forms;
    83
     
    1712    public ArrayValueVM() { }
    1813   
    19     public abstract T[] Value { get; set; }
    2014    public bool Resizable {
    2115      get => Item.Resizable;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ConcreteRestrictedJsonItemVM.cs

    r17828 r17843  
    1 using System;
    2 using System.Collections.Generic;
     1using System.Collections.Generic;
    32using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    63using System.Windows.Forms;
    74
     
    1714    public override UserControl Control {
    1815      get {
    19         var control = new ConcreteItemsRestrictor();
    20         control.Init(Item.ConcreteRestrictedItems);
     16        var control = ConcreteItemsRestrictor.Create(Item.ConcreteRestrictedItems);
    2117        control.OnChecked += AddComboOption;
    2218        control.OnUnchecked += RemoveComboOption;
    2319        return control;
    24       }
    25     }
    26 
    27     public V Value {
    28       get => Item.Value;
    29       set {
    30         Item.Value = value;
    31         OnPropertyChange(this, nameof(Value));
    3220      }
    3321    }
     
    4028
    4129        if (!RangeContainsValue()) {
    42           Value = GetDefaultValue();
     30          Item.Value = GetDefaultValue();
    4331
    4432          //if no elements exists -> deselect item
    4533          if (Range.Count() == 0)
    4634            base.Selected = false;
    47 
    48           OnPropertyChange(this, nameof(Value));
    4935        }
    5036
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/DoubleVMs.cs

    r17828 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 using System.Windows.Forms;
    7 
    8 namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     1namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    92  public class DoubleRangeVM : RangeVM<double, DoubleRangeJsonItem> {
    103    protected override double MinTypeValue => double.MinValue;
     
    158    protected override double MinTypeValue => double.MinValue;
    169    protected override double MaxTypeValue => double.MaxValue;
    17     public override double[] Value {
    18       get => Item.Value;
    19       set {
    20         Item.Value = value;
    21         OnPropertyChange(this, nameof(Value));
    22       }
    23     }
    2410  }
    2511
    2612  public class DoubleMatrixValueVM : MatrixValueVM<double, DoubleMatrixJsonItem> {
    27     public override double[][] Value {
    28       get => Item.Value;
    29       set {
    30         Item.Value = value;
    31         OnPropertyChange(this, nameof(Value));
    32       }
    33     }
    3413    protected override double MinTypeValue => double.MinValue;
    3514    protected override double MaxTypeValue => double.MaxValue;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/IntVMs.cs

    r17828 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 using System.Windows.Forms;
    7 
    8 namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     1namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    92  public class IntArrayValueVM : ArrayValueVM<int, IntArrayJsonItem> {
    103    protected override int MinTypeValue => int.MinValue;
    114    protected override int MaxTypeValue => int.MaxValue;
    12 
    13     public override int[] Value {
    14       get => Item.Value;
    15       set {
    16         Item.Value = value;
    17         OnPropertyChange(this, nameof(Value));
    18       }
    19     }
    205  }
    216
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVMBase.cs

    r17828 r17843  
    11using System;
    2 using System.Collections.Generic;
    32using System.ComponentModel;
    43using System.Drawing;
    5 using System.Linq;
    6 using System.Text;
    7 using System.Threading.Tasks;
    84using System.Windows.Forms;
    95
     
    2117      get => item;
    2218      set {
    23         item?.LoosenPath();
    2419        item = value;
    25         item.FixatePath();
    2620        ItemChanged?.Invoke();
    2721      }
     
    6559    public event Action SelectedChanged;
    6660
    67 
    6861    protected void OnPropertyChange(object sender, string propertyName) {
    6962      // Make a temporary copy of the event to avoid possibility of
     
    7568      tmp?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    7669    }
    77    
    78     #region IDisposable Support
    79     private bool disposedValue = false; // To detect redundant calls
    80 
    81     protected virtual void Dispose(bool disposing) {
    82       if (!disposedValue) {
    83         if (disposing) {
    84           item.LoosenPath();
    85           item = null;
    86         }
    87         disposedValue = true;
    88       }
    89     }
    90 
    91     // This code added to correctly implement the disposable pattern.
    92     public void Dispose() {
    93       // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
    94       Dispose(true);
    95     }
    96     #endregion
    9770  }
    9871}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/LookupJsonItemVM.cs

    r17828 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    6 using System.Windows.Forms;
     1using System.Windows.Forms;
    72
    83namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    94  public class LookupJsonItemVM : JsonItemVMBase<LookupJsonItem>, ILookupJsonItemVM {
    105    public override UserControl Control => null;
    11     public string ActualName {
    12       get => Item.ActualName;
    13       set {
    14         Item.ActualName = value;
    15         OnPropertyChange(this, nameof(ActualName));
    16       }
    17     }
    186  }
    197}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/MatrixValueVM.cs

    r17828 r17843  
    11using System;
    22using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    73using System.Windows.Forms;
    84
     
    1612    public override UserControl Control => CompoundControl.Create(base.Control, MatrixJsonItemControl.Create(this));
    1713
    18     public abstract T[][] Value { get; set; }
    1914    public bool RowsResizable {
    2015      get => Item.RowsResizable;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/RangeVM.cs

    r17519 r17843  
    11using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    7 using System.Windows.Forms;
    8 
    92namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    10 
    113  public abstract class RangeVM<T, JsonItemType> : RangedValueBaseVM<T, JsonItemType>
    124    where T : IComparable
    135    where JsonItemType : class, IRangedJsonItem<T>
    14   {
    15 
    16     public T MinValue {
    17       get => Item.MinValue;
    18       set {
    19         Item.MinValue = value;
    20         OnPropertyChange(this, nameof(MinValue));
    21       }
    22     }
    23 
    24     public T MaxValue {
    25       get => Item.MaxValue;
    26       set {
    27         Item.MaxValue = value;
    28         OnPropertyChange(this, nameof(MaxValue));
    29       }
    30     }
    31   }
     6  { }
    327}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/RangedValueBaseVM.cs

    r17828 r17843  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    62using System.Windows.Forms;
    73
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ResultItemVM.cs

    r17834 r17843  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    62using System.Windows.Forms;
    73
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/SingleValueVM.cs

    r17828 r17843  
    11using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    72using System.Windows.Forms;
    83
     
    105
    116  public class BoolValueVM : JsonItemVMBase<BoolJsonItem> {
    12 
    13     public bool Value {
    14       get => Item.Value;
    15       set {
    16         Item.Value = value;
    17         OnPropertyChange(this, nameof(Value));
    18       }
    19     }
    20    
    217    public override UserControl Control => null;
    228  }
     
    2511    where T : IComparable
    2612    where JsonItemType : class, IIntervalRestrictedJsonItem<T>, IValueJsonItem<T>
    27   {
    28 
    29     public T Value {
    30       get => Item.Value;
    31       set {
    32         Item.Value = value;
    33         OnPropertyChange(this, nameof(Value));
    34       }
    35     }
    36   }
     13  { }
    3714}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/StringValueVM.cs

    r17828 r17843  
    22
    33namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    4 
    54  public class StringValueVM : ConcreteRestrictedJsonItemVM<StringJsonItem, string, string> {
    65    protected override string GetDefaultValue() => Range.FirstOrDefault();
    7 
    8     protected override bool RangeContainsValue() => Range.Contains(Value);
     6    protected override bool RangeContainsValue() => Range.Contains(Item.Value);
    97  }
    108
    119  public class StringArrayVM : ConcreteRestrictedJsonItemVM<StringArrayJsonItem, string, string[]> {
    1210    protected override string[] GetDefaultValue() => Range.ToArray();
    13 
    14     protected override bool RangeContainsValue() => Value.All(x => Range.Any(y => x == y));
     11    protected override bool RangeContainsValue() => Item.Value.All(x => Range.Any(y => x == y));
    1512  }
    1613}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ValueLookupJsonItemVM.cs

    r17477 r17843  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    62using System.Windows.Forms;
    73
     
    95  public class ValueLookupJsonItemVM : LookupJsonItemVM, IValueLookupJsonItemVM {
    106    public override Type TargetedJsonItemType => typeof(ValueLookupJsonItem);
    11     public override UserControl Control => new ValueLookupJsonItemControl(this);
     7    public override UserControl Control => ValueLookupJsonItemControl.Create(this);
    128    public IJsonItem JsonItemReference => ((IValueLookupJsonItem)Item).ActualValue;
    139
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ArrayJsonItemControl.cs

    r17829 r17843  
    44  public partial class ArrayJsonItemControl : UserControl {
    55
    6     public ArrayJsonItemControl() {
     6    private ArrayJsonItemControl() {
    77      InitializeComponent();
    88    }
    99
    10     public static ArrayJsonItemControl Create(IJsonItemVM vm) {
    11       var control = new ArrayJsonItemControl();
    12       control.checkBoxResizable.DataBindings.Add("Checked", vm, nameof(IArrayJsonItemVM.Resizable));
    13       return control;
     10    protected ArrayJsonItemControl(IJsonItemVM vm) {
     11      InitializeComponent();
     12      checkBoxResizable.DataBindings.Add("Checked", vm, nameof(IArrayJsonItemVM.Resizable));
    1413    }
     14
     15    public static ArrayJsonItemControl Create(IJsonItemVM vm) => new ArrayJsonItemControl(vm);
    1516  }
    1617}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/CompoundControl.cs

    r17829 r17843  
    3232      }
    3333    }
    34     public CompoundControl() {
     34
     35    protected CompoundControl() {
    3536      InitializeComponent();
    3637    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ConcreteItemsRestrictor.cs

    r17829 r17843  
    1515    public event Action<object> OnUnchecked;
    1616
    17     public ConcreteItemsRestrictor() {
     17    protected ConcreteItemsRestrictor() {
    1818      InitializeComponent();
    1919    }
    2020
    21     public void Init<T>(IEnumerable<T> objs) {
    22       if(objs != null) {
    23         foreach(var obj in objs) {
     21    public static ConcreteItemsRestrictor Create<T>(IEnumerable<T> objs) {
     22      ConcreteItemsRestrictor ctrl = new ConcreteItemsRestrictor();
     23      ctrl.Init<T>(objs);
     24      return ctrl;
     25    }
     26
     27    protected void Init<T>(IEnumerable<T> objs) {
     28      if(objs != null)
     29        foreach(var obj in objs)
    2430          SetupOption(obj);
    25         }
    26       }
    2731    }
    2832
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs

    r17828 r17843  
    116116        VMs.Add(vm);
    117117        Node2VM.Add(node, vm);
    118         UserControl control = new JsonItemBaseControl(vm, vm.Control);
     118        UserControl control = JsonItemBaseControl.Create(vm, vm.Control);
    119119        Node2Control.Add(node, control);
    120120        return vm;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemBaseControl.cs

    r17829 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Drawing;
    5 using System.Data;
    6 using System.Linq;
    7 using System.Text;
    8 using System.Threading.Tasks;
     1using System.ComponentModel;
    92using System.Windows.Forms;
    103
     
    169      InitializeComponent();
    1710    }
    18    
    19     public JsonItemBaseControl(IJsonItemVM vm) {
     11
     12    protected JsonItemBaseControl(IJsonItemVM vm, UserControl control) {
    2013      InitializeComponent();
    2114      VM = vm;
    22       Init();
    23     }
    24 
    25     public JsonItemBaseControl(IJsonItemVM vm, UserControl control) {
    26       InitializeComponent();
    27       VM = vm;
    28       if(control != null) {
     15      if (control != null) {
    2916        control.Margin = new Padding() { All = 0 };
    3017        tableLayoutPanel1.Controls.Add(control, 0, 1);
    3118        control.Dock = DockStyle.Fill;
    3219      }
    33       Init();
    34     }
    35 
    36     private void Init() {
    3720      textBoxName.DataBindings.Add("Text", VM, nameof(IJsonItemVM.Name));
    3821      textBoxDescription.DataBindings.Add("Text", VM, nameof(IJsonItemVM.Description));
     
    4730      }
    4831    }
     32
     33    public static JsonItemBaseControl Create(IJsonItemVM vm, UserControl control) => new JsonItemBaseControl(vm, control);
    4934  }
    5035}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/MatrixJsonItemControl.cs

    r17829 r17843  
    33namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    44  public partial class MatrixJsonItemControl : UserControl {
    5     public MatrixJsonItemControl() {
     5    private MatrixJsonItemControl() {
    66      InitializeComponent();
    77    }
    88
    9     public static MatrixJsonItemControl Create(IJsonItemVM vm) {
    10       var control = new MatrixJsonItemControl();
    11       control.checkBoxRowsResizable.DataBindings.Add("Checked", vm, nameof(IMatrixJsonItemVM.RowsResizable));
    12       control.checkBoxColumnsResizable .DataBindings.Add("Checked", vm, nameof(IMatrixJsonItemVM.ColumnsResizable));
    13       return control;
     9    protected MatrixJsonItemControl(IJsonItemVM vm) {
     10      InitializeComponent();
     11      checkBoxRowsResizable.DataBindings.Add("Checked", vm, nameof(IMatrixJsonItemVM.RowsResizable));
     12      checkBoxColumnsResizable.DataBindings.Add("Checked", vm, nameof(IMatrixJsonItemVM.ColumnsResizable));
    1413    }
     14
     15    public static MatrixJsonItemControl Create(IJsonItemVM vm) => new MatrixJsonItemControl(vm);
    1516  }
    1617}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/NumericRangeControl.cs

    r17829 r17843  
    1616    public CheckBox EnableMinRange { get; set; }
    1717    public CheckBox EnableMaxRange { get; set; }
    18     public NumericRangeControl() {
     18
     19    private NumericRangeControl() {
    1920      InitializeComponent();
     21      Init();
     22    }
     23
     24    protected NumericRangeControl(IJsonItemVM vm) {
     25      InitializeComponent();
     26      Init();
     27      TBMinRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MinRange));
     28      TBMaxRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MaxRange));
     29      EnableMinRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMinRange),
     30        false, DataSourceUpdateMode.OnPropertyChanged);
     31      EnableMaxRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMaxRange),
     32        false, DataSourceUpdateMode.OnPropertyChanged);
     33    }
     34
     35
     36    private void Init() {
    2037      TBMinRange = textBoxFrom;
    2138      TBMaxRange = textBoxTo;
     
    5269    }
    5370
    54     public static UserControl Create(IJsonItemVM vm) {
    55       NumericRangeControl numericRangeControl = new NumericRangeControl();
    56       numericRangeControl.TBMinRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MinRange));
    57       numericRangeControl.TBMaxRange.DataBindings.Add("Text", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.MaxRange));
    58       numericRangeControl.EnableMinRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMinRange),
    59         false, DataSourceUpdateMode.OnPropertyChanged);
    60       numericRangeControl.EnableMaxRange.DataBindings.Add("Checked", vm, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMaxRange),
    61         false, DataSourceUpdateMode.OnPropertyChanged);
    62       return numericRangeControl;
    63     }
     71    public static UserControl Create(IJsonItemVM vm) => new NumericRangeControl(vm);
    6472  }
    6573}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ResultJsonItemControl.cs

    r17834 r17843  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Data;
    5 using System.Drawing;
    6 using System.Linq;
    7 using System.Text;
    8 using System.Threading.Tasks;
     1using System.Linq;
    92using System.Windows.Forms;
    103
    114namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    125  public partial class ResultJsonItemControl : UserControl {
    13     public ResultJsonItemControl() {
     6    private ResultJsonItemControl() {
    147      InitializeComponent();
    158    }
    169
    17     public static ResultJsonItemControl Create(ResultItemVM vm) {
    18       var control = new ResultJsonItemControl();
     10    protected ResultJsonItemControl(ResultItemVM vm) {
     11      InitializeComponent();
    1912      var formatters = ResultFormatter.ForType(vm.Item.ValueType).ToList();
    20       control.comboBoxFormatter.DataSource = formatters;
    21       control.comboBoxFormatter.DisplayMember = "Name";
    22      
     13      comboBoxFormatter.DataSource = formatters;
     14      comboBoxFormatter.DisplayMember = "Name";
     15
    2316      // set action to override the ResultFormatterType property for changing the selected value
    24       control.comboBoxFormatter.SelectedValueChanged += (s, e) => vm.ResultFormatterType = control.comboBoxFormatter.SelectedValue.GetType().FullName;
    25       control.comboBoxFormatter.SelectedItem = formatters.Last();
     17      comboBoxFormatter.SelectedValueChanged += (s, e) => vm.ResultFormatterType = comboBoxFormatter.SelectedValue.GetType().FullName;
     18      comboBoxFormatter.SelectedItem = formatters.Last();
     19    }
    2620
    27       return control;
    28     }
     21    public static ResultJsonItemControl Create(ResultItemVM vm) => new ResultJsonItemControl(vm);
    2922  }
    3023}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ValueLookupJsonItemControl.cs

    r17828 r17843  
    1212namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    1313  public partial class ValueLookupJsonItemControl : UserControl {
    14     private static IDictionary<Type, Type> JI2VM { get; set; }
    1514
    16     public ValueLookupJsonItemControl(IValueLookupJsonItemVM vm) {
     15    private static IDictionary<Type, Type> ji2vm = null;
     16    private static IDictionary<Type, Type> JI2VM {
     17      get {
     18        if (ji2vm == null) {
     19          ji2vm = new Dictionary<Type, Type>();
     20          foreach (var vmType in ApplicationManager.Manager.GetTypes(typeof(IJsonItemVM))) {
     21            IJsonItemVM vm = (IJsonItemVM)Activator.CreateInstance(vmType);
     22            ji2vm.Add(vm.TargetedJsonItemType, vmType);
     23          }
     24        }
     25        return ji2vm;
     26      }
     27    }
     28
     29    private ValueLookupJsonItemControl() {
    1730      InitializeComponent();
    18       InitCache();
     31    }
     32
     33    protected ValueLookupJsonItemControl(IValueLookupJsonItemVM vm) {
     34      InitializeComponent();
    1935      if (vm.JsonItemReference != null && JI2VM.TryGetValue(vm.JsonItemReference.GetType(), out Type vmType)) {
    2036        IJsonItemVM tmp = (IJsonItemVM)Activator.CreateInstance(vmType);
     
    2945    }
    3046
    31     private void InitCache() {
    32       if(JI2VM == null) {
    33         JI2VM = new Dictionary<Type, Type>();
    34         foreach (var vmType in ApplicationManager.Manager.GetTypes(typeof(IJsonItemVM))) {
    35           IJsonItemVM vm = (IJsonItemVM)Activator.CreateInstance(vmType);
    36           JI2VM.Add(vm.TargetedJsonItemType, vmType);
    37         }
    38       }
    39     }
     47    public static ValueLookupJsonItemControl Create(IValueLookupJsonItemVM vm) => new ValueLookupJsonItemControl(vm);
    4048  }
    4149}
Note: See TracChangeset for help on using the changeset viewer.