Changeset 16870


Ignore:
Timestamp:
04/24/19 10:59:39 (4 months ago)
Author:
chaider
Message:

#2971 changed content events in ParsedConstraintView

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/ParsedConstraintView.cs

    r16862 r16870  
    4040      errorOutput.Text = "";
    4141      intervalConstraints = new CheckedItemList<IntervalConstraint>();
    42       intervalConstraints.CheckedItemsChanged += constraint_CheckedItemChanged;
    43       //intervalConstraints.ItemsRemoved
    4442    }
    4543
     
    4846      UpdateControl();
    4947    }
    50     //ParameterCollectionView
    51     //Remove method directly at parsebutton event
     48
     49    protected override void RegisterContentEvents() {
     50      base.RegisterContentEvents();
     51      intervalConstraints.CheckedItemsChanged += constraint_CheckedItemChanged;
     52      intervalConstraints.ItemsAdded += constraints_Updated;
     53      intervalConstraints.ItemsRemoved += constraints_Updated;
     54    }
     55
     56    protected override void DeregisterContentEvents() {
     57      intervalConstraints.CheckedItemsChanged -= constraint_CheckedItemChanged;
     58      intervalConstraints.ItemsAdded -= constraints_Updated;
     59      intervalConstraints.ItemsRemoved -= constraints_Updated;
     60      base.DeregisterContentEvents();
     61    }
     62
     63
    5264    private IEnumerable<IntervalConstraint> ParseConstraints(string input) {
    5365      return IntervalConstraintsParser.ParseInput(input, Content.ProblemData.TargetVariable,
     
    5769    private void parseBtn_Click(object sender, EventArgs e) {
    5870      if (constraintsInput.Text != null) {
    59         ClearConstraints();
     71        intervalConstraints.Clear();
    6072        var parsedConstraints = ParseConstraints(constraintsInput.Text);
    6173        foreach (var constraint in parsedConstraints) {
    62           constraint.Changed += constraint_Changed;
    6374          intervalConstraints.Add(constraint, constraint.Enabled);
    6475        }
     
    7485    private void UpdateControl() {
    7586      if (Content == null) {
    76         ClearConstraints();
     87        intervalConstraints.Clear();
    7788        constraintsOutput.Content = intervalConstraints.AsReadOnly();
    7889      } else {
    79         ClearConstraints();
     90        intervalConstraints.Clear();
    8091        constraintsInput.Text = Content.Input;
    8192        foreach (var constraint in Content.Constraints) {
    82           constraint.Changed += constraint_Changed;
    8393          intervalConstraints.Add(constraint, constraint.Enabled);
    8494        }
     
    91101      var constraint = (IntervalConstraint) sender;
    92102      intervalConstraints.SetItemCheckedState(constraint, constraint.Enabled);
     103    }
     104
     105    private void constraints_Updated(object sender, CollectionItemsChangedEventArgs<IndexedItem<IntervalConstraint>> e) {
     106      foreach (var addedItem in e.Items) {
     107        addedItem.Value.Changed += constraint_Changed;
     108      }
    93109    }
    94110
     
    105121    }
    106122
    107     private void ClearConstraints() {
    108       foreach (var constraint in intervalConstraints) {
    109         constraint.Changed -= constraint_Changed;
    110       }
    111       intervalConstraints.Clear();
    112     }
    113 
    114123  }
    115124}
Note: See TracChangeset for help on using the changeset viewer.