Changeset 17890


Ignore:
Timestamp:
03/12/21 15:00:21 (16 months ago)
Author:
gkronber
Message:

#3073: intermediate commit while refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataConstraintView.cs

    r17887 r17890  
    3434  [Content(typeof(ShapeConstraints), true)]
    3535  public partial class ProblemDataConstraintView : AsynchronousContentView {
    36     private readonly CheckedItemList<ShapeConstraint>
    37       intervalConstraints = new CheckedItemList<ShapeConstraint>();
    38 
    3936    public new ShapeConstraints Content {
    40       get => (ShapeConstraints) base.Content;
     37      get => (ShapeConstraints)base.Content;
    4138      set => base.Content = value;
    4239    }
     
    5451    protected override void RegisterContentEvents() {
    5552      base.RegisterContentEvents();
    56       intervalConstraints.CheckedItemsChanged += constraint_CheckedItemChanged;
    57       intervalConstraints.ItemsAdded          += constraints_Updated;
    58       intervalConstraints.ItemsRemoved        += constraint_removed;
    59       Content.Changed                         += Content_Changed;
     53      Content.ItemsAdded += constraints_Updated;
     54      Content.ItemsRemoved += constraint_removed;
     55      Content.Changed += Content_Changed;
    6056    }
    6157
    6258    protected override void DeregisterContentEvents() {
    63       intervalConstraints.CheckedItemsChanged -= constraint_CheckedItemChanged;
    64       intervalConstraints.ItemsAdded          -= constraints_Updated;
    65       intervalConstraints.ItemsRemoved        -= constraint_removed;
    66       Content.Changed                         -= Content_Changed;
     59      Content.ItemsAdded -= constraints_Updated;
     60      Content.ItemsRemoved -= constraint_removed;
     61      Content.Changed -= Content_Changed;
    6762      base.DeregisterContentEvents();
    6863    }
     
    7368
    7469
    75     private IEnumerable<ShapeConstraint> ParseConstraints(string input) {
    76       return ShapeConstraintsParser.ParseInput(input, Content.ProblemData.TargetVariable,
    77                                                   Content.ProblemData.AllowedInputVariables);
    78     }
    7970
    8071    private void parseBtn_Click(object sender, EventArgs e) {
     
    8273        intervalConstraints.Clear();
    8374        try {
    84           var parsedConstraints = ParseConstraints(constraintsInput.Text);
    85           Content.Constraints = parsedConstraints;
    86           Content.Input       = constraintsInput.Text;
    87           Content.InfoText    = "Constraints successfully parsed.";
    88           Content.InfoColor  = Color.DarkGreen;
     75          var parsedConstraints = ShapeConstraintsParser.ParseConstraints(constraintsInput.Text);
     76          Content.Clear();
     77          Content.AddRange(parsedConstraints);
     78          InfoText = "Constraints successfully parsed.";
     79          InfoColor = Color.DarkGreen;
    8980          //Catch the exception from the constraints parser and show it in the error dialog
     81        } catch (ArgumentException ex) {
     82          Content.Clear();
     83          InfoText = ex.Message.Replace("Parameter name", "@Line");
     84          InfoColor = Color.DarkRed;
    9085        }
    91         catch (ArgumentException ex) {
    92           Content.Constraints = new List<ShapeConstraint>();
    93           Content.InfoText    = ex.Message.Replace("Parameter name", "@Line");
    94           Content.InfoColor   = Color.DarkRed;
    95         }
    96       }
    97       else {
     86      } else {
    9887        errorOutput.Text = "No constraints were found!";
    9988      }
     
    10493        intervalConstraints.Clear();
    10594        intervalConstraintsView.Content = intervalConstraints;
    106       }
    107       else {
     95      } else {
    10896        intervalConstraints.Clear();
    10997        constraintsInput.Text = Content.Input;
    110         errorOutput.ForeColor = Content.InfoColor;
    111         errorOutput.Text      = Content.InfoText;
    112         foreach (var constraint in Content.Constraints) intervalConstraints.Add(constraint, constraint.Enabled);
     98        errorOutput.ForeColor = InfoColor;
     99        errorOutput.Text = InfoText;
     100        foreach (var constraint in Content) intervalConstraints.Add(constraint, constraint.Enabled);
    113101
    114102        intervalConstraintsView.Content = intervalConstraints;
     
    117105
    118106    private void constraint_Changed(object sender, EventArgs e) {
    119       var constraint = (ShapeConstraint) sender;
     107      var constraint = (ShapeConstraint)sender;
    120108      intervalConstraints.SetItemCheckedState(constraint, constraint.Enabled);
    121109    }
    122110
    123     private void constraints_Updated(object                                                           sender,
     111    private void constraints_Updated(object sender,
    124112                                     CollectionItemsChangedEventArgs<IndexedItem<ShapeConstraint>> e) {
    125113      foreach (var addedItem in e.Items) addedItem.Value.Changed += constraint_Changed;
     
    130118    }
    131119
    132     private void constraint_CheckedItemChanged(object                                                           sender,
     120    private void constraint_CheckedItemChanged(object sender,
    133121                                               CollectionItemsChangedEventArgs<IndexedItem<ShapeConstraint>> e) {
    134       ICheckedItemList<ShapeConstraint> checkedItemList           = (ICheckedItemList<ShapeConstraint>) sender;
     122      ICheckedItemList<ShapeConstraint> checkedItemList = (ICheckedItemList<ShapeConstraint>)sender;
    135123      foreach (var indexedItem in e.Items) indexedItem.Value.Enabled = checkedItemList.ItemChecked(indexedItem.Value);
    136124    }
     
    138126    private void constraintsInput_TextChanged(object sender, EventArgs e) {
    139127      if (Content.Input != constraintsInput.Text) {
    140         Content.Input     = constraintsInput.Text;
    141         Content.InfoText  = "Unparsed changes! Press parse button to save changes.";
     128        Content.Input = constraintsInput.Text;
     129        Content.InfoText = "Unparsed changes! Press parse button to save changes.";
    142130        Content.InfoColor = Color.DarkOrange;
    143       }
    144       else {
     131      } else {
    145132        errorOutput.Text = "";
    146133      }
Note: See TracChangeset for help on using the changeset viewer.