Skip to content

Commit 627dec3

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

File tree

30 files changed

+2103
-50
lines changed

30 files changed

+2103
-50
lines changed

CHANGELOG.adoc

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
= Changelog
22

3-
== v2025.4.0 (work in progress)
3+
== v2025.6.0 (work in progress)
4+
5+
=== Shapes
6+
7+
=== Breaking changes
8+
9+
=== Dependency update
10+
11+
=== Bug fixes
12+
13+
=== Improvements
14+
15+
=== New features
16+
17+
- https://github.com/eclipse-syson/syson/issues/1237[#1237] [general-view] Add `ViewUsage` node in the General View.
18+
19+
20+
== v2025.4.0
421

522
=== Shapes
623

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-25
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,55 +95,38 @@
9695
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
9796
public class GVTopNodeCreationTests extends AbstractIntegrationTests {
9897

98+
private final IDescriptionNameGenerator descriptionNameGenerator = new GVDescriptionNameGenerator();
9999
@Autowired
100100
private IGivenInitialServerState givenInitialServerState;
101-
102101
@Autowired
103102
private IGivenDiagramReference givenDiagram;
104-
105103
@Autowired
106104
private IGivenDiagramDescription givenDiagramDescription;
107-
108105
@Autowired
109106
private IGivenDiagramSubscription givenDiagramSubscription;
110-
111107
@Autowired
112108
private IDiagramIdProvider diagramIdProvider;
113-
114109
@Autowired
115110
private IIdentityService identityService;
116-
117111
@Autowired
118112
private IObjectSearchService objectSearchService;
119-
120113
@Autowired
121114
private NodeCreationTester nodeCreationTester;
122-
123115
@Autowired
124116
private SemanticRunnableFactory semanticRunnableFactory;
125-
126117
@Autowired
127118
private DiagramComparator diagramComparator;
128-
129119
@Autowired
130120
private SelectionDialogTreeEventSubscriptionRunner selectionDialogTreeEventSubscriptionRunner;
131-
132121
@Autowired
133122
private RepresentationIdBuilder representationIdBuilder;
134-
135123
@Autowired
136124
private IViewDiagramDescriptionSearchService viewDiagramDescriptionSearchService;
137-
138125
private DiagramDescriptionIdProvider diagramDescriptionIdProvider;
139-
140126
private Step<DiagramRefreshedEventPayload> verifier;
141-
142127
private AtomicReference<Diagram> diagram;
143-
144128
private DiagramDescription diagramDescription;
145129

146-
private final IDescriptionNameGenerator descriptionNameGenerator = new GVDescriptionNameGenerator();
147-
148130
private static Stream<Arguments> topNodeParameters() {
149131
return Stream.of(
150132
Arguments.of(SysmlPackage.eINSTANCE.getAttributeUsage(), 3),
@@ -180,7 +162,8 @@ private static Stream<Arguments> topNodeParameters() {
180162
Arguments.of(SysmlPackage.eINSTANCE.getSatisfyRequirementUsage(), 7),
181163
Arguments.of(SysmlPackage.eINSTANCE.getStateUsage(), 4),
182164
Arguments.of(SysmlPackage.eINSTANCE.getStateDefinition(), 4),
183-
Arguments.of(SysmlPackage.eINSTANCE.getExhibitStateUsage(), 4)
165+
Arguments.of(SysmlPackage.eINSTANCE.getExhibitStateUsage(), 4),
166+
Arguments.of(SysmlPackage.eINSTANCE.getViewUsage(), 0)
184167
).map(TestNameGenerator::namedArguments);
185168
}
186169

@@ -222,9 +205,9 @@ public void createTopNode(EClass eClass, int compartmentCount) {
222205
.ifPresentOrElse(newDiagram -> {
223206
int createdNodesExpectedCount = 1 + compartmentCount;
224207
new CheckDiagramElementCount(this.diagramComparator)
225-
.hasNewEdgeCount(0)
226-
.hasNewNodeCount(createdNodesExpectedCount)
227-
.check(this.diagram.get(), newDiagram);
208+
.hasNewEdgeCount(0)
209+
.hasNewNodeCount(createdNodesExpectedCount)
210+
.check(this.diagram.get(), newDiagram);
228211

229212
String newNodeDescriptionName = this.descriptionNameGenerator.getNodeName(eClass);
230213

@@ -272,7 +255,7 @@ public void createTopNamespaceImportNode() {
272255
this.diagram,
273256
null,
274257
creationToolId,
275-
List.of(new ToolVariable("selectedObject", libId.get().get(), ToolVariableType.OBJECT_ID)));
258+
List.of(new ToolVariable("selectedObject", libId.get().get(), ToolVariableType.OBJECT_ID)));
276259
});
277260

278261
Consumer<DiagramRefreshedEventPayload> updatedDiagramConsumer = payload -> Optional.of(payload)
@@ -356,7 +339,7 @@ private Optional<LibraryPackage> getISQAcousticsLibraryPackageElement(Resource r
356339
.filter(Namespace.class::isInstance)
357340
.map(Namespace.class::cast)
358341
.flatMap(namespace -> namespace.getOwnedMembership().stream())
359-
.map(Membership.class::cast)
342+
.map(t -> t)
360343
.flatMap(membership -> membership.getRelatedElement().stream())
361344
.filter(LibraryPackage.class::isInstance)
362345
.filter(element -> "ISQAcoustics".equals(element.getDeclaredName()))

0 commit comments

Comments
 (0)