use of org.eclipse.elk.graph.properties.MapPropertyHolder in project sirius-components by eclipse-sirius.
the class SiriusWebLayoutConfigurator method overrideWith.
private SiriusWebLayoutConfigurator overrideWith(SiriusWebLayoutConfigurator layoutConfigurator) {
super.overrideWith(layoutConfigurator);
for (Map.Entry<String, MapPropertyHolder> entry : layoutConfigurator.idIndex.entrySet()) {
MapPropertyHolder thisHolder = this.idIndex.get(entry.getKey());
if (thisHolder == null) {
thisHolder = new MapPropertyHolder();
this.idIndex.put(entry.getKey(), thisHolder);
}
thisHolder.copyProperties(entry.getValue());
}
for (Map.Entry<String, MapPropertyHolder> entry : layoutConfigurator.typeIndex.entrySet()) {
MapPropertyHolder thisHolder = this.typeIndex.get(entry.getKey());
if (thisHolder == null) {
thisHolder = new MapPropertyHolder();
this.typeIndex.put(entry.getKey(), thisHolder);
}
thisHolder.copyProperties(entry.getValue());
}
return this;
}
use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.
the class LayoutConfigurator method configure.
/**
* Add and return a property holder for the given element class. If such a property holder is
* already present, the previous instance is returned.
*
* It is possible to configure options for every graph element by using {@code KGraphElement.class}
* as argument. Such options are overridden if a more specific type is configured as well,
* for instance {@code KNode.class}.
*/
public IPropertyHolder configure(final Class<? extends ElkGraphElement> elementClass) {
MapPropertyHolder result = classOptionMap.get(elementClass);
if (result == null) {
result = new MapPropertyHolder();
classOptionMap.put(elementClass, result);
}
return result;
}
use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.
the class DotImporter method transform.
/*---------- Transformation Dot to KGraph ----------*/
/**
* Transform a Dot graph to a KNode.
*
* @param statements
* a list of Dot statements
* @param parent
* a KNode
* @param transData
* transformation data instance
* @param nodeProps
* properties that are applied to all nodes
* @param edgeProps
* properties that are applied to all edges
*/
private void transform(final List<Statement> statements, final ElkNode parent, final IDotTransformationData<GraphvizModel, ElkNode> transData, final IPropertyHolder nodeProps, final IPropertyHolder edgeProps) {
DotSwitch<Object> statementSwitch = new DotSwitch<Object>() {
public Object caseNodeStatement(final NodeStatement statement) {
transformNode(statement, parent, transData, nodeProps);
return null;
}
public Object caseEdgeStatement(final EdgeStatement statement) {
transformEdge(statement, parent, transData, edgeProps);
return null;
}
public Object caseSubgraph(final Subgraph subgraph) {
ElkNode subElkNode = parent;
if (subgraph.getName() != null && subgraph.getName().startsWith("cluster")) {
subElkNode = transformNode(subgraph.getName(), parent, transData);
if (subElkNode.getProperty(PROP_STATEMENT) != null) {
transData.log("Discarding cluster subgraph \"" + subgraph.getName() + "\" since its id is already used.");
return null;
} else {
// the subgraph inherits all settings of its parent
subElkNode.copyProperties(parent);
subElkNode.setProperty(PROP_STATEMENT, subgraph);
}
}
MapPropertyHolder subNodeProps = new MapPropertyHolder();
subNodeProps.copyProperties(nodeProps);
MapPropertyHolder subEdgeProps = new MapPropertyHolder();
subEdgeProps.copyProperties(edgeProps);
transform(subgraph.getStatements(), subElkNode, transData, subNodeProps, subEdgeProps);
return null;
}
public Object caseAttributeStatement(final AttributeStatement statement) {
switch(statement.getType()) {
case GRAPH:
for (Attribute attr : statement.getAttributes()) {
caseAttribute(attr);
}
break;
case NODE:
for (Attribute attr : statement.getAttributes()) {
transformAttribute(nodeProps, attr, transData);
}
break;
case EDGE:
for (Attribute attr : statement.getAttributes()) {
transformAttribute(edgeProps, attr, transData);
}
break;
}
return null;
}
public Object caseAttribute(final Attribute attribute) {
if (Attributes.MARGIN.equals(attribute.getName())) {
ElkPadding padding = parent.getProperty(CoreOptions.PADDING);
if (attribute.getValue().indexOf(',') >= 0) {
KVector value = new KVector();
try {
value.parse(attribute.getValue());
padding.setLeft((float) value.x);
padding.setRight((float) value.x);
padding.setTop((float) value.y);
padding.setBottom((float) value.y);
} catch (IllegalArgumentException exception) {
transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
}
} else {
try {
float value = Float.parseFloat(trimValue(attribute));
padding.setLeft(value);
padding.setRight(value);
padding.setTop(value);
padding.setBottom(value);
} catch (NumberFormatException exception) {
transData.log("Discarding attribute \"" + attribute.getName() + "\" since its value could not be parsed correctly.");
}
}
} else {
transformAttribute(parent, attribute, transData);
}
return null;
}
};
for (Statement statement : statements) {
statementSwitch.doSwitch(statement);
}
}
use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.
the class DotImporter method transform.
/**
* Transform the GraphViz model into a KGraph.
*
* @param transData
* the transformation data instance that holds the source graph and is enriched with
* the new target graphs
*/
public void transform(final IDotTransformationData<GraphvizModel, ElkNode> transData) {
for (Graph graph : transData.getSourceGraph().getGraphs()) {
ElkNode parent = ElkGraphUtil.createGraph();
Map<String, ElkNode> nodeIdMap = Maps.newHashMap();
transData.setProperty(NODE_ID_MAP, nodeIdMap);
Map<Pair<ElkNode, String>, ElkPort> portIdMap = Maps.newHashMap();
transData.setProperty(PORT_ID_MAP, portIdMap);
transform(graph.getStatements(), parent, transData, new MapPropertyHolder(), new MapPropertyHolder());
transData.getTargetGraphs().add(parent);
parent.setProperty(PROP_GRAPH, graph);
}
}
use of org.eclipse.elk.graph.properties.MapPropertyHolder in project elk by eclipse.
the class CompoundGraphPreprocessor method createExternalPortProperties.
/**
* Create suitable port properties for dummy external ports.
*
* @param graph
* the graph for which the dummy external port is created
* @return properties to apply to the dummy port
*/
private static IPropertyHolder createExternalPortProperties(final LGraph graph) {
IPropertyHolder propertyHolder = new MapPropertyHolder();
// FIXME No idea why ...
double offset = graph.getProperty(LayeredOptions.SPACING_EDGE_EDGE) / 2;
propertyHolder.setProperty(LayeredOptions.PORT_BORDER_OFFSET, offset);
return propertyHolder;
}
Aggregations