Skip to content

Commit c9dfbd0

Browse files
committed
[1535] Update ViewUsage default name
Bug: #1535 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
1 parent 22532cc commit c9dfbd0

25 files changed

Lines changed: 104 additions & 82 deletions

File tree

CHANGELOG.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Consumers may override this by providing an implementation of `org.eclipse.syson
8585
- https://github.com/eclipse-syson/syson/issues/1530[#1530] [details] Move `RequirementUsage`'s _ReqId_ property from the _Advanced_ tab to the _Core_ tab of the _Details View_.
8686
- https://github.com/eclipse-syson/syson/issues/1534[#1534] [explorer] Since it is now possible to switch from a _Standard Diagram View_ to another in SysON (for example from _General View_ to _Interconnection View_), the `ViewDefinition` name in displayed in the label of the `ViewUsage` in the _Explorer View_.
8787
With this enhancement, users can now easily identify which `ViewDefinition` is used by a `ViewUsage`.
88+
- https://github.com/eclipse-syson/syson/issues/1535[#1535] [explorer] Since it is now possible to switch from a _Standard Diagram View_ to another in SysON (for example from _General View_ to _Interconnection View_), the `ViewUsages` default name does not contain the name of the `ViewDefinition` anymore.
89+
With this enhancement, users avoid confusion when switching from one _ViewDefinition_ to another one in a `ViewUsage`.
8890

8991
=== New features
9092

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public SysMLv2PropertiesConfigurer(ComposedAdapterFactory composedAdapterFactory
126126
@Override
127127
public void addPropertiesDescriptions(IPropertiesDescriptionRegistry registry) {
128128
// Build the actual FormDescription that will be used in Detail view.
129-
FormDescription viewFormDescription = this.createDetailsView();
129+
FormDescription viewFormDescription = this.createDetailsViewForElement();
130130

131131
// The FormDescription must be part of View inside a proper EMF Resource to be correctly handled
132132
URI uri = URI.createURI(IEMFEditingContext.RESOURCE_SCHEME + ":///" + UUID.nameUUIDFromBytes(SysMLv2PropertiesConfigurer.class.getCanonicalName().getBytes()));
@@ -150,7 +150,7 @@ public void addPropertiesDescriptions(IPropertiesDescriptionRegistry registry) {
150150
}
151151
}
152152

153-
private FormDescription createDetailsView() {
153+
private FormDescription createDetailsViewForElement() {
154154
String domainType = SysMLMetamodelHelper.buildQualifiedName(SysmlPackage.eINSTANCE.getElement());
155155
FormDescription form = FormFactory.eINSTANCE.createFormDescription();
156156
form.setName("SysON Details View");
@@ -187,6 +187,7 @@ private FormDescription createDetailsView() {
187187
return form;
188188
}
189189

190+
190191
/**
191192
* Creates a group to display the value of a Feature or FeatureValue.
192193
*

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/sysmlv2/SysMLv2ProjectTemplatesInitializer.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,18 @@ private Optional<RepresentationMetadata> initializeSysMLv2Project(ICause cause,
104104
var resource = this.defaultSysMLv2ResourceProvider.getDefaultSysMLv2Resource(UUID.randomUUID(), SYSMLV2_DOCUMENT_NAME);
105105
resourceSet.getResources().add(resource);
106106

107+
// General View is the description name of SDVDiagramDescriptionProvider
107108
var optionalGeneralViewDiagram = this.findDiagramDescription(editingContext, "General View");
108109
if (optionalGeneralViewDiagram.isPresent()) {
109110
DiagramDescription generalViewDiagram = optionalGeneralViewDiagram.get();
110-
var viewUsage = this.getOrCreateViewUsage(resource);
111-
if (viewUsage.isPresent()) {
111+
var optViewUsage = this.getOrCreateViewUsage(resource);
112+
if (optViewUsage.isPresent()) {
112113
var variableManager = new VariableManager();
114+
var viewUsage = optViewUsage.get();
113115
variableManager.put(VariableManager.SELF, viewUsage);
114-
variableManager.put(DiagramDescription.LABEL, generalViewDiagram.getLabel());
116+
variableManager.put(DiagramDescription.LABEL, viewUsage.getDeclaredName());
115117
String label = generalViewDiagram.getLabelProvider().apply(variableManager);
116-
Diagram diagram = this.diagramCreationService.create(viewUsage.get(), generalViewDiagram, editingContext);
118+
Diagram diagram = this.diagramCreationService.create(viewUsage, generalViewDiagram, editingContext);
117119
List<String> iconURLs = generalViewDiagram.getIconURLsProvider().apply(variableManager);
118120

119121
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(diagram.getId())
@@ -139,16 +141,18 @@ private Optional<RepresentationMetadata> initializeSysMLv2LibraryProject(ICause
139141
var resource = this.defaultSysMLv2ResourceProvider.getDefaultSysMLv2LibraryResource(UUID.randomUUID(), SYSMLV2_LIBRARY_DOCUMENT_NAME);
140142
resourceSet.getResources().add(resource);
141143

144+
// General View is the description name of SDVDiagramDescriptionProvider
142145
var optionalGeneralViewDiagram = this.findDiagramDescription(editingContext, "General View");
143146
if (optionalGeneralViewDiagram.isPresent()) {
144147
DiagramDescription generalViewDiagram = optionalGeneralViewDiagram.get();
145-
var viewUsage = this.getOrCreateViewUsage(resource);
146-
if (viewUsage.isPresent()) {
148+
var optViewUsage = this.getOrCreateViewUsage(resource);
149+
if (optViewUsage.isPresent()) {
147150
var variableManager = new VariableManager();
151+
var viewUsage = optViewUsage.get();
148152
variableManager.put(VariableManager.SELF, viewUsage);
149-
variableManager.put(DiagramDescription.LABEL, generalViewDiagram.getLabel());
153+
variableManager.put(DiagramDescription.LABEL, viewUsage.getDeclaredName());
150154
String label = generalViewDiagram.getLabelProvider().apply(variableManager);
151-
Diagram diagram = this.diagramCreationService.create(viewUsage.get(), generalViewDiagram, editingContext);
155+
Diagram diagram = this.diagramCreationService.create(viewUsage, generalViewDiagram, editingContext);
152156
List<String> iconURLs = generalViewDiagram.getIconURLsProvider().apply(variableManager);
153157

154158
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(diagram.getId())
@@ -177,16 +181,18 @@ private Optional<RepresentationMetadata> initializeBatmobileProject(ICause cause
177181
// Load after adding the resource to the resourceSet, to be sure that references will be resolved.
178182
this.defaultSysMLv2ResourceProvider.loadBatmobileResource(resource);
179183

184+
// General View is the description name of SDVDiagramDescriptionProvider
180185
var optionalGeneralViewDiagram = this.findDiagramDescription(editingContext, "General View");
181186
if (optionalGeneralViewDiagram.isPresent()) {
182187
DiagramDescription generalViewDiagram = optionalGeneralViewDiagram.get();
183-
var viewUsage = this.getOrCreateViewUsage(resource);
184-
if (viewUsage.isPresent()) {
188+
var optViewUsage = this.getOrCreateViewUsage(resource);
189+
if (optViewUsage.isPresent()) {
185190
var variableManager = new VariableManager();
191+
var viewUsage = optViewUsage.get();
186192
variableManager.put(VariableManager.SELF, viewUsage);
187-
variableManager.put(DiagramDescription.LABEL, generalViewDiagram.getLabel());
193+
variableManager.put(DiagramDescription.LABEL, viewUsage.getDeclaredName());
188194
String label = generalViewDiagram.getLabelProvider().apply(variableManager);
189-
Diagram diagram = this.diagramCreationService.create(viewUsage.get(), generalViewDiagram, editingContext);
195+
Diagram diagram = this.diagramCreationService.create(viewUsage, generalViewDiagram, editingContext);
190196
List<String> iconURLs = generalViewDiagram.getIconURLsProvider().apply(variableManager);
191197

192198
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(diagram.getId())
@@ -249,7 +255,7 @@ private Optional<ViewUsage> getViewUsage(Element element) {
249255
return element.getOwnedElement().stream()
250256
.filter(ViewUsage.class::isInstance)
251257
.map(ViewUsage.class::cast)
252-
.filter(vu -> Objects.equals(vu.getDeclaredName(), "General View"))
258+
.filter(vu -> Objects.equals(vu.getDeclaredName(), "view1"))
253259
.findFirst();
254260
}
255261

@@ -258,7 +264,7 @@ private Optional<ViewUsage> createViewUsage(Element element) {
258264
var viewUsage = SysmlFactory.eINSTANCE.createViewUsage();
259265
element.getOwnedRelationship().add(viewUsageMembership);
260266
viewUsageMembership.getOwnedRelatedElement().add(viewUsage);
261-
viewUsage.setDeclaredName("General View");
267+
viewUsage.setDeclaredName("view1");
262268
viewUsage.setElementId(ElementUtil.generateUUID(viewUsage).toString());
263269

264270
var featureTyping = SysmlFactory.eINSTANCE.createFeatureTyping();

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/sysmlv2/SysONDefaultResourceProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Resource getDefaultSysMLv2Resource(UUID resourcePath, String name) {
7272
var package1 = SysmlFactory.eINSTANCE.createPackage();
7373
rootNamespace.getOwnedRelationship().add(rootMembership);
7474
rootMembership.getOwnedRelatedElement().add(package1);
75-
package1.setDeclaredName("Package 1");
75+
package1.setDeclaredName("Package1");
7676
package1.setElementId(ElementUtil.generateUUID(package1).toString());
7777

7878
resource.getContents().add(rootNamespace);

backend/application/syson-application-configuration/src/main/resources/templates/Batmobile.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6276,7 +6276,7 @@
62766276
"id": "b38b489f-9052-47f7-a417-0c1e137d0dca",
62776277
"eClass": "sysml:ViewUsage",
62786278
"data": {
6279-
"declaredName": "General View",
6279+
"declaredName": "view1",
62806280
"elementId": "b63738a8-448c-4de2-a71d-00c512807fdf",
62816281
"ownedRelationship": [
62826282
{

backend/application/syson-application-configuration/src/main/resources/templates/Batmobile.sysml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ package Batmobile {
292292
part :>> wheels = wheels.xWheel;
293293
}
294294

295-
view 'General View' : StandardViewDefinitions::GeneralView {
295+
view 'view1' : StandardViewDefinitions::GeneralView {
296296
expose Vehicle;
297297
expose Vehicle::driver;
298298
expose Vehicle::engine;

backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/templates/TemplatesControllerIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void givenSysMLv2ProjectTemplateWhenMutationIsPerformedThenTheProjectIsCr
140140
var emfEditingContext = (IEMFEditingContext) editingContext;
141141
var rootObject = this.getRooObject(emfEditingContext);
142142
assertNotNull(rootObject);
143-
assertEquals("Package 1", rootObject.getDeclaredName());
143+
assertEquals("Package1", rootObject.getDeclaredName());
144144
}
145145

146146
@DisplayName("GIVEN the SysMLv2-Library project template, WHEN the mutation is performed, THEN the project is created")

backend/metamodel/syson-sysml-metamodel/src/main/java/org/eclipse/syson/sysml/util/ElementUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ public <T extends Element> T findByNameAndType(Collection<EObject> roots, String
230230
return null;
231231
}
232232

233+
/**
234+
* Count the number of existing elements having the same type than the given Element inside the owning Namespace of
235+
* the given Element.
236+
*
237+
* @param element
238+
* the given {@link Element}.
239+
* @return the number of existing elements having the same type than the given Element inside the owning Namespace
240+
* of the given Element.
241+
*/
242+
public long existingElementsCount(Element element) {
243+
Namespace owningNamespace = element.getOwningNamespace();
244+
if (owningNamespace != null) {
245+
return owningNamespace.getOwnedMember().stream()
246+
.filter(member -> element.eClass().equals(member.eClass()))
247+
.count();
248+
}
249+
return 0;
250+
}
251+
233252
/**
234253
* Iterate over the children of the given root {@link EObject} to find an {@link Element} with the given qualified
235254
* name and type.

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public Element caseDependency(Dependency object) {
119119

120120
@Override
121121
public Element caseDefinition(Definition object) {
122-
var existingElements = this.existingElementsCount(object);
122+
var existingElements = this.elementUtil.existingElementsCount(object);
123123
object.setDeclaredName(object.eClass().getName() + existingElements);
124124
return object;
125125
}
@@ -138,7 +138,7 @@ public Element caseElement(Element object) {
138138
@Override
139139
public Element caseEnumerationDefinition(EnumerationDefinition object) {
140140
object.setIsVariation(true);
141-
var existingElements = this.existingElementsCount(object);
141+
var existingElements = this.elementUtil.existingElementsCount(object);
142142
object.setDeclaredName(object.eClass().getName() + existingElements);
143143
return object;
144144
}
@@ -155,7 +155,7 @@ public Element caseFlowUsage(FlowUsage object) {
155155

156156
@Override
157157
public Element casePackage(Package object) {
158-
var existingElements = this.existingElementsCount(object);
158+
var existingElements = this.elementUtil.existingElementsCount(object);
159159
object.setDeclaredName(object.eClass().getName() + existingElements);
160160
return object;
161161
}
@@ -193,7 +193,7 @@ public Element casePerformActionUsage(PerformActionUsage object) {
193193

194194
@Override
195195
public Element casePortDefinition(PortDefinition object) {
196-
var existingElements = this.existingElementsCount(object);
196+
var existingElements = this.elementUtil.existingElementsCount(object);
197197
object.setDeclaredName(object.eClass().getName() + existingElements);
198198
OwningMembership owningMembership = SysmlFactory.eINSTANCE.createOwningMembership();
199199
object.getOwnedRelationship().add(owningMembership);
@@ -272,7 +272,7 @@ public Element caseUsage(Usage object) {
272272
defaultName = defaultName.substring(0, defaultName.length() - 5);
273273
}
274274

275-
var existingElements = this.existingElementsCount(object);
275+
var existingElements = this.elementUtil.existingElementsCount(object);
276276

277277
object.setDeclaredName(defaultName + existingElements);
278278
object.setIsComposite(true);
@@ -290,16 +290,6 @@ public Element caseViewUsage(ViewUsage object) {
290290
return object;
291291
}
292292

293-
private long existingElementsCount(Element element) {
294-
Namespace owningNamespace = element.getOwningNamespace();
295-
if (owningNamespace != null) {
296-
return owningNamespace.getOwnedMember().stream()
297-
.filter(member -> element.eClass().equals(member.eClass()))
298-
.count();
299-
}
300-
return 0;
301-
}
302-
303293
private ParameterMembership createParameterMembershipWithReferenceUsage(String refName, FeatureDirectionKind direction) {
304294
var reference = SysmlFactory.eINSTANCE.createReferenceUsage();
305295
reference.setDirection(direction);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,19 @@ public boolean isEmptyObjectiveRequirement(Element self) {
10141014
.isEmpty();
10151015
}
10161016

1017+
/**
1018+
* Count the number of existing elements having the same type than the given Element inside the owning Namespace of
1019+
* the given Element.
1020+
*
1021+
* @param element
1022+
* the given {@link Element}.
1023+
* @return the number of existing elements having the same type than the given Element inside the owning Namespace
1024+
* of the given Element.
1025+
*/
1026+
public long existingElementsCount(Element element) {
1027+
return this.elementUtil.existingElementsCount(element);
1028+
}
1029+
10171030
private ReferenceUsage addConnectorEnd(ConnectorAsUsage connectorAsUsage, Feature end, Type connectorContainer) {
10181031
FeatureChainComputer cmp = new FeatureChainComputer();
10191032
List<Feature> sourceFeaturePath = cmp.computeShortestPath(connectorContainer, end).orElse(List.of());

0 commit comments

Comments
 (0)