From 1e380392820b26f4ee4712f61d4aadabe49cec88 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 9 Nov 2020 18:59:18 +0200 Subject: [PATCH] Support VirtualGraph in GraphToDiagramSynchronizer and DiagramSGProvider gitlab #640 Change-Id: I6763bb7d27a1dc430d1823fff97dba56b7ef1c91 --- .../adapter/GraphToDiagramSynchronizer.java | 7 ++++++- .../graph/ModificationProcessRequest.java | 9 ++++++++- .../synchronization/graph/ModificationQueue.java | 14 ++++++++++++-- .../modeling/ui/sg/DiagramSceneGraphProvider.java | 11 ++++++++++- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java index 37471eb3a..981047f7c 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GraphToDiagramSynchronizer.java @@ -40,6 +40,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; import org.simantics.db.Session; +import org.simantics.db.VirtualGraph; import org.simantics.db.common.ResourceArray; import org.simantics.db.common.exception.DebugException; import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter; @@ -1041,6 +1042,7 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID // Internal state machine handling END // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + /** * @param processor * @param canvas @@ -1048,6 +1050,9 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID * @throws DatabaseException */ public GraphToDiagramSynchronizer(RequestProcessor processor, ICanvasContext canvas, IElementClassProvider elementClassProvider) throws DatabaseException { + this(processor,canvas,elementClassProvider, null); + } + public GraphToDiagramSynchronizer(RequestProcessor processor, ICanvasContext canvas, IElementClassProvider elementClassProvider, VirtualGraph virtualGraph) throws DatabaseException { if (processor == null) throw new IllegalArgumentException("null processor"); if (canvas == null) @@ -1057,7 +1062,7 @@ public class GraphToDiagramSynchronizer extends AbstractDisposable implements ID this.session = processor.getSession(); this.canvas = canvas; - this.modificationQueue = new ModificationQueue(session, errorHandler); + this.modificationQueue = new ModificationQueue(session, errorHandler, virtualGraph); processor.syncRequest(new ReadRequest() { @Override diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationProcessRequest.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationProcessRequest.java index 22059cc21..fc0b8a5d2 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationProcessRequest.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationProcessRequest.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.diagram.synchronization.graph; +import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; @@ -20,7 +21,6 @@ import org.simantics.diagram.internal.timing.GTask; import org.simantics.diagram.internal.timing.Timing; import org.simantics.diagram.synchronization.ErrorHandler; import org.simantics.diagram.synchronization.IModification; -import org.simantics.utils.logging.TimeLogger; /** * A graph database write request that composes several {@link IModification} @@ -39,6 +39,13 @@ public class ModificationProcessRequest extends WriteRequest { this.errorHandler = errorHandler; this.modifications = modifications; } + + public ModificationProcessRequest(ErrorHandler errorHandler, IModification[] modifications, VirtualGraph provider) { + super(provider); + this.errorHandler = errorHandler; + this.modifications = modifications; + } + @Override public void perform(final WriteGraph g) throws DatabaseException { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationQueue.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationQueue.java index 0e74431bd..27b40c79d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationQueue.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/ModificationQueue.java @@ -15,6 +15,7 @@ import java.util.ArrayDeque; import java.util.Deque; import org.simantics.db.RequestProcessor; +import org.simantics.db.VirtualGraph; import org.simantics.diagram.internal.DebugPolicy; import org.simantics.diagram.synchronization.ErrorHandler; import org.simantics.diagram.synchronization.IModification; @@ -31,14 +32,23 @@ public class ModificationQueue implements IModificationQueue { private final RequestProcessor writebackProcessor; private final ErrorHandler errorHandler; private final Deque writebackQueue = new ArrayDeque(); - + private final VirtualGraph virtualGraph; + public ModificationQueue(RequestProcessor writebackProcessor, ErrorHandler errorHandler) { this.writebackProcessor = writebackProcessor; this.errorHandler = errorHandler; + this.virtualGraph = null; + } + + public ModificationQueue(RequestProcessor writebackProcessor, ErrorHandler errorHandler, VirtualGraph virtualGraph) { + this.writebackProcessor = writebackProcessor; + this.errorHandler = errorHandler; + this.virtualGraph = virtualGraph; } public void dispose() { } + ModificationProcessRequest createModificationRequest() { IModification[] mods = IModification.NONE; @@ -46,7 +56,7 @@ public class ModificationQueue implements IModificationQueue { mods = writebackQueue.toArray(IModification.NONE); writebackQueue.clear(); } - return new ModificationProcessRequest(errorHandler, mods); + return new ModificationProcessRequest(errorHandler, mods, virtualGraph); } void dispatchModifications() { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java index 302e074fc..e08984e7f 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/sg/DiagramSceneGraphProvider.java @@ -19,6 +19,7 @@ import org.simantics.Simantics; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.VirtualGraph; import org.simantics.db.common.ResourceArray; import org.simantics.db.common.primitiverequest.PossibleAdapter; import org.simantics.db.exception.DatabaseException; @@ -28,6 +29,7 @@ import org.simantics.db.exception.ServiceException; import org.simantics.db.management.ISessionContext; import org.simantics.db.procedure.Listener; import org.simantics.db.request.Read; +import org.simantics.db.service.VirtualGraphSupport; import org.simantics.diagram.adapter.DefaultConnectionClassFactory; import org.simantics.diagram.adapter.FlagClassFactory; import org.simantics.diagram.adapter.GraphToDiagramSynchronizer; @@ -379,6 +381,7 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi fillInitialDiagramHints(initialHints); final RuntimeDiagramManager runtimeDiagramManager = RuntimeDiagramManager.create(Simantics.getSession(), resource, modelURI, RVI); + VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class); synchronizer = Simantics.getSession().syncRequest(new Read() { @Override @@ -388,7 +391,13 @@ public class DiagramSceneGraphProvider implements ICanvasSceneGraphProvider, IDi if(val != null && navigation == null) { // Set only if navigation has not been set manually navigation = val; } - GraphToDiagramSynchronizer sync = new GraphToDiagramSynchronizer(graph, ctx,createElementClassProvider(graph)); + VirtualGraph virtualGraph = support.getGraph(graph, resource); + GraphToDiagramSynchronizer sync; + if (virtualGraph != null) { + sync = new GraphToDiagramSynchronizer(graph, ctx,createElementClassProvider(graph), virtualGraph); + } else { + sync = new GraphToDiagramSynchronizer(graph, ctx,createElementClassProvider(graph)); + } sync.set(ModelingSynchronizationHints.MODELING_RESOURCE, ModelingResources.getInstance(graph)); diagram = sync.loadDiagram(new NullProgressMonitor(), graph, null, resource, runtimeDiagramManager.getRuntimeDiagram(), structuralPath, initialHints); // FIXME -- 2.47.1