From: JaniSimomaa Date: Mon, 8 Jul 2019 08:04:40 +0000 (+0300) Subject: ChangeMappingType SCL function to change district UC type for scripting X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=9150a8d6764f3000f30c014c3eadf7a73508d829;p=simantics%2Fdistrict.git ChangeMappingType SCL function to change district UC type for scripting gitlab #53 Change-Id: I238de0d0f8f3c898a208d4645c98ad37e03abe42 --- diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java index a2c02532..3f32f445 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/ChangeMappingTypeHandler.java @@ -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> entry : results.entrySet()) { - Resource newMapping = entry.getKey(); - Collection elements = entry.getValue(); - for (NamedResource element : elements) { - graph.deny(element.getResource(), DN.HasMapping); - graph.claim(element.getResource(), DN.HasMapping, newMapping); - } + List elements = entry.getValue().stream() + .map(NamedResource::getResource) + .collect(Collectors.toList()); + DistrictNetworkUtil.changeMappingType(graph, entry.getKey(), elements); } } }); diff --git a/org.simantics.district.network/scl/Simantics/District.scl b/org.simantics.district.network/scl/Simantics/District.scl index 8e96b518..56e8edb4 100644 --- a/org.simantics.district.network/scl/Simantics/District.scl +++ b/org.simantics.district.network/scl/Simantics/District.scl @@ -152,3 +152,4 @@ dnElementsMappedToComponents mappedComponents = mapMaybe possibleDNElementMapped importJava "org.simantics.district.network.DistrictNetworkUtil" where createNetworkDiagram :: Resource -> Resource -> String -> Resource -> Resource -> Resource -> Resource -> Resource -> Resource + changeMappingType :: Resource -> [Resource] -> () diff --git a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java index 519ad512..cf06ca8c 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java +++ b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java @@ -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 elements) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + for (Resource element : elements) { + graph.deny(element, DN.HasMapping); + graph.claim(element, DN.HasMapping, newMapping); + } + } }