]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.route/src/org/simantics/district/route/internal/RoutePersistence.java
Improved Routes view functionality
[simantics/district.git] / org.simantics.district.route / src / org / simantics / district / route / internal / RoutePersistence.java
index c3ba7571e82c3af15c96c4534a45a3d55c3965a4..fceb6612cb521fd2d81e3d5759046c4daee2f120 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.common.utils.ListUtils;
 import org.simantics.db.common.utils.NameUtils;
@@ -78,7 +79,7 @@ public class RoutePersistence {
         Layer0 L0 = Layer0.getInstance(graph);
 
         String existingLabel = graph.getPossibleRelatedValue(route, L0.HasLabel, Bindings.STRING);
-        if (ObjectUtils.objectEquals(existingLabel, label)) {
+        if (!ObjectUtils.objectEquals(existingLabel, label)) {
             graph.claimLiteral(route, L0.HasLabel, label, Bindings.STRING);
         }
 
@@ -124,7 +125,7 @@ public class RoutePersistence {
     }
 
     public static List<RouteImpl> findRoutes(ReadGraph graph, Resource model) throws DatabaseException {
-        Resource rf = getRouteFolder(graph, model);
+        Resource rf = model != null ? getRouteFolder(graph, model) : null;
         if (rf == null)
             return Collections.emptyList();
 
@@ -144,6 +145,16 @@ public class RoutePersistence {
         return routes;
     }
 
+    public static class ModelRoutesRequest extends ResourceRead<List<RouteImpl>> {
+        public ModelRoutesRequest(Resource model) {
+            super(model);
+        }
+        @Override
+        public List<RouteImpl> perform(ReadGraph graph) throws DatabaseException {
+            return findRoutes(graph, resource);
+        }
+    }
+
     public static class ActiveModelRoutesRequest extends UniqueRead<List<RouteImpl>> {
         @Override
         public List<RouteImpl> perform(ReadGraph graph) throws DatabaseException {