Skip to content

Commit 6f42a56

Browse files
committed
[1247] Type new ViewUsage from Explorer view with GeneralView ViewDef
Bug: #1247 Signed-off-by: Axel RICHARD <[email protected]>
1 parent 901c4e1 commit 6f42a56

File tree

7 files changed

+108
-39
lines changed

7 files changed

+108
-39
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
- https://github.com/eclipse-syson/syson/issues/1222[#1222] [general-view] Add `ItemUsage` as _bordered nodes_ of `ActionUsage` and `ActionDefinition` in the _General View_ diagram.
2121
- https://github.com/eclipse-syson/syson/issues/1226[#1226] [general-view] Add the possibility to create `FlowConnectionUsage` as graphical edges from `ItemUsage` _bordered nodes_ on _General View_ diagram.
2222
- https://github.com/eclipse-syson/syson/issues/1249[#1249] [import][export] Implement textual import/export of `AcceptActionUsage`.
23+
- https://github.com/eclipse-syson/syson/issues/1247[#1247] [explorer] Type new `ViewUsage` from _Explorer_ view with _General View_ `ViewDefinition`.
24+
When end-users click on _New Object_ on a semantic element, and select a `ViewUsage`, then a `ViewUsage` typed by default with the _General View_ `ViewDefinition` from the standard library will be created.
2325

2426
=== New features
2527

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/services/GetChildCreationSwitch.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.eclipse.syson.sysml.RequirementUsage;
3838
import org.eclipse.syson.sysml.SysmlPackage;
3939
import org.eclipse.syson.sysml.Usage;
40+
import org.eclipse.syson.sysml.ViewUsage;
4041
import org.eclipse.syson.util.SysmlEClassSwitch;
4142

4243
/**
@@ -253,6 +254,16 @@ public List<EClass> caseUsage(Usage object) {
253254
return childrenCandidates;
254255
}
255256

257+
@Override
258+
public List<EClass> caseViewUsage(ViewUsage object) {
259+
List<EClass> childrenCandidates = new ArrayList<>();
260+
childrenCandidates.add(SysmlPackage.eINSTANCE.getViewUsage());
261+
childrenCandidates.add(SysmlPackage.eINSTANCE.getDocumentation());
262+
childrenCandidates.add(SysmlPackage.eINSTANCE.getComment());
263+
childrenCandidates.add(SysmlPackage.eINSTANCE.getTextualRepresentation());
264+
return childrenCandidates;
265+
}
266+
256267
private List<EClass> getPackageChildren() {
257268
List<EClass> childrenCandidates = new ArrayList<>();
258269
SysmlPackage.eINSTANCE.getEClassifiers().stream()

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/services/GetIntermediateContainerCreationSwitch.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ public Optional<EClass> caseDocumentation(Documentation object) {
6464
return Optional.of(SysmlPackage.eINSTANCE.getOwningMembership());
6565
}
6666

67-
@Override
68-
public Optional<EClass> caseTextualRepresentation(TextualRepresentation object) {
69-
return Optional.of(SysmlPackage.eINSTANCE.getOwningMembership());
70-
}
71-
7267
@Override
7368
public Optional<EClass> caseEnumerationUsage(EnumerationUsage object) {
7469
return Optional.of(SysmlPackage.eINSTANCE.getVariantMembership());
@@ -94,4 +89,9 @@ public Optional<EClass> caseLiteralExpression(LiteralExpression object) {
9489
public Optional<EClass> casePackage(Package object) {
9590
return Optional.of(SysmlPackage.eINSTANCE.getOwningMembership());
9691
}
92+
93+
@Override
94+
public Optional<EClass> caseTextualRepresentation(TextualRepresentation object) {
95+
return Optional.of(SysmlPackage.eINSTANCE.getOwningMembership());
96+
}
9797
}

backend/application/syson-application-configuration/src/test/java/org/eclipse/syson/application/services/GetChildCreationSwitchTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@ public void testNamespaceChildren() {
6666
|| SysmlPackage.eINSTANCE.getPackage().isSuperTypeOf(eClass));
6767
}
6868

69+
@Test
70+
public void testViewUsageChildren() {
71+
List<EClass> children = new GetChildCreationSwitch().doSwitch(SysmlFactory.eINSTANCE.createViewUsage());
72+
List<EClass> expectedChildren = List.of(SysmlPackage.eINSTANCE.getDocumentation(),
73+
SysmlPackage.eINSTANCE.getComment(),
74+
SysmlPackage.eINSTANCE.getTextualRepresentation(),
75+
SysmlPackage.eINSTANCE.getViewUsage());
76+
assertThat(children).containsAll(expectedChildren);
77+
children.removeAll(expectedChildren);
78+
assertThat(children).isEmpty();
79+
}
6980
}

backend/services/syson-services/src/main/java/org/eclipse/syson/services/ElementInitializerSwitch.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
import org.eclipse.syson.sysml.Usage;
5353
import org.eclipse.syson.sysml.UseCaseDefinition;
5454
import org.eclipse.syson.sysml.UseCaseUsage;
55+
import org.eclipse.syson.sysml.ViewDefinition;
56+
import org.eclipse.syson.sysml.ViewUsage;
57+
import org.eclipse.syson.sysml.util.ElementUtil;
5558
import org.eclipse.syson.sysml.util.SysmlSwitch;
5659

5760
/**
@@ -61,6 +64,12 @@
6164
*/
6265
public class ElementInitializerSwitch extends SysmlSwitch<Element> {
6366

67+
private final ElementUtil elementUtil;
68+
69+
public ElementInitializerSwitch() {
70+
this.elementUtil = new ElementUtil();
71+
}
72+
6473
@Override
6574
public Element defaultCase(EObject object) {
6675
if (object instanceof Element element) {
@@ -270,6 +279,17 @@ public Element caseUsage(Usage object) {
270279
return object;
271280
}
272281

282+
@Override
283+
public Element caseViewUsage(ViewUsage object) {
284+
this.caseUsage(object);
285+
var featureTyping = SysmlFactory.eINSTANCE.createFeatureTyping();
286+
object.getOwnedRelationship().add(featureTyping);
287+
var generalViewViewDef = this.elementUtil.findByNameAndType(object, "StandardViewDefinitions::GeneralView", ViewDefinition.class);
288+
featureTyping.setType(generalViewViewDef);
289+
featureTyping.setTypedFeature(object);
290+
return object;
291+
}
292+
273293
private long existingElementsCount(Element element) {
274294
Namespace owningNamespace = element.getOwningNamespace();
275295
if (owningNamespace != null) {

backend/services/syson-services/src/test/java/org/eclipse/syson/services/ElementInitializerSwitchTest.java

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.eclipse.syson.sysml.Relationship;
2828
import org.eclipse.syson.sysml.SysmlFactory;
2929
import org.eclipse.syson.sysml.SysmlPackage;
30+
import org.eclipse.syson.sysml.ViewDefinition;
31+
import org.eclipse.syson.sysml.ViewUsage;
32+
import org.eclipse.syson.sysml.util.ElementUtil;
3033
import org.junit.jupiter.api.BeforeEach;
3134
import org.junit.jupiter.api.DisplayName;
3235
import org.junit.jupiter.api.Test;
@@ -46,6 +49,8 @@ public class ElementInitializerSwitchTest {
4649

4750
private ElementInitializerSwitch elementInitializerSwitch;
4851

52+
private ElementUtil elementUtil;
53+
4954
@BeforeEach
5055
public void setUp() {
5156
this.rSet = new ResourceSetImpl();
@@ -56,38 +61,26 @@ public void setUp() {
5661
this.resource = new JsonResourceFactoryImpl().createResource(URI.createURI("ElementInitializerSwitchTest"));
5762
this.rSet.getResources().add(this.resource);
5863
this.elementInitializerSwitch = new ElementInitializerSwitch();
59-
}
64+
this.elementUtil = new ElementUtil();
6065

61-
@DisplayName("Given a PartUsage, when it is initialized, then it's name contains the count of the same kind of elements")
62-
@Test
63-
public void testPartUsageDefaultName() {
64-
var root = SysmlFactory.eINSTANCE.createPackage();
65-
this.resource.getContents().add(root);
66-
root.setDeclaredName(ROOT);
67-
var p1 = SysmlFactory.eINSTANCE.createPartUsage();
68-
this.addInParent(p1, root);
69-
var initializedP1 = this.elementInitializerSwitch.doSwitch(p1);
70-
assertThat(initializedP1.getDeclaredName()).isEqualTo("part1");
71-
var p2 = SysmlFactory.eINSTANCE.createPartUsage();
72-
this.addInParent(p2, root);
73-
var initializedP2 = this.elementInitializerSwitch.doSwitch(p2);
74-
assertThat(initializedP2.getDeclaredName()).isEqualTo("part2");
7566
}
7667

77-
@DisplayName("Given a PartDefinition, when it is initialized, then it's name contains the count of the same kind of elements")
68+
@DisplayName("Given an Actor, when it is initialized, then it's name contains the count of the same kind of elements")
7869
@Test
79-
public void testPartDefinitionDefaultName() {
70+
public void testActorDefaultName() {
8071
var root = SysmlFactory.eINSTANCE.createPackage();
8172
this.resource.getContents().add(root);
8273
root.setDeclaredName(ROOT);
83-
var p1 = SysmlFactory.eINSTANCE.createPartDefinition();
74+
var p1 = SysmlFactory.eINSTANCE.createPartUsage();
8475
this.addInParent(p1, root);
85-
var initializedP1 = this.elementInitializerSwitch.doSwitch(p1);
86-
assertThat(initializedP1.getDeclaredName()).isEqualTo("PartDefinition1");
87-
var p2 = SysmlFactory.eINSTANCE.createPartDefinition();
88-
this.addInParent(p2, root);
89-
var initializedP2 = this.elementInitializerSwitch.doSwitch(p2);
90-
assertThat(initializedP2.getDeclaredName()).isEqualTo("PartDefinition2");
76+
var a1 = SysmlFactory.eINSTANCE.createPartUsage();
77+
this.addInParent(a1, p1, SysmlPackage.eINSTANCE.getActorMembership());
78+
var initializedA1 = this.elementInitializerSwitch.doSwitch(a1);
79+
assertThat(initializedA1.getDeclaredName()).isEqualTo("actor1");
80+
var a2 = SysmlFactory.eINSTANCE.createPartUsage();
81+
this.addInParent(a2, p1, SysmlPackage.eINSTANCE.getActorMembership());
82+
var initializedA2 = this.elementInitializerSwitch.doSwitch(a2);
83+
assertThat(initializedA2.getDeclaredName()).isEqualTo("actor2");
9184
}
9285

9386
@DisplayName("Given a EnumerationDefinition, when it is initialized, then it's name contains the count of the same kind of elements")
@@ -122,22 +115,36 @@ public void testPackageDefaultName() {
122115
assertThat(initializedP2.getDeclaredName()).isEqualTo("Package2");
123116
}
124117

125-
@DisplayName("Given an Actor, when it is initialized, then it's name contains the count of the same kind of elements")
118+
@DisplayName("Given a PartDefinition, when it is initialized, then it's name contains the count of the same kind of elements")
126119
@Test
127-
public void testActorDefaultName() {
120+
public void testPartDefinitionDefaultName() {
121+
var root = SysmlFactory.eINSTANCE.createPackage();
122+
this.resource.getContents().add(root);
123+
root.setDeclaredName(ROOT);
124+
var p1 = SysmlFactory.eINSTANCE.createPartDefinition();
125+
this.addInParent(p1, root);
126+
var initializedP1 = this.elementInitializerSwitch.doSwitch(p1);
127+
assertThat(initializedP1.getDeclaredName()).isEqualTo("PartDefinition1");
128+
var p2 = SysmlFactory.eINSTANCE.createPartDefinition();
129+
this.addInParent(p2, root);
130+
var initializedP2 = this.elementInitializerSwitch.doSwitch(p2);
131+
assertThat(initializedP2.getDeclaredName()).isEqualTo("PartDefinition2");
132+
}
133+
134+
@DisplayName("Given a PartUsage, when it is initialized, then it's name contains the count of the same kind of elements")
135+
@Test
136+
public void testPartUsageDefaultName() {
128137
var root = SysmlFactory.eINSTANCE.createPackage();
129138
this.resource.getContents().add(root);
130139
root.setDeclaredName(ROOT);
131140
var p1 = SysmlFactory.eINSTANCE.createPartUsage();
132141
this.addInParent(p1, root);
133-
var a1 = SysmlFactory.eINSTANCE.createPartUsage();
134-
this.addInParent(a1, p1, SysmlPackage.eINSTANCE.getActorMembership());
135-
var initializedA1 = this.elementInitializerSwitch.doSwitch(a1);
136-
assertThat(initializedA1.getDeclaredName()).isEqualTo("actor1");
137-
var a2 = SysmlFactory.eINSTANCE.createPartUsage();
138-
this.addInParent(a2, p1, SysmlPackage.eINSTANCE.getActorMembership());
139-
var initializedA2 = this.elementInitializerSwitch.doSwitch(a2);
140-
assertThat(initializedA2.getDeclaredName()).isEqualTo("actor2");
142+
var initializedP1 = this.elementInitializerSwitch.doSwitch(p1);
143+
assertThat(initializedP1.getDeclaredName()).isEqualTo("part1");
144+
var p2 = SysmlFactory.eINSTANCE.createPartUsage();
145+
this.addInParent(p2, root);
146+
var initializedP2 = this.elementInitializerSwitch.doSwitch(p2);
147+
assertThat(initializedP2.getDeclaredName()).isEqualTo("part2");
141148
}
142149

143150
@DisplayName("Given a Stakeholder, when it is initialized, then it's name contains the count of the same kind of elements")
@@ -158,6 +165,21 @@ public void testStakeholderDefaultName() {
158165
assertThat(initializedS2.getDeclaredName()).isEqualTo("stakeholder2");
159166
}
160167

168+
@DisplayName("Given a ViewUsage, when it is initialized, then it's typed by default with the GeneralView ViewDefinition")
169+
@Test
170+
public void testViewUsageDefaultType() {
171+
var root = SysmlFactory.eINSTANCE.createPackage();
172+
this.resource.getContents().add(root);
173+
root.setDeclaredName(ROOT);
174+
var view1 = SysmlFactory.eINSTANCE.createViewUsage();
175+
this.addInParent(view1, root);
176+
var initializedView1 = this.elementInitializerSwitch.doSwitch(view1);
177+
assertThat(initializedView1).isInstanceOf(ViewUsage.class);
178+
var generalViewViewDef = this.elementUtil.findByNameAndType(view1, "StandardViewDefinitions::GeneralView", ViewDefinition.class);
179+
assertThat(((ViewUsage) initializedView1).getType()).contains(generalViewViewDef);
180+
181+
}
182+
161183
private void addInParent(Element element, Element parent) {
162184
OwningMembership owningMembership = SysmlFactory.eINSTANCE.createOwningMembership();
163185
parent.getOwnedRelationship().add(owningMembership);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ action a1 {
9797
}
9898
```
9999

100+
- Type new `ViewUsage` from _Explorer_ view with _General View_ `ViewDefinition`.
101+
When end-users click on _New Object_ on a semantic element, and select a `ViewUsage`, then a `ViewUsage` typed by default with the _General View_ `ViewDefinition` from the standard library will be created.
102+
100103
== Dependency update
101104

102105
== Technical details

0 commit comments

Comments
 (0)