]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
No point computing ordered set if resource does not have any statements 83/2683/2
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 25 Feb 2019 09:21:06 +0000 (11:21 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Mon, 25 Feb 2019 09:21:34 +0000 (09:21 +0000)
gitlab #263

Change-Id: I92dbe0ea64bb8d7969124c27a37614abc724a8e1

bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DiagramContentRequest.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/TypeGroup.java

index 9be72d29f53fabb6e8d2d906618a1fb0a2fb8f9f..8f5afab1ac5faee7115d3164827014c3bbd100fe 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) -> {
 
index b7b4ba2ff13bb9d9a55fec7a155bbc389bdd8883..7e4cb0e37bc7d448eb3a79fea764a4bcc6d908bf 100644 (file)
@@ -29,12 +29,16 @@ import org.simantics.db.procedure.SetListener;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.layer0.Layer0;
 import org.simantics.scenegraph.profile.Group;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Tuukka Lehtonen
  */
 public class TypeGroup implements Group {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(TypeGroup.class);
+
     private final Collection<Resource> types;
     private final String               name;
 
@@ -103,14 +107,17 @@ public class TypeGroup implements Group {
 //                for (Resource t : types)
 //                    System.out.println("\t" + NameUtils.getSafeName(graph, t, true));
 
-                Collection<Resource> elements = graph.syncRequest(new OrderedSet(realDiagram));
-                for (Resource element : elements) {
-//                    System.out.println("checking element " + NameUtils.getSafeName(graph, element, true));
-                    Collection<Resource> elementTypes = graph.getTypes(element);
-                    if (!Collections.disjoint(types, elementTypes))
-                        result.add(element);
+                if (graph.hasStatement(realDiagram)) {
+                    Collection<Resource> elements = graph.syncRequest(new OrderedSet(realDiagram));
+                    for (Resource element : elements) {
+    //                    System.out.println("checking element " + NameUtils.getSafeName(graph, element, true));
+                        Collection<Resource> elementTypes = graph.getTypes(element);
+                        if (!Collections.disjoint(types, elementTypes))
+                            result.add(element);
+                    }
+                } else {
+                    LOGGER.warn("Most likely after deleting a diagram or something therefore no ordered set can be found for {}", realDiagram);
                 }
-
                 return result;
             }