Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVMBase.cs @ 17420

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

#3026:

  • refactored ranged based VMs -> created new 'base' class for ranged based VMs RangedValueBaseVM
  • renamed AddChilds to AddChildren
  • implemented ArrayValueVM and JsonItemArrayValueControl
  • added ranges for array and matrix values
File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace HeuristicLab.JsonInterface.OptimizerIntegration {
9  public class JsonItemVMBase : INotifyPropertyChanged {
10    public event PropertyChangedEventHandler PropertyChanged;
11    public event Action ItemChanged;
12
13    private IJsonItem item;
14    public IJsonItem Item {
15      get => item;
16      set {
17        item = value;
18        ItemChanged?.Invoke();
19      }
20    }
21
22    protected void OnPropertyChange(object sender, string propertyName) {
23      // Make a temporary copy of the event to avoid possibility of
24      // a race condition if the last subscriber unsubscribes
25      // immediately after the null check and before the event is raised.
26      // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/how-to-raise-base-class-events-in-derived-classes
27     
28      PropertyChangedEventHandler tmp = PropertyChanged;
29      tmp?.Invoke(this, new PropertyChangedEventArgs(propertyName));
30    }
31
32    public virtual Type JsonItemType => typeof(JsonItem);
33
34    private bool selected = true;
35    public bool Selected {
36      get => selected;
37      set {
38        selected = value;
39        OnPropertyChange(this, nameof(Selected));
40      }
41    }
42
43    public string Name {
44      get => Item.Name;
45      set {
46        Item.Name = value;
47        OnPropertyChange(this, nameof(Name));
48      }
49    }
50
51    public string ActualName {
52      get => Item.ActualName;
53      set {
54        Item.ActualName = value;
55        OnPropertyChange(this, nameof(ActualName));
56      }
57    }
58
59    public virtual JsonItemBaseControl GetControl() {
60      return new JsonItemBaseControl(this);
61    }
62
63  }
64}
Note: See TracBrowser for help on using the repository browser.