Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • renamed ResultItem to ResultJsonItem
  • implemented RegressionProblemDataConverter
  • added support for "named matrices" (named = rows and columns have names) -> INamedMatrixJsonItem incl. base classes and views
  • added a bool property Active in IJsonItem -> marks items, which should be written into the template
File size: 2.8 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 : IJsonItemVM {
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?.LoosenPath();
20        item = value;
21        item.FixatePath();
22        ItemChanged?.Invoke();
23      }
24    }
25
26    public TreeNode TreeNode { get; set; }
27    public TreeView TreeView { get; set; }
28
29    protected void OnPropertyChange(object sender, string propertyName) {
30      // Make a temporary copy of the event to avoid possibility of
31      // a race condition if the last subscriber unsubscribes
32      // immediately after the null check and before the event is raised.
33      // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/how-to-raise-base-class-events-in-derived-classes
34     
35      PropertyChangedEventHandler tmp = PropertyChanged;
36      tmp?.Invoke(this, new PropertyChangedEventArgs(propertyName));
37    }
38
39    public virtual Type JsonItemType => typeof(JsonItem);
40
41   
42    public bool Selected {
43      get => Item.Active;
44      set {
45        Item.Active = value;
46        if(TreeNode != null) {
47          TreeNode.ForeColor = (Selected ? Color.Black : Color.Red);
48          TreeNode.Checked = value;
49        }
50        if (TreeView != null)
51          TreeView.Refresh();
52        OnPropertyChange(this, nameof(Selected));
53      }
54    }
55
56    public string Name {
57      get => Item.Name;
58      set {
59        Item.Name = value;
60        OnPropertyChange(this, nameof(Name));
61      }
62    }
63
64    public string Description {
65      get => Item.Description;
66      set {
67        Item.Description = value;
68        OnPropertyChange(this, nameof(Description));
69      }
70    }
71
72    public string ActualName {
73      get => Item.ActualName;
74      set {
75        Item.ActualName = value;
76        OnPropertyChange(this, nameof(ActualName));
77      }
78    }
79
80    public virtual JsonItemBaseControl Control => new JsonItemBaseControl(this);
81   
82    #region IDisposable Support
83    private bool disposedValue = false; // To detect redundant calls
84
85    protected virtual void Dispose(bool disposing) {
86      if (!disposedValue) {
87        if (disposing) {
88          item.LoosenPath();
89          item = null;
90        }
91        disposedValue = true;
92      }
93    }
94
95    // This code added to correctly implement the disposable pattern.
96    public void Dispose() {
97      // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
98      Dispose(true);
99    }
100    #endregion
101  }
102}
Note: See TracBrowser for help on using the repository browser.