]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementFactory.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / DefinedElementFactory.java
index 9f02393c7dd90cc30b2ec1d73757329c862b4d15..10855496becc36fce003acafba8e0cac4fb3489a 100644 (file)
@@ -20,6 +20,8 @@ import java.util.concurrent.atomic.AtomicInteger;
 import org.simantics.databoard.Bindings;
 import org.simantics.db.AsyncReadGraph;
 import org.simantics.db.Resource;
+import org.simantics.db.common.primitiverequest.PossibleAdapter;
+import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
 import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;
@@ -44,9 +46,7 @@ import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
 import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer;
 import org.simantics.g2d.element.handler.impl.StaticSymbolImpl;
-import org.simantics.g2d.element.handler.impl.Terminals;
 import org.simantics.g2d.element.handler.impl.TextImpl;
-import org.simantics.g2d.elementclass.ImageClass;
 import org.simantics.g2d.elementclass.PlainElementPropertySetter;
 import org.simantics.g2d.tooltip.TerminalTooltipProvider;
 import org.simantics.g2d.tooltip.TooltipParticipant;
@@ -259,6 +259,15 @@ public class DefinedElementFactory extends ElementFactoryAdapter {
         // This is needed for terminal tooltips.
         e.setHint(TooltipParticipant.TOOLTIP_KEY, TerminalTooltipProvider.INSTANCE);
 
+        graph.asyncRequest(new PossibleAdapter<ElementFactory>(element, ElementFactory.class), new AsyncProcedureAdapter<ElementFactory>() {
+            @Override
+            public void execute(AsyncReadGraph graph, ElementFactory factory) {
+                if (factory != null) {
+                    graph.asyncRequest(new GetElementClassRequest(factory, element, canvas, diagram));
+                }
+            }
+        });
+
         ElementFactoryUtil.readParameters(graph, element, e);
 
         GuardedAsyncProcedureWrapper<IElement> guard = new GuardedAsyncProcedureWrapper<IElement>(procedure, 1);