Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/10/20 16:46:09 (5 years ago)
Author:
dpiringe
Message:

#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
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ArrayValueVM.cs

    r17420 r17431  
    1616
    1717    public override JsonItemBaseControl GetControl() => new JsonItemDoubleArrayValueControl(this);
    18 
    19     protected override void OnItemChanged() {
    20       IList<IndexedArrayValueVM> list = new List<IndexedArrayValueVM>();
    21       var arr = ((DoubleArrayJsonItem)Item).Value;
    22       for(int i = 0; i < arr.Length; ++i) {
    23         list.Add(new IndexedArrayValueVM(arr, i));
     18   
     19    public override double[] Value {
     20      get => ((DoubleArrayJsonItem)Item).Value;
     21      set {
     22        ((DoubleArrayJsonItem)Item).Value = value;
     23        OnPropertyChange(this, nameof(Value));
    2424      }
    25       Value = list.ToArray();
    2625    }
    2726  }
     
    3534
    3635    public override JsonItemBaseControl GetControl() => new JsonItemIntArrayValueControl(this);
    37 
    38     protected override void OnItemChanged() {
    39       IList<IndexedArrayValueVM> list = new List<IndexedArrayValueVM>();
    40       var arr = ((IntArrayJsonItem)Item).Value;
    41       for (int i = 0; i < arr.Length; ++i) {
    42         list.Add(new IndexedArrayValueVM(arr, i));
     36   
     37    public override int[] Value {
     38      get => ((IntArrayJsonItem)Item).Value;
     39      set {
     40        ((IntArrayJsonItem)Item).Value = value;
     41        OnPropertyChange(this, nameof(Value));
    4342      }
    44       Value = list.ToArray();
    4543    }
    4644  }
    4745
    4846  public abstract class ArrayValueVM<T> : RangedValueBaseVM<T> {
    49 
    50     public class IndexedArrayValueVM : INotifyPropertyChanged {
    51       private T[] arr;
    52       private int index;
    53 
    54       public IndexedArrayValueVM(T[] arr, int index) {
    55         this.arr = arr;
    56         this.index = index;
    57       }
    58 
    59       public T Value {
    60         get => arr[index];
    61         set {
    62           arr[index] = value;
    63           PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));
    64         }
    65       }
    66 
    67       public event PropertyChangedEventHandler PropertyChanged;
     47   
     48    public ArrayValueVM() {
     49      //base.ItemChanged += OnItemChanged;
    6850    }
    6951
    70     public ArrayValueVM() {
    71       base.ItemChanged += OnItemChanged;
     52    public void SetIndexValue(object obj, int index) {
     53      T[] tmp = Value;
     54      if(index >= tmp.Length) { // increasing array
     55        T[] newArr = new T[index+1];
     56        Array.Copy(tmp, 0, newArr, 0, tmp.Length);
     57        tmp = newArr;
     58      }
     59      tmp[index] = (T)Convert.ChangeType(obj, typeof(T));
     60      Value = tmp;
    7261    }
    7362
    74     protected abstract void OnItemChanged();
    75 
    76     IndexedArrayValueVM[] vms;
    77     public IndexedArrayValueVM[] Value {
    78       get => vms;
    79       set {
    80         vms = value;
    81         OnPropertyChange(this, nameof(Value));
    82       }
    83     }
     63    public abstract T[] Value { get; set; }
    8464  }
    8565}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVMBase.cs

    r17420 r17431  
    22using System.Collections.Generic;
    33using System.ComponentModel;
     4using System.Drawing;
    45using System.Linq;
    56using System.Text;
    67using System.Threading.Tasks;
     8using System.Windows.Forms;
    79
    810namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     
    1921      }
    2022    }
     23
     24    public TreeNode TreeNode { get; set; }
     25    public TreeView TreeView { get; set; }
    2126
    2227    protected void OnPropertyChange(object sender, string propertyName) {
     
    3742      set {
    3843        selected = value;
     44        if(TreeNode != null)
     45          TreeNode.ForeColor = (selected ? Color.Black : Color.Red);
     46        if (TreeView != null)
     47          TreeView.Refresh();
    3948        OnPropertyChange(this, nameof(Selected));
    4049      }
Note: See TracChangeset for help on using the changeset viewer.