package org.simantics.district.network.profile; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.profile.StyleBase; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.scenegraph.INode; import org.simantics.scenegraph.g2d.G2DSceneGraph; import org.simantics.scenegraph.g2d.nodes.SingleElementNode; import org.simantics.scenegraph.profile.EvaluationContext; import org.simantics.scenegraph.profile.common.ProfileVariables; import org.simantics.scl.runtime.function.Function; public class VertexSymbolStyle extends StyleBase { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public String calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource symbolFunctionResource = graph.getPossibleObject(entry, DN.HasSymbolFunction); if (symbolFunctionResource == null) return null; Function symbolFunction = (Function) graph.getPossibleValue2(symbolFunctionResource, null); if (symbolFunction == null) return null; return (String) symbolFunction.apply(graph, entry); } @Override public void applyStyleForNode(EvaluationContext observer, INode node, String value) { SingleElementNode n = (SingleElementNode) node; for (INode nn : n.getNodes()) ProfileVariables.claimNodeProperty(nn, "SVG", value, observer); } @Override protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) { ((G2DSceneGraph)node.getRootNode()).clearPending(node); SingleElementNode n = (SingleElementNode) node; for (INode nn : n.getNodes()) ProfileVariables.claimNodeProperty(nn, "SVG", null, evaluationContext); } }