Skip to content

Commit

Permalink
Merge branch 'main' into eba/enh/843
Browse files Browse the repository at this point in the history
  • Loading branch information
ebausson-obeo authored Nov 8, 2024
2 parents 087631f + 6e3b482 commit 6093847
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

/**
* Unit test for the imported package custom node style.
*
* @author jgout
*/
public class SysMLImportedPackageNodeStyleDescriptionTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.sirius.components.diagrams.events.HideDiagramElementEvent;
import org.eclipse.sirius.components.view.diagram.DiagramDescription;
import org.eclipse.syson.sysml.Element;
import org.eclipse.syson.sysml.Import;
import org.eclipse.syson.sysml.helper.EMFUtils;

/**
Expand Down Expand Up @@ -232,12 +233,32 @@ protected Optional<String> getChildNodeDescriptionIdForRendering(Element element

protected void moveElement(Element droppedElement, Node droppedNode, Element targetElement, Node targetNode, IEditingContext editingContext, IDiagramContext diagramContext,
Map<org.eclipse.sirius.components.view.diagram.NodeDescription, NodeDescription> convertedNodes) {
this.utilService.moveMembership(droppedElement, targetElement);
this.moveSemanticElement(droppedElement, targetElement);
ViewCreationRequest droppedElementViewCreationRequest = this.createView(droppedElement, editingContext, diagramContext, targetNode, convertedNodes);
this.moveSubNodes(droppedElementViewCreationRequest, droppedNode, diagramContext);
diagramContext.getViewDeletionRequests().add(ViewDeletionRequest.newViewDeletionRequest().elementId(droppedNode.getId()).build());
}

protected void moveSemanticElement(Element element, Element newParent) {
if (element instanceof Import imprt) {
newParent.getOwnedRelationship().add(0, imprt);
} else {
this.utilService.moveMembership(element, newParent);
}
}

protected Optional<org.eclipse.sirius.components.view.diagram.NodeDescription> getViewNodeDescription(String descriptionId, DiagramDescription diagramDescription,
Map<org.eclipse.sirius.components.view.diagram.NodeDescription, NodeDescription> convertedNodes) {
return EMFUtils.eAllContentStreamWithSelf(diagramDescription)
.filter(org.eclipse.sirius.components.view.diagram.NodeDescription.class::isInstance)
.map(org.eclipse.sirius.components.view.diagram.NodeDescription.class::cast)
.filter(nodeDesc -> {
NodeDescription convertedNodeDesc = convertedNodes.get(nodeDesc);
return convertedNodeDesc != null && descriptionId.equals(convertedNodeDesc.getId());
})
.findFirst();
}

/**
* Moves the sub-nodes of the provided {@code parentNode} inside the graphical element created by
* {@code parentViewCreationRequest}.
Expand All @@ -258,7 +279,7 @@ protected void moveElement(Element droppedElement, Node droppedNode, Element tar
* @param diagramContext
* the diagram context
*/
private void moveSubNodes(ViewCreationRequest parentViewCreationRequest, Node parentNode, IDiagramContext diagramContext) {
protected void moveSubNodes(ViewCreationRequest parentViewCreationRequest, Node parentNode, IDiagramContext diagramContext) {
for (Node childNode : parentNode.getChildNodes()) {
ViewCreationRequest childViewCreationRequest = ViewCreationRequest.newViewCreationRequest()
.containmentKind(NodeContainmentKind.CHILD_NODE)
Expand Down Expand Up @@ -289,16 +310,4 @@ private void moveSubNodes(ViewCreationRequest parentViewCreationRequest, Node pa
}
}
}

protected Optional<org.eclipse.sirius.components.view.diagram.NodeDescription> getViewNodeDescription(String descriptionId, DiagramDescription diagramDescription,
Map<org.eclipse.sirius.components.view.diagram.NodeDescription, NodeDescription> convertedNodes) {
return EMFUtils.eAllContentStreamWithSelf(diagramDescription)
.filter(org.eclipse.sirius.components.view.diagram.NodeDescription.class::isInstance)
.map(org.eclipse.sirius.components.view.diagram.NodeDescription.class::cast)
.filter(nodeDesc -> {
NodeDescription convertedNodeDesc = convertedNodes.get(nodeDesc);
return convertedNodeDesc != null && descriptionId.equals(convertedNodeDesc.getId());
})
.findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.emf.ecore.EClass;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.view.builder.IViewDiagramElementFinder;
import org.eclipse.sirius.components.view.builder.generated.diagram.FreeFormLayoutStrategyDescriptionBuilder;
import org.eclipse.sirius.components.view.builder.generated.diagram.NodeToolSectionBuilder;
Expand Down Expand Up @@ -191,7 +192,7 @@ private NodePalette createNodePalette(NodeDescription nodeDescription, IViewDiag
.initialDirectEditLabelExpression(AQLConstants.AQL_SELF + ".getDefaultInitialDirectEditLabel()")
.body(callEditService.build());

var edgeTools = new ArrayList<EdgeTool>(this.getEdgeTools(nodeDescription, cache));
var edgeTools = new ArrayList<>(this.getEdgeTools(nodeDescription, cache));

return this.diagramBuilderHelper.newNodePalette()
.deleteTool(deleteTool.build())
Expand All @@ -209,7 +210,8 @@ private List<EdgeTool> getEdgeTools(NodeDescription nodeDescription, IViewDiagra

private DropNodeTool createDropFromDiagramTool(IViewDiagramElementFinder cache) {
var dropElementFromDiagram = this.viewBuilderHelper.newChangeContext()
.expression("aql:droppedElement.dropElementFromDiagram(droppedNode, targetElement, targetNode, editingContext, diagramContext, convertedNodes)");
.expression(AQLUtils.getServiceCallExpression("droppedElement", "dropElementFromDiagram",
List.of("droppedNode", "targetElement", "targetNode", IEditingContext.EDITING_CONTEXT, IDiagramContext.DIAGRAM_CONTEXT, "convertedNodes")));

return this.diagramBuilderHelper.newDropNodeTool()
.name("Drop from Diagram")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ protected IDescriptionNameGenerator getDescriptionNameGenerator() {
}

private void addCustomNodeDescriptionProviders(IColorProvider colorProvider,
ArrayList<IDiagramElementDescriptionProvider<? extends DiagramElementDescription>> diagramElementDescriptionProviders) {
List<IDiagramElementDescriptionProvider<? extends DiagramElementDescription>> diagramElementDescriptionProviders) {
diagramElementDescriptionProviders.add(new RequirementUsageSubjectCompartmentNodeDescriptionProvider(colorProvider, this.getDescriptionNameGenerator()));
diagramElementDescriptionProviders.add(new RequirementDefinitionSubjectCompartmentNodeDescriptionProvider(colorProvider, this.getDescriptionNameGenerator()));
diagramElementDescriptionProviders.add(new CompartmentItemNodeDescriptionProvider(SysmlPackage.eINSTANCE.getRequirementUsage(), SysmlPackage.eINSTANCE.getRequirementUsage_SubjectParameter(),
Expand Down Expand Up @@ -433,7 +433,7 @@ private void addCustomNodeDescriptionProviders(IColorProvider colorProvider,
diagramElementDescriptionProviders.add(new DecisionActionNodeDescriptionProvider(colorProvider, this.getDescriptionNameGenerator()));
diagramElementDescriptionProviders.add(new ReferencingPerformActionUsageNodeDescriptionProvider(colorProvider));
diagramElementDescriptionProviders.add(new ActorNodeDescriptionProvider(colorProvider));
diagramElementDescriptionProviders.add(new ImportedPackageNodeDescriptionProvider(colorProvider, this.descriptionNameGenerator));
diagramElementDescriptionProviders.add(new ImportedPackageNodeDescriptionProvider(colorProvider, this.getDescriptionNameGenerator()));
}

private void addEdgeDescriptionProviders(IColorProvider colorProvider, ArrayList<IDiagramElementDescriptionProvider<? extends DiagramElementDescription>> diagramElementDescriptionProviders) {
Expand Down Expand Up @@ -633,8 +633,8 @@ private DropNodeTool createDropFromDiagramTool(IViewDiagramElementFinder cache)
});
});

var optPackageNodeDescription = cache.getNodeDescription(this.getDescriptionNameGenerator().getNodeName(SysmlPackage.eINSTANCE.getPackage()));
acceptedNodeTypes.add(optPackageNodeDescription.get());
cache.getNodeDescription(this.getDescriptionNameGenerator().getNodeName(SysmlPackage.eINSTANCE.getNamespaceImport()))
.ifPresent(acceptedNodeTypes::add);

var dropElementFromDiagram = this.viewBuilderHelper.newChangeContext()
.expression(AQLUtils.getServiceCallExpression("droppedElement", "dropElementFromDiagram",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

== Improvements

- `OccurrenceUsag#portionKind` is now unsettable and its default value is `null` in the SysMLv2 metamodel to conform to the specification.
- `OccurrenceUsage#portionKind` is now unsettable and its default value is `null` in the SysMLv2 metamodel to conform to the specification.
- Add support of `AllocationDefinition` and 'AllocationUsage` in export from model to textual SysMLv2.

== New features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DiagramElementPalette,
Label,
useConnectorNodeStyle,
useDrop,
useDropNodeStyle,
useRefreshConnectionHandles,
} from '@eclipse-sirius/sirius-components-diagrams';
Expand Down Expand Up @@ -133,9 +134,14 @@ export const SysMLImportedPackageNode: NodeComponentsMap['sysMLImportedPackageNo
({ data, id, selected, dragging }: NodeProps<Node<SysMLImportedPackageNodeData>>) => {
const { readOnly } = useContext<DiagramContextValue>(DiagramContext);
const theme: Theme = useTheme();
const { onDrop, onDragOver } = useDrop();
const { style: connectionFeedbackStyle } = useConnectorNodeStyle(id, data.nodeDescription.id);
const { style: dropFeedbackStyle } = useDropNodeStyle(data.isDropNodeTarget, data.isDropNodeCandidate, dragging);

const handleOnDrop = (event: React.DragEvent) => {
onDrop(event, id);
};

const label: any = {
...data.insideLabel,
style: {
Expand Down Expand Up @@ -201,6 +207,8 @@ export const SysMLImportedPackageNode: NodeComponentsMap['sysMLImportedPackageNo
style={{
...sysMLImportedPackageNodeStyle(theme, data.style, !!selected, data.isHovered, data.faded),
}}
onDragOver={onDragOver}
onDrop={handleOnDrop}
data-testid={`SysMLImportedPackage - ${data?.insideLabel?.text}`}>
{!!selected ? (
<DiagramElementPalette
Expand Down

0 comments on commit 6093847

Please sign in to comment.