Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/StringValueVM.cs @ 17519

Last change on this file since 17519 was 17519, checked in by dpiringe, 4 years ago

#3026:

  • added error output for failed runner initialization
  • reorganised some final view models
  • TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
  • code cleanup
  • refactored RegressionProblemDataConverter
  • added lots of comments
  • added new view for StringArrayJsonItem
  • added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading;
6using System.Threading.Tasks;
7using System.Windows.Forms;
8
9namespace HeuristicLab.JsonInterface.OptimizerIntegration {
10  public class StringValueVM : JsonItemVMBase<StringJsonItem> {
11    public override UserControl Control =>
12       new JsonItemValidValuesControl(this);
13
14    public string Value {
15      get => Item.Value?.ToString();
16      set {
17        Item.Value = value;
18        OnPropertyChange(this, nameof(Value));
19      }
20    }
21
22    public IEnumerable<string> Range {
23      get => Item.ConcreteRestrictedItems;
24      set {
25        Item.ConcreteRestrictedItems = value;
26        //check if value is still in range
27        if (!Range.Any(x => x == Value)) {
28          Value = Range.FirstOrDefault();
29          if (Range.Count() == 0)
30            //if no elements exists -> deselect item
31            base.Selected = false;
32          OnPropertyChange(this, nameof(Value));
33        }
34       
35        OnPropertyChange(this, nameof(Range));
36      }
37    }
38  }
39
40  public class StringArrayVM : JsonItemVMBase<StringArrayJsonItem> {
41    public override UserControl Control =>
42       new JsonItemConcreteItemArrayControl(this);
43
44    public string[] Value {
45      get => Item.Value;
46      set {
47        Item.Value = value;
48        OnPropertyChange(this, nameof(Value));
49      }
50    }
51
52    public IEnumerable<string> Range {
53      get => Item.ConcreteRestrictedItems;
54      set {
55        Item.ConcreteRestrictedItems = value;
56        OnPropertyChange(this, nameof(Range));
57      }
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.