package elkDemo5; import org.eclipse.elk.alg.graphviz.layouter.DotOptions; import org.eclipse.elk.alg.graphviz.layouter.GraphvizMetaDataProvider; import org.eclipse.elk.core.RecursiveGraphLayoutEngine; import org.eclipse.elk.core.data.LayoutMetaDataService; import org.eclipse.elk.core.options.CoreOptions; import org.eclipse.elk.core.options.EdgeLabelPlacement; import org.eclipse.elk.core.util.BasicProgressMonitor; import org.eclipse.elk.core.util.IElkProgressMonitor; import org.eclipse.elk.graph.ElkEdge; import org.eclipse.elk.graph.ElkLabel; import org.eclipse.elk.graph.ElkNode; import org.eclipse.elk.graph.util.ElkGraphUtil; import com.google.common.collect.Iterators; import com.google.common.collect.UnmodifiableIterator; public class Main { public static void main(String[] args) { ElkNode top = ElkGraphUtil.createGraph(); top.setProperty(CoreOptions.ALGORITHM, DotOptions.ALGORITHM_ID); ElkLabel L1 = ElkGraphUtil.createLabel("Top",top); setPropertyValues(L1); ElkNode A = ElkGraphUtil.createNode(top); ElkLabel L2 = ElkGraphUtil.createLabel("A",A); setPropertyValues(L2); ElkNode B = ElkGraphUtil.createNode(top); ElkLabel L3 = ElkGraphUtil.createLabel("B",B); setPropertyValues(L3); ElkEdge E1 = ElkGraphUtil.createSimpleEdge(A, B); ElkLabel L4 = ElkGraphUtil.createLabel("A=>B",E1); setPropertyValues(L4); getAllElkNodes(top).forEachRemaining(node -> { if (!node.getChildren().isEmpty()) { node.setProperty(CoreOptions.ALGORITHM, DotOptions.ALGORITHM_ID); } }); IElkProgressMonitor progressMonitor = new BasicProgressMonitor(); LayoutMetaDataService service = LayoutMetaDataService.getInstance(); service.registerLayoutMetaDataProviders(new GraphvizMetaDataProvider()); RecursiveGraphLayoutEngine layoutEngine = new RecursiveGraphLayoutEngine(); layoutEngine.layout(top, progressMonitor); } private static UnmodifiableIterator getAllElkNodes(final ElkNode parentNode) { return Iterators.filter(parentNode.eAllContents(), ElkNode.class); } private static void setPropertyValues(ElkLabel labelIn) { labelIn.setProperty(CoreOptions.FONT_SIZE,10); labelIn.setProperty(CoreOptions.FONT_NAME,"Helvetica"); labelIn.setProperty(CoreOptions.EDGE_LABELS_PLACEMENT,EdgeLabelPlacement.HEAD); } }