[17410] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
[17431] | 4 | using System.Drawing;
|
---|
[17410] | 5 | using System.Linq;
|
---|
| 6 | using System.Text;
|
---|
| 7 | using System.Threading.Tasks;
|
---|
[17431] | 8 | using System.Windows.Forms;
|
---|
[17410] | 9 |
|
---|
| 10 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
[17446] | 11 | public class JsonItemVMBase : IJsonItemVM {
|
---|
[17410] | 12 | public event PropertyChangedEventHandler PropertyChanged;
|
---|
[17420] | 13 | public event Action ItemChanged;
|
---|
[17410] | 14 |
|
---|
[17420] | 15 | private IJsonItem item;
|
---|
| 16 | public IJsonItem Item {
|
---|
| 17 | get => item;
|
---|
| 18 | set {
|
---|
[17444] | 19 | item?.LoosenPath();
|
---|
[17420] | 20 | item = value;
|
---|
[17444] | 21 | item.FixatePath();
|
---|
[17420] | 22 | ItemChanged?.Invoke();
|
---|
| 23 | }
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[17431] | 26 | public TreeNode TreeNode { get; set; }
|
---|
| 27 | public TreeView TreeView { get; set; }
|
---|
| 28 |
|
---|
[17410] | 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 | private bool selected = true;
|
---|
| 42 | public bool Selected {
|
---|
| 43 | get => selected;
|
---|
| 44 | set {
|
---|
| 45 | selected = value;
|
---|
[17439] | 46 | if(TreeNode != null) {
|
---|
[17431] | 47 | TreeNode.ForeColor = (selected ? Color.Black : Color.Red);
|
---|
[17439] | 48 | TreeNode.Checked = value;
|
---|
| 49 | }
|
---|
[17431] | 50 | if (TreeView != null)
|
---|
| 51 | TreeView.Refresh();
|
---|
[17410] | 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 |
|
---|
[17433] | 64 | public string Description {
|
---|
| 65 | get => Item.Description;
|
---|
| 66 | set {
|
---|
| 67 | Item.Description = value;
|
---|
| 68 | OnPropertyChange(this, nameof(Description));
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[17410] | 72 | public string ActualName {
|
---|
| 73 | get => Item.ActualName;
|
---|
| 74 | set {
|
---|
| 75 | Item.ActualName = value;
|
---|
| 76 | OnPropertyChange(this, nameof(ActualName));
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
[17412] | 79 |
|
---|
[17446] | 80 | public virtual JsonItemBaseControl Control => new JsonItemBaseControl(this);
|
---|
| 81 |
|
---|
[17444] | 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
|
---|
[17410] | 101 | }
|
---|
| 102 | }
|
---|