Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • renamed JsonItemArrayValueControl to JsonItemMultiValueControl
  • extracted converter logic from property Value in JsonItem<V,R> into new private method ConvertObject
  • added references to TreeNode and TreeView in JsonItemVMBase -> for additional user feedback when enabling/disabling an item (changes the fore color of referenced node)
  • changed implementation and interplay between ArrayValueVM and JsonItemMultiValueControl -> removed the direct access of property DataSource of DataGridView -> now: dynamically adds new columns/rows and accesses grid cells manually (better handling with matrices)
  • added new VM MatrixValueVM
File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using System.Windows.Forms;
9
10namespace HeuristicLab.JsonInterface.OptimizerIntegration {
11  public class JsonItemVMBase : INotifyPropertyChanged {
12    public event PropertyChangedEventHandler PropertyChanged;
13    public event Action ItemChanged;
14
15    private IJsonItem item;
16    public IJsonItem Item {
17      get => item;
18      set {
19        item = value;
20        ItemChanged?.Invoke();
21      }
22    }
23
24    public TreeNode TreeNode { get; set; }
25    public TreeView TreeView { get; set; }
26
27    protected void OnPropertyChange(object sender, string propertyName) {
28      // Make a temporary copy of the event to avoid possibility of
29      // a race condition if the last subscriber unsubscribes
30      // immediately after the null check and before the event is raised.
31      // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/how-to-raise-base-class-events-in-derived-classes
32     
33      PropertyChangedEventHandler tmp = PropertyChanged;
34      tmp?.Invoke(this, new PropertyChangedEventArgs(propertyName));
35    }
36
37    public virtual Type JsonItemType => typeof(JsonItem);
38
39    private bool selected = true;
40    public bool Selected {
41      get => selected;
42      set {
43        selected = value;
44        if(TreeNode != null)
45          TreeNode.ForeColor = (selected ? Color.Black : Color.Red);
46        if (TreeView != null)
47          TreeView.Refresh();
48        OnPropertyChange(this, nameof(Selected));
49      }
50    }
51
52    public string Name {
53      get => Item.Name;
54      set {
55        Item.Name = value;
56        OnPropertyChange(this, nameof(Name));
57      }
58    }
59
60    public string ActualName {
61      get => Item.ActualName;
62      set {
63        Item.ActualName = value;
64        OnPropertyChange(this, nameof(ActualName));
65      }
66    }
67
68    public virtual JsonItemBaseControl GetControl() {
69      return new JsonItemBaseControl(this);
70    }
71
72  }
73}
Note: See TracBrowser for help on using the repository browser.