* @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);