use of org.eclipse.sirius.components.diagrams.description.NodeDescription in project sirius-components by eclipse-sirius.
the class AbstractNodeMappingConverter method convert.
public NodeDescription convert(AbstractNodeMapping abstractNodeMapping, AQLInterpreter interpreter, Map<UUID, NodeDescription> id2NodeDescriptions) {
LabelStyleDescriptionConverter labelStyleDescriptionConverter = new LabelStyleDescriptionConverter(interpreter, this.objectService);
Function<VariableManager, org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription> abstractNodeMappingDescriptionProvider = new LabelStyleDescriptionProvider(interpreter, abstractNodeMapping);
Function<VariableManager, String> labelIdProvider = this.getLabelIdProvider();
Function<VariableManager, String> labelExpressionProvider = this.getLabelExpressionProvider(interpreter, abstractNodeMappingDescriptionProvider);
Function<VariableManager, LabelStyleDescription> labelStyleDescriptionProvider = this.getLabelStyleDescriptionProvider(labelStyleDescriptionConverter, abstractNodeMappingDescriptionProvider);
// @formatter:off
LabelDescription labelDescription = LabelDescription.newLabelDescription(this.identifierProvider.getIdentifier(abstractNodeMapping) + LabelDescription.LABEL_SUFFIX).idProvider(labelIdProvider).textProvider(labelExpressionProvider).styleDescriptionProvider(labelStyleDescriptionProvider).build();
// @formatter:on
Function<VariableManager, String> semanticTargetIdProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null);
};
Function<VariableManager, String> semanticTargetKindProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getKind).orElse(null);
};
Function<VariableManager, String> semanticTargetLabelProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getLabel).orElse(null);
};
Function<VariableManager, INodeStyle> styleProvider = new AbstractNodeMappingStyleProvider(interpreter, abstractNodeMapping);
Function<VariableManager, String> typeProvider = variableManager -> {
var result = NodeType.NODE_RECTANGLE;
INodeStyle style = styleProvider.apply(variableManager);
if (style instanceof ImageNodeStyle) {
result = NodeType.NODE_IMAGE;
} else if (style instanceof ListItemNodeStyle) {
result = NodeType.NODE_LIST_ITEM;
} else if (style instanceof ListNodeStyle) {
result = NodeType.NODE_LIST;
}
return result;
};
AbstractNodeMappingSizeProvider sizeProvider = new AbstractNodeMappingSizeProvider(interpreter, abstractNodeMapping);
String domainClass = abstractNodeMapping.getDomainClass();
String semanticCandidatesExpression = abstractNodeMapping.getSemanticCandidatesExpression();
String preconditionExpression = abstractNodeMapping.getPreconditionExpression();
Function<VariableManager, List<?>> semanticElementsProvider = this.semanticCandidatesProviderFactory.getSemanticCandidatesProvider(interpreter, domainClass, semanticCandidatesExpression, preconditionExpression);
List<NodeDescription> childNodeDescriptions = this.getChildNodeDescriptions(abstractNodeMapping, interpreter, id2NodeDescriptions);
// @formatter:off
List<NodeDescription> borderNodeDescriptions = abstractNodeMapping.getBorderedNodeMappings().stream().map(borderNodeMapping -> this.convert(borderNodeMapping, interpreter, id2NodeDescriptions)).collect(Collectors.toList());
// @formatter:on
ToolConverter toolConverter = new ToolConverter(interpreter, this.editService, this.modelOperationHandlerSwitchProvider);
var deleteHandler = toolConverter.createDeleteToolHandler(abstractNodeMapping.getDeletionDescription());
var labelEditHandler = toolConverter.createDirectEditToolHandler(abstractNodeMapping.getLabelDirectEdit());
SynchronizationPolicy synchronizationPolicy = SynchronizationPolicy.SYNCHRONIZED;
if (!abstractNodeMapping.isCreateElements()) {
synchronizationPolicy = SynchronizationPolicy.UNSYNCHRONIZED;
}
// @formatter:off
NodeDescription description = NodeDescription.newNodeDescription(UUID.fromString(this.identifierProvider.getIdentifier(abstractNodeMapping))).typeProvider(typeProvider).targetObjectIdProvider(semanticTargetIdProvider).targetObjectKindProvider(semanticTargetKindProvider).targetObjectLabelProvider(semanticTargetLabelProvider).semanticElementsProvider(semanticElementsProvider).synchronizationPolicy(synchronizationPolicy).labelDescription(labelDescription).styleProvider(styleProvider).sizeProvider(sizeProvider).borderNodeDescriptions(borderNodeDescriptions).childNodeDescriptions(childNodeDescriptions).labelEditHandler(labelEditHandler).deleteHandler(deleteHandler).build();
// @formatter:on
id2NodeDescriptions.put(description.getId(), description);
return description;
}
use of org.eclipse.sirius.components.diagrams.description.NodeDescription in project sirius-components by eclipse-sirius.
the class ViewToolSectionsProvider method createExtraToolSections.
private List<ToolSection> createExtraToolSections(Object diagramElementDescription) {
List<ToolSection> extraToolSections = new ArrayList<>();
List<NodeDescription> targetDescriptions = new ArrayList<>();
boolean unsynchronizedMapping = false;
// @formatter:off
if (diagramElementDescription instanceof NodeDescription) {
targetDescriptions.add((NodeDescription) diagramElementDescription);
unsynchronizedMapping = SynchronizationPolicy.UNSYNCHRONIZED.equals(((NodeDescription) diagramElementDescription).getSynchronizationPolicy());
} else if (diagramElementDescription instanceof EdgeDescription) {
EdgeDescription edgeDescription = (EdgeDescription) diagramElementDescription;
targetDescriptions.addAll(edgeDescription.getSourceNodeDescriptions());
unsynchronizedMapping = SynchronizationPolicy.UNSYNCHRONIZED.equals(((EdgeDescription) diagramElementDescription).getSynchronizationPolicy());
}
Function<VariableManager, IStatus> fakeHandler = variableManager -> new Success();
// Graphical Delete Tool for unsynchronized mapping only (the handler is never called)
if (diagramElementDescription instanceof NodeDescription || diagramElementDescription instanceof EdgeDescription) {
// Edit Tool (the handler is never called)
SingleClickOnDiagramElementTool editTool = // $NON-NLS-1$
SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool("edit").label(// $NON-NLS-1$
"Edit").imageURL(DiagramImageConstants.EDIT_SVG).targetDescriptions(targetDescriptions).handler(fakeHandler).appliesToDiagramRoot(false).build();
var editToolSection = // $NON-NLS-1$
ToolSection.newToolSection("edit-section").label(// $NON-NLS-1$
"").imageURL(// $NON-NLS-1$
"").tools(List.of(editTool)).build();
extraToolSections.add(editToolSection);
if (unsynchronizedMapping) {
SingleClickOnDiagramElementTool graphicalDeleteTool = // $NON-NLS-1$
SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool("graphical-delete").label(// $NON-NLS-1$
"Delete from diagram").imageURL(DiagramImageConstants.GRAPHICAL_DELETE_SVG).targetDescriptions(targetDescriptions).handler(fakeHandler).appliesToDiagramRoot(false).build();
var graphicalDeleteToolSection = // $NON-NLS-1$
ToolSection.newToolSection("graphical-delete-section").label(// $NON-NLS-1$
"").imageURL(// $NON-NLS-1$
"").tools(List.of(graphicalDeleteTool)).build();
extraToolSections.add(graphicalDeleteToolSection);
}
// Semantic Delete Tool (the handler is never called)
SingleClickOnDiagramElementTool semanticDeleteTool = // $NON-NLS-1$
SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool("semantic-delete").label(// $NON-NLS-1$
"Delete from model").imageURL(DiagramImageConstants.SEMANTIC_DELETE_SVG).targetDescriptions(targetDescriptions).handler(fakeHandler).appliesToDiagramRoot(false).build();
var semanticDeleteToolSection = // $NON-NLS-1$
ToolSection.newToolSection("semantic-delete-section").label(// $NON-NLS-1$
"").imageURL(// $NON-NLS-1$
"").tools(List.of(semanticDeleteTool)).build();
extraToolSections.add(semanticDeleteToolSection);
}
return extraToolSections;
// @formatter:on
}
use of org.eclipse.sirius.components.diagrams.description.NodeDescription in project sirius-components by eclipse-sirius.
the class ViewToolSectionsProvider method getNodeToolSections.
private List<ToolSection> getNodeToolSections(DiagramDescription diagramDescription, NodeDescription nodeDescription) {
List<ToolSection> toolSections = new ArrayList<>();
for (ToolSection toolSection : diagramDescription.getToolSections()) {
List<ITool> tools = toolSection.getTools().stream().filter(tool -> this.isValidTool(tool, nodeDescription)).collect(Collectors.toList());
if (!tools.isEmpty()) {
ToolSection filteredToolSection = ToolSection.newToolSection(toolSection).tools(tools).build();
toolSections.add(filteredToolSection);
}
}
return toolSections;
}
use of org.eclipse.sirius.components.diagrams.description.NodeDescription in project sirius-components by eclipse-sirius.
the class EdgeMappingConverterTests method testEdgeFromNodeToContainer.
/**
* Non-regression test for the create edges issue. This test will ensure that a container description can be used as
* a valid target for an edge.
*/
@Test
public void testEdgeFromNodeToContainer() {
EdgeMapping edgeMapping = DescriptionFactory.eINSTANCE.createEdgeMapping();
NodeMapping nodeMapping = DescriptionFactory.eINSTANCE.createNodeMapping();
// $NON-NLS-1$
nodeMapping.setName("nodeMapping");
ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
// $NON-NLS-1$
containerMapping.setName("containerMapping");
edgeMapping.getSourceMapping().add(nodeMapping);
edgeMapping.getTargetMapping().add(containerMapping);
// @formatter:off
UUID nodeMappingUUID = UUID.nameUUIDFromBytes(nodeMapping.getName().getBytes());
UUID containerMappingUUID = UUID.nameUUIDFromBytes(containerMapping.getName().getBytes());
Map<UUID, NodeDescription> id2NodeDescriptions = Map.of(nodeMappingUUID, this.createNodeDescription(nodeMappingUUID), containerMappingUUID, this.createNodeDescription(containerMappingUUID));
// @formatter:on
IObjectService objectService = new IObjectService.NoOp();
IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp();
IIdentifierProvider identifierProvider = new IIdentifierProvider.NoOp() {
@Override
public String getIdentifier(Object element) {
return containerMappingUUID.toString();
}
};
ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = SemanticCandidatesProvider::new;
IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpeter -> new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, List.of(), interpeter);
EdgeMappingConverter edgeMappingConverter = new EdgeMappingConverter(new IObjectService.NoOp(), new IEditService.NoOp(), identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider);
EdgeDescription edgeDescription = edgeMappingConverter.convert(edgeMapping, new AQLInterpreter(List.of(), List.of()), id2NodeDescriptions);
assertThat(edgeDescription.getTargetNodeDescriptions()).contains(id2NodeDescriptions.get(containerMappingUUID));
}
use of org.eclipse.sirius.components.diagrams.description.NodeDescription in project sirius-components by eclipse-sirius.
the class EdgeMappingConverterTests method testEdgeFromContainerToContainer.
/**
* Non-regression test for the create edges issue. This test will ensure that a container description can be used as
* both a valid source and a valid target for an edge.
*/
@Test
public void testEdgeFromContainerToContainer() {
EdgeMapping edgeMapping = DescriptionFactory.eINSTANCE.createEdgeMapping();
ContainerMapping sourceContainerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
// $NON-NLS-1$
sourceContainerMapping.setName("sourceContainerMapping");
ContainerMapping targetContainerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
// $NON-NLS-1$
targetContainerMapping.setName("targetContainerMapping");
edgeMapping.getSourceMapping().add(sourceContainerMapping);
edgeMapping.getTargetMapping().add(targetContainerMapping);
// @formatter:off
UUID sourceContainerMappingUUID = UUID.nameUUIDFromBytes(sourceContainerMapping.getName().getBytes());
UUID targetContainerMappingUUID = UUID.nameUUIDFromBytes(targetContainerMapping.getName().getBytes());
Map<UUID, NodeDescription> id2NodeDescriptions = Map.of(sourceContainerMappingUUID, this.createNodeDescription(sourceContainerMappingUUID), targetContainerMappingUUID, this.createNodeDescription(targetContainerMappingUUID));
// @formatter:on
IObjectService objectService = new IObjectService.NoOp();
IRepresentationMetadataSearchService representationMetadataSearchService = new IRepresentationMetadataSearchService.NoOp();
IIdentifierProvider identifierProvider = new IIdentifierProvider() {
@Override
public String getIdentifier(Object element) {
return targetContainerMappingUUID.toString();
}
@Override
public Optional<String> findVsmElementId(UUID id) {
return Optional.empty();
}
};
ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = SemanticCandidatesProvider::new;
IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpeter -> new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, List.of(), interpeter);
EdgeMappingConverter edgeMappingConverter = new EdgeMappingConverter(objectService, new IEditService.NoOp(), identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider);
EdgeDescription edgeDescription = edgeMappingConverter.convert(edgeMapping, new AQLInterpreter(List.of(), List.of()), id2NodeDescriptions);
edgeDescription.getSourceNodeDescriptions().contains(id2NodeDescriptions.get(sourceContainerMappingUUID));
assertThat(edgeDescription.getTargetNodeDescriptions()).contains(id2NodeDescriptions.get(targetContainerMappingUUID));
}
Aggregations