Skip to content

Commit 8760048

Browse files
gcoutableAxelRICHARD
authored andcommitted
[2237] Fix the item label of frames compartments
Bug: #2237 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
1 parent ac714f6 commit 8760048

4 files changed

Lines changed: 72 additions & 12 deletions

File tree

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
=== Bug fixes
2121

2222
- https://github.com/eclipse-syson/syson/issues/2232[#2232] [configuration] Fix a serialization problem of the View models of SysON representations.
23+
- https://github.com/eclipse-syson/syson/issues/2237[#2237] [diagrams] Fix the item label inside `frames`, `require constraints`, and `assume constraints` compartments.
2324

2425
=== Improvements
2526

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ public class DiagramQueryLabelService implements IDiagramLabelService {
9696
@Override
9797
public String getIdentificationLabel(Element element) {
9898
StringBuilder label = new StringBuilder();
99+
var shortNameLabel = this.getShortNameLabel(element);
100+
String declaredName = element.getDeclaredName();
101+
99102
if (element instanceof ActionUsage && element.eContainer() instanceof StateSubactionMembership ssm) {
100-
label.append(ssm.getKind()).append(LabelConstants.SPACE);
103+
label.append(ssm.getKind());
104+
if (!shortNameLabel.isBlank() || declaredName != null) {
105+
label.append(LabelConstants.SPACE);
106+
}
101107
}
102-
label.append(this.getShortNameLabel(element));
103-
String declaredName = element.getDeclaredName();
108+
label.append(shortNameLabel);
104109
if (declaredName != null) {
105110
label.append(declaredName);
106111
}
@@ -119,6 +124,7 @@ public String getReferenceSubsettingLabel(Element element) {
119124
if (!referenceSubsetting.isIsImplied()) {
120125
var referencedFeature = referenceSubsetting.getReferencedFeature();
121126
if (referencedFeature != null) {
127+
label.append(LabelConstants.SPACE);
122128
label.append(LabelConstants.REFERENCES);
123129
label.append(LabelConstants.SPACE);
124130
label.append(this.getDeclaredNameLabel(referencedFeature));
@@ -549,11 +555,11 @@ public String getDependencyLabel(Dependency dependency) {
549555
}
550556

551557
/**
552-
* Returns the label for the given {@code dependency}.
558+
* Returns the label for the given {@link SatisfyRequirementUsage}.
553559
*
554-
* @param dependency
555-
* the dependency to get the edge label from
556-
* @return the edge label
560+
* @param satisfyRequirementUsage
561+
* The given {@link SatisfyRequirementUsage}
562+
* @return the label for the given {@link SatisfyRequirementUsage}
557563
*/
558564
public String getSatisfyLabel(SatisfyRequirementUsage satisfyRequirementUsage) {
559565
StringBuilder label = new StringBuilder();
@@ -577,8 +583,19 @@ private String getCompartmentItemLabel(ConstraintUsage constraintUsage, boolean
577583
} else if (!constraintUsage.getOwnedMember().isEmpty() && constraintUsage.getOwnedMember().get(0) instanceof Expression expression) {
578584
label.append(this.getSysmlTextualRepresentation(expression, directEditInput));
579585
} else {
580-
// The constraint doesn't have an expression, we use its name as default label.
581-
label.append(this.getIdentificationLabel(constraintUsage));
586+
var identificationLabel = this.getIdentificationLabel(constraintUsage);
587+
if (identificationLabel.isBlank()) {
588+
// The constraint doesn't have an expression and does not have a name, we use the referenced feature name if the referenced feature exists
589+
var ownedReferenceSubsetting = constraintUsage.getOwnedReferenceSubsetting();
590+
if (ownedReferenceSubsetting != null) {
591+
label.append(this.getIdentificationLabel(ownedReferenceSubsetting.getReferencedFeature()));
592+
}
593+
} else {
594+
// The constraint doesn't have an expression and has a name, we use its name and the referenced feature name
595+
label.append(this.getIdentificationLabel(constraintUsage));
596+
label.append(this.getReferenceSubsettingLabel(constraintUsage));
597+
}
598+
582599
}
583600
return label.toString();
584601
}
@@ -648,7 +665,7 @@ public String getInitialDirectEditListItemLabel(Documentation documentation) {
648665
* Get the value to display when a direct edit has been called on the given {@link Comment}.
649666
*
650667
* @param comment
651-
* the given {@link comment}.
668+
* the given {@link Comment}.
652669
* @return the value to display.
653670
*/
654671
public String getInitialDirectEditListItemLabel(Comment comment) {

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void testItemCompartmentLabelWithName() {
179179
}
180180

181181
@DisplayName("Check Attribute Usage item label with name and short name")
182+
@Test
182183
void testItemCompartmentLabelWithNameAndShortName() {
183184
AttributeUsage attributeUsage = SysmlFactory.eINSTANCE.createAttributeUsage();
184185
attributeUsage.setDeclaredName(ATTRIBUTE_USAGE_NAME);
@@ -270,9 +271,9 @@ void testItemCompartmentLabelWithPrefixAndMultiplicity() {
270271
this.labelService.getCompartmentItemLabel(attributeUsage));
271272
}
272273

273-
@DisplayName("GIVEN a ConstraintUsage with no expression, WHEN its label is computed, THEN the label contains the name of the constraint")
274+
@DisplayName("GIVEN a ConstraintUsage without expression, with declared name, without requiring another constraint, WHEN its label is computed, THEN the label contains the name of the constraint")
274275
@Test
275-
public void testGetCompartmentItemLabelOfConstraintWithNoExpression() {
276+
public void testGetCompartmentItemLabelOfConstraintWithoutExpressionWithDeclaredNameWithoutRequiringAnotherConstraint() {
276277
ConstraintUsage constraintUsage = SysmlFactory.eINSTANCE.createConstraintUsage();
277278
constraintUsage.setDeclaredName(CONSTRAINT_USAGE_NAME);
278279
// Constraints have a special label when they are inside a RequirementConstraintMembership
@@ -281,6 +282,41 @@ public void testGetCompartmentItemLabelOfConstraintWithNoExpression() {
281282
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo(CONSTRAINT_USAGE_NAME);
282283
}
283284

285+
@DisplayName("GIVEN a ConstraintUsage without expression, with declared name, requiring another constraint, WHEN its label is computed, THEN the label contains the constraint name with subsetted refence name")
286+
@Test
287+
public void testGetCompartmentItemLabelOfConstraintWithoutExpressionWithDeclaredNameRequiringAnotherConstraint() {
288+
ConstraintUsage constraintUsage = SysmlFactory.eINSTANCE.createConstraintUsage();
289+
constraintUsage.setDeclaredName(CONSTRAINT_USAGE_NAME);
290+
291+
ConstraintUsage referenceConstraintUsage = SysmlFactory.eINSTANCE.createConstraintUsage();
292+
referenceConstraintUsage.setDeclaredName("referencedConstraint");
293+
var referenceSubsetting = SysmlFactory.eINSTANCE.createReferenceSubsetting();
294+
referenceSubsetting.setReferencedFeature(referenceConstraintUsage);
295+
constraintUsage.getOwnedRelationship().add(referenceSubsetting);
296+
297+
// Constraints have a special label when they are inside a RequirementConstraintMembership
298+
RequirementConstraintMembership requirementConstraintMembership = SysmlFactory.eINSTANCE.createRequirementConstraintMembership();
299+
requirementConstraintMembership.getOwnedRelatedElement().add(constraintUsage);
300+
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo(CONSTRAINT_USAGE_NAME + LabelConstants.SPACE + LabelConstants.REFERENCES + LabelConstants.SPACE + "referencedConstraint");
301+
}
302+
303+
@DisplayName("GIVEN a ConstraintUsage without expression, without declared name, requiring another constraint, WHEN its label is computed, THEN the label contains only subsetted refence name")
304+
@Test
305+
public void testGetCompartmentItemLabelOfConstraintWithoutExpressionWithoutDeclaredNameRequiringAnotherConstraint() {
306+
ConstraintUsage constraintUsage = SysmlFactory.eINSTANCE.createConstraintUsage();
307+
308+
ConstraintUsage referenceConstraintUsage = SysmlFactory.eINSTANCE.createConstraintUsage();
309+
referenceConstraintUsage.setDeclaredName("referencedConstraint");
310+
var referenceSubsetting = SysmlFactory.eINSTANCE.createReferenceSubsetting();
311+
referenceSubsetting.setReferencedFeature(referenceConstraintUsage);
312+
constraintUsage.getOwnedRelationship().add(referenceSubsetting);
313+
314+
// Constraints have a special label when they are inside a RequirementConstraintMembership
315+
RequirementConstraintMembership requirementConstraintMembership = SysmlFactory.eINSTANCE.createRequirementConstraintMembership();
316+
requirementConstraintMembership.getOwnedRelatedElement().add(constraintUsage);
317+
assertThat(this.labelService.getCompartmentItemLabel(constraintUsage)).isEqualTo("referencedConstraint");
318+
}
319+
284320
@DisplayName("GIVEN a ConstraintUsage with a boolean expression, WHEN its label is computed, THEN the label represents the expression")
285321
@Test
286322
public void testGetCompartmentItemLabelOfConstraintWithBooleanExpression() {

doc/content/modules/user-manual/pages/release-notes/2026.7.0.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ a|image::explorer-expression-internals-visible.png[Internals visible]
5151

5252
** Improve diagram-to-diagram drag and drop to support dropping multiple graphical nodes at once.
5353
** Improve feedback message reporting while moving elements in diagrams.
54+
** Fix and improve the labeling logic inside `frames`, `require constraints`, and `assume constraints` compartments.
55+
Previously, the label was always the name of the `ConcernUsage` or the `ConstraintUsage` displayed in the compartment.
56+
Now, the label dynamically adapts based on whether the `ConcernUsage` or `ConstraintUsage` has a name and an owned reference subsetting:
57+
*** Elements having both a name and an owned reference subsetting now display using the standard subsetting notation (e.g., `ElementName ::> SubsettingName`).
58+
*** Elements without name and an owned reference subsetting display only the reference subsetting name
59+
*** Elements without reference subsetting display their name.
5460

5561
== Technical details
5662

0 commit comments

Comments
 (0)