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