Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17828 was 17828, checked in by dpiringe, 3 years ago

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File size: 2.9 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 abstract class JsonItemVMBase<JsonItemType> : IJsonItemVM<JsonItemType>
12    where JsonItemType : class, IJsonItem
13  {
14    IJsonItem IJsonItemVM.Item {
15      get => Item;
16      set => Item = (JsonItemType)value;
17    }
18
19    private JsonItemType item;
20    public JsonItemType Item {
21      get => item;
22      set {
23        item?.LoosenPath();
24        item = value;
25        item.FixatePath();
26        ItemChanged?.Invoke();
27      }
28    }
29    public TreeNode TreeNode { get; set; }
30    public TreeView TreeView { get; set; }
31    public bool Selected {
32      get => Item.Active;
33      set {
34        Item.Active = value;
35        if(TreeNode != null) {
36          TreeNode.ForeColor = (Selected ? Color.Green : Color.Black);
37          TreeNode.Checked = value;
38        }
39        if (TreeView != null)
40          TreeView.Refresh();
41        SelectedChanged?.Invoke();
42        OnPropertyChange(this, nameof(Selected));
43      }
44    }
45    public string Name {
46      get => Item.Name;
47      set {
48        Item.Name = value;
49        OnPropertyChange(this, nameof(Name));
50      }
51    }
52    public string Description {
53      get => Item.Description;
54      set {
55        Item.Description = value;
56        OnPropertyChange(this, nameof(Description));
57      }
58    }
59
60    public virtual Type TargetedJsonItemType => typeof(JsonItemType);
61    public abstract UserControl Control { get; }
62
63    public event PropertyChangedEventHandler PropertyChanged;
64    public event Action ItemChanged;
65    public event Action SelectedChanged;
66
67
68    protected void OnPropertyChange(object sender, string propertyName) {
69      // Make a temporary copy of the event to avoid possibility of
70      // a race condition if the last subscriber unsubscribes
71      // immediately after the null check and before the event is raised.
72      // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/events/how-to-raise-base-class-events-in-derived-classes
73     
74      PropertyChangedEventHandler tmp = PropertyChanged;
75      tmp?.Invoke(this, new PropertyChangedEventArgs(propertyName));
76    }
77   
78    #region IDisposable Support
79    private bool disposedValue = false; // To detect redundant calls
80
81    protected virtual void Dispose(bool disposing) {
82      if (!disposedValue) {
83        if (disposing) {
84          item.LoosenPath();
85          item = null;
86        }
87        disposedValue = true;
88      }
89    }
90
91    // This code added to correctly implement the disposable pattern.
92    public void Dispose() {
93      // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
94      Dispose(true);
95    }
96    #endregion
97  }
98}
Note: See TracBrowser for help on using the repository browser.