]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DiagramContentRequest.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / adapter / DiagramContentRequest.java
index 9be72d29f53fabb6e8d2d906618a1fb0a2fb8f9f..0dea37763e727d2ddc7c778395b20a3690beebe1 100644 (file)
@@ -31,6 +31,8 @@ import org.simantics.diagram.content.RouteGraphConnectionPartRequest;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.diagram.synchronization.ErrorHandler;
 import org.simantics.g2d.canvas.ICanvasContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.list.array.TIntArrayList;
 import gnu.trove.map.hash.THashMap;
@@ -42,6 +44,8 @@ import gnu.trove.set.hash.THashSet;
  */
 public class DiagramContentRequest extends BaseRequest<Resource, DiagramContents> {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DiagramContentRequest.class);
+
     int previousElementCount = 32;
     ErrorHandler errorHandler;
 
@@ -58,7 +62,11 @@ public class DiagramContentRequest extends BaseRequest<Resource, DiagramContents
         // These help loading result.elements in the correct order.
         final AtomicInteger index = new AtomicInteger();
         final TIntArrayList unrecognizedElementIndices = new TIntArrayList();
-
+        
+        if (!g.hasStatement(data)) {
+            LOGGER.warn("Most likely diagram is being removed and therefore ordered list can not be found for {}", data);
+            return new DiagramContents(); // or null, I don't know
+        }
         Collection<Resource> components = OrderedSetUtils.toList(g, data);
         DiagramContents res = g.syncRequest((AsyncRead<DiagramContents>)(graph, procedure) -> {
 
@@ -83,8 +91,8 @@ public class DiagramContentRequest extends BaseRequest<Resource, DiagramContents
                 // keep their order the same as in the ordered set.
                 final int elementIndex = index.getAndIncrement();
                 result.elements.add(component);
-
-                graph.forTypes(component, new ProcedureAdapter<Set<Resource>>() {
+                
+                graph.asyncRequest(new org.simantics.db.common.primitiverequest.Types(component), new ProcedureAdapter<Set<Resource>>() {
 
                     @Override
                     public void execute(Set<Resource> types) {