Search in sources :

Example 1 with EdgeDescription

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
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Node(org.eclipse.sirius.components.diagrams.Node) SynchronizationPolicy(org.eclipse.sirius.components.diagrams.description.SynchronizationPolicy) Success(org.eclipse.sirius.components.representations.Success) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) IToolSectionsProvider(org.eclipse.sirius.components.collaborative.diagrams.api.IToolSectionsProvider) Objects(java.util.Objects) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IStatus(org.eclipse.sirius.components.representations.IStatus) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool) Service(org.springframework.stereotype.Service) DiagramImageConstants(org.eclipse.sirius.components.collaborative.diagrams.api.DiagramImageConstants) VariableManager(org.eclipse.sirius.components.representations.VariableManager) SingleClickOnTwoDiagramElementsTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IStatus(org.eclipse.sirius.components.representations.IStatus) ArrayList(java.util.ArrayList) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Success(org.eclipse.sirius.components.representations.Success) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection)

Example 2 with EdgeDescription

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));
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Size(org.eclipse.sirius.components.diagrams.Size) EdgeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.EdgeMappingConverter) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) Map(java.util.Map) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) IEditService(org.eclipse.sirius.components.core.api.IEditService) SemanticCandidatesProvider(org.eclipse.sirius.components.emf.compatibility.SemanticCandidatesProvider) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) Success(org.eclipse.sirius.components.representations.Success) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) DescriptionFactory(org.eclipse.sirius.diagram.description.DescriptionFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Optional(java.util.Optional) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) EdgeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.EdgeMappingConverter) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) IEditService(org.eclipse.sirius.components.core.api.IEditService) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 3 with EdgeDescription

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));
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Size(org.eclipse.sirius.components.diagrams.Size) EdgeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.EdgeMappingConverter) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) Map(java.util.Map) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) IEditService(org.eclipse.sirius.components.core.api.IEditService) SemanticCandidatesProvider(org.eclipse.sirius.components.emf.compatibility.SemanticCandidatesProvider) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) Success(org.eclipse.sirius.components.representations.Success) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) DescriptionFactory(org.eclipse.sirius.diagram.description.DescriptionFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Optional(java.util.Optional) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) EdgeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.EdgeMappingConverter) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) IEditService(org.eclipse.sirius.components.core.api.IEditService) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with EdgeDescription

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));
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) Size(org.eclipse.sirius.components.diagrams.Size) EdgeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.EdgeMappingConverter) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) Map(java.util.Map) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) IEditService(org.eclipse.sirius.components.core.api.IEditService) SemanticCandidatesProvider(org.eclipse.sirius.components.emf.compatibility.SemanticCandidatesProvider) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) Success(org.eclipse.sirius.components.representations.Success) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) DescriptionFactory(org.eclipse.sirius.diagram.description.DescriptionFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Optional(java.util.Optional) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) EdgeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.EdgeMappingConverter) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) ModelOperationHandlerSwitch(org.eclipse.sirius.components.emf.compatibility.modeloperations.ModelOperationHandlerSwitch) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) IEditService(org.eclipse.sirius.components.core.api.IEditService) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 5 with EdgeDescription

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);
        }
    }
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Environment(org.eclipse.sirius.components.core.api.Environment) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription)

Aggregations

EdgeDescription (org.eclipse.sirius.components.diagrams.description.EdgeDescription)20 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)18 List (java.util.List)15 VariableManager (org.eclipse.sirius.components.representations.VariableManager)14 UUID (java.util.UUID)13 ArrayList (java.util.ArrayList)12 Optional (java.util.Optional)12 Objects (java.util.Objects)11 LabelDescription (org.eclipse.sirius.components.diagrams.description.LabelDescription)11 Map (java.util.Map)10 Function (java.util.function.Function)10 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)10 LabelStyleDescription (org.eclipse.sirius.components.diagrams.description.LabelStyleDescription)10 Success (org.eclipse.sirius.components.representations.Success)10 Collectors (java.util.stream.Collectors)9 Diagram (org.eclipse.sirius.components.diagrams.Diagram)9 EdgeStyle (org.eclipse.sirius.components.diagrams.EdgeStyle)9 Size (org.eclipse.sirius.components.diagrams.Size)9 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)8 Edge (org.eclipse.sirius.components.diagrams.Edge)8