Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16872


Ignore:
Timestamp:
04/29/19 15:00:56 (6 years ago)
Author:
mkommend
Message:

#3005: Added readonly flag to all value parameters.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Core/3.3/Interfaces/IValueParameter.cs

    r16565 r16872  
    2727  public interface IValueParameter : IParameter {
    2828    IItem Value { get; set; }
     29    bool ReadOnly { get; set; }
    2930    bool GetsCollected { get; set; }
    3031    event EventHandler ValueChanged;
     32    event EventHandler ReadOnlyChanged;
    3133    event EventHandler GetsCollectedChanged;
    3234  }
  • trunk/HeuristicLab.Parameters.Views/3.3/ConstrainedValueParameterView.cs

    r16565 r16872  
    6262    protected override void DeregisterContentEvents() {
    6363      Content.GetsCollectedChanged -= new EventHandler(Content_GetsCollectedChanged);
     64      Content.ReadOnlyChanged -= new EventHandler(Content_ReadOnlyChanged);
    6465      Content.ValidValues.ItemsAdded -= new CollectionItemsChangedEventHandler<T>(ValidValues_ItemsAdded);
    6566      Content.ValidValues.ItemsRemoved -= new CollectionItemsChangedEventHandler<T>(ValidValues_ItemsRemoved);
     
    7677      base.RegisterContentEvents();
    7778      Content.GetsCollectedChanged += new EventHandler(Content_GetsCollectedChanged);
     79      Content.ReadOnlyChanged += new EventHandler(Content_ReadOnlyChanged);
    7880      Content.ValidValues.ItemsAdded += new CollectionItemsChangedEventHandler<T>(ValidValues_ItemsAdded);
    7981      Content.ValidValues.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(ValidValues_ItemsRemoved);
     
    100102      base.SetEnabledStateOfControls();
    101103      valueGroupBox.Enabled = Content != null;
    102       valueComboBox.Enabled = (valueComboBox.Items.Count > 0) && !ReadOnly;
     104      valueComboBox.Enabled = (valueComboBox.Items.Count > 0) && !Content.ReadOnly && !ReadOnly;
    103105      showInRunCheckBox.Enabled = Content != null && !ReadOnly;
    104106    }
     
    153155        FillValueComboBox();
    154156    }
     157    protected virtual void Content_ReadOnlyChanged(object sender, EventArgs e) {
     158      if (InvokeRequired)
     159        Invoke(new EventHandler(Content_ReadOnlyChanged), sender, e);
     160      else {
     161        SetEnabledStateOfControls();
     162      }
     163    }
    155164    protected virtual void Content_GetsCollectedChanged(object sender, EventArgs e) {
    156165      if (InvokeRequired)
  • trunk/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.cs

    r16565 r16872  
    7474      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
    7575      Content.GetsCollectedChanged -= new EventHandler(Content_GetsCollectedChanged);
     76      Content.ReadOnlyChanged -= new EventHandler(Content_ReadOnlyChanged);
    7677      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
    7778      base.DeregisterContentEvents();
     
    8687      Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
    8788      Content.GetsCollectedChanged += new EventHandler(Content_GetsCollectedChanged);
     89      Content.ReadOnlyChanged += new EventHandler(Content_ReadOnlyChanged);
    8890      Content.ValueChanged += new EventHandler(Content_ValueChanged);
    8991    }
     
    108110      actualNameTextBox.Enabled = Content != null;
    109111      actualNameTextBox.ReadOnly = ReadOnly;
    110       setValueButton.Enabled = Content != null && !ReadOnly;
    111       clearValueButton.Enabled = Content != null && Content.Value != null && !ReadOnly;
     112      setValueButton.Enabled = Content != null && !Content.ReadOnly && !ReadOnly;
     113      clearValueButton.Enabled = Content != null && !Content.ReadOnly && Content.Value != null && !ReadOnly;
    112114      showInRunCheckBox.Enabled = Content != null && !ReadOnly;
    113115    }
     
    124126      else {
    125127        SetDataTypeTextBoxText();
    126         clearValueButton.Enabled = Content != null && Content.Value != null && !ReadOnly;
     128        clearValueButton.Enabled = Content != null && !Content.ReadOnly && Content.Value != null && !ReadOnly;
    127129        valueViewHost.ViewType = null;
    128130        valueViewHost.Content = Content != null ? Content.Value : null;
     131      }
     132    }
     133    protected virtual void Content_ReadOnlyChanged(object sender, EventArgs e) {
     134      if (InvokeRequired)
     135        Invoke(new EventHandler(Content_ReadOnlyChanged), sender, e);
     136      else {
     137        SetEnabledStateOfControls();
    129138      }
    130139    }
  • trunk/HeuristicLab.Parameters.Views/3.3/ValueParameterView.cs

    r16565 r16872  
    7474    protected override void DeregisterContentEvents() {
    7575      Content.GetsCollectedChanged -= new EventHandler(Content_GetsCollectedChanged);
     76      Content.ReadOnlyChanged -= new EventHandler(Content_ReadOnlyChanged);
    7677      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
    7778      base.DeregisterContentEvents();
     
    8586      base.RegisterContentEvents();
    8687      Content.GetsCollectedChanged += new EventHandler(Content_GetsCollectedChanged);
     88      Content.ReadOnlyChanged += new EventHandler(Content_ReadOnlyChanged);
    8789      Content.ValueChanged += new EventHandler(Content_ValueChanged);
    8890    }
     
    103105    protected override void SetEnabledStateOfControls() {
    104106      base.SetEnabledStateOfControls();
    105       setValueButton.Enabled = Content != null && !(Content is IFixedValueParameter) && !ReadOnly;
    106       clearValueButton.Enabled = Content != null && Content.Value != null && !(Content is IFixedValueParameter) && !(Content is ValueParameter<T>) && !ReadOnly;
     107      setValueButton.Enabled = Content != null && !Content.ReadOnly && !(Content is IFixedValueParameter) && !ReadOnly;
     108      clearValueButton.Enabled = Content != null && !Content.ReadOnly && Content.Value != null && !(Content is IFixedValueParameter) && !(Content is ValueParameter<T>) && !ReadOnly;
    107109      showInRunCheckBox.Enabled = Content != null && !ReadOnly;
    108110    }
     
    113115      else {
    114116        SetDataTypeTextBoxText();
    115         setValueButton.Enabled = Content != null && !(Content is IFixedValueParameter) && !ReadOnly;
    116         clearValueButton.Enabled = Content != null && Content.Value != null && !(Content is IFixedValueParameter<T>) && !(Content is ValueParameter<T>) && !ReadOnly;
     117        setValueButton.Enabled = Content != null && !Content.ReadOnly && !(Content is IFixedValueParameter) && !ReadOnly;
     118        clearValueButton.Enabled = Content != null && !Content.ReadOnly && Content.Value != null && !(Content is IFixedValueParameter<T>) && !(Content is ValueParameter<T>) && !ReadOnly;
    117119        valueViewHost.ViewType = null;
    118120        valueViewHost.Content = Content != null ? Content.Value : null;
     121      }
     122    }
     123
     124    protected virtual void Content_ReadOnlyChanged(object sender, EventArgs e) {
     125      if (InvokeRequired)
     126        Invoke(new EventHandler(Content_ReadOnlyChanged), sender, e);
     127      else {
     128        SetEnabledStateOfControls();
    119129      }
    120130    }
     
    135145        try {
    136146          Content.Value = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    137         }
    138         catch (Exception ex) {
     147        } catch (Exception ex) {
    139148          ErrorHandling.ShowErrorDialog(this, ex);
    140149        }
  • trunk/HeuristicLab.Parameters/3.3/OptionalConstrainedValueParameter.cs

    r16565 r16872  
    2222using System;
    2323using System.Drawing;
     24using HEAL.Attic;
    2425using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    27 using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Parameters {
     
    4040      }
    4141    }
    42      
     42
    4343    [Storable]
    4444    private ItemSet<T> validValues;
     
    5252      get { return this.value; }
    5353      set {
     54        if (ReadOnly) throw new InvalidOperationException("Cannot set the value of a readonly parameter.");
    5455        if (value != this.value) {
    5556          if ((value != null) && !validValues.Contains(value)) throw new ArgumentException("Invalid value.");
     
    7475    }
    7576
     77    [Storable(DefaultValue = false)]
     78    private bool readOnly;
     79    public bool ReadOnly {
     80      get { return readOnly; }
     81      set {
     82        if (value == readOnly) return;
     83        readOnly = value;
     84        OnReadOnlyChanged();
     85      }
     86    }
     87
    7688    [Storable(DefaultValue = true)]
    7789    private bool getsCollected;
     
    93105      validValues = cloner.Clone(original.validValues);
    94106      value = cloner.Clone(original.value);
     107      readOnly = original.readOnly;
    95108      getsCollected = original.getsCollected;
    96109      Initialize();
     
    99112      : base("Anonymous", typeof(T)) {
    100113      this.validValues = new ItemSet<T>();
     114      this.readOnly = false;
    101115      this.getsCollected = true;
    102116      Initialize();
     
    105119      : base(name, typeof(T)) {
    106120      this.validValues = new ItemSet<T>();
     121      this.readOnly = false;
    107122      this.getsCollected = true;
    108123      Initialize();
     
    111126      : base(name, typeof(T)) {
    112127      this.validValues = new ItemSet<T>();
     128      this.readOnly = false;
    113129      this.getsCollected = getsCollected;
    114130      Initialize();
     
    117133      : base(name, typeof(T)) {
    118134      this.validValues = validValues;
     135      this.readOnly = false;
    119136      this.getsCollected = true;
    120137      Initialize();
     
    123140      : base(name, typeof(T)) {
    124141      this.validValues = validValues;
     142      this.readOnly = false;
    125143      this.getsCollected = getsCollected;
    126144      Initialize();
     
    130148      this.validValues = validValues;
    131149      this.value = value;
     150      this.readOnly = false;
    132151      this.getsCollected = true;
    133152      Initialize();
     
    137156      this.validValues = validValues;
    138157      this.value = value;
     158      this.readOnly = false;
    139159      this.getsCollected = getsCollected;
    140160      Initialize();
     
    143163      : base(name, description, typeof(T)) {
    144164      this.validValues = new ItemSet<T>();
     165      this.readOnly = false;
    145166      this.getsCollected = true;
    146167      Initialize();
     
    149170      : base(name, description, typeof(T)) {
    150171      this.validValues = new ItemSet<T>();
     172      this.readOnly = false;
    151173      this.getsCollected = getsCollected;
    152174      Initialize();
     
    155177      : base(name, description, typeof(T)) {
    156178      this.validValues = validValues;
     179      this.readOnly = false;
    157180      this.getsCollected = true;
    158181      Initialize();
     
    161184      : base(name, description, typeof(T)) {
    162185      this.validValues = validValues;
     186      this.readOnly = false;
    163187      this.getsCollected = getsCollected;
    164188      Initialize();
     
    168192      this.validValues = validValues;
    169193      this.value = value;
     194      this.readOnly = false;
    170195      this.getsCollected = true;
    171196      Initialize();
     
    175200      this.validValues = validValues;
    176201      this.value = value;
     202      this.readOnly = false;
    177203      this.getsCollected = getsCollected;
    178204      Initialize();
     
    212238      OnToStringChanged();
    213239    }
     240    public event EventHandler ReadOnlyChanged;
     241    protected virtual void OnReadOnlyChanged() {
     242      EventHandler handler = ReadOnlyChanged;
     243      if (handler != null) handler(this, EventArgs.Empty);
     244    }
    214245    public event EventHandler GetsCollectedChanged;
    215246    protected virtual void OnGetsCollectedChanged() {
  • trunk/HeuristicLab.Parameters/3.3/OptionalValueParameter.cs

    r16565 r16872  
    2222using System;
    2323using System.Drawing;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Parameters {
     
    4545      get { return this.value; }
    4646      set {
     47        if (ReadOnly) throw new InvalidOperationException("Cannot set the value of a readonly parameter.");
    4748        if (value != this.value) {
    4849          DeregisterValueEvents();
     
    6364          );
    6465        Value = val;
     66      }
     67    }
     68
     69    [Storable(DefaultValue = false)]
     70    private bool readOnly;
     71    public bool ReadOnly {
     72      get { return readOnly; }
     73      set {
     74        if (value == readOnly) return;
     75        readOnly = value;
     76        OnReadOnlyChanged();
    6577      }
    6678    }
     
    108120      : base(original, cloner) {
    109121      value = cloner.Clone(original.value);
     122      readOnly = original.readOnly;
    110123      getsCollected = original.getsCollected;
    111124      reactOnValueToStringChangedAndValueItemImageChanged = original.reactOnValueToStringChangedAndValueItemImageChanged;
     
    114127    public OptionalValueParameter()
    115128      : base("Anonymous", typeof(T)) {
     129      this.readOnly = false;
    116130      this.getsCollected = true;
    117131      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    119133    public OptionalValueParameter(string name)
    120134      : base(name, typeof(T)) {
     135      this.readOnly = false;
    121136      this.getsCollected = true;
    122137      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    124139    public OptionalValueParameter(string name, bool getsCollected)
    125140      : base(name, typeof(T)) {
     141      this.readOnly = false;
    126142      this.getsCollected = getsCollected;
    127143      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    130146      : base(name, typeof(T)) {
    131147      this.value = value;
     148      this.readOnly = false;
    132149      this.getsCollected = true;
    133150      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    137154      : base(name, typeof(T)) {
    138155      this.value = value;
     156      this.readOnly = false;
    139157      this.getsCollected = getsCollected;
    140158      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    143161    public OptionalValueParameter(string name, string description)
    144162      : base(name, description, typeof(T)) {
     163      this.readOnly = false;
    145164      this.getsCollected = true;
    146165      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    148167    public OptionalValueParameter(string name, string description, bool getsCollected)
    149168      : base(name, description, typeof(T)) {
     169      this.readOnly = false;
    150170      this.getsCollected = getsCollected;
    151171      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    154174      : base(name, description, typeof(T)) {
    155175      this.value = value;
     176      this.readOnly = false;
    156177      this.getsCollected = true;
    157178      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    161182      : base(name, description, typeof(T)) {
    162183      this.value = value;
     184      this.readOnly = false;
    163185      this.getsCollected = getsCollected;
    164186      this.reactOnValueToStringChangedAndValueItemImageChanged = true;
     
    197219      OnToStringChanged();
    198220    }
     221
     222    public event EventHandler ReadOnlyChanged;
     223    protected virtual void OnReadOnlyChanged() {
     224      EventHandler handler = ReadOnlyChanged;
     225      if (handler != null) handler(this, EventArgs.Empty);
     226    }
    199227    public event EventHandler GetsCollectedChanged;
    200228    protected virtual void OnGetsCollectedChanged() {
  • trunk/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs

    r16565 r16872  
    2222using System;
    2323using System.Drawing;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Parameters {
     
    4545      get { return this.value; }
    4646      set {
     47        if (ReadOnly) throw new InvalidOperationException("Cannot set the value of a readonly parameter.");
    4748        if (value != this.value) {
    4849          DeregisterValueEvents();
     
    6667    }
    6768
     69    [Storable(DefaultValue = false)]
     70    private bool readOnly;
     71    public bool ReadOnly {
     72      get { return readOnly; }
     73      set {
     74        if (value == readOnly) return;
     75        readOnly = value;
     76        OnReadOnlyChanged();
     77      }
     78    }
     79
    6880    [Storable(DefaultValue = true)]
    6981    private bool getsCollected;
     
    8496      : base(original, cloner) {
    8597      value = cloner.Clone(original.value);
     98      readOnly = original.readOnly;
    8699      getsCollected = original.getsCollected;
    87100      RegisterValueEvents();
     
    89102    public ValueLookupParameter()
    90103      : base() {
     104      this.readOnly = false;
    91105      this.Hidden = false;
    92106      this.getsCollected = true;
     
    94108    public ValueLookupParameter(string name)
    95109      : base(name) {
     110      this.readOnly = false;
    96111      this.Hidden = false;
    97112      this.getsCollected = true;
     
    99114    public ValueLookupParameter(string name, bool getsCollected)
    100115      : base(name) {
     116      this.readOnly = false;
    101117      this.Hidden = false;
    102118      this.getsCollected = getsCollected;
     
    105121      : base(name) {
    106122      this.value = value;
     123      this.readOnly = false;
    107124      this.Hidden = false;
    108125      this.getsCollected = true;
     
    112129      : base(name) {
    113130      this.value = value;
     131      this.readOnly = false;
    114132      this.Hidden = false;
    115133      this.getsCollected = getsCollected;
     
    118136    public ValueLookupParameter(string name, string description)
    119137      : base(name, description) {
     138      this.readOnly = false;
    120139      this.Hidden = false;
    121140      this.getsCollected = true;
     
    123142    public ValueLookupParameter(string name, string description, bool getsCollected)
    124143      : base(name, description) {
     144      this.readOnly = false;
    125145      this.Hidden = false;
    126146      this.getsCollected = getsCollected;
     
    129149      : base(name, description) {
    130150      this.value = value;
     151      this.readOnly = false;
    131152      this.Hidden = false;
    132153      this.getsCollected = true;
     
    136157      : base(name, description) {
    137158      this.value = value;
     159      this.readOnly = false;
    138160      this.Hidden = false;
    139161      this.getsCollected = getsCollected;
     
    142164    public ValueLookupParameter(string name, string description, string actualName)
    143165      : base(name, description, actualName) {
     166      this.readOnly = false;
    144167      this.Hidden = false;
    145168      this.getsCollected = true;
     
    147170    public ValueLookupParameter(string name, string description, string actualName, bool getsCollected)
    148171      : base(name, description, actualName) {
     172      this.readOnly = false;
    149173      this.Hidden = false;
    150174      this.getsCollected = getsCollected;
     
    177201      OnToStringChanged();
    178202    }
     203    public event EventHandler ReadOnlyChanged;
     204    protected virtual void OnReadOnlyChanged() {
     205      EventHandler handler = ReadOnlyChanged;
     206      if (handler != null) handler(this, EventArgs.Empty);
     207    }
    179208    public event EventHandler GetsCollectedChanged;
    180209    protected virtual void OnGetsCollectedChanged() {
Note: See TracChangeset for help on using the changeset viewer.