Search in sources :

Example 1 with WorkspaceImageDescription

use of org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription 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 2 with WorkspaceImageDescription

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

the class WorkspaceImageDescriptionConverterTests method testBasicScalingFactorExp10.

/**
 * Test the value of the scalingFactor according to the following sizeComputationExpression.
 *
 * <pre>
 * aql:10
 * </pre>
 *
 * Expected <strong>10</strong>
 */
@Test
public void testBasicScalingFactorExp10() {
    int expectedSize = 10;
    AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
    VariableManager variableManager = new VariableManager();
    WorkspaceImageDescription workspaceImageDescription = StyleFactory.eINSTANCE.createWorkspaceImageDescription();
    workspaceImageDescription.setWorkspacePath(WORKSPACE_IMAGE_PATH);
    // $NON-NLS-1$
    workspaceImageDescription.setSizeComputationExpression("aql:" + expectedSize);
    ImageNodeStyle imageNodeStyle = new WorkspaceImageDescriptionConverter(interpreter, variableManager, workspaceImageDescription).convert();
    assertThat(imageNodeStyle.getScalingFactor()).isEqualTo(expectedSize);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) WorkspaceImageDescription(org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription) Test(org.junit.jupiter.api.Test)

Example 3 with WorkspaceImageDescription

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

the class WorkspaceImageDescriptionConverterTests method testDefaultScalingFactor.

/**
 * Test the default value of the scalingFactor according to an unset sizeComputationExpression. <br/>
 * <br/>
 * Expected <strong>3</strong>
 *
 * @see org.eclipse.sirius.diagram.description.style.impl.NodeStyleDescriptionImpl.SIZE_COMPUTATION_EXPRESSION_EDEFAULT
 */
@Test
public void testDefaultScalingFactor() {
    int defaultSizeComputation = 3;
    AQLInterpreter interpreter = new AQLInterpreter(List.of(), List.of(EcorePackage.eINSTANCE));
    VariableManager variableManager = new VariableManager();
    WorkspaceImageDescription workspaceImageDescription = StyleFactory.eINSTANCE.createWorkspaceImageDescription();
    workspaceImageDescription.setWorkspacePath(WORKSPACE_IMAGE_PATH);
    ImageNodeStyle imageNodeStyle = new WorkspaceImageDescriptionConverter(interpreter, variableManager, workspaceImageDescription).convert();
    assertThat(imageNodeStyle.getScalingFactor()).isEqualTo(defaultSizeComputation);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ImageNodeStyle(org.eclipse.sirius.components.diagrams.ImageNodeStyle) WorkspaceImageDescription(org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription) Test(org.junit.jupiter.api.Test)

Example 4 with WorkspaceImageDescription

use of org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription 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

WorkspaceImageDescription (org.eclipse.sirius.diagram.description.style.WorkspaceImageDescription)4 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)3 VariableManager (org.eclipse.sirius.components.representations.VariableManager)3 Test (org.junit.jupiter.api.Test)3 ImageNodeStyle (org.eclipse.sirius.components.diagrams.ImageNodeStyle)2 ContainerMapping (org.eclipse.sirius.diagram.description.ContainerMapping)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 ListNodeStyle (org.eclipse.sirius.components.diagrams.ListNodeStyle)1