]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/profile/VertexSizeStyle.java
Merge remote-tracking branch 'origin/master' into release/1.35.1
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / VertexSizeStyle.java
index b33cd1c0851f1b1d786e001cf0567a8a2d96def5..b59590b6e301a5e122f6c3c9175eb04a125f49e9 100644 (file)
@@ -5,37 +5,43 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.diagram.profile.StyleBase;
 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;
 
-public class VertexSizeStyle extends StyleBase<Double> {
+public class VertexSizeStyle extends ThrottledStyleBase<Double> {
 
        private static final Double PENDING = Double.NaN;
        private static final Double ONE = 1.0;
 
        @Override
-       public Double calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
+       public Double calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
                DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
                Double scaling = ONE;
-               if (ds.vertexScaleProperty.isPresent()) {
-                       scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem);
-                       if (scaling == null) {
-                               scaling = ONE;
-                       } else {
-//                             System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty);
-                               scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias;
-//                             System.out.println("RESULT: " + scaling);
+               // Prevent PendingVariableExceptions from coming through
+               boolean wasSynchronous = graph.setSynchronous(true);
+               try {
+                       if (ds.vertexScaleProperty.isPresent()) {
+                               scaling = Simantics.applySCLRead(graph, ds.vertexScaleProperty.get(), groupItem);
+                               if (scaling == null) {
+                                       scaling = ONE;
+                               } else {
+       //                              System.out.println("read vertex scaling: " + scaling + " : " + ds.vertexScaleProperty);
+                                       scaling = scaling * ds.vertexScaleGain + ds.vertexScaleBias;
+       //                              System.out.println("RESULT: " + scaling);
+                               }
                        }
+                       return scaling;
+               }
+               finally {
+                       graph.setSynchronous(wasSynchronous);
                }
-               return scaling;
        }
 
        @Override
-       public void applyStyleForNode(EvaluationContext observer, INode node, Double value) {
+       public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Double value) {
                //System.out.println("apply: " + node + " : " + value);
                SingleElementNode n = (SingleElementNode) node;
                if (value == PENDING) {