Skip to content

Commit 7665642

Browse files
committed
[1237] Add support for ViewUsage in General View.
Bug: #1237 Signed-off-by: Florian ROUËNÉ <[email protected]>
1 parent 90aef32 commit 7665642

File tree

30 files changed

+2075
-42
lines changed

30 files changed

+2075
-42
lines changed

CHANGELOG.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ When end-users click on _New Object_ on a semantic element, and select a `ViewUs
3333

3434
=== New features
3535

36+
- https://github.com/eclipse-syson/syson/issues/1237[#1237] [general-view] Add `ViewUsage` graphical node in the General View diagram.
3637

3738
== v2025.4.0
3839

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.nodes;
14+
15+
import java.text.MessageFormat;
16+
import java.util.Objects;
17+
18+
import org.eclipse.sirius.components.annotations.Immutable;
19+
import org.eclipse.sirius.components.diagrams.INodeStyle;
20+
import org.eclipse.sirius.components.diagrams.LineStyle;
21+
22+
/**
23+
* The SysML view frame node style.
24+
*
25+
* @author frouene
26+
*/
27+
@Immutable
28+
public final class SysMLViewFrameNodeStyle implements INodeStyle {
29+
30+
private String background;
31+
32+
private String borderColor;
33+
34+
private int borderSize;
35+
36+
private LineStyle borderStyle;
37+
38+
private int borderRadius;
39+
40+
private SysMLViewFrameNodeStyle() {
41+
// Prevent instantiation
42+
}
43+
44+
public static Builder newSysMLViewFrameNodeStyle() {
45+
return new Builder();
46+
}
47+
48+
public String getBackground() {
49+
return this.background;
50+
}
51+
52+
public String getBorderColor() {
53+
return this.borderColor;
54+
}
55+
56+
public int getBorderSize() {
57+
return this.borderSize;
58+
}
59+
60+
public LineStyle getBorderStyle() {
61+
return this.borderStyle;
62+
}
63+
64+
public int getBorderRadius() {
65+
return this.borderRadius;
66+
}
67+
68+
@Override
69+
public String toString() {
70+
String pattern = "{0} '{'color: {1}, border: '{' background: {2}, size: {3}, style: {4} '}''}'";
71+
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.background, this.borderColor, this.borderSize, this.borderStyle);
72+
}
73+
74+
/**
75+
* The builder used to create the view frame node style.
76+
*
77+
* @author frouene
78+
*/
79+
@SuppressWarnings("checkstyle:HiddenField")
80+
public static final class Builder {
81+
82+
private String background;
83+
84+
private String borderColor;
85+
86+
private int borderSize;
87+
88+
private LineStyle borderStyle;
89+
90+
private int borderRadius;
91+
92+
private Builder() {
93+
// Prevent instantiation
94+
}
95+
96+
public Builder background(String background) {
97+
this.background = Objects.requireNonNull(background);
98+
return this;
99+
}
100+
101+
public Builder borderColor(String borderColor) {
102+
this.borderColor = Objects.requireNonNull(borderColor);
103+
return this;
104+
}
105+
106+
public Builder borderSize(int borderSize) {
107+
this.borderSize = borderSize;
108+
return this;
109+
}
110+
111+
public Builder borderStyle(LineStyle borderStyle) {
112+
this.borderStyle = Objects.requireNonNull(borderStyle);
113+
return this;
114+
}
115+
116+
public Builder borderRadius(int borderRadius) {
117+
this.borderRadius = borderRadius;
118+
return this;
119+
}
120+
121+
public SysMLViewFrameNodeStyle build() {
122+
SysMLViewFrameNodeStyle nodeStyleDescription = new SysMLViewFrameNodeStyle();
123+
nodeStyleDescription.background = Objects.requireNonNull(this.background);
124+
nodeStyleDescription.borderColor = Objects.requireNonNull(this.borderColor);
125+
nodeStyleDescription.borderSize = this.borderSize;
126+
nodeStyleDescription.borderStyle = Objects.requireNonNull(this.borderStyle);
127+
nodeStyleDescription.borderRadius = this.borderRadius;
128+
return nodeStyleDescription;
129+
}
130+
}
131+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.nodes;
14+
15+
import java.util.Optional;
16+
17+
import org.eclipse.sirius.components.diagrams.INodeStyle;
18+
import org.eclipse.sirius.components.diagrams.LineStyle;
19+
import org.eclipse.sirius.components.view.FixedColor;
20+
import org.eclipse.sirius.components.view.diagram.NodeStyleDescription;
21+
import org.eclipse.sirius.components.view.emf.diagram.INodeStyleProvider;
22+
import org.eclipse.syson.sysmlcustomnodes.SysMLViewFrameNodeStyleDescription;
23+
import org.springframework.stereotype.Service;
24+
25+
/**
26+
* This class provides style information for the view frame custom node.
27+
*
28+
* @author frouene
29+
*/
30+
@Service
31+
public class SysMLViewFrameNodeStyleProvider implements INodeStyleProvider {
32+
33+
public static final String NODE_SYSML_VIEW_FRAME = "customnode:sysmlviewframe";
34+
35+
@Override
36+
public Optional<String> getNodeType(NodeStyleDescription nodeStyle) {
37+
if (nodeStyle instanceof SysMLViewFrameNodeStyleDescription) {
38+
return Optional.of(NODE_SYSML_VIEW_FRAME);
39+
}
40+
return Optional.empty();
41+
}
42+
43+
@Override
44+
public Optional<INodeStyle> createNodeStyle(NodeStyleDescription nodeStyle, Optional<String> optionalEditingContextId) {
45+
Optional<INodeStyle> iNodeStyle = Optional.empty();
46+
Optional<String> nodeType = this.getNodeType(nodeStyle);
47+
if (nodeType.isPresent()) {
48+
return Optional.of(SysMLViewFrameNodeStyle.newSysMLViewFrameNodeStyle()
49+
.background(Optional.ofNullable(((SysMLViewFrameNodeStyleDescription) nodeStyle).getBackground())
50+
.filter(FixedColor.class::isInstance)
51+
.map(FixedColor.class::cast)
52+
.map(FixedColor::getValue)
53+
.orElse("transparent"))
54+
.borderColor(Optional.ofNullable(nodeStyle.getBorderColor())
55+
.filter(FixedColor.class::isInstance)
56+
.map(FixedColor.class::cast)
57+
.map(FixedColor::getValue)
58+
.orElse("black"))
59+
.borderSize(nodeStyle.getBorderSize())
60+
.borderStyle(LineStyle.valueOf(nodeStyle.getBorderLineStyle().getLiteral()))
61+
.borderRadius(nodeStyle.getBorderRadius())
62+
.build());
63+
}
64+
65+
return iNodeStyle;
66+
}
67+
}

backend/application/syson-application-configuration/src/main/resources/schema/sysmlcustomnodes.graphqls

+11-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ type SysMLNoteNodeStyle {
2323
borderColor: String!
2424
borderSize: Int!
2525
borderStyle: LineStyle!
26-
}
26+
}
27+
28+
extend union INodeStyle = SysMLViewFrameNodeStyle
29+
30+
type SysMLViewFrameNodeStyle {
31+
background: String!
32+
borderColor: String!
33+
borderSize: Int!
34+
borderStyle: LineStyle!
35+
borderRadius: Int!
36+
}

backend/application/syson-application/src/test/java/org/eclipse/syson/application/controllers/diagrams/general/view/GVTopNodeCreationTests.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.eclipse.syson.services.diagrams.api.IGivenDiagramSubscription;
6767
import org.eclipse.syson.sysml.Element;
6868
import org.eclipse.syson.sysml.LibraryPackage;
69-
import org.eclipse.syson.sysml.Membership;
7069
import org.eclipse.syson.sysml.Namespace;
7170
import org.eclipse.syson.sysml.SysmlPackage;
7271
import org.eclipse.syson.util.IDescriptionNameGenerator;
@@ -96,6 +95,8 @@
9695
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
9796
public class GVTopNodeCreationTests extends AbstractIntegrationTests {
9897

98+
private final IDescriptionNameGenerator descriptionNameGenerator = new GVDescriptionNameGenerator();
99+
99100
@Autowired
100101
private IGivenInitialServerState givenInitialServerState;
101102

@@ -143,8 +144,6 @@ public class GVTopNodeCreationTests extends AbstractIntegrationTests {
143144

144145
private DiagramDescription diagramDescription;
145146

146-
private final IDescriptionNameGenerator descriptionNameGenerator = new GVDescriptionNameGenerator();
147-
148147
private static Stream<Arguments> topNodeParameters() {
149148
return Stream.of(
150149
Arguments.of(SysmlPackage.eINSTANCE.getAttributeUsage(), 3),
@@ -181,7 +180,8 @@ private static Stream<Arguments> topNodeParameters() {
181180
Arguments.of(SysmlPackage.eINSTANCE.getSatisfyRequirementUsage(), 7),
182181
Arguments.of(SysmlPackage.eINSTANCE.getStateUsage(), 4),
183182
Arguments.of(SysmlPackage.eINSTANCE.getStateDefinition(), 4),
184-
Arguments.of(SysmlPackage.eINSTANCE.getExhibitStateUsage(), 4)
183+
Arguments.of(SysmlPackage.eINSTANCE.getExhibitStateUsage(), 4),
184+
Arguments.of(SysmlPackage.eINSTANCE.getViewUsage(), 0)
185185
).map(TestNameGenerator::namedArguments);
186186
}
187187

@@ -223,9 +223,9 @@ public void createTopNode(EClass eClass, int compartmentCount) {
223223
.ifPresentOrElse(newDiagram -> {
224224
int createdNodesExpectedCount = 1 + compartmentCount;
225225
new CheckDiagramElementCount(this.diagramComparator)
226-
.hasNewEdgeCount(0)
227-
.hasNewNodeCount(createdNodesExpectedCount)
228-
.check(this.diagram.get(), newDiagram);
226+
.hasNewEdgeCount(0)
227+
.hasNewNodeCount(createdNodesExpectedCount)
228+
.check(this.diagram.get(), newDiagram);
229229

230230
String newNodeDescriptionName = this.descriptionNameGenerator.getNodeName(eClass);
231231

@@ -273,7 +273,7 @@ public void createTopNamespaceImportNode() {
273273
this.diagram,
274274
null,
275275
creationToolId,
276-
List.of(new ToolVariable("selectedObject", libId.get().get(), ToolVariableType.OBJECT_ID)));
276+
List.of(new ToolVariable("selectedObject", libId.get().get(), ToolVariableType.OBJECT_ID)));
277277
});
278278

279279
Consumer<DiagramRefreshedEventPayload> updatedDiagramConsumer = payload -> Optional.of(payload)
@@ -357,7 +357,6 @@ private Optional<LibraryPackage> getISQAcousticsLibraryPackageElement(Resource r
357357
.filter(Namespace.class::isInstance)
358358
.map(Namespace.class::cast)
359359
.flatMap(namespace -> namespace.getOwnedMembership().stream())
360-
.map(Membership.class::cast)
361360
.flatMap(membership -> membership.getRelatedElement().stream())
362361
.filter(LibraryPackage.class::isInstance)
363362
.filter(element -> "ISQAcoustics".equals(element.getDeclaredName()))

backend/metamodel/syson-siriusweb-customnodes-metamodel-edit/src/main/java/org/eclipse/syson/sysmlcustomnodes/provider/SysMLCustomnodesItemProviderAdapterFactory.java

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2023, 2024 Obeo.
2+
* Copyright (c) 2023, 2025 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -161,6 +161,30 @@ public Adapter createSysMLImportedPackageNodeStyleDescriptionAdapter() {
161161
return this.sysMLImportedPackageNodeStyleDescriptionItemProvider;
162162
}
163163

164+
/**
165+
* This keeps track of the one adapter used for all
166+
* {@link org.eclipse.syson.sysmlcustomnodes.SysMLViewFrameNodeStyleDescription} instances. <!-- begin-user-doc -->
167+
* <!-- end-user-doc -->
168+
*
169+
* @generated
170+
*/
171+
protected SysMLViewFrameNodeStyleDescriptionItemProvider sysMLViewFrameNodeStyleDescriptionItemProvider;
172+
173+
/**
174+
* This creates an adapter for a {@link org.eclipse.syson.sysmlcustomnodes.SysMLViewFrameNodeStyleDescription}. <!--
175+
* begin-user-doc --> <!-- end-user-doc -->
176+
*
177+
* @generated
178+
*/
179+
@Override
180+
public Adapter createSysMLViewFrameNodeStyleDescriptionAdapter() {
181+
if (this.sysMLViewFrameNodeStyleDescriptionItemProvider == null) {
182+
this.sysMLViewFrameNodeStyleDescriptionItemProvider = new SysMLViewFrameNodeStyleDescriptionItemProvider(this);
183+
}
184+
185+
return this.sysMLViewFrameNodeStyleDescriptionItemProvider;
186+
}
187+
164188
/**
165189
* This returns the root adapter factory that contains this factory. <!-- begin-user-doc --> <!-- end-user-doc -->
166190
*
@@ -267,6 +291,8 @@ public void dispose() {
267291
this.sysMLNoteNodeStyleDescriptionItemProvider.dispose();
268292
if (this.sysMLImportedPackageNodeStyleDescriptionItemProvider != null)
269293
this.sysMLImportedPackageNodeStyleDescriptionItemProvider.dispose();
294+
if (this.sysMLViewFrameNodeStyleDescriptionItemProvider != null)
295+
this.sysMLViewFrameNodeStyleDescriptionItemProvider.dispose();
270296
}
271297

272298
/**
@@ -323,6 +349,9 @@ public Object caseNodeDescription(NodeDescription object) {
323349
this.newChildDescriptors.add(this.createChildParameter(DiagramPackage.Literals.NODE_DESCRIPTION__STYLE,
324350
SysMLCustomnodesFactory.eINSTANCE.createSysMLImportedPackageNodeStyleDescription()));
325351

352+
this.newChildDescriptors.add(this.createChildParameter(DiagramPackage.Literals.NODE_DESCRIPTION__STYLE,
353+
SysMLCustomnodesFactory.eINSTANCE.createSysMLViewFrameNodeStyleDescription()));
354+
326355
return null;
327356
}
328357

@@ -342,6 +371,9 @@ public Object caseConditionalNodeStyle(ConditionalNodeStyle object) {
342371
this.newChildDescriptors.add(this.createChildParameter(DiagramPackage.Literals.CONDITIONAL_NODE_STYLE__STYLE,
343372
SysMLCustomnodesFactory.eINSTANCE.createSysMLImportedPackageNodeStyleDescription()));
344373

374+
this.newChildDescriptors.add(this.createChildParameter(DiagramPackage.Literals.CONDITIONAL_NODE_STYLE__STYLE,
375+
SysMLCustomnodesFactory.eINSTANCE.createSysMLViewFrameNodeStyleDescription()));
376+
345377
return null;
346378
}
347379

0 commit comments

Comments
 (0)