Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.cs @ 17530

Last change on this file since 17530 was 17473, checked in by dpiringe, 5 years ago

#3026:

  • refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
  • updated view models for new json item structure
  • updated SingleLineArrayJsonWriter
File size: 2.6 KB
RevLine 
[17404]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;
10using System.Globalization;
11
12namespace HeuristicLab.JsonInterface.OptimizerIntegration {
[17433]13 
[17410]14  public class JsonItemIntValueControl : JsonItemValueControl {
[17443]15   
[17411]16    #region Overriden Properties
17    protected override string ValuePropertyId => nameof(IntValueVM.Value);
18    #endregion
[17443]19   
[17411]20    public JsonItemIntValueControl(IntValueVM vm) : base(vm) {
21      Init();
22    }
[17410]23  }
24
25  public class JsonItemDoubleValueControl : JsonItemValueControl {
[17443]26   
[17411]27    #region Overriden Properties
28    protected override string ValuePropertyId => nameof(DoubleValueVM.Value);
29    #endregion
[17471]30   
[17411]31    public JsonItemDoubleValueControl(DoubleValueVM vm) : base(vm) {
32      Init();
[17404]33    }
[17410]34  }
[17433]35 
[17464]36  public abstract partial class JsonItemValueControl : UserControl {
[17411]37    #region Protected Properties
[17464]38    protected IJsonItemVM VM { get; set; }
[17411]39    protected TextBox TBValue { get; set; }
40    protected NumericRangeControl NumericRangeControl { get; set; }
41    #endregion
[17410]42
[17411]43    #region Abstract Properties
44    protected abstract string ValuePropertyId { get; }
45    #endregion
46
[17471]47    public JsonItemValueControl() {
[17410]48      InitializeComponent();
[17471]49    }
50
51    public JsonItemValueControl(IJsonItemVM vm) {
52      InitializeComponent();
[17464]53      VM = vm;
[17411]54      TBValue = textBoxValue;
55      NumericRangeControl = numericRangeControl1;
[17404]56    }
[17443]57   
[17444]58    protected void Init() {
[17464]59      TBValue.DataBindings.Add("Text", VM, ValuePropertyId);
[17473]60      NumericRangeControl.TBMinRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.MinRange));
61      NumericRangeControl.TBMaxRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.MaxRange));
62      NumericRangeControl.EnableMinRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMinRange),
[17411]63        false, DataSourceUpdateMode.OnPropertyChanged);
[17473]64      NumericRangeControl.EnableMaxRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM<int, IntJsonItem>.EnableMaxRange),
[17411]65        false, DataSourceUpdateMode.OnPropertyChanged);
66    }
67
[17444]68    private void textBoxValue_Validating(object sender, CancelEventArgs e) {
69      if (string.IsNullOrWhiteSpace(textBoxValue.Text)) {
70        errorProvider.SetError(textBoxValue, "Value must not be empty.");
71        e.Cancel = true;
72      } else {
73        errorProvider.SetError(textBoxValue, null);
74      }
75    }
[17404]76  }
77}
Note: See TracBrowser for help on using the repository browser.