Skip to content

Commit f475cdd

Browse files
committed
[enh] Migrate label services to new services organization
Bug: #1628 Signed-off-by: Axel RICHARD <axel.richard@obeo.fr>
1 parent 2d0f1cf commit f475cdd

36 files changed

Lines changed: 1438 additions & 1167 deletions

File tree

CHANGELOG.adoc

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,29 @@
1515
- https://github.com/eclipse-syson/syson/issues/1628[#1628] [services] Introduce new services organization.
1616
https://doc.mbse-syson.org/syson/main/developer-guide/index.html#services_organization[See the developer guide in the documentation for more details].
1717
Also introduces new `ServiceMethod` helper class to build AQL service call expressions from type-safe Java method references instead of hardcoded strings.
18-
- [services] _isActor(Element)_ has been moved from `ViewNodeService` to `ElementQueryService`.
18+
- [services] _isActor(Element)_ has been moved from `ViewNodeService` to `MetamodelElementQueryService`.
19+
- [services] The following services have been moved from `LabelService` and `ViewLabelService` to `DiagramQueryLabelService`:
20+
* String getCompartmentItemLabel(Documentation documentation)
21+
* String getCompartmentItemLabel(Usage usage)
22+
* String getContainerLabel(Element element)
23+
* String getDefaultInitialDirectEditLabel(Comment comment)
24+
* String getDefaultInitialDirectEditLabel(Element element)
25+
* String getDefaultInitialDirectEditLabel(TextualRepresentation textualRepresentation)
26+
* String getDependencyLabel(Dependency dependency)
27+
* String getEdgeLabel(Element element)
28+
* String getInitialDirectEditListItemLabel(Documentation documentation)
29+
* String getInitialDirectEditListItemLabel(Comment comment)
30+
* String getInitialDirectEditListItemLabel(Usage usage)
31+
* String getMultiplicityLabel(Element element)
32+
* String getTransitionLabel(TransitionUsage transition)
33+
- [services] The following services have been moved from `LabelService` and `ViewLabelService` to `DiagramMutationLabelService`:
34+
* Element directEdit(Element element, String newLabel)
35+
* Element directEdit(Element element, String newLabel, String... options)
36+
* Element directEdit(Element element, String newLabel, boolean isCompartmentItem, String... options)
37+
* Element directEditNode(Element element, String newLabel)
38+
* Element directEditListItem(Element element, String newLabel)
39+
* Element editMultiplicityRangeCenterLabel(Element element, String newLabel)
40+
* Element editEdgeCenterLabel(Element element, String newLabel)
1941

2042
=== Dependency update
2143

backend/services/syson-diagram-services/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
<artifactId>syson-sysml-metamodel</artifactId>
6363
<version>2025.10.1</version>
6464
</dependency>
65+
<dependency>
66+
<groupId>org.eclipse.syson</groupId>
67+
<artifactId>syson-services</artifactId>
68+
<version>2025.10.1</version>
69+
</dependency>
6570
<!-- Tests -->
6671
<dependency>
6772
<groupId>org.testcontainers</groupId>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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.diagram.services;
14+
15+
import java.text.MessageFormat;
16+
import java.util.Objects;
17+
18+
import org.antlr.v4.runtime.CharStreams;
19+
import org.antlr.v4.runtime.CommonTokenStream;
20+
import org.antlr.v4.runtime.tree.ParseTree;
21+
import org.antlr.v4.runtime.tree.ParseTreeWalker;
22+
import org.eclipse.sirius.components.core.api.IFeedbackMessageService;
23+
import org.eclipse.sirius.components.representations.Message;
24+
import org.eclipse.sirius.components.representations.MessageLevel;
25+
import org.eclipse.syson.direct.edit.grammars.DirectEditLexer;
26+
import org.eclipse.syson.direct.edit.grammars.DirectEditParser;
27+
import org.eclipse.syson.services.DiagramDirectEditListener;
28+
import org.eclipse.syson.services.LabelService;
29+
import org.eclipse.syson.sysml.ConstraintUsage;
30+
import org.eclipse.syson.sysml.Element;
31+
import org.eclipse.syson.sysml.RequirementConstraintMembership;
32+
import org.springframework.stereotype.Service;
33+
34+
/**
35+
* Label-related services doing mutations in diagrams.
36+
*
37+
* @author arichard
38+
*/
39+
@Service
40+
public class DiagramMutationLabelService {
41+
42+
private final IFeedbackMessageService feedbackMessageService;
43+
44+
public DiagramMutationLabelService(IFeedbackMessageService feedbackMessageService) {
45+
this.feedbackMessageService = Objects.requireNonNull(feedbackMessageService);
46+
}
47+
48+
/**
49+
* Apply the direct edit result (i.e. the newLabel) to the given {@link Element}.
50+
*
51+
* @param element
52+
* the given {@link Element}.
53+
* @param newLabel
54+
* the new value to apply.
55+
* @return the given {@link Element}.
56+
*/
57+
public Element directEdit(Element element, String newLabel) {
58+
return this.directEdit(element, newLabel, (String[]) null);
59+
}
60+
61+
/**
62+
* Apply the direct edit result (i.e. the newLabel) to the given {@link Element}, with the provided {@code options}.
63+
* <p>
64+
* This method is typically used to enable direct edit with some restrictions (e.g. de-activate the ability to edit
65+
* the name of an element via direct edit). See {@link #directEdit(Element, String)} to perform a direct edit with
66+
* default options.
67+
* </p>
68+
*
69+
* @param element
70+
* the given {@link Element}
71+
* @param newLabel
72+
* the new value to apply
73+
* @param options
74+
* the options of the direct edit
75+
* @return the given {@link Element}
76+
*/
77+
public Element directEdit(Element element, String newLabel, String... options) {
78+
return this.directEdit(element, newLabel, false, options);
79+
}
80+
81+
/**
82+
* Apply the direct edit result (i.e. the newLabel) to the given {@link Element}.
83+
*
84+
* @param element
85+
* the given {@link Element}.
86+
* @param newLabel
87+
* the new value to apply.
88+
* @return the given {@link Element}.
89+
*/
90+
public Element directEdit(Element element, String newLabel, boolean isCompartmentItem, String... options) {
91+
DirectEditLexer lexer = new DirectEditLexer(CharStreams.fromString(newLabel));
92+
CommonTokenStream tokens = new CommonTokenStream(lexer);
93+
DirectEditParser parser = new DirectEditParser(tokens);
94+
ParseTree tree;
95+
if (element instanceof ConstraintUsage && element.getOwningMembership() instanceof RequirementConstraintMembership && isCompartmentItem) {
96+
// Use the constraint expression parser only if the element is a constraint owned by a requirement, other
97+
// constraints (including requirements) are parsed as regular elements.
98+
tree = parser.constraintExpression();
99+
} else if (isCompartmentItem) {
100+
tree = parser.listItemExpression();
101+
} else {
102+
tree = parser.nodeExpression();
103+
}
104+
ParseTreeWalker walker = new ParseTreeWalker();
105+
DiagramDirectEditListener listener = new DiagramDirectEditListener(element, this.feedbackMessageService, options);
106+
walker.walk(listener, tree);
107+
listener.resolveProxies().forEach(proxy -> {
108+
this.feedbackMessageService.addFeedbackMessage(new Message(MessageFormat.format("Unable to resolve \u2035{0}\u2035", proxy.nameToResolve()), MessageLevel.WARNING));
109+
});
110+
return element;
111+
}
112+
113+
/**
114+
* Apply the direct edit result (i.e. the newLabel) to the given graphical node {@link Element}.
115+
*
116+
* @param element
117+
* the given {@link Element}.
118+
* @param newLabel
119+
* the new value to apply.
120+
* @return the given {@link Element}.
121+
*/
122+
public Element directEditNode(Element element, String newLabel) {
123+
return this.directEdit(element, newLabel, false, (String[]) null);
124+
}
125+
126+
/**
127+
* Apply the direct edit result (i.e. the newLabel) to the given graphical list item {@link Element}.
128+
*
129+
* @param element
130+
* the given {@link Element}.
131+
* @param newLabel
132+
* the new value to apply.
133+
* @return the given {@link Element}.
134+
*/
135+
public Element directEditListItem(Element element, String newLabel) {
136+
return this.directEdit(element, newLabel, true, (String[]) null);
137+
}
138+
139+
public Element editMultiplicityRangeCenterLabel(Element element, String newLabel) {
140+
return this.directEdit(element, newLabel, LabelService.NAME_OFF, LabelService.REDEFINITION_OFF, LabelService.SUBSETTING_OFF, LabelService.TYPING_OFF, LabelService.VALUE_OFF);
141+
}
142+
143+
public Element editEdgeCenterLabel(Element element, String newLabel) {
144+
return this.directEdit(element, newLabel, LabelService.REDEFINITION_OFF, LabelService.SUBSETTING_OFF, LabelService.VALUE_OFF);
145+
}
146+
}

0 commit comments

Comments
 (0)