]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Wait for pending transactions when loading scene graph provider 32/1132/2
authorJussi Koskela <jussi.koskela@semantum.fi>
Fri, 20 Oct 2017 06:18:21 +0000 (09:18 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 20 Oct 2017 07:11:28 +0000 (10:11 +0300)
Prior to this asynchronously applied styling was missing from exported
diagrams.

refs #7566

Change-Id: I2fd927ef2b65831fa9fc431a7430a2df7ac8ed6d

bundles/org.simantics.diagram/src/org/simantics/diagram/elements/DiagramNodeUtil.java

index 893573d0f057841e769e73f7216b22e48b2ba923..f2cccf7749527df9c5d7a851a17040fac3f19ef5 100644 (file)
@@ -14,6 +14,7 @@ import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.request.Read;
+import org.simantics.db.service.TransactionSupport;
 import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.ui.DiagramModelHints;
@@ -146,22 +147,7 @@ public class DiagramNodeUtil {
         G2DSceneGraph sg = provider.initializeSceneGraph(new G2DSceneGraph(), modelURI, diagramRVI);
 
         NodeUtil.waitPending(cp.getCanvasContext().getThreadAccess(), sg);
-
-        return cp.getCanvasContext();
-    }
-
-    /**
-     * @deprecated this leaks ICanvasSceneGraphProvider, use
-     *             {@link #loadSceneGraphProvider(ICanvasContext, Resource, Resource, String)}
-     *             instead
-     */
-    public static ICanvasContext loadDiagram(ICanvasContext context, Resource model, Resource composite, String diagramRVI) throws DatabaseException, InterruptedException {
-        String modelURI = Simantics.getSession().syncRequest(Queries.uri(model));
-        ISceneGraphProvider provider = Simantics.getSession().syncRequest( Queries.adapt( composite, ISceneGraphProvider.class ) );
-        ICanvasSceneGraphProvider cp = (ICanvasSceneGraphProvider) provider;
-        cp.initializeSceneGraph(context, modelURI, diagramRVI);
-
-        NodeUtil.waitPending(cp.getCanvasContext().getThreadAccess(), context.getSceneGraph());
+        Simantics.getSession().getService(TransactionSupport.class).waitCompletion();
 
         return cp.getCanvasContext();
     }
@@ -173,6 +159,7 @@ public class DiagramNodeUtil {
         G2DSceneGraph sg = cp.initializeSceneGraph(new G2DSceneGraph(), modelURI, diagramRVI);
 
         NodeUtil.waitPending(cp.getCanvasContext().getThreadAccess(), sg);
+        Simantics.getSession().getService(TransactionSupport.class).waitCompletion();
 
         return cp;
     }
@@ -188,6 +175,7 @@ public class DiagramNodeUtil {
         ICanvasSceneGraphProvider cp = (ICanvasSceneGraphProvider) provider;
         cp.initializeSceneGraph(context, modelURI, diagramRVI);
         NodeUtil.waitPending(cp.getCanvasContext().getThreadAccess(), context.getSceneGraph(), timeoutMs);
+        Simantics.getSession().getService(TransactionSupport.class).waitCompletion();
         return cp;
     }
 
@@ -197,6 +185,7 @@ public class DiagramNodeUtil {
         ICanvasSceneGraphProvider cp = (ICanvasSceneGraphProvider) provider;
         cp.initializeSceneGraph(context, modelURI, diagramRVI);
         NodeUtil.waitPending(cp.getCanvasContext().getThreadAccess(), context.getSceneGraph());
+        Simantics.getSession().getService(TransactionSupport.class).waitCompletion();
         return cp;
     }