Search in sources :

Example 1 with ContainerStyleDescription

use of org.eclipse.sirius.diagram.description.style.ContainerStyleDescription in project sirius-components by eclipse-sirius.

the class ContainerMappingStyleProviderTests method testBorderLineStyleConversion.

@Test
public void testBorderLineStyleConversion() {
    // @formatter:off
    var conversions = Map.of(LineStyle.DASH_DOT_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dash_Dot, LineStyle.DASH_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dash, LineStyle.DOT_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Dot, LineStyle.SOLID_LITERAL, org.eclipse.sirius.components.diagrams.LineStyle.Solid);
    for (var entry : conversions.entrySet()) {
        ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
        ContainerStyleDescription style = this.createFlatStyle(0, 0, 0);
        style.setBorderLineStyle(entry.getKey());
        containerMapping.setStyle(style);
        VariableManager variableManager = new VariableManager();
        AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
        INodeStyle nodeStyle = new AbstractNodeMappingStyleProvider(interpreter, containerMapping).apply(variableManager);
        assertThat(nodeStyle).isInstanceOf(RectangularNodeStyle.class);
        RectangularNodeStyle rectangularNodeStyle = (RectangularNodeStyle) nodeStyle;
        assertThat(rectangularNodeStyle.getBorderStyle()).isEqualTo(entry.getValue());
    }
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) FlatContainerStyleDescription(org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription) ContainerStyleDescription(org.eclipse.sirius.diagram.description.style.ContainerStyleDescription) ConditionalContainerStyleDescription(org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription) Test(org.junit.jupiter.api.Test)

Example 2 with ContainerStyleDescription

use of org.eclipse.sirius.diagram.description.style.ContainerStyleDescription in project sirius-components by eclipse-sirius.

the class MappingConverterTests method testContainerWithImageSubNode.

/**
 * Test that nodes inside a list are always typed as list items with a matching style, regardless of their "native"
 * style.
 */
@Test
public void testContainerWithImageSubNode() {
    ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
    // $NON-NLS-1$
    containerMapping.setName("EClass");
    // $NON-NLS-1$
    containerMapping.setDomainClass("ecore::EClass");
    // $NON-NLS-1$
    containerMapping.setSemanticCandidatesExpression("aql:self.eClassifiers");
    containerMapping.setChildrenPresentation(ContainerLayout.LIST);
    ContainerStyleDescription containerStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription();
    // $NON-NLS-1$
    containerStyle.setLabelExpression("aql:self.name");
    containerMapping.setStyle(containerStyle);
    NodeMapping itemMapping = DescriptionFactory.eINSTANCE.createNodeMapping();
    // $NON-NLS-1$
    itemMapping.setDomainClass("ecore::EAttribute");
    // $NON-NLS-1$
    itemMapping.setSemanticCandidatesExpression("aql:self.eStructuralFeatures");
    WorkspaceImageDescription imageStyle = StyleFactory.eINSTANCE.createWorkspaceImageDescription();
    // $NON-NLS-1$
    imageStyle.setLabelExpression("aql:self.name");
    // $NON-NLS-1$
    imageStyle.setWorkspacePath("path/to/image.svg");
    itemMapping.setStyle(imageStyle);
    containerMapping.getSubNodeMappings().add(itemMapping);
    IIdentifierProvider identifierProvider = new IIdentifierProvider() {

        @Override
        public String getIdentifier(Object element) {
            return UUID.randomUUID().toString();
        }

        @Override
        public Optional<String> findVsmElementId(UUID id) {
            return Optional.empty();
        }
    };
    ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = (interpreter, domainClass, semanticCandidatesExpression, preconditionExpression) -> variableManager -> List.of();
    IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpreter -> modelOperation -> Optional.empty();
    AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
    var converter = new AbstractNodeMappingConverter(new IObjectService.NoOp(), new IEditService.NoOp(), identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider);
    NodeDescription convertedNodeDescription = converter.convert(containerMapping, interpreter, new HashMap<UUID, NodeDescription>());
    VariableManager variableManager = new VariableManager();
    variableManager.put(VariableManager.SELF, EcorePackage.Literals.ECLASS);
    assertThat(convertedNodeDescription.getTypeProvider().apply(variableManager)).isEqualTo(NodeType.NODE_LIST);
    assertThat(convertedNodeDescription.getStyleProvider().apply(variableManager)).isInstanceOf(ListNodeStyle.class);
    assertThat(convertedNodeDescription.getChildNodeDescriptions()).hasSize(1);
    NodeDescription subNodeDescription = convertedNodeDescription.getChildNodeDescriptions().get(0);
    variableManager.put(VariableManager.SELF, EcorePackage.Literals.ECLASS__ABSTRACT);
    assertThat(subNodeDescription.getTypeProvider().apply(variableManager)).isEqualTo(NodeType.NODE_LIST_ITEM);
    assertThat(subNodeDescription.getStyleProvider().apply(variableManager)).isInstanceOf(ListItemNodeStyle.class);
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) EcorePackage(org.eclipse.emf.ecore.EcorePackage) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ContainerStyleDescription(org.eclipse.sirius.diagram.description.style.ContainerStyleDescription) HashMap(java.util.HashMap) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ListNodeStyle(org.eclipse.sirius.components.diagrams.ListNodeStyle) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) ContainerLayout(org.eclipse.sirius.diagram.ContainerLayout) NodeStyleDescription(org.eclipse.sirius.diagram.description.style.NodeStyleDescription) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) FixedColor(org.eclipse.sirius.viewpoint.description.FixedColor) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) IEditService(org.eclipse.sirius.components.core.api.IEditService) WorkspaceImageDescription(org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription) StyleFactory(org.eclipse.sirius.diagram.description.style.StyleFactory) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) ListItemNodeStyle(org.eclipse.sirius.components.diagrams.ListItemNodeStyle) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) ConditionalContainerStyleDescription(org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) DescriptionFactory(org.eclipse.sirius.diagram.description.DescriptionFactory) ConditionalNodeStyleDescription(org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription) Test(org.junit.jupiter.api.Test) List(java.util.List) NodeType(org.eclipse.sirius.components.diagrams.NodeType) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ContainerStyleDescription(org.eclipse.sirius.diagram.description.style.ContainerStyleDescription) ConditionalContainerStyleDescription(org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription) 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) WorkspaceImageDescription(org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription) 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 ContainerStyleDescription

use of org.eclipse.sirius.diagram.description.style.ContainerStyleDescription in project sirius-components by eclipse-sirius.

the class MappingConverterTests method testContainerStylePropertiesFromConditionalStyle.

@Test
public void testContainerStylePropertiesFromConditionalStyle() {
    ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
    // $NON-NLS-1$
    String mappingName = "TestMapping";
    containerMapping.setName(mappingName);
    // @formatter:off
    ContainerStyleDescription defaultStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription();
    new BasicLabelStyleDescriptionPopulator(defaultStyle).labelExpression(// $NON-NLS-1$
    "aql: defaultStyle").labelSize(10).labelColor(this.getColor(1, 1, 1));
    ContainerStyleDescription firstConditionalStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription();
    new BasicLabelStyleDescriptionPopulator(firstConditionalStyle).labelExpression(// $NON-NLS-1$
    "aql:'firstConditionalStyle'").labelSize(4).labelColor(this.getColor(3, 3, 3));
    ContainerStyleDescription secondConditionalStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription();
    new BasicLabelStyleDescriptionPopulator(secondConditionalStyle).labelExpression(// $NON-NLS-1$
    "aql:'secondConditionalStyle'").labelSize(6).bold().italic().underline().strikeThrough().labelColor(this.getColor(2, 2, 2)).iconPath(PLUGIN_ID + ICON_PATH);
    ContainerStyleDescription thirdConditionalStyle = StyleFactory.eINSTANCE.createFlatContainerStyleDescription();
    new BasicLabelStyleDescriptionPopulator(thirdConditionalStyle).labelExpression(// $NON-NLS-1$
    "aql:'thirdConditionalStyle'").labelSize(8).labelColor(this.getColor(4, 4, 4));
    // @formatter:on
    containerMapping.setStyle(defaultStyle);
    containerMapping.getConditionnalStyles().add(this.createConditionalContainerStyle(EXPRESSION_FALSE, firstConditionalStyle));
    containerMapping.getConditionnalStyles().add(this.createConditionalContainerStyle(EXPRESSION_TRUE, secondConditionalStyle));
    containerMapping.getConditionnalStyles().add(this.createConditionalContainerStyle(EXPRESSION_TRUE, thirdConditionalStyle));
    IIdentifierProvider identifierProvider = new IIdentifierProvider.NoOp() {

        @Override
        public String getIdentifier(Object element) {
            return UUID.randomUUID().toString();
        }
    };
    ISemanticCandidatesProviderFactory semanticCandidatesProviderFactory = (interpreter, domainClass, semanticCandidatesExpression, preconditionExpression) -> variableManager -> List.of();
    IModelOperationHandlerSwitchProvider modelOperationHandlerSwitchProvider = interpreter -> modelOperation -> Optional.empty();
    VariableManager variableManager = new VariableManager();
    AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
    var converter = new AbstractNodeMappingConverter(new IObjectService.NoOp(), new IEditService.NoOp(), identifierProvider, semanticCandidatesProviderFactory, modelOperationHandlerSwitchProvider);
    NodeDescription convertedNodeDescription = converter.convert(containerMapping, interpreter, new HashMap<UUID, NodeDescription>());
    LabelDescription labelDescription = convertedNodeDescription.getLabelDescription();
    String text = labelDescription.getTextProvider().apply(variableManager);
    LabelStyleDescription labelStyleDescription = labelDescription.getStyleDescriptionProvider().apply(variableManager);
    Integer fontSize = labelStyleDescription.getFontSizeProvider().apply(variableManager);
    Boolean isBold = labelStyleDescription.getBoldProvider().apply(variableManager);
    Boolean isItalic = labelStyleDescription.getItalicProvider().apply(variableManager);
    Boolean isUnderline = labelStyleDescription.getUnderlineProvider().apply(variableManager);
    Boolean isStrikeThrough = labelStyleDescription.getStrikeThroughProvider().apply(variableManager);
    String color = labelStyleDescription.getColorProvider().apply(variableManager);
    String iconURL = labelStyleDescription.getIconURLProvider().apply(variableManager);
    // $NON-NLS-1$
    assertThat(text).isEqualTo("secondConditionalStyle");
    assertThat(fontSize).isEqualTo(6);
    assertThat(isBold).isTrue();
    assertThat(isItalic).isTrue();
    assertThat(isUnderline).isTrue();
    assertThat(isStrikeThrough).isTrue();
    // $NON-NLS-1$
    assertThat(color).isEqualTo("#020202");
    assertThat(iconURL).isEqualTo(ICON_PATH);
}
Also used : LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) EcorePackage(org.eclipse.emf.ecore.EcorePackage) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ContainerStyleDescription(org.eclipse.sirius.diagram.description.style.ContainerStyleDescription) HashMap(java.util.HashMap) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ListNodeStyle(org.eclipse.sirius.components.diagrams.ListNodeStyle) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) ContainerLayout(org.eclipse.sirius.diagram.ContainerLayout) NodeStyleDescription(org.eclipse.sirius.diagram.description.style.NodeStyleDescription) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) FixedColor(org.eclipse.sirius.viewpoint.description.FixedColor) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) IEditService(org.eclipse.sirius.components.core.api.IEditService) WorkspaceImageDescription(org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription) StyleFactory(org.eclipse.sirius.diagram.description.style.StyleFactory) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) ListItemNodeStyle(org.eclipse.sirius.components.diagrams.ListItemNodeStyle) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) UUID(java.util.UUID) ConditionalContainerStyleDescription(org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) DescriptionFactory(org.eclipse.sirius.diagram.description.DescriptionFactory) ConditionalNodeStyleDescription(org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription) Test(org.junit.jupiter.api.Test) List(java.util.List) NodeType(org.eclipse.sirius.components.diagrams.NodeType) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ContainerStyleDescription(org.eclipse.sirius.diagram.description.style.ContainerStyleDescription) ConditionalContainerStyleDescription(org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) IEditService(org.eclipse.sirius.components.core.api.IEditService) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) UUID(java.util.UUID) ISemanticCandidatesProviderFactory(org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) Test(org.junit.jupiter.api.Test)

Aggregations

AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)3 VariableManager (org.eclipse.sirius.components.representations.VariableManager)3 ConditionalContainerStyleDescription (org.eclipse.sirius.diagram.description.ConditionalContainerStyleDescription)3 ContainerMapping (org.eclipse.sirius.diagram.description.ContainerMapping)3 ContainerStyleDescription (org.eclipse.sirius.diagram.description.style.ContainerStyleDescription)3 Test (org.junit.jupiter.api.Test)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 EcorePackage (org.eclipse.emf.ecore.EcorePackage)2 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)2 IModelOperationHandlerSwitchProvider (org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider)2 ISemanticCandidatesProviderFactory (org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory)2 IEditService (org.eclipse.sirius.components.core.api.IEditService)2 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)2 ListItemNodeStyle (org.eclipse.sirius.components.diagrams.ListItemNodeStyle)2 ListNodeStyle (org.eclipse.sirius.components.diagrams.ListNodeStyle)2 NodeType (org.eclipse.sirius.components.diagrams.NodeType)2