Search in sources :

Example 1 with NodeStyleDescription

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

the class NodeMappingStyleProviderTests 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()) {
        NodeMapping nodeMapping = DescriptionFactory.eINSTANCE.createNodeMapping();
        NodeStyleDescription style = this.createSquareStyle(0, 0, 0);
        style.setBorderLineStyle(entry.getKey());
        nodeMapping.setStyle(style);
        VariableManager variableManager = new VariableManager();
        AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
        INodeStyle nodeStyle = new AbstractNodeMappingStyleProvider(interpreter, nodeMapping).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) NodeMapping(org.eclipse.sirius.diagram.description.NodeMapping) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ConditionalNodeStyleDescription(org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription) NodeStyleDescription(org.eclipse.sirius.diagram.description.style.NodeStyleDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) RectangularNodeStyle(org.eclipse.sirius.components.diagrams.RectangularNodeStyle) Test(org.junit.jupiter.api.Test)

Example 2 with NodeStyleDescription

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

the class NodeMappingStyleProviderTests method createSquareStyle.

private NodeStyleDescription createSquareStyle(int red, int green, int blue) {
    NodeStyleDescription nodeStyleDescription = StyleFactory.eINSTANCE.createSquareDescription();
    FixedColor fixedColor = org.eclipse.sirius.viewpoint.description.DescriptionFactory.eINSTANCE.createFixedColor();
    fixedColor.setRed(red);
    fixedColor.setGreen(green);
    fixedColor.setBlue(blue);
    nodeStyleDescription.setBorderColor(fixedColor);
    return nodeStyleDescription;
}
Also used : ConditionalNodeStyleDescription(org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription) NodeStyleDescription(org.eclipse.sirius.diagram.description.style.NodeStyleDescription) FixedColor(org.eclipse.sirius.viewpoint.description.FixedColor)

Example 3 with NodeStyleDescription

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

the class MappingConverterTests method testNodeStylePropertiesFromConditionalStyle.

@Test
public void testNodeStylePropertiesFromConditionalStyle() {
    NodeMapping nodeMapping = DescriptionFactory.eINSTANCE.createNodeMapping();
    // $NON-NLS-1$
    String mappingName = "TestMapping";
    nodeMapping.setName(mappingName);
    // @formatter:off
    NodeStyleDescription defaultStyle = StyleFactory.eINSTANCE.createSquareDescription();
    new BasicLabelStyleDescriptionPopulator(defaultStyle).labelExpression(// $NON-NLS-1$
    "aql:'defaultStyle'").labelSize(10).labelColor(this.getColor(1, 1, 1));
    NodeStyleDescription firstConditionalStyle = StyleFactory.eINSTANCE.createSquareDescription();
    new BasicLabelStyleDescriptionPopulator(firstConditionalStyle).labelExpression(// $NON-NLS-1$
    "aql:'firstConditionalStyle'").labelSize(4).labelColor(this.getColor(3, 3, 3));
    NodeStyleDescription secondConditionalStyle = StyleFactory.eINSTANCE.createSquareDescription();
    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);
    NodeStyleDescription thirdConditionalStyle = StyleFactory.eINSTANCE.createSquareDescription();
    new BasicLabelStyleDescriptionPopulator(thirdConditionalStyle).labelExpression(// $NON-NLS-1$
    "aql:'thirdConditionalStyle'").labelSize(8).labelColor(this.getColor(4, 4, 4));
    // @formatter:on
    nodeMapping.setStyle(defaultStyle);
    nodeMapping.getConditionnalStyles().add(this.createConditionalNodeStyle(EXPRESSION_FALSE, firstConditionalStyle));
    nodeMapping.getConditionnalStyles().add(this.createConditionalNodeStyle(EXPRESSION_TRUE, secondConditionalStyle));
    nodeMapping.getConditionnalStyles().add(this.createConditionalNodeStyle(EXPRESSION_TRUE, thirdConditionalStyle));
    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();
    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(nodeMapping, 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) LabelStyleDescription(org.eclipse.sirius.components.diagrams.description.LabelStyleDescription) 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) LabelDescription(org.eclipse.sirius.components.diagrams.description.LabelDescription) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) NodeStyleDescription(org.eclipse.sirius.diagram.description.style.NodeStyleDescription) ConditionalNodeStyleDescription(org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

ConditionalNodeStyleDescription (org.eclipse.sirius.diagram.description.ConditionalNodeStyleDescription)3 NodeStyleDescription (org.eclipse.sirius.diagram.description.style.NodeStyleDescription)3 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)2 VariableManager (org.eclipse.sirius.components.representations.VariableManager)2 NodeMapping (org.eclipse.sirius.diagram.description.NodeMapping)2 FixedColor (org.eclipse.sirius.viewpoint.description.FixedColor)2 Test (org.junit.jupiter.api.Test)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 EcorePackage (org.eclipse.emf.ecore.EcorePackage)1 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)1 IModelOperationHandlerSwitchProvider (org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider)1 ISemanticCandidatesProviderFactory (org.eclipse.sirius.components.compatibility.api.ISemanticCandidatesProviderFactory)1 IEditService (org.eclipse.sirius.components.core.api.IEditService)1 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)1 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)1 ListItemNodeStyle (org.eclipse.sirius.components.diagrams.ListItemNodeStyle)1