use of org.eclipse.sirius.components.representations.VariableManager in project sirius-components by eclipse-sirius.
the class AbstractNodeMappingConverter method convert.
public NodeDescription convert(AbstractNodeMapping abstractNodeMapping, AQLInterpreter interpreter, Map<UUID, NodeDescription> id2NodeDescriptions) {
LabelStyleDescriptionConverter labelStyleDescriptionConverter = new LabelStyleDescriptionConverter(interpreter, this.objectService);
Function<VariableManager, org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription> abstractNodeMappingDescriptionProvider = new LabelStyleDescriptionProvider(interpreter, abstractNodeMapping);
Function<VariableManager, String> labelIdProvider = this.getLabelIdProvider();
Function<VariableManager, String> labelExpressionProvider = this.getLabelExpressionProvider(interpreter, abstractNodeMappingDescriptionProvider);
Function<VariableManager, LabelStyleDescription> labelStyleDescriptionProvider = this.getLabelStyleDescriptionProvider(labelStyleDescriptionConverter, abstractNodeMappingDescriptionProvider);
// @formatter:off
LabelDescription labelDescription = LabelDescription.newLabelDescription(this.identifierProvider.getIdentifier(abstractNodeMapping) + LabelDescription.LABEL_SUFFIX).idProvider(labelIdProvider).textProvider(labelExpressionProvider).styleDescriptionProvider(labelStyleDescriptionProvider).build();
// @formatter:on
Function<VariableManager, String> semanticTargetIdProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null);
};
Function<VariableManager, String> semanticTargetKindProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getKind).orElse(null);
};
Function<VariableManager, String> semanticTargetLabelProvider = variableManager -> {
return variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getLabel).orElse(null);
};
Function<VariableManager, INodeStyle> styleProvider = new AbstractNodeMappingStyleProvider(interpreter, abstractNodeMapping);
Function<VariableManager, String> typeProvider = variableManager -> {
var result = NodeType.NODE_RECTANGLE;
INodeStyle style = styleProvider.apply(variableManager);
if (style instanceof ImageNodeStyle) {
result = NodeType.NODE_IMAGE;
} else if (style instanceof ListItemNodeStyle) {
result = NodeType.NODE_LIST_ITEM;
} else if (style instanceof ListNodeStyle) {
result = NodeType.NODE_LIST;
}
return result;
};
AbstractNodeMappingSizeProvider sizeProvider = new AbstractNodeMappingSizeProvider(interpreter, abstractNodeMapping);
String domainClass = abstractNodeMapping.getDomainClass();
String semanticCandidatesExpression = abstractNodeMapping.getSemanticCandidatesExpression();
String preconditionExpression = abstractNodeMapping.getPreconditionExpression();
Function<VariableManager, List<?>> semanticElementsProvider = this.semanticCandidatesProviderFactory.getSemanticCandidatesProvider(interpreter, domainClass, semanticCandidatesExpression, preconditionExpression);
List<NodeDescription> childNodeDescriptions = this.getChildNodeDescriptions(abstractNodeMapping, interpreter, id2NodeDescriptions);
// @formatter:off
List<NodeDescription> borderNodeDescriptions = abstractNodeMapping.getBorderedNodeMappings().stream().map(borderNodeMapping -> this.convert(borderNodeMapping, interpreter, id2NodeDescriptions)).collect(Collectors.toList());
// @formatter:on
ToolConverter toolConverter = new ToolConverter(interpreter, this.editService, this.modelOperationHandlerSwitchProvider);
var deleteHandler = toolConverter.createDeleteToolHandler(abstractNodeMapping.getDeletionDescription());
var labelEditHandler = toolConverter.createDirectEditToolHandler(abstractNodeMapping.getLabelDirectEdit());
SynchronizationPolicy synchronizationPolicy = SynchronizationPolicy.SYNCHRONIZED;
if (!abstractNodeMapping.isCreateElements()) {
synchronizationPolicy = SynchronizationPolicy.UNSYNCHRONIZED;
}
// @formatter:off
NodeDescription description = NodeDescription.newNodeDescription(UUID.fromString(this.identifierProvider.getIdentifier(abstractNodeMapping))).typeProvider(typeProvider).targetObjectIdProvider(semanticTargetIdProvider).targetObjectKindProvider(semanticTargetKindProvider).targetObjectLabelProvider(semanticTargetLabelProvider).semanticElementsProvider(semanticElementsProvider).synchronizationPolicy(synchronizationPolicy).labelDescription(labelDescription).styleProvider(styleProvider).sizeProvider(sizeProvider).borderNodeDescriptions(borderNodeDescriptions).childNodeDescriptions(childNodeDescriptions).labelEditHandler(labelEditHandler).deleteHandler(deleteHandler).build();
// @formatter:on
id2NodeDescriptions.put(description.getId(), description);
return description;
}
use of org.eclipse.sirius.components.representations.VariableManager in project sirius-components by eclipse-sirius.
the class DomainBasedSourceNodesProvider method apply.
@Override
public List<Element> apply(VariableManager variableManager) {
var optionalCache = variableManager.get(DiagramDescription.CACHE, DiagramRenderingCache.class);
if (optionalCache.isEmpty()) {
return List.of();
}
DiagramRenderingCache cache = optionalCache.get();
String sourceFinderExpression = this.edgeMapping.getSourceFinderExpression();
Result result = this.interpreter.evaluateExpression(variableManager.getVariables(), sourceFinderExpression);
List<Object> semanticCandidates = result.asObjects().orElse(List.of());
// @formatter:off
return semanticCandidates.stream().flatMap(semanticObject -> cache.getElementsRepresenting(semanticObject).stream()).filter(this.isFromCompatibleSourceMapping()).filter(Objects::nonNull).collect(Collectors.toList());
// @formatter:on
}
use of org.eclipse.sirius.components.representations.VariableManager in project sirius-components by eclipse-sirius.
the class EdgeMappingConverter method createLabelDescription.
private LabelDescription createLabelDescription(AQLInterpreter interpreter, LabelStyleDescriptionConverter labelStyleDescriptionConverter, BasicLabelStyleDescription siriusBasicLabelStyleDescription, String idSuffix, EdgeMapping edgeMapping) {
String labelExpression = siriusBasicLabelStyleDescription.getLabelExpression();
Function<VariableManager, LabelStyleDescription> labelStyleDescriptionProvider = variableManager -> {
return labelStyleDescriptionConverter.convert(siriusBasicLabelStyleDescription);
};
Function<VariableManager, String> labelIdProvider = variableManager -> {
Object parentId = variableManager.getVariables().get(LabelDescription.OWNER_ID);
return String.valueOf(parentId) + idSuffix;
};
String id = this.identifierProvider.getIdentifier(edgeMapping) + idSuffix;
StringValueProvider textProvider = new StringValueProvider(interpreter, labelExpression);
// @formatter:off
return LabelDescription.newLabelDescription(id).idProvider(labelIdProvider).textProvider(textProvider).styleDescriptionProvider(labelStyleDescriptionProvider).build();
// @formatter:on
}
use of org.eclipse.sirius.components.representations.VariableManager in project sirius-components by eclipse-sirius.
the class NodeStylePropertiesConfigurer method getNodeStyleProperties.
private FormDescription getNodeStyleProperties() {
// $NON-NLS-1$
UUID formDescriptionId = UUID.nameUUIDFromBytes("nodestyle".getBytes());
// @formatter:off
List<AbstractControlDescription> controls = List.of(// $NON-NLS-1$ //$NON-NLS-2$
this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.sizeExpression", // $NON-NLS-1$ //$NON-NLS-2$
"Size Expression", style -> ((NodeStyle) style).getSizeComputationExpression(), (style, newSizeExpression) -> ((NodeStyle) style).setSizeComputationExpression(newSizeExpression), ViewPackage.Literals.NODE_STYLE__SIZE_COMPUTATION_EXPRESSION), // $NON-NLS-1$ //$NON-NLS-2$
this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.labelColor", // $NON-NLS-1$ //$NON-NLS-2$
"Label Color", style -> ((NodeStyle) style).getLabelColor(), (style, newLabelColor) -> ((NodeStyle) style).setLabelColor(newLabelColor), ViewPackage.Literals.NODE_STYLE__LABEL_COLOR), // $NON-NLS-1$ //$NON-NLS-2$
this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.color", // $NON-NLS-1$ //$NON-NLS-2$
"Color", style -> ((NodeStyle) style).getColor(), (style, newColor) -> ((NodeStyle) style).setColor(newColor), ViewPackage.Literals.STYLE__COLOR), // $NON-NLS-1$ //$NON-NLS-2$
this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.borderColor", // $NON-NLS-1$ //$NON-NLS-2$
"Border Color", style -> ((NodeStyle) style).getBorderColor(), (style, newColor) -> ((NodeStyle) style).setBorderColor(newColor), ViewPackage.Literals.BORDER_STYLE__BORDER_COLOR), // $NON-NLS-1$ //$NON-NLS-2$
this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.borderRadius", // $NON-NLS-1$ //$NON-NLS-2$
"Border Radius", style -> String.valueOf(((NodeStyle) style).getBorderRadius()), (style, newBorderRadius) -> {
try {
((NodeStyle) style).setBorderRadius(Integer.parseInt(newBorderRadius));
} catch (NumberFormatException nfe) {
// Ignore.
}
}, ViewPackage.Literals.BORDER_STYLE__BORDER_RADIUS), // $NON-NLS-1$ //$NON-NLS-2$
this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.borderSize", // $NON-NLS-1$ //$NON-NLS-2$
"Border Size", style -> String.valueOf(((NodeStyle) style).getBorderSize()), (style, newBorderSize) -> {
try {
((NodeStyle) style).setBorderSize(Integer.parseInt(newBorderSize));
} catch (NumberFormatException nfe) {
// Ignore.
}
}, ViewPackage.Literals.BORDER_STYLE__BORDER_SIZE), // $NON-NLS-1$
this.createBorderLineStyleSelectionField("nodestyle.borderstyle", ViewPackage.Literals.BORDER_STYLE__BORDER_LINE_STYLE), // $NON-NLS-1$ //$NON-NLS-2$
this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.listMode", // $NON-NLS-1$ //$NON-NLS-2$
"List Mode", style -> ((NodeStyle) style).isListMode(), (style, newListMode) -> ((NodeStyle) style).setListMode(newListMode), ViewPackage.Literals.NODE_STYLE__LIST_MODE), // $NON-NLS-1$ //$NON-NLS-2$
this.createTextField(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.fontSize", // $NON-NLS-1$ //$NON-NLS-2$
"Font Size", style -> String.valueOf(((LabelStyle) style).getFontSize()), (style, newColor) -> {
try {
((LabelStyle) style).setFontSize(Integer.parseInt(newColor));
} catch (NumberFormatException nfe) {
// Ignore.
}
}, ViewPackage.Literals.LABEL_STYLE__FONT_SIZE), // $NON-NLS-1$ //$NON-NLS-2$
this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.italic", // $NON-NLS-1$ //$NON-NLS-2$
"Italic", style -> ((LabelStyle) style).isItalic(), (style, newItalic) -> ((LabelStyle) style).setItalic(newItalic), ViewPackage.Literals.LABEL_STYLE__ITALIC), // $NON-NLS-1$ //$NON-NLS-2$
this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.bold", // $NON-NLS-1$ //$NON-NLS-2$
"Bold", style -> ((LabelStyle) style).isBold(), (style, newBold) -> ((LabelStyle) style).setBold(newBold), ViewPackage.Literals.LABEL_STYLE__BOLD), // $NON-NLS-1$ //$NON-NLS-2$
this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.underline", // $NON-NLS-1$ //$NON-NLS-2$
"Underline", style -> ((LabelStyle) style).isUnderline(), (style, newUnderline) -> ((LabelStyle) style).setUnderline(newUnderline), ViewPackage.Literals.LABEL_STYLE__UNDERLINE), // $NON-NLS-1$ //$NON-NLS-2$
this.createCheckbox(// $NON-NLS-1$ //$NON-NLS-2$
"nodestyle.strikeThrough", // $NON-NLS-1$ //$NON-NLS-2$
"Strike Through", style -> ((LabelStyle) style).isStrikeThrough(), (style, newStrikeThrough) -> ((LabelStyle) style).setStrikeThrough(newStrikeThrough), ViewPackage.Literals.LABEL_STYLE__STRIKE_THROUGH), this.createShapeSelectionField(ViewPackage.Literals.NODE_STYLE__SHAPE));
GroupDescription groupDescription = this.createSimpleGroupDescription(controls);
Predicate<VariableManager> canCreatePagePredicate = variableManager -> variableManager.get(VariableManager.SELF, Object.class).filter(self -> self instanceof List<?>).map(self -> (List<?>) self).flatMap(self -> self.stream().findFirst()).filter(self -> self instanceof NodeStyle && !(self instanceof ConditionalNodeStyle)).isPresent();
return FormDescription.newFormDescription(formDescriptionId).label(// $NON-NLS-1$
"Node Style").labelProvider(variableManager -> variableManager.get(VariableManager.SELF, NodeStyle.class).map(NodeStyle::getColor).orElse(UNNAMED)).canCreatePredicate(variableManager -> true).idProvider(new GetOrCreateRandomIdProvider()).targetObjectIdProvider(this.getTargetObjectIdProvider()).pageDescriptions(List.of(this.createSimplePageDescription(groupDescription, canCreatePagePredicate))).groupDescriptions(List.of(groupDescription)).build();
// @formatter:on
}
use of org.eclipse.sirius.components.representations.VariableManager in project sirius-components by eclipse-sirius.
the class NodeStylePropertiesConfigurer method createTextField.
private TextfieldDescription createTextField(String id, String title, Function<Object, String> reader, BiConsumer<Object, String> writer, Object feature) {
Function<VariableManager, String> valueProvider = variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(reader).orElse(EMPTY);
BiFunction<VariableManager, String, IStatus> newValueHandler = (variableManager, newValue) -> {
var optionalDiagramMapping = variableManager.get(VariableManager.SELF, Object.class);
if (optionalDiagramMapping.isPresent()) {
writer.accept(optionalDiagramMapping.get(), newValue);
return new Success();
} else {
// $NON-NLS-1$
return new Failure("");
}
};
// @formatter:off
return TextfieldDescription.newTextfieldDescription(id).idProvider(variableManager -> id).labelProvider(variableManager -> title).valueProvider(valueProvider).newValueHandler(newValueHandler).diagnosticsProvider(this.getDiagnosticsProvider(feature)).kindProvider(this::kindProvider).messageProvider(this::messageProvider).build();
// @formatter:on
}
Aggregations