use of org.eclipse.sirius.components.diagrams.description.EdgeDescription 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.EdgeDescription 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.EdgeDescription 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));
}
use of org.eclipse.sirius.components.diagrams.description.EdgeDescription in project sirius-components by eclipse-sirius.
the class EdgeMappingConverterTests method testEdgeFromContainerToNode.
/**
* Non-regression test for the create edges issue. This test will ensure that a container description can be used as
* a valid source for an edge.
*/
@Test
public void testEdgeFromContainerToNode() {
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(containerMapping);
edgeMapping.getTargetMapping().add(nodeMapping);
// @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() {
@Override
public String getIdentifier(Object element) {
return containerMappingUUID.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);
assertThat(edgeDescription.getSourceNodeDescriptions()).contains(id2NodeDescriptions.get(containerMappingUUID));
}
use of org.eclipse.sirius.components.diagrams.description.EdgeDescription in project sirius-components by eclipse-sirius.
the class EditLabelEventHandler method invokeDirectEditTool.
private void invokeDirectEditTool(Edge edge, IEditingContext editingContext, Diagram diagram, String newText) {
var optionalEdgeDescription = this.findEdgeDescription(edge, diagram, editingContext);
if (optionalEdgeDescription.isPresent()) {
EdgeDescription edgeDescription = optionalEdgeDescription.get();
var optionalSelf = this.objectService.getObject(editingContext, edge.getTargetObjectId());
if (optionalSelf.isPresent()) {
Object self = optionalSelf.get();
VariableManager variableManager = new VariableManager();
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
variableManager.put(VariableManager.SELF, self);
edgeDescription.getLabelEditHandler().apply(variableManager, newText);
// $NON-NLS-1$
this.logger.debug("Edited label of diagram element {} to {}", edge.getId(), newText);
}
}
}
Aggregations