Changeset 17890
- Timestamp:
- 03/12/21 15:00:21 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataConstraintView.cs
r17887 r17890 34 34 [Content(typeof(ShapeConstraints), true)] 35 35 public partial class ProblemDataConstraintView : AsynchronousContentView { 36 private readonly CheckedItemList<ShapeConstraint>37 intervalConstraints = new CheckedItemList<ShapeConstraint>();38 39 36 public new ShapeConstraints Content { 40 get => (ShapeConstraints) 37 get => (ShapeConstraints)base.Content; 41 38 set => base.Content = value; 42 39 } … … 54 51 protected override void RegisterContentEvents() { 55 52 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; 60 56 } 61 57 62 58 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; 67 62 base.DeregisterContentEvents(); 68 63 } … … 73 68 74 69 75 private IEnumerable<ShapeConstraint> ParseConstraints(string input) {76 return ShapeConstraintsParser.ParseInput(input, Content.ProblemData.TargetVariable,77 Content.ProblemData.AllowedInputVariables);78 }79 70 80 71 private void parseBtn_Click(object sender, EventArgs e) { … … 82 73 intervalConstraints.Clear(); 83 74 try { 84 var parsedConstraints = ParseConstraints(constraintsInput.Text);85 Content.C onstraints = 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; 89 80 //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; 90 85 } 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 { 98 87 errorOutput.Text = "No constraints were found!"; 99 88 } … … 104 93 intervalConstraints.Clear(); 105 94 intervalConstraintsView.Content = intervalConstraints; 106 } 107 else { 95 } else { 108 96 intervalConstraints.Clear(); 109 97 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); 113 101 114 102 intervalConstraintsView.Content = intervalConstraints; … … 117 105 118 106 private void constraint_Changed(object sender, EventArgs e) { 119 var constraint = (ShapeConstraint) 107 var constraint = (ShapeConstraint)sender; 120 108 intervalConstraints.SetItemCheckedState(constraint, constraint.Enabled); 121 109 } 122 110 123 private void constraints_Updated(object 111 private void constraints_Updated(object sender, 124 112 CollectionItemsChangedEventArgs<IndexedItem<ShapeConstraint>> e) { 125 113 foreach (var addedItem in e.Items) addedItem.Value.Changed += constraint_Changed; … … 130 118 } 131 119 132 private void constraint_CheckedItemChanged(object 120 private void constraint_CheckedItemChanged(object sender, 133 121 CollectionItemsChangedEventArgs<IndexedItem<ShapeConstraint>> e) { 134 ICheckedItemList<ShapeConstraint> checkedItemList = (ICheckedItemList<ShapeConstraint>)sender;122 ICheckedItemList<ShapeConstraint> checkedItemList = (ICheckedItemList<ShapeConstraint>)sender; 135 123 foreach (var indexedItem in e.Items) indexedItem.Value.Enabled = checkedItemList.ItemChecked(indexedItem.Value); 136 124 } … … 138 126 private void constraintsInput_TextChanged(object sender, EventArgs e) { 139 127 if (Content.Input != constraintsInput.Text) { 140 Content.Input 141 Content.InfoText 128 Content.Input = constraintsInput.Text; 129 Content.InfoText = "Unparsed changes! Press parse button to save changes."; 142 130 Content.InfoColor = Color.DarkOrange; 143 } 144 else { 131 } else { 145 132 errorOutput.Text = ""; 146 133 }
Note: See TracChangeset
for help on using the changeset viewer.