+
+ public static <T> T doWithICanvasSceneGraphProvider(Resource diagram, Function1<ICanvasSceneGraphProvider, T> func) throws DatabaseException {
+ return doWithICanvasSceneGraphProvider(diagram, (Function<ICanvasSceneGraphProvider, T>) provider -> func.apply(provider));
+ }
+
+ public static <T> T doWithICanvasSceneGraphProvider(Resource diagram, Function<ICanvasSceneGraphProvider, T> func) throws DatabaseException {
+ Tuple2 result = Simantics.getSession().syncRequest(new ResourceRead<Tuple2>(diagram) {
+
+ @Override
+ public Tuple2 perform(ReadGraph graph) throws DatabaseException {
+ Resource indexRoot = graph.syncRequest(new IndexRoot(resource));
+ String diagramRVI = Variables.getRVI(graph, resource);
+ return new Tuple2(indexRoot, diagramRVI);
+ }
+ });
+ ICanvasSceneGraphProvider provider = DiagramNodeUtil.loadSceneGraphProvider((Resource) result.c0, diagram, (String) result.c1);
+ try {
+ return func.apply(provider);
+ } finally {
+ provider.dispose();
+ }
+ }
+
+ public static <T> T doWithCanvasContext(Resource diagram, Function1<ICanvasContext, T> func) throws DatabaseException {
+ return doWithCanvasContext(diagram, (Function<ICanvasContext, T>) canvasContext -> func.apply(canvasContext));
+ }
+
+ public static <T> T doWithCanvasContext(Resource diagram, Function<ICanvasContext, T> func) throws DatabaseException {
+ return doWithICanvasSceneGraphProvider(diagram, (Function<ICanvasSceneGraphProvider, T>) provider -> func.apply(provider.getCanvasContext()));
+ }
+