Skip to content

Commit 2e04d31

Browse files
pcdavidAxelRICHARD
authored andcommitted
[2291] Fix item label for constraint to show their name and expression
Bug: #2291 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
1 parent 804e317 commit 2e04d31

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ It has long been unused by Sirius Web itself (since the transition to MUI).
3030
- https://github.com/eclipse-syson/syson/issues/2232[#2232] [configuration] Fix a serialization problem of the View models of SysON representations.
3131
- https://github.com/eclipse-syson/syson/issues/2237[#2237] [diagrams] Fix the item label inside `frames`, `require constraints`, and `assume constraints` compartments.
3232
- https://github.com/eclipse-syson/syson/issues/2278[#2278] [diagrams] Display inherited behavior parameters in the _parameters_ compartment of `ActionDefinition` and `ActionUsage` graphical nodes.
33+
- https://github.com/eclipse-syson/syson/issues/2291[#2291] [diagrams] Fix item label for constraint to show their name and expression value between braces (if present).
3334

3435
=== Improvements
3536

backend/services/syson-diagram-services/src/main/java/org/eclipse/syson/diagram/services/DiagramQueryLabelService.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,7 @@ public String getCompartmentItemLabel(Usage usage) {
493493

494494
private String getCompartmentItemStringRepresentation(Usage usage, boolean directEditInput) {
495495
StringBuilder label = new StringBuilder();
496-
if (usage instanceof ConstraintUsage constraintUsage
497-
&& usage.getOwningMembership() instanceof RequirementConstraintMembership) {
498-
// Use the constraint-specific rendering only if the element is a constraint owned by a requirement. Other
499-
// constraints (including requirements) are rendered as regular elements.
496+
if (usage instanceof ConstraintUsage constraintUsage) {
500497
label.append(this.getCompartmentItemLabel(constraintUsage, directEditInput));
501498
} else {
502499
label.append(this.getUsageListItemPrefix(usage));
@@ -597,11 +594,7 @@ public String getSatisfyLabel(SatisfyRequirementUsage satisfyRequirementUsage) {
597594
*/
598595
private String getCompartmentItemLabel(ConstraintUsage constraintUsage, boolean directEditInput) {
599596
StringBuilder label = new StringBuilder();
600-
if (constraintUsage == null) {
601-
label.append("");
602-
} else if (!constraintUsage.getOwnedMember().isEmpty() && constraintUsage.getOwnedMember().get(0) instanceof Expression expression) {
603-
label.append(this.getSysmlTextualRepresentation(expression, directEditInput));
604-
} else {
597+
if (constraintUsage != null) {
605598
var identificationLabel = this.getIdentificationLabel(constraintUsage);
606599
if (identificationLabel.isBlank()) {
607600
// The constraint doesn't have an expression and does not have a name, we use the referenced feature name if the referenced feature exists
@@ -615,6 +608,14 @@ private String getCompartmentItemLabel(ConstraintUsage constraintUsage, boolean
615608
label.append(this.getReferenceSubsettingLabel(constraintUsage));
616609
}
617610

611+
if (!directEditInput && !constraintUsage.getOwnedMember().isEmpty() && constraintUsage.getOwnedMember().get(0) instanceof Expression expression) {
612+
if (!label.isEmpty()) {
613+
label.append(LabelConstants.SPACE);
614+
}
615+
label.append(LabelConstants.OPEN_BRACE).append(LabelConstants.SPACE);
616+
label.append(this.getSysmlTextualRepresentation(expression, directEditInput));
617+
label.append(LabelConstants.SPACE).append(LabelConstants.CLOSE_BRACE);
618+
}
618619
}
619620
return label.toString();
620621
}

backend/services/syson-diagram-services/src/test/java/org/eclipse/syson/diagram/services/DiagramQueryLabelServiceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public void testGetCompartmentItemLabelOfConstraintWithBooleanExpression() {
333333
literalInteger.setValue(2);
334334
yValue.getOwnedRelatedElement().add(literalInteger);
335335

336-
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo("1 >= 2");
336+
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo(CONSTRAINT_USAGE_NAME + " { 1 >= 2 }");
337337
}
338338

339339
@DisplayName("GIVEN a ConstraintUsage with an expression containing a subject reference, WHEN its label is computed, THEN the label represents the expression")
@@ -356,7 +356,7 @@ public void testGetCompartmentItemLabelOfConstraintWithSubjectReferenceExpressio
356356
yFeatureReference.getOwnedRelationship().add(yFeatureReferenceMembership);
357357
yFeatureReferenceMembership.setMemberElement(subjectReference);
358358

359-
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo("1 >= mySubject");
359+
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo(CONSTRAINT_USAGE_NAME + " { 1 >= mySubject }");
360360

361361
}
362362

@@ -381,7 +381,7 @@ public void testGetCompartmentItemLabelOfConstraintWithAttributeReferenceExpress
381381
yFeatureReference.getOwnedRelationship().add(yFeatureReferenceMembership);
382382
yFeatureReferenceMembership.setMemberElement(attributeUsage);
383383

384-
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo("1 >= myAttribute");
384+
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo(CONSTRAINT_USAGE_NAME + " { 1 >= myAttribute }");
385385
}
386386

387387
@DisplayName("GIVEN a ConstraintUsage with an expression containing a single feature chaining, WHEN its label is computed, THEN the label represents the expression")
@@ -406,7 +406,7 @@ public void testGetCompartmentItemLabelOfConstraintWithSingleFeatureChainingExpr
406406
featureChainExpression.getOwnedRelationship().add(featureChainMembership);
407407
featureChainMembership.setMemberElement(subAttributeUsage);
408408

409-
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo("1 >= myAttribute.mySubAttribute");
409+
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo(CONSTRAINT_USAGE_NAME + " { 1 >= myAttribute.mySubAttribute }");
410410
}
411411

412412
@DisplayName("GIVEN a ConstraintUsage with an expression containing multiple feature chainings, WHEN its label is computed, THEN the label represents the expression")
@@ -439,7 +439,7 @@ public void testGetCompartmentItemLabelOfConstraintWithMultipleFeatureChainingEx
439439
featureChaining2.setChainingFeature(zAttributeUsage);
440440
feature.getOwnedRelationship().addAll(List.of(featureChaining1, featureChaining2));
441441

442-
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo("1 >= x.y.z");
442+
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo(CONSTRAINT_USAGE_NAME + " { 1 >= x.y.z }");
443443
}
444444

445445
@DisplayName("GIVEN a Dependency with a name and short name, WHEN its edge label is computed, THEN the label contains the name and short name")

backend/services/syson-sysml-metamodel-services/src/main/java/org/eclipse/syson/sysml/metamodel/helper/LabelConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class LabelConstants {
2525

2626
public static final String ASSUME = SysMLv2Keywords.ASSUME;
2727

28+
public static final String CLOSE_BRACE = SysMLv2Keywords.RIGHT_BRACE;
29+
2830
public static final String CLOSE_BRACKET = SysMLv2Keywords.RIGHT_BRACKET;
2931

3032
public static final String CLOSE_PARENTHESIS = SysMLv2Keywords.RIGHT_PAREN;
@@ -63,6 +65,8 @@ public class LabelConstants {
6365

6466
public static final String NON_UNIQUE = SysMLv2Keywords.NONUNIQUE;
6567

68+
public static final String OPEN_BRACE = SysMLv2Keywords.LEFT_BRACE;
69+
6670
public static final String OPEN_BRACKET = SysMLv2Keywords.LEFT_BRACKET;
6771

6872
public static final String OPEN_PARENTHESIS = SysMLv2Keywords.LEFT_PAREN;

0 commit comments

Comments
 (0)