Search in sources :

Example 1 with FlatContainerStyleDescription

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

the class ContainerMappingStyleProviderTests method createFlatStyle.

private FlatContainerStyleDescription createFlatStyle(int red, int green, int blue) {
    FlatContainerStyleDescription containerStyleDescription = StyleFactory.eINSTANCE.createFlatContainerStyleDescription();
    FixedColor fixedColor = org.eclipse.sirius.viewpoint.description.DescriptionFactory.eINSTANCE.createFixedColor();
    fixedColor.setRed(red);
    fixedColor.setGreen(green);
    fixedColor.setBlue(blue);
    containerStyleDescription.setBorderColor(fixedColor);
    return containerStyleDescription;
}
Also used : FlatContainerStyleDescription(org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription) FixedColor(org.eclipse.sirius.viewpoint.description.FixedColor)

Example 2 with FlatContainerStyleDescription

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

the class ContainerMappingSizeProviderTests method createFlatStyle.

private FlatContainerStyleDescription createFlatStyle(int red, int green, int blue) {
    FlatContainerStyleDescription containerStyleDescription = StyleFactory.eINSTANCE.createFlatContainerStyleDescription();
    FixedColor fixedColor = org.eclipse.sirius.viewpoint.description.DescriptionFactory.eINSTANCE.createFixedColor();
    fixedColor.setRed(red);
    fixedColor.setGreen(green);
    fixedColor.setBlue(blue);
    containerStyleDescription.setBorderColor(fixedColor);
    return containerStyleDescription;
}
Also used : FlatContainerStyleDescription(org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription) FixedColor(org.eclipse.sirius.viewpoint.description.FixedColor)

Example 3 with FlatContainerStyleDescription

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

the class ContainerMappingSizeProviderTests method testSizeProviderWithProvidedSizeFromVSM.

@Test
public void testSizeProviderWithProvidedSizeFromVSM() {
    ContainerMapping containerMapping = DescriptionFactory.eINSTANCE.createContainerMapping();
    FlatContainerStyleDescription flatStyle = this.createFlatStyle(0, 0, 0);
    flatStyle.setHeightComputationExpression(AQL_10);
    flatStyle.setWidthComputationExpression(AQL_20);
    containerMapping.setStyle(flatStyle);
    VariableManager variableManager = new VariableManager();
    AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
    var abstractNodeMappingSizeProvider = new AbstractNodeMappingSizeProvider(interpreter, containerMapping);
    Size size = abstractNodeMappingSizeProvider.apply(variableManager);
    assertThat(size).extracting(Size::getHeight).isEqualTo(100.0);
    assertThat(size).extracting(Size::getWidth).isEqualTo(200.0);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Size(org.eclipse.sirius.components.diagrams.Size) FlatContainerStyleDescription(org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) Test(org.junit.jupiter.api.Test)

Example 4 with FlatContainerStyleDescription

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

the class AbstractNodeMappingSizeProvider method apply.

@Override
public Size apply(VariableManager variableManager) {
    LabelStyleDescription labelStyleDescription = new LabelStyleDescriptionProvider(this.interpreter, this.abstractNodeMapping).apply(variableManager);
    Size size = Size.UNDEFINED;
    if (labelStyleDescription instanceof SquareDescription) {
        SquareDescription squareDescription = (SquareDescription) labelStyleDescription;
        int width = squareDescription.getWidth() * SIZE_FACTOR;
        int height = squareDescription.getHeight() * SIZE_FACTOR;
        // expression to set the width and/or height
        if (width == 0 || height == 0) {
            Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), squareDescription.getSizeComputationExpression());
            int computedSize = result.asInt().getAsInt() * SIZE_FACTOR;
            if (computedSize > 0) {
                if (width == 0) {
                    width = computedSize;
                }
                if (height == 0) {
                    height = computedSize;
                }
            }
        }
        size = Size.of(width, height);
    } else if (labelStyleDescription instanceof FlatContainerStyleDescription) {
        int width = -1;
        int height = -1;
        FlatContainerStyleDescription flatContainerStyleDescription = (FlatContainerStyleDescription) labelStyleDescription;
        Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), flatContainerStyleDescription.getWidthComputationExpression());
        int computedWidth = result.asInt().getAsInt();
        if (computedWidth > 0) {
            width = computedWidth * SIZE_FACTOR;
        }
        result = this.interpreter.evaluateExpression(variableManager.getVariables(), flatContainerStyleDescription.getHeightComputationExpression());
        int computedHeight = result.asInt().getAsInt();
        if (computedHeight > 0) {
            height = computedHeight * SIZE_FACTOR;
        }
        size = Size.of(width, height);
    } else if (labelStyleDescription instanceof DotDescription) {
        int width = -1;
        int height = -1;
        DotDescription dotDescription = (DotDescription) labelStyleDescription;
        Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), dotDescription.getSizeComputationExpression());
        int computedSize = result.asInt().getAsInt();
        if (computedSize > 0) {
            width = computedSize * SIZE_FACTOR;
            height = computedSize * SIZE_FACTOR;
        }
        size = Size.of(width, height);
    }
    return size;
}
Also used : DotDescription(org.eclipse.sirius.diagram.description.style.DotDescription) Size(org.eclipse.sirius.components.diagrams.Size) SquareDescription(org.eclipse.sirius.diagram.description.style.SquareDescription) FlatContainerStyleDescription(org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription) LabelStyleDescription(org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription) Result(org.eclipse.sirius.components.interpreter.Result)

Example 5 with FlatContainerStyleDescription

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

the class AbstractNodeMappingStyleProvider method getNodeStyle.

private INodeStyle getNodeStyle(VariableManager variableManager, LabelStyleDescription nodeStyleDescription) {
    INodeStyle style = null;
    if (this.shouldBeConsideredAsListItemNodeStyle(variableManager, nodeStyleDescription)) {
        style = this.createListItemNodeStyle(variableManager, nodeStyleDescription);
    } else if (nodeStyleDescription instanceof SquareDescription) {
        SquareDescription squareDescription = (SquareDescription) nodeStyleDescription;
        style = this.createRectangularNodeStyle(variableManager, squareDescription);
    } else if (nodeStyleDescription instanceof DotDescription) {
        DotDescription dotDescription = (DotDescription) nodeStyleDescription;
        style = this.createRectangularNodeStyle(variableManager, dotDescription);
    } else if (nodeStyleDescription instanceof FlatContainerStyleDescription) {
        FlatContainerStyleDescription flatContainerStyleDescription = (FlatContainerStyleDescription) nodeStyleDescription;
        if (this.abstractNodeMapping instanceof ContainerMapping && new ContainerMappingQuery((ContainerMapping) this.abstractNodeMapping).isListContainer()) {
            style = this.createListNodeStyle(variableManager, flatContainerStyleDescription);
        } else {
            style = this.createRectangularNodeStyle(variableManager, flatContainerStyleDescription);
        }
    } else if (nodeStyleDescription instanceof WorkspaceImageDescription) {
        WorkspaceImageDescription workspaceImageDescription = (WorkspaceImageDescription) nodeStyleDescription;
        WorkspaceImageDescriptionConverter workspaceImageDescriptionConverter = new WorkspaceImageDescriptionConverter(this.interpreter, variableManager, workspaceImageDescription);
        style = workspaceImageDescriptionConverter.convert();
    } else {
        // Fallback on Rectangular node style for now, until other styles are supported
        // @formatter:off
        style = RectangularNodeStyle.newRectangularNodeStyle().color(// $NON-NLS-1$
        "rgb(200, 200, 200)").borderColor(// $NON-NLS-1$
        "rgb(0, 0, 0)").borderSize(1).borderStyle(LineStyle.Solid).build();
    // @formatter:on
    }
    return style;
}
Also used : DotDescription(org.eclipse.sirius.diagram.description.style.DotDescription) INodeStyle(org.eclipse.sirius.components.diagrams.INodeStyle) WorkspaceImageDescription(org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription) SquareDescription(org.eclipse.sirius.diagram.description.style.SquareDescription) FlatContainerStyleDescription(org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) ContainerMappingQuery(org.eclipse.sirius.diagram.business.api.query.ContainerMappingQuery)

Aggregations

FlatContainerStyleDescription (org.eclipse.sirius.diagram.description.style.FlatContainerStyleDescription)5 Size (org.eclipse.sirius.components.diagrams.Size)2 ContainerMapping (org.eclipse.sirius.diagram.description.ContainerMapping)2 DotDescription (org.eclipse.sirius.diagram.description.style.DotDescription)2 SquareDescription (org.eclipse.sirius.diagram.description.style.SquareDescription)2 FixedColor (org.eclipse.sirius.viewpoint.description.FixedColor)2 INodeStyle (org.eclipse.sirius.components.diagrams.INodeStyle)1 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)1 Result (org.eclipse.sirius.components.interpreter.Result)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1 ContainerMappingQuery (org.eclipse.sirius.diagram.business.api.query.ContainerMappingQuery)1 WorkspaceImageDescription (org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription)1 LabelStyleDescription (org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription)1 Test (org.junit.jupiter.api.Test)1