Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • added two new methods in IJsonItem -> FixatePath and LoosenPath to fixate/loosen the path (to enable name changing without effects on path)
  • set IsInRange to virtual and made overrides for IntMatrixJsonItem and DoubleMatrixJsonItem (IsInRange is a bad name and needs to be renamed in future versions)
  • implemented basic validation feedback with ErrorProvider for some inputs (templateName, Name, Range)
  • now all items gets validated before export (validation errors are shown with ErrorHandling.ShowErrorDialog)
  • added a check in AlgorithmConverter to prevent an exception for accessing the first element of an empty IEnumerable
File size: 2.4 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;
10using System.Globalization;
11
12namespace HeuristicLab.JsonInterface.OptimizerIntegration {
13 
14  public class JsonItemIntValueControl : JsonItemValueControl {
15   
16    #region Overriden Properties
17    protected override string ValuePropertyId => nameof(IntValueVM.Value);
18    #endregion
19   
20    public JsonItemIntValueControl(IntValueVM vm) : base(vm) {
21      Init();
22    }
23  }
24
25  public class JsonItemDoubleValueControl : JsonItemValueControl {
26   
27    #region Overriden Properties
28    protected override string ValuePropertyId => nameof(DoubleValueVM.Value);
29    #endregion
30
31    public JsonItemDoubleValueControl(DoubleValueVM vm) : base(vm) {
32      Init();
33    }
34  }
35 
36  public abstract partial class JsonItemValueControl : JsonItemBaseControl {
37    #region Protected Properties
38    protected TextBox TBValue { get; set; }
39    protected NumericRangeControl NumericRangeControl { get; set; }
40    #endregion
41
42    #region Abstract Properties
43    protected abstract string ValuePropertyId { get; }
44    #endregion
45
46    public JsonItemValueControl(JsonItemVMBase vm) : base(vm) {
47      InitializeComponent();
48      TBValue = textBoxValue;
49      NumericRangeControl = numericRangeControl1;
50    }
51   
52    protected void Init() {
53      TBValue.DataBindings.Add("Text", base.VM, ValuePropertyId);
54      NumericRangeControl.TBMinRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM.MinRange));
55      NumericRangeControl.TBMaxRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM.MaxRange));
56      NumericRangeControl.EnableMinRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM.EnableMinRange),
57        false, DataSourceUpdateMode.OnPropertyChanged);
58      NumericRangeControl.EnableMaxRange.DataBindings.Add("Checked", VM, nameof(RangedValueBaseVM.EnableMaxRange),
59        false, DataSourceUpdateMode.OnPropertyChanged);
60    }
61
62    private void textBoxValue_Validating(object sender, CancelEventArgs e) {
63      if (string.IsNullOrWhiteSpace(textBoxValue.Text)) {
64        errorProvider.SetError(textBoxValue, "Value must not be empty.");
65        e.Cancel = true;
66      } else {
67        errorProvider.SetError(textBoxValue, null);
68      }
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.