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());
}
}
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);
}
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);
}
Aggregations