1 package org.simantics.district.network.profile;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.exception.DatabaseException;
6 import org.simantics.diagram.profile.StyleBase;
7 import org.simantics.district.network.ontology.DistrictNetworkResource;
8 import org.simantics.scenegraph.INode;
9 import org.simantics.scenegraph.g2d.G2DSceneGraph;
10 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
11 import org.simantics.scenegraph.profile.EvaluationContext;
12 import org.simantics.scenegraph.profile.common.ProfileVariables;
13 import org.simantics.scl.runtime.function.Function;
15 public class VertexSymbolStyle extends StyleBase<String> {
17 @SuppressWarnings({ "rawtypes", "unchecked" })
19 public String calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
20 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
21 Resource symbolFunctionResource = graph.getPossibleObject(entry, DN.HasSymbolFunction);
22 if (symbolFunctionResource == null)
25 Function symbolFunction = (Function) graph.getPossibleValue2(symbolFunctionResource, null);
26 if (symbolFunction == null)
29 return (String) symbolFunction.apply(graph, entry);
33 public void applyStyleForNode(EvaluationContext observer, INode node, String value) {
34 SingleElementNode n = (SingleElementNode) node;
35 for (INode nn : n.getNodes())
36 ProfileVariables.claimNodeProperty(nn, "SVG", value, observer);
40 protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
41 ((G2DSceneGraph)node.getRootNode()).clearPending(node);
42 SingleElementNode n = (SingleElementNode) node;
43 for (INode nn : n.getNodes())
44 ProfileVariables.claimNodeProperty(nn, "SVG", null, evaluationContext);