]> gerrit.simantics Code Review - simantics/district.git/commitdiff
ChangeMappingType SCL function to change district UC type for scripting 08/3008/1
authorJaniSimomaa <JaniSimomaa@DESKTOP-91EJL8G>
Mon, 8 Jul 2019 08:04:40 +0000 (11:04 +0300)
committerJaniSimomaa <JaniSimomaa@DESKTOP-91EJL8G>
Mon, 8 Jul 2019 08:04:40 +0000 (11:04 +0300)
gitlab #53

Change-Id: I238de0d0f8f3c898a208d4645c98ad37e03abe42

org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java
org.simantics.district.network/scl/Simantics/District.scl
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java

index a2c02532c4b3f84c23065e27ca7f068a414e6534..3f32f445265a84325082b195f417b40ab2278fc6 100644 (file)
@@ -7,6 +7,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
 
 import javax.inject.Named;
 
@@ -48,6 +49,7 @@ import org.simantics.db.exception.ValidationException;
 import org.simantics.db.layer0.SelectionHints;
 import org.simantics.db.procedure.Procedure;
 import org.simantics.db.request.Read;
+import org.simantics.district.network.DistrictNetworkUtil;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
 import org.simantics.district.network.ui.function.Functions;
 import org.simantics.district.network.ui.internal.Activator;
@@ -149,12 +151,10 @@ public class ChangeMappingTypeHandler {
                                     DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
                                     
                                     for (Map.Entry<Resource, Collection<NamedResource>> entry : results.entrySet()) {
-                                        Resource newMapping = entry.getKey();
-                                        Collection<NamedResource> elements = entry.getValue();
-                                        for (NamedResource element : elements) {
-                                            graph.deny(element.getResource(), DN.HasMapping);
-                                            graph.claim(element.getResource(), DN.HasMapping, newMapping);
-                                        }
+                                        List<Resource> elements = entry.getValue().stream()
+                                            .map(NamedResource::getResource)
+                                            .collect(Collectors.toList());
+                                        DistrictNetworkUtil.changeMappingType(graph, entry.getKey(), elements);
                                     }
                                 }
                             });
index 8e96b518a2dbb98a548de21eb23e984adaf2ebf5..56e8edb45367a08ef6e5e2f481e0d3c8a3c36f4d 100644 (file)
@@ -152,3 +152,4 @@ dnElementsMappedToComponents mappedComponents = mapMaybe possibleDNElementMapped
 
 importJava "org.simantics.district.network.DistrictNetworkUtil" where
     createNetworkDiagram :: Resource -> Resource -> String -> Resource -> Resource -> Resource -> Resource -> Resource -> <WriteGraph, Proc> Resource
+    changeMappingType :: Resource -> [Resource] -> <WriteGraph, Proc> ()
index 519ad512404d8a961a29a998aaece538b9dd8641..cf06ca8c703a87f2e47dcb024271260aae0edb44 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.district.network;
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 
 import org.simantics.databoard.Bindings;
 import org.simantics.datatypes.literal.RGB;
@@ -294,4 +295,12 @@ public class DistrictNetworkUtil {
             this.isConsumer = isConsumer;
         }
     }
+    
+    public static void changeMappingType(WriteGraph graph, Resource newMapping, List<Resource> elements) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        for (Resource element : elements) {
+            graph.deny(element, DN.HasMapping);
+            graph.claim(element, DN.HasMapping, newMapping);
+        }
+    }
 }