Changeset 17828 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/StringValueVM.cs
- Timestamp:
- 02/01/21 14:37:18 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/StringValueVM.cs
r17560 r17828 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading; 6 using System.Threading.Tasks; 7 using System.Windows.Forms; 1 using System.Linq; 8 2 9 3 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 10 public class StringValueVM : JsonItemVMBase<StringJsonItem> {11 public override UserControl Control =>12 new JsonItemValidValuesControl(this);13 4 14 public string Value { 15 get => Item.Value?.ToString(); 16 set { 17 Item.Value = value; 18 OnPropertyChange(this, nameof(Value)); 19 } 20 } 5 public class StringValueVM : ConcreteRestrictedJsonItemVM<StringJsonItem, string, string> { 6 protected override string GetDefaultValue() => Range.FirstOrDefault(); 21 7 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.Contains(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 } 8 protected override bool RangeContainsValue() => Range.Contains(Value); 38 9 } 39 10 40 public class StringArrayVM : JsonItemVMBase<StringArrayJsonItem> { 41 public override UserControl Control => 42 new JsonItemConcreteItemArrayControl(this); 11 public class StringArrayVM : ConcreteRestrictedJsonItemVM<StringArrayJsonItem, string, string[]> { 12 protected override string[] GetDefaultValue() => Range.ToArray(); 43 13 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 } 14 protected override bool RangeContainsValue() => Value.All(x => Range.Any(y => x == y)); 59 15 } 60 16 }
Note: See TracChangeset
for help on using the changeset viewer.