]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.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 / DNElementColorStyle.java
index 682c91fb1d00782b53ddae99bba9e875b1d14bcf..f8f6ba5c5760d8ddd2c1e118382dc3b35269dfa4 100644 (file)
@@ -17,30 +17,37 @@ import org.simantics.scenegraph.profile.common.ProfileVariables;
  * @author Tuukka Lehtonen
  * @since 1.35.0
  */
-public class DNElementColorStyle extends StyleBase<Color> {
+public class DNElementColorStyle extends ThrottledStyleBase<Color> {
 
        private static final boolean DEBUG = false;
 
        @Override
-       public Color calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
+       public Color calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
                DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
-               if (ds.elementColoringFunction.isPresent()) {
-                       if (DEBUG)
-                               System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): ");
-                       Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem);
-                       if (DEBUG)
-                               System.out.print(t);
-                       if (t != null) {
-                               Color result = ds.coloringGradient.get(t);
-                               //System.out.println("color(" + t + "): " + result);
-                               return result;
+               // Prevent PendingVariableExceptions from coming through
+               boolean wasSynchronous = graph.setSynchronous(true);
+               try {
+                       if (ds.elementColoringFunction.isPresent()) {
+                               if (DEBUG)
+                                       System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): ");
+                               Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem);
+                               if (DEBUG)
+                                       System.out.print(t);
+                               if (t != null) {
+                                       Color result = ds.coloringGradient.get(t);
+                                       //System.out.println("color(" + t + "): " + result);
+                                       return result;
+                               }
                        }
                }
+               finally {
+                       graph.setSynchronous(wasSynchronous);
+               }
                return null;
        }
 
        @Override
-       public void applyStyleForNode(EvaluationContext observer, INode node, Color color) {
+       public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Color color) {
                SingleElementNode n = (SingleElementNode) node;
                for (INode nn : n.getNodes())
                        ProfileVariables.claimNodeProperty(nn, "dynamicColor", color, observer);