use of org.eclipse.sirius.components.representations.Fragment in project sirius-components by eclipse-sirius.
the class PageComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
PageDescription pageDescription = this.props.getPageDescription();
List<?> semanticElements = pageDescription.getSemanticElementsProvider().apply(variableManager);
List<Element> children = new ArrayList<>(semanticElements.size());
for (Object semanticElement : semanticElements) {
VariableManager pageVariableManager = variableManager.createChild();
pageVariableManager.put(VariableManager.SELF, semanticElement);
String id = pageDescription.getIdProvider().apply(pageVariableManager);
String label = pageDescription.getLabelProvider().apply(pageVariableManager);
// @formatter:off
List<Element> groupComponents = pageDescription.getGroupDescriptions().stream().map(groupDescription -> {
GroupComponentProps groupComponentProps = new GroupComponentProps(pageVariableManager, groupDescription);
return new Element(GroupComponent.class, groupComponentProps);
}).collect(Collectors.toList());
PageElementProps pageElementProps = PageElementProps.newPageElementProps(id).label(label).children(groupComponents).build();
Element pageElement = new Element(PageElementProps.TYPE, pageElementProps);
// @formatter:on
children.add(pageElement);
}
FragmentProps fragmentProps = new FragmentProps(children);
return new Fragment(fragmentProps);
}
use of org.eclipse.sirius.components.representations.Fragment in project sirius-components by eclipse-sirius.
the class EdgeComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
EdgeDescription edgeDescription = this.props.getEdgeDescription();
IEdgesRequestor edgesRequestor = this.props.getEdgesRequestor();
DiagramRenderingCache cache = this.props.getCache();
List<Element> children = new ArrayList<>();
// @formatter:off
boolean hasCandidates = this.hasNodeCandidates(edgeDescription.getSourceNodeDescriptions(), cache) && this.hasNodeCandidates(edgeDescription.getTargetNodeDescriptions(), cache);
if (hasCandidates) {
VariableManager semanticElementsVariableManager = new VariableManager();
variableManager.getVariables().forEach(semanticElementsVariableManager::put);
semanticElementsVariableManager.put(DiagramDescription.CACHE, cache);
List<?> semanticElements = edgeDescription.getSemanticElementsProvider().apply(semanticElementsVariableManager);
int count = 0;
for (Object semanticElement : semanticElements) {
VariableManager edgeVariableManager = variableManager.createChild();
edgeVariableManager.put(VariableManager.SELF, semanticElement);
edgeVariableManager.put(DiagramDescription.CACHE, cache);
String targetObjectId = edgeDescription.getTargetObjectIdProvider().apply(edgeVariableManager);
String targetObjectKind = edgeDescription.getTargetObjectKindProvider().apply(edgeVariableManager);
String targetObjectLabel = edgeDescription.getTargetObjectLabelProvider().apply(edgeVariableManager);
List<Element> sourceNodes = edgeDescription.getSourceNodesProvider().apply(edgeVariableManager);
if (!sourceNodes.isEmpty()) {
List<Element> targetNodes = edgeDescription.getTargetNodesProvider().apply(edgeVariableManager);
for (Element sourceNode : sourceNodes) {
for (Element targetNode : targetNodes) {
String id = this.computeEdgeId(edgeDescription, sourceNode, targetNode, count);
var optionalPreviousEdge = edgesRequestor.getById(id);
var edgeInstanceVariableManager = edgeVariableManager.createChild();
edgeInstanceVariableManager.put(EdgeDescription.SEMANTIC_EDGE_SOURCE, cache.getNodeToObject().get(sourceNode));
edgeInstanceVariableManager.put(EdgeDescription.SEMANTIC_EDGE_TARGET, cache.getNodeToObject().get(targetNode));
SynchronizationPolicy synchronizationPolicy = edgeDescription.getSynchronizationPolicy();
boolean shouldRender = synchronizationPolicy == SynchronizationPolicy.SYNCHRONIZED || (synchronizationPolicy == SynchronizationPolicy.UNSYNCHRONIZED && optionalPreviousEdge.isPresent());
if (shouldRender) {
EdgeStyle style = edgeDescription.getStyleProvider().apply(edgeInstanceVariableManager);
String sourceId = this.getId(sourceNode);
String targetId = this.getId(targetNode);
// @formatter:off
String edgeType = optionalPreviousEdge.map(Edge::getType).orElse(// $NON-NLS-1$
"edge:straight");
List<Position> routingPoints = optionalPreviousEdge.map(Edge::getRoutingPoints).orElse(List.of());
Ratio sourceAnchorRelativePosition = optionalPreviousEdge.map(Edge::getSourceAnchorRelativePosition).orElse(Ratio.UNDEFINED);
Ratio targetAnchorRelativePosition = optionalPreviousEdge.map(Edge::getTargetAnchorRelativePosition).orElse(Ratio.UNDEFINED);
List<Element> labelChildren = this.getLabelsChildren(edgeDescription, edgeInstanceVariableManager, optionalPreviousEdge, id, routingPoints);
EdgeElementProps edgeElementProps = EdgeElementProps.newEdgeElementProps(id).type(edgeType).descriptionId(edgeDescription.getId()).targetObjectId(targetObjectId).targetObjectKind(targetObjectKind).targetObjectLabel(targetObjectLabel).sourceId(sourceId).targetId(targetId).style(style).routingPoints(routingPoints).sourceAnchorRelativePosition(sourceAnchorRelativePosition).targetAnchorRelativePosition(targetAnchorRelativePosition).children(labelChildren).build();
// @formatter:on
Element edgeElement = new Element(EdgeElementProps.TYPE, edgeElementProps);
children.add(edgeElement);
count++;
}
}
}
}
}
}
FragmentProps fragmentProps = new FragmentProps(children);
return new Fragment(fragmentProps);
}
use of org.eclipse.sirius.components.representations.Fragment in project sirius-components by eclipse-sirius.
the class NodeComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
NodeDescription nodeDescription = this.props.getNodeDescription();
INodesRequestor nodesRequestor = this.props.getNodesRequestor();
DiagramRenderingCache cache = this.props.getCache();
List<Element> children = new ArrayList<>();
List<?> semanticElements = nodeDescription.getSemanticElementsProvider().apply(variableManager);
for (Object semanticElement : semanticElements) {
VariableManager nodeVariableManager = variableManager.createChild();
nodeVariableManager.put(VariableManager.SELF, semanticElement);
String targetObjectId = nodeDescription.getTargetObjectIdProvider().apply(nodeVariableManager);
var optionalPreviousNode = nodesRequestor.getByTargetObjectId(targetObjectId);
if (this.shouldRender(targetObjectId, optionalPreviousNode)) {
Element nodeElement = this.doRender(nodeVariableManager, targetObjectId, optionalPreviousNode);
children.add(nodeElement);
cache.put(nodeDescription.getId(), nodeElement);
cache.put(semanticElement, nodeElement);
}
}
FragmentProps fragmentProps = new FragmentProps(children);
return new Fragment(fragmentProps);
}
use of org.eclipse.sirius.components.representations.Fragment in project sirius-components by eclipse-sirius.
the class GroupComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
GroupDescription groupDescription = this.props.getGroupDescription();
WidgetIdCounter widgetIdCounter = new WidgetIdCounter();
List<?> semanticElements = groupDescription.getSemanticElementsProvider().apply(variableManager);
List<Element> children = new ArrayList<>(semanticElements.size());
for (Object semanticElement : semanticElements) {
VariableManager groupVariableManager = variableManager.createChild();
groupVariableManager.put(VariableManager.SELF, semanticElement);
groupVariableManager.put(WIDGET_ID_PROVIDER_COUNTER, widgetIdCounter);
String id = groupDescription.getIdProvider().apply(groupVariableManager);
String label = groupDescription.getLabelProvider().apply(groupVariableManager);
// @formatter:off
List<Element> groupChildren = new ArrayList<>();
List<AbstractControlDescription> controlDescriptions = groupDescription.getControlDescriptions();
for (AbstractControlDescription controlDescription : controlDescriptions) {
if (controlDescription instanceof AbstractWidgetDescription) {
AbstractWidgetDescription widgetDescription = (AbstractWidgetDescription) controlDescription;
WidgetComponentProps widgetComponentProps = new WidgetComponentProps(groupVariableManager, widgetDescription);
groupChildren.add(new Element(WidgetComponent.class, widgetComponentProps));
} else if (controlDescription instanceof ForDescription) {
ForDescription forDescription = (ForDescription) controlDescription;
ForComponentProps forComponentProps = new ForComponentProps(groupVariableManager, forDescription);
groupChildren.add(new Element(ForComponent.class, forComponentProps));
}
}
GroupElementProps groupElementProps = GroupElementProps.newGroupElementProps(id).label(label).children(groupChildren).build();
Element groupElement = new Element(GroupElementProps.TYPE, groupElementProps);
// @formatter:on
children.add(groupElement);
}
FragmentProps fragmentProps = new FragmentProps(children);
return new Fragment(fragmentProps);
}
use of org.eclipse.sirius.components.representations.Fragment in project sirius-components by eclipse-sirius.
the class ForComponent method render.
@Override
public Element render() {
VariableManager variableManager = this.props.getVariableManager();
ForDescription forDescription = this.props.getForDescription();
// @formatter:off
List<?> objects = forDescription.getIterableProvider().apply(variableManager);
List<Element> children = new ArrayList<>(objects.size());
for (Object object : objects) {
VariableManager childVariableManager = variableManager.createChild();
childVariableManager.put(forDescription.getIterator(), object);
List<Element> forChildren = new ArrayList<>();
List<IfDescription> ifDescriptions = forDescription.getIfDescriptions();
for (IfDescription ifDescription : ifDescriptions) {
IfComponentProps ifComponentProps = new IfComponentProps(childVariableManager, ifDescription);
forChildren.add(new Element(IfComponent.class, ifComponentProps));
}
FragmentProps fragmentProps = new FragmentProps(forChildren);
children.add(new Fragment(fragmentProps));
}
// @formatter:on
FragmentProps fragmentProps = new FragmentProps(children);
return new Fragment(fragmentProps);
}
Aggregations